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;
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,
- LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /*minDistance=*/ 0,
- mFusedLocationListener, mHandler.getLooper());
- sNumFusedLocationUpdatesRequests++;
- mHandler.postDelayed(() -> {
- if (--sNumFusedLocationUpdatesRequests == 0) {
- locationManager.removeUpdates(mFusedLocationListener);
- }
- }, LOCATION_UPDATE_DURATION_MILLIS);
+ 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,
+ 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);
+ }
+ }, LOCATION_UPDATE_DURATION_MILLIS);
}
private void injectBestLocation(Location location) {
}
private abstract class LocationChangeListener implements LocationListener {
+ int numLocationUpdateRequest;
+
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onLocationChanged(Location location) {
if (LocationManager.FUSED_PROVIDER.equals(location.getProvider())) {
- Log.d(TAG, "fused location listener: " + location);
injectBestLocation(location);
}
}