Loading services/core/java/com/android/server/location/GnssLocationProvider.java +23 −21 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 | Loading Loading @@ -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) { } Loading Loading @@ -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); } } Loading Loading
services/core/java/com/android/server/location/GnssLocationProvider.java +23 −21 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 | Loading Loading @@ -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) { } Loading Loading @@ -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); } } Loading