From a2da6ceb47c8025c5d8b2bb48606aa65ac7ed356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 30 Mar 2020 22:43:45 +0200 Subject: [PATCH] Target Android SDK 29. Includes a nasty SDK bug workaround. --- android/AndroidManifest.xml | 3 ++- android/build.gradle | 6 ++--- .../src/org/ppsspp/ppsspp/LocationHelper.java | 27 +++++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index 435ee9c4db..bd0ce81ff0 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -39,7 +39,8 @@ android:label="@string/app_name" android:logo="@drawable/ic_banner" android:isGame="true" - android:banner="@drawable/tv_banner"> + android:banner="@drawable/tv_banner" + android:requestLegacyExternalStorage="true"> = 14000000) { @@ -51,7 +51,7 @@ android { new File("versioncode.txt").write(androidGitVersion.code().toString()) minSdkVersion 9 - targetSdkVersion 28 + targetSdkVersion 29 if (project.hasProperty("ANDROID_VERSION_CODE") && project.hasProperty("ANDROID_VERSION_NAME")) { versionCode ANDROID_VERSION_CODE versionName ANDROID_VERSION_NAME diff --git a/android/src/org/ppsspp/ppsspp/LocationHelper.java b/android/src/org/ppsspp/ppsspp/LocationHelper.java index f5582964df..a487857a91 100644 --- a/android/src/org/ppsspp/ppsspp/LocationHelper.java +++ b/android/src/org/ppsspp/ppsspp/LocationHelper.java @@ -13,6 +13,8 @@ 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 { @@ -25,6 +27,8 @@ 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); @@ -70,7 +74,17 @@ class LocationHelper implements LocationListener { onNmea(nmea); } }; - mLocationManager.addNmeaListener(mNmeaListener); + + // 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()); + } } mLocationEnable = true; } catch (SecurityException e) { @@ -100,7 +114,16 @@ class LocationHelper implements LocationListener { mGpsStatusListener = null; } if (mNmeaListener != null) { - mLocationManager.removeNmeaListener(mNmeaListener); + // 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()); + } mNmeaListener = null; } }