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

Commit aa080f96 authored by Maggie's avatar Maggie
Browse files

Deprecate location modes

1. Mark public fields as deprecated: LOCATION_MODE, LOCATION_MODE_HIGH_ACCURACY, LOCATION_MODE_SENSORS_ONLY,
LOCATION_MODE_BATTERY_SAVING, LOCATION_MODE_OFF.

2. Add new public  methods to LocationManager:
setLocationEnabled(boolean)
isLocationEnabled()
setLocationProviderEnabled(String, boolean)

3. Remove LOCATION_PREVIOUS_MODE and constant
LOCATION_MODE_PREVIOUS. Refactor code that references
LOCATION_MODE_PREVIOUS to use LocationManager.setLocationEnabled or
LOCATION_MODE_HIGH_ACCURACY.

4. Mark deprecated fields and methods as removed: LOCATION_PROVIDERS_ALLOWED, setLocationProviderEnabled(), isLocationProviderEnabled()

5. Refactor logic in Settings app and Quick Settings to call
LocationManager.setLocationEnabled() instead of setting location mode.

Bug: 70990911
Test: Manual
Change-Id: Ia49b385f8b6a358b62291983eb0146af0ecf8e02
parent e65bd19f
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -21506,6 +21506,7 @@ package android.location {
    method public android.location.LocationProvider getProvider(java.lang.String);
    method public java.util.List<java.lang.String> getProviders(boolean);
    method public java.util.List<java.lang.String> getProviders(android.location.Criteria, boolean);
    method public boolean isLocationEnabled();
    method public boolean isProviderEnabled(java.lang.String);
    method public boolean registerGnssMeasurementsCallback(android.location.GnssMeasurementsEvent.Callback);
    method public boolean registerGnssMeasurementsCallback(android.location.GnssMeasurementsEvent.Callback, android.os.Handler);
@@ -35885,11 +35886,11 @@ package android.provider {
    field public static final deprecated java.lang.String HTTP_PROXY = "http_proxy";
    field public static final java.lang.String INPUT_METHOD_SELECTOR_VISIBILITY = "input_method_selector_visibility";
    field public static final deprecated java.lang.String INSTALL_NON_MARKET_APPS = "install_non_market_apps";
    field public static final java.lang.String LOCATION_MODE = "location_mode";
    field public static final int LOCATION_MODE_BATTERY_SAVING = 2; // 0x2
    field public static final int LOCATION_MODE_HIGH_ACCURACY = 3; // 0x3
    field public static final int LOCATION_MODE_OFF = 0; // 0x0
    field public static final int LOCATION_MODE_SENSORS_ONLY = 1; // 0x1
    field public static final deprecated java.lang.String LOCATION_MODE = "location_mode";
    field public static final deprecated int LOCATION_MODE_BATTERY_SAVING = 2; // 0x2
    field public static final deprecated int LOCATION_MODE_HIGH_ACCURACY = 3; // 0x3
    field public static final deprecated int LOCATION_MODE_OFF = 0; // 0x0
    field public static final deprecated int LOCATION_MODE_SENSORS_ONLY = 1; // 0x1
    field public static final deprecated java.lang.String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
    field public static final deprecated java.lang.String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
    field public static final deprecated java.lang.String LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED = "lock_pattern_tactile_feedback_enabled";
+4 −0
Original line number Diff line number Diff line
@@ -2331,11 +2331,15 @@ package android.location {
    method public deprecated boolean addGpsNavigationMessageListener(android.location.GpsNavigationMessageEvent.Listener);
    method public void flushGnssBatch();
    method public int getGnssBatchSize();
    method public boolean isLocationEnabledForUser(android.os.UserHandle);
    method public boolean isProviderEnabledForUser(java.lang.String, android.os.UserHandle);
    method public boolean registerGnssBatchedLocationCallback(long, boolean, android.location.BatchedLocationCallback, android.os.Handler);
    method public deprecated void removeGpsMeasurementListener(android.location.GpsMeasurementsEvent.Listener);
    method public deprecated void removeGpsNavigationMessageListener(android.location.GpsNavigationMessageEvent.Listener);
    method public void requestLocationUpdates(android.location.LocationRequest, android.location.LocationListener, android.os.Looper);
    method public void requestLocationUpdates(android.location.LocationRequest, android.app.PendingIntent);
    method public void setLocationEnabledForUser(boolean, android.os.UserHandle);
    method public boolean setProviderEnabledForUser(java.lang.String, boolean, android.os.UserHandle);
    method public boolean unregisterGnssBatchedLocationCallback(android.location.BatchedLocationCallback);
  }

+46 −57
Original line number Diff line number Diff line
@@ -5509,37 +5509,54 @@ public final class Settings {
         * Note: do not rely on this value being present in settings.db or on ContentObserver
         * notifications for the corresponding Uri. Use {@link LocationManager#MODE_CHANGED_ACTION}
         * to receive changes in this value.
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
        @Deprecated
        public static final String LOCATION_MODE = "location_mode";
        /**
         * Stores the previous location mode when {@link #LOCATION_MODE} is set to
         * {@link #LOCATION_MODE_OFF}
         * @hide
         */
        public static final String LOCATION_PREVIOUS_MODE = "location_previous_mode";

        /**
         * Sets all location providers to the previous states before location was turned off.
         * @hide
         */
        public static final int LOCATION_MODE_PREVIOUS = -1;
        /**
         * Location access disabled.
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
        @Deprecated
        public static final int LOCATION_MODE_OFF = 0;

        /**
         * Network Location Provider disabled, but GPS and other sensors enabled.
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
        @Deprecated
        public static final int LOCATION_MODE_SENSORS_ONLY = 1;

        /**
         * Reduced power usage, such as limiting the number of GPS updates per hour. Requests
         * with {@link android.location.Criteria#POWER_HIGH} may be downgraded to
         * {@link android.location.Criteria#POWER_MEDIUM}.
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
        @Deprecated
        public static final int LOCATION_MODE_BATTERY_SAVING = 2;

        /**
         * Best-effort location computation allowed.
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
        @Deprecated
        public static final int LOCATION_MODE_HIGH_ACCURACY = 3;

        /**
@@ -7866,7 +7883,6 @@ public final class Settings {
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_ACCESSIBILITY_SERVICES);
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_INPUT_METHODS);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_PREVIOUS_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_PROVIDERS_ALLOWED);
            CLONE_TO_MANAGED_PROFILE.add(SELECTED_INPUT_METHOD_SUBTYPE);
        }
@@ -7917,8 +7933,7 @@ public final class Settings {
         * @param provider the location provider to query
         * @return true if the provider is enabled
         *
         * @deprecated use {@link #LOCATION_MODE} or
         *             {@link LocationManager#isProviderEnabled(String)}
         * @deprecated use {@link LocationManager#isProviderEnabled(String)}
         */
        @Deprecated
        public static final boolean isLocationProviderEnabled(ContentResolver cr, String provider) {
@@ -7931,12 +7946,13 @@ public final class Settings {
         * @param provider the location provider to query
         * @param userId the userId to query
         * @return true if the provider is enabled
         * @deprecated use {@link #LOCATION_MODE} or
         *             {@link LocationManager#isProviderEnabled(String)}
         *
         * @deprecated use {@link LocationManager#isProviderEnabled(String)}
         * @hide
         */
        @Deprecated
        public static final boolean isLocationProviderEnabledForUser(ContentResolver cr, String provider, int userId) {
        public static final boolean isLocationProviderEnabledForUser(
                ContentResolver cr, String provider, int userId) {
            String allowedProviders = Settings.Secure.getStringForUser(cr,
                    LOCATION_PROVIDERS_ALLOWED, userId);
            return TextUtils.delimitedStringContains(allowedProviders, ',', provider);
@@ -7947,7 +7963,8 @@ public final class Settings {
         * @param cr the content resolver to use
         * @param provider the location provider to enable or disable
         * @param enabled true if the provider should be enabled
         * @deprecated use {@link #putInt(ContentResolver, String, int)} and {@link #LOCATION_MODE}
         * @deprecated This API is deprecated. It requires WRITE_SECURE_SETTINGS permission to
         *             change location settings.
         */
        @Deprecated
        public static final void setLocationProviderEnabled(ContentResolver cr,
@@ -7963,8 +7980,8 @@ public final class Settings {
         * @param enabled true if the provider should be enabled
         * @param userId the userId for which to enable/disable providers
         * @return true if the value was set, false on database errors
         * @deprecated use {@link #putIntForUser(ContentResolver, String, int, int)} and
         *             {@link #LOCATION_MODE}
         *
         * @deprecated use {@link LocationManager#setProviderEnabledForUser(String, boolean, int)}
         * @hide
         */
        @Deprecated
@@ -7984,28 +8001,6 @@ public final class Settings {
            }
        }

        /**
         * Saves the current location mode into {@link #LOCATION_PREVIOUS_MODE}.
         */
        private static final boolean saveLocationModeForUser(ContentResolver cr, int userId) {
            final int mode = getLocationModeForUser(cr, userId);
            return putIntForUser(cr, Settings.Secure.LOCATION_PREVIOUS_MODE, mode, userId);
        }

        /**
         * Restores the current location mode from {@link #LOCATION_PREVIOUS_MODE}.
         */
        private static final boolean restoreLocationModeForUser(ContentResolver cr, int userId) {
            int mode = getIntForUser(cr, Settings.Secure.LOCATION_PREVIOUS_MODE,
                    LOCATION_MODE_HIGH_ACCURACY, userId);
            // Make sure that the previous mode is never "off". Otherwise the user won't be able to
            // turn on location any longer.
            if (mode == LOCATION_MODE_OFF) {
                mode = LOCATION_MODE_HIGH_ACCURACY;
            }
            return setLocationModeForUser(cr, mode, userId);
        }

        /**
         * Thread-safe method for setting the location mode to one of
         * {@link #LOCATION_MODE_HIGH_ACCURACY}, {@link #LOCATION_MODE_SENSORS_ONLY},
@@ -8019,18 +8014,20 @@ public final class Settings {
         * @return true if the value was set, false on database errors
         *
         * @throws IllegalArgumentException if mode is not one of the supported values
         *
         * @deprecated To enable/disable location, use
         *             {@link LocationManager#setLocationEnabledForUser(boolean, int)}.
         *             To enable/disable a specific location provider, use
         *             {@link LocationManager#setProviderEnabledForUser(String, boolean, int)}.
         */
        private static final boolean setLocationModeForUser(ContentResolver cr, int mode,
                int userId) {
        @Deprecated
        private static boolean setLocationModeForUser(
                ContentResolver cr, int mode, int userId) {
            synchronized (mLocationSettingsLock) {
                boolean gps = false;
                boolean network = false;
                switch (mode) {
                    case LOCATION_MODE_PREVIOUS:
                        // Retrieve the actual mode and set to that mode.
                        return restoreLocationModeForUser(cr, userId);
                    case LOCATION_MODE_OFF:
                        saveLocationModeForUser(cr, userId);
                        break;
                    case LOCATION_MODE_SENSORS_ONLY:
                        gps = true;
@@ -8045,15 +8042,7 @@ public final class Settings {
                    default:
                        throw new IllegalArgumentException("Invalid location mode: " + mode);
                }
                // Note it's important that we set the NLP mode first. The Google implementation
                // of NLP clears its NLP consent setting any time it receives a
                // LocationManager.PROVIDERS_CHANGED_ACTION broadcast and NLP is disabled. Also,
                // it shows an NLP consent dialog any time it receives the broadcast, NLP is
                // enabled, and the NLP consent is not set. If 1) we were to enable GPS first,
                // 2) a setup wizard has its own NLP consent UI that sets the NLP consent setting,
                // and 3) the receiver happened to complete before we enabled NLP, then the Google
                // NLP would detect the attempt to enable NLP and show a redundant NLP consent
                // dialog. Then the people who wrote the setup wizard would be sad.

                boolean nlpSuccess = Settings.Secure.setLocationProviderEnabledForUser(
                        cr, LocationManager.NETWORK_PROVIDER, network, userId);
                boolean gpsSuccess = Settings.Secure.setLocationProviderEnabledForUser(
+0 −1
Original line number Diff line number Diff line
@@ -479,7 +479,6 @@ public class SettingsBackupTest {
                 Settings.Secure.INSTALL_NON_MARKET_APPS,
                 Settings.Secure.LAST_SETUP_SHOWN,
                 Settings.Secure.LOCATION_MODE,
                 Settings.Secure.LOCATION_PREVIOUS_MODE,
                 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, // Candidate?
                 Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, // Candidate?
                 Settings.Secure.LOCK_SCREEN_LOCK_AFTER_TIMEOUT,
+4 −0
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ interface ILocationManager
    ProviderProperties getProviderProperties(String provider);
    String getNetworkProviderPackage();
    boolean isProviderEnabled(String provider);
    boolean isProviderEnabledForUser(String provider, int userId);
    boolean setProviderEnabledForUser(String provider, boolean enabled, int userId);
    boolean isLocationEnabledForUser(int userId);
    void setLocationEnabledForUser(boolean enabled, int userId);

    void addTestProvider(String name, in ProviderProperties properties, String opPackageName);
    void removeTestProvider(String provider, String opPackageName);
Loading