diff --git a/location/java/android/location/CountryDetector.java b/location/java/android/location/CountryDetector.java index 0b780cea8407c..ce3c56f73c012 100644 --- a/location/java/android/location/CountryDetector.java +++ b/location/java/android/location/CountryDetector.java @@ -44,8 +44,6 @@ import android.util.Log; * You do not instantiate this class directly; instead, retrieve it through * {@link android.content.Context#getSystemService * Context.getSystemService(Context.COUNTRY_DETECTOR)}. - *

- * Both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions are needed. * * @hide */ diff --git a/services/core/java/com/android/server/location/LocationBasedCountryDetector.java b/services/core/java/com/android/server/location/LocationBasedCountryDetector.java index 03db621c03a88..6527899f29790 100644 --- a/services/core/java/com/android/server/location/LocationBasedCountryDetector.java +++ b/services/core/java/com/android/server/location/LocationBasedCountryDetector.java @@ -23,6 +23,7 @@ import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; +import android.os.Binder; import android.os.Bundle; import android.util.Slog; @@ -95,33 +96,48 @@ public class LocationBasedCountryDetector extends CountryDetectorBase { * Register a listener with a provider name */ protected void registerListener(String provider, LocationListener listener) { - mLocationManager.requestLocationUpdates(provider, 0, 0, listener); + final long bid = Binder.clearCallingIdentity(); + try { + mLocationManager.requestLocationUpdates(provider, 0, 0, listener); + } finally { + Binder.restoreCallingIdentity(bid); + } } /** * Unregister an already registered listener */ protected void unregisterListener(LocationListener listener) { - mLocationManager.removeUpdates(listener); + final long bid = Binder.clearCallingIdentity(); + try { + mLocationManager.removeUpdates(listener); + } finally { + Binder.restoreCallingIdentity(bid); + } } /** * @return the last known location from all providers */ protected Location getLastKnownLocation() { - List providers = mLocationManager.getAllProviders(); - Location bestLocation = null; - for (String provider : providers) { - Location lastKnownLocation = mLocationManager.getLastKnownLocation(provider); - if (lastKnownLocation != null) { - if (bestLocation == null || - bestLocation.getElapsedRealtimeNanos() < - lastKnownLocation.getElapsedRealtimeNanos()) { - bestLocation = lastKnownLocation; + final long bid = Binder.clearCallingIdentity(); + try { + List providers = mLocationManager.getAllProviders(); + Location bestLocation = null; + for (String provider : providers) { + Location lastKnownLocation = mLocationManager.getLastKnownLocation(provider); + if (lastKnownLocation != null) { + if (bestLocation == null || + bestLocation.getElapsedRealtimeNanos() < + lastKnownLocation.getElapsedRealtimeNanos()) { + bestLocation = lastKnownLocation; + } } } + return bestLocation; + } finally { + Binder.restoreCallingIdentity(bid); } - return bestLocation; } /**