Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e684ddac authored by Yu-Han Yang's avatar Yu-Han Yang
Browse files

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.
parent 621fd20f
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -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));
        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));
                    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) {