From 394b86831bee279822a74d012830f9b2a50168d6 Mon Sep 17 00:00:00 2001 From: Soonil Nagarkar Date: Mon, 11 Nov 2019 13:35:53 -0800 Subject: Reduce GpsStatus API crashes to SDK S+ Bug: 144125622 Test: n/a Change-Id: Ic1f6e1ed8daf867fbfdc1ce94d42420577e29bac --- location/java/android/location/LocationManager.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'location/java/android') diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index c48f6e83ff20..2eef2747d682 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1810,6 +1810,14 @@ public class LocationManager { @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 @@ public class LocationManager { @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 @@ public class LocationManager { @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); -- cgit v1.2.3-59-g8ed1b