diff options
author | Wei Liu <luciferleo@google.com> | 2015-05-11 14:00:36 -0700 |
---|---|---|
committer | Wei Liu <luciferleo@google.com> | 2015-05-11 17:39:49 -0700 |
commit | 5241a4cb55b4015549242ac7d8aa5c99e5f157e5 (patch) | |
tree | c94c3adda00539b6d85c13c235a801e2ead090f6 | |
parent | 4f35e1699a4b62bd71bed27fece85e2c026210d1 (diff) | |
download | frameworks_base-5241a4cb55b4015549242ac7d8aa5c99e5f157e5.zip frameworks_base-5241a4cb55b4015549242ac7d8aa5c99e5f157e5.tar.gz frameworks_base-5241a4cb55b4015549242ac7d8aa5c99e5f157e5.tar.bz2 |
Create GpsLocationProvider only if GPS is supported.
The creation of GpsLocationProvider used to be inside the
GpsLocationProvider.isSupported() check.
https://googleplex-android-review.git.corp.google.com/#/c/288260/8/services/java/com/android/server/LocationManagerService.java
incorrectly moved it out.
b/20949616
Change-Id: I6ddd5be5a78f3156a4d5cfc4c756930558c3a8fc
3 files changed, 21 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index be83b9b..21c9224 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -62,6 +62,7 @@ import android.location.GeocoderParams; import android.location.Geofence; import android.location.GpsMeasurementsEvent; import android.location.GpsNavigationMessageEvent; +import android.location.IGpsGeofenceHardware; import android.location.IGpsMeasurementsListener; import android.location.IGpsNavigationMessageListener; import android.location.IGpsStatusListener; @@ -164,6 +165,7 @@ public class LocationManagerService extends ILocationManager.Stub { private LocationBlacklist mBlacklist; private GpsMeasurementsProvider mGpsMeasurementsProvider; private GpsNavigationMessageProvider mGpsNavigationMessageProvider; + private IGpsGeofenceHardware mGpsGeofenceProxy; // --- fields below are protected by mLock --- // Set of providers that are explicitly enabled @@ -403,18 +405,19 @@ public class LocationManagerService extends ILocationManager.Stub { addProviderLocked(passiveProvider); mEnabledProviders.add(passiveProvider.getName()); mPassiveProvider = passiveProvider; - // Create a gps location provider - GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this, - mLocationHandler.getLooper()); if (GpsLocationProvider.isSupported()) { + // Create a gps location provider + GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this, + mLocationHandler.getLooper()); mGpsStatusProvider = gpsProvider.getGpsStatusProvider(); mNetInitiatedListener = gpsProvider.getNetInitiatedListener(); addProviderLocked(gpsProvider); mRealProviders.put(LocationManager.GPS_PROVIDER, gpsProvider); + mGpsMeasurementsProvider = gpsProvider.getGpsMeasurementsProvider(); + mGpsNavigationMessageProvider = gpsProvider.getGpsNavigationMessageProvider(); + mGpsGeofenceProxy = gpsProvider.getGpsGeofenceProxy(); } - mGpsMeasurementsProvider = gpsProvider.getGpsMeasurementsProvider(); - mGpsNavigationMessageProvider = gpsProvider.getGpsNavigationMessageProvider(); /* Load package name(s) containing location provider support. @@ -510,7 +513,7 @@ public class LocationManagerService extends ILocationManager.Stub { com.android.internal.R.string.config_geofenceProviderPackageName, com.android.internal.R.array.config_locationProviderPackageNames, mLocationHandler, - gpsProvider.getGpsGeofenceProxy(), + mGpsGeofenceProxy, flpHardwareProvider != null ? flpHardwareProvider.getGeofenceHardware() : null); if (provider == null) { Slog.e(TAG, "Unable to bind FLP Geofence proxy."); @@ -1854,7 +1857,7 @@ public class LocationManagerService extends ILocationManager.Stub { Binder.restoreCallingIdentity(identity); } - if (!hasLocationAccess) { + if (!hasLocationAccess || mGpsMeasurementsProvider == null) { return false; } return mGpsMeasurementsProvider.addListener(listener); @@ -1862,7 +1865,9 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void removeGpsMeasurementsListener(IGpsMeasurementsListener listener) { - mGpsMeasurementsProvider.removeListener(listener); + if (mGpsMeasurementsProvider != null) { + mGpsMeasurementsProvider.removeListener(listener); + } } @Override @@ -1883,7 +1888,7 @@ public class LocationManagerService extends ILocationManager.Stub { Binder.restoreCallingIdentity(identity); } - if (!hasLocationAccess) { + if (!hasLocationAccess || mGpsNavigationMessageProvider == null) { return false; } return mGpsNavigationMessageProvider.addListener(listener); @@ -1891,7 +1896,9 @@ public class LocationManagerService extends ILocationManager.Stub { @Override public void removeGpsNavigationMessageListener(IGpsNavigationMessageListener listener) { - mGpsNavigationMessageProvider.removeListener(listener); + if (mGpsNavigationMessageProvider != null) { + mGpsNavigationMessageProvider.removeListener(listener); + } } @Override diff --git a/services/core/java/com/android/server/location/GeofenceProxy.java b/services/core/java/com/android/server/location/GeofenceProxy.java index b886eef..d1bb8db 100644 --- a/services/core/java/com/android/server/location/GeofenceProxy.java +++ b/services/core/java/com/android/server/location/GeofenceProxy.java @@ -129,7 +129,9 @@ public final class GeofenceProxy { private void setGpsGeofenceLocked() { try { - mGeofenceHardware.setGpsGeofenceHardware(mGpsGeofenceHardware); + if (mGpsGeofenceHardware != null) { + mGeofenceHardware.setGpsGeofenceHardware(mGpsGeofenceHardware); + } } catch (RemoteException e) { Log.e(TAG, "Error while connecting to GeofenceHardwareService"); } diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java index 5ae6300..621e1bd 100644 --- a/services/core/java/com/android/server/location/GpsLocationProvider.java +++ b/services/core/java/com/android/server/location/GpsLocationProvider.java @@ -444,13 +444,12 @@ public class GpsLocationProvider implements LocationProviderInterface { int networkState; if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false) || - !info.isConnected()) { + !info.isConnected()) { networkState = LocationProvider.TEMPORARILY_UNAVAILABLE; } else { networkState = LocationProvider.AVAILABLE; } - updateNetworkState(networkState, info); } else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action) || Intent.ACTION_SCREEN_OFF.equals(action) |