From e684ddac67038526e73f46ed261c34af46ef015c Mon Sep 17 00:00:00 2001 From: Yu-Han Yang Date: Thu, 24 May 2018 10:29:39 -0700 Subject: [PATCH] Catch IllegalArgumentException when calling LocationManager#requestLocationUpdate - Cannot depend on LocationManager#isProviderEnabled, since it always returns false for FLP. Bug: 80199046 Change-Id: I9c85b8a9468bceca0620c5aff16655ed633ee36b Fixes: 80199046 Test: Manually added a CTS test to trigger the flow in AOSP build on device, and successfully caught the exception when requesting location updates from NLP. --- .../server/location/GnssLocationProvider.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 4e6307dbca8ad..0f8c5269a95cc 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -1015,26 +1015,25 @@ public class GnssLocationProvider implements LocationProviderInterface, InjectNt locationListener = mFusedLocationListener; } - if (!locationManager.isProviderEnabled(provider)) { - Log.w(TAG, "Unable to request location since " + provider - + " provider does not exist or is not enabled."); - return; - } - Log.i(TAG, String.format( "GNSS HAL Requesting location updates from %s provider for %d millis.", provider, durationMillis)); - locationManager.requestLocationUpdates(provider, - LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0, - locationListener, mHandler.getLooper()); - locationListener.numLocationUpdateRequest++; - mHandler.postDelayed(() -> { - if (--locationListener.numLocationUpdateRequest == 0) { - Log.i(TAG, String.format("Removing location updates from %s provider.", provider)); - locationManager.removeUpdates(locationListener); - } - }, durationMillis); + try { + locationManager.requestLocationUpdates(provider, + LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0, + locationListener, mHandler.getLooper()); + locationListener.numLocationUpdateRequest++; + mHandler.postDelayed(() -> { + if (--locationListener.numLocationUpdateRequest == 0) { + Log.i(TAG, + String.format("Removing location updates from %s provider.", provider)); + locationManager.removeUpdates(locationListener); + } + }, durationMillis); + } catch (IllegalArgumentException e) { + Log.w(TAG, "Unable to request location.", e); + } } private void injectBestLocation(Location location) {