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

Commit 3bc533d2 authored by Yu-Han Yang's avatar Yu-Han Yang Committed by Android (Google) Code Review
Browse files

Merge "Catch IllegalArgumentException when calling...

Merge "Catch IllegalArgumentException when calling LocationManager#requestLocationUpdate" into pi-dev
parents d8f3889b e684ddac
Loading
Loading
Loading
Loading
+15 −16
Original line number Original line Diff line number Diff line
@@ -1015,26 +1015,25 @@ public class GnssLocationProvider implements LocationProviderInterface, InjectNt
            locationListener = mFusedLocationListener;
            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,
        Log.i(TAG,
                String.format(
                String.format(
                        "GNSS HAL Requesting location updates from %s provider for %d millis.",
                        "GNSS HAL Requesting location updates from %s provider for %d millis.",
                        provider, durationMillis));
                        provider, durationMillis));
        try {
            locationManager.requestLocationUpdates(provider,
            locationManager.requestLocationUpdates(provider,
                    LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0,
                    LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0,
                    locationListener, mHandler.getLooper());
                    locationListener, mHandler.getLooper());
            locationListener.numLocationUpdateRequest++;
            locationListener.numLocationUpdateRequest++;
            mHandler.postDelayed(() -> {
            mHandler.postDelayed(() -> {
                if (--locationListener.numLocationUpdateRequest == 0) {
                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);
                    locationManager.removeUpdates(locationListener);
                }
                }
            }, durationMillis);
            }, durationMillis);
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "Unable to request location.", e);
        }
    }
    }


    private void injectBestLocation(Location location) {
    private void injectBestLocation(Location location) {