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

Commit 6e5b7c46 authored by Yu-Han Yang's avatar Yu-Han Yang Committed by android-build-merger
Browse files

Merge "Make NLP/FLP location request behavior consistent" into pi-dev

am: d6133639

Change-Id: I8b70a343320a3e3d2445744b7135e0a087d37312
parents 54245482 d6133639
Loading
Loading
Loading
Loading
+23 −21
Original line number Diff line number Diff line
@@ -423,8 +423,8 @@ public class GnssLocationProvider implements LocationProviderInterface {
    private final GnssStatusListenerHelper mListenerHelper;
    private final GnssMeasurementsProvider mGnssMeasurementsProvider;
    private final GnssNavigationMessageProvider mGnssNavigationMessageProvider;
    private final FusedLocationListener mFusedLocationListener = new FusedLocationListener();
    private static int sNumFusedLocationUpdatesRequests = 0;
    private final LocationChangeListener mNetworkLocationListener = new NetworkLocationListener();
    private final LocationChangeListener mFusedLocationListener = new FusedLocationListener();

    // Handler for processing events
    private Handler mHandler;
@@ -1097,31 +1097,32 @@ public class GnssLocationProvider implements LocationProviderInterface {

        LocationManager locationManager = (LocationManager) mContext.getSystemService(
                Context.LOCATION_SERVICE);
        String provider;
        LocationChangeListener locationListener;

        if (independentFromGnss) {
            // For fast GNSS TTFF
            Location networkLocation = getLastFreshLocation(locationManager,
                    LocationManager.NETWORK_PROVIDER);
            if (networkLocation != null) {
                handleUpdateLocation(networkLocation);
                return;
            }
            locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER,
                    new NetworkLocationListener(),
                    mHandler.getLooper());
            provider = LocationManager.NETWORK_PROVIDER;
            locationListener = mNetworkLocationListener;
        } else {
            // For Device-Based Hybrid (E911)
            locationManager.requestLocationUpdates(LocationManager.FUSED_PROVIDER,
            provider = LocationManager.FUSED_PROVIDER;
            locationListener = mFusedLocationListener;
        }

        Log.i(TAG,
                String.format("GNSS HAL Requesting location updates from %s provider.", provider));
        locationManager.requestLocationUpdates(provider,
                LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0,
                    mFusedLocationListener, mHandler.getLooper());
            sNumFusedLocationUpdatesRequests++;
                locationListener, mHandler.getLooper());
        locationListener.numLocationUpdateRequest++;
        mHandler.postDelayed(() -> {
                if (--sNumFusedLocationUpdatesRequests == 0) {
                    locationManager.removeUpdates(mFusedLocationListener);
            if (--locationListener.numLocationUpdateRequest == 0) {
                Log.i(TAG, String.format("Removing location updates from %s provider.", provider));
                locationManager.removeUpdates(locationListener);
            }
        }, LOCATION_UPDATE_DURATION_MILLIS);
    }
    }

    private void injectBestLocation(Location location) {
        int gnssLocationFlags = LOCATION_HAS_LAT_LONG |
@@ -2603,6 +2604,8 @@ public class GnssLocationProvider implements LocationProviderInterface {
    }

    private abstract class LocationChangeListener implements LocationListener {
        int numLocationUpdateRequest;

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
@@ -2630,7 +2633,6 @@ public class GnssLocationProvider implements LocationProviderInterface {
        @Override
        public void onLocationChanged(Location location) {
            if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) {
                Log.d(TAG, "fused location listener: " + location);
                injectBestLocation(location);
            }
        }