Merge "Reduce GpsStatus API crashes to SDK S+"
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index c48f6e8..2eef274 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -1810,6 +1810,14 @@
@Deprecated
@RequiresPermission(ACCESS_FINE_LOCATION)
public @Nullable GpsStatus getGpsStatus(@Nullable GpsStatus status) {
+ UnsupportedOperationException ex = new UnsupportedOperationException(
+ "GpsStatus APIs not supported in S and above, use GnssStatus APIs instead");
+ if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.R) {
+ throw ex;
+ } else {
+ Log.w(TAG, ex);
+ }
+
if (status == null) {
status = new GpsStatus();
}
@@ -1837,8 +1845,8 @@
@RequiresPermission(ACCESS_FINE_LOCATION)
public boolean addGpsStatusListener(GpsStatus.Listener listener) {
UnsupportedOperationException ex = new UnsupportedOperationException(
- "GpsStatus APIs not supported in R and above, use GnssStatus APIs instead");
- if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R) {
+ "GpsStatus APIs not supported in S and above, use GnssStatus APIs instead");
+ if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.R) {
throw ex;
} else {
Log.w(TAG, ex);
@@ -1862,8 +1870,8 @@
@Deprecated
public void removeGpsStatusListener(GpsStatus.Listener listener) {
UnsupportedOperationException ex = new UnsupportedOperationException(
- "GpsStatus APIs not supported in R and above, use GnssStatus APIs instead");
- if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R) {
+ "GpsStatus APIs not supported in S and above, use GnssStatus APIs instead");
+ if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.R) {
throw ex;
} else {
Log.w(TAG, ex);