From bda9c99e79493d6d64ec6b3d7f8427e114fd5481 Mon Sep 17 00:00:00 2001 From: Florin9doi Date: Sun, 7 Jan 2024 02:17:01 +0200 Subject: [PATCH] GPS: Remove NmeaListener workaround for Android 29 SDK --- .../src/org/ppsspp/ppsspp/LocationHelper.java | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/android/src/org/ppsspp/ppsspp/LocationHelper.java b/android/src/org/ppsspp/ppsspp/LocationHelper.java index a487857a91..f5582964df 100644 --- a/android/src/org/ppsspp/ppsspp/LocationHelper.java +++ b/android/src/org/ppsspp/ppsspp/LocationHelper.java @@ -13,8 +13,6 @@ import android.os.Build; import android.os.Bundle; import android.util.Log; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Iterator; class LocationHelper implements LocationListener { @@ -27,8 +25,6 @@ class LocationHelper implements LocationListener { private GpsStatus.NmeaListener mNmeaListener; private float mAltitudeAboveSeaLevel = 0f; private float mHdop = 0f; - private Method addNmeaListenerMethod = null; - private Method removeNmeaListenerMethod = null; LocationHelper(Context context) { mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); @@ -74,17 +70,7 @@ class LocationHelper implements LocationListener { onNmea(nmea); } }; - - // Use reflection to work around a bug in the Android 29 SDK. - // https://stackoverflow.com/questions/57975969/accessing-nmea-on-android-api-level-24-when-compiled-for-target-api-level-29 - try { - if (addNmeaListenerMethod == null) { - addNmeaListenerMethod = LocationManager.class.getMethod("addNmeaListener", GpsStatus.NmeaListener.class); - } - addNmeaListenerMethod.invoke(mLocationManager, mNmeaListener); - } catch (Exception e) { - Log.w(TAG, "Couldn't get the nmea add method: " + e.toString()); - } + mLocationManager.addNmeaListener(mNmeaListener); } mLocationEnable = true; } catch (SecurityException e) { @@ -114,16 +100,7 @@ class LocationHelper implements LocationListener { mGpsStatusListener = null; } if (mNmeaListener != null) { - // Use reflection to work around a bug in the Android 29 SDK. - // https://stackoverflow.com/questions/57975969/accessing-nmea-on-android-api-level-24-when-compiled-for-target-api-level-29 - try { - if (removeNmeaListenerMethod == null) { - removeNmeaListenerMethod = LocationManager.class.getMethod("removeNmeaListener", GpsStatus.NmeaListener.class); - } - removeNmeaListenerMethod.invoke(mLocationManager, mNmeaListener); - } catch (Exception e) { - Log.w(TAG, "Couldn't get the nmea remove method: " + e.toString()); - } + mLocationManager.removeNmeaListener(mNmeaListener); mNmeaListener = null; } }