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

Commit 8c48834b authored by Makoto Onuki's avatar Makoto Onuki Committed by Android Git Automerger
Browse files

am 0d889cde: Merge "CountryDetector no longer requires location permissions." into mnc-dev

* commit '0d889cde':
  CountryDetector no longer requires location permissions.
parents 92086e06 0d889cde
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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)}.
 * <p>
 * Both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions are needed.
 *
 * @hide
 */
+28 −12
Original line number Diff line number Diff line
@@ -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,20 +96,32 @@ public class LocationBasedCountryDetector extends CountryDetectorBase {
     * Register a listener with a provider name
     */
    protected void registerListener(String provider, LocationListener 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) {
        final long bid = Binder.clearCallingIdentity();
        try {
            mLocationManager.removeUpdates(listener);
        } finally {
            Binder.restoreCallingIdentity(bid);
        }
    }

    /**
     * @return the last known location from all providers
     */
    protected Location getLastKnownLocation() {
        final long bid = Binder.clearCallingIdentity();
        try {
            List<String> providers = mLocationManager.getAllProviders();
            Location bestLocation = null;
            for (String provider : providers) {
@@ -122,6 +135,9 @@ public class LocationBasedCountryDetector extends CountryDetectorBase {
                }
            }
            return bestLocation;
        } finally {
            Binder.restoreCallingIdentity(bid);
        }
    }

    /**