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

Commit 5e185019 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Location settings documentation and migration

-Add new LOCATION_MODE_ON for internal use only
-Update location docs for Q
-Fix egregious copy/pasta bug

Bug: 118883513
Test: NA
Change-Id: I5c04786f912f1b8db33930449ae2ba5854a55981
parent ee269f6e
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -38854,6 +38854,7 @@ package android.provider {
    field @Deprecated public static final int LOCATION_MODE_BATTERY_SAVING = 2; // 0x2
    field @Deprecated public static final int LOCATION_MODE_BATTERY_SAVING = 2; // 0x2
    field @Deprecated public static final int LOCATION_MODE_HIGH_ACCURACY = 3; // 0x3
    field @Deprecated public static final int LOCATION_MODE_HIGH_ACCURACY = 3; // 0x3
    field @Deprecated public static final int LOCATION_MODE_OFF = 0; // 0x0
    field @Deprecated public static final int LOCATION_MODE_OFF = 0; // 0x0
    field @Deprecated public static final int LOCATION_MODE_ON = 3; // 0x3
    field @Deprecated public static final int LOCATION_MODE_SENSORS_ONLY = 1; // 0x1
    field @Deprecated public static final int LOCATION_MODE_SENSORS_ONLY = 1; // 0x1
    field @Deprecated public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
    field @Deprecated public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
    field @Deprecated public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
    field @Deprecated public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock";
+28 −27
Original line number Original line Diff line number Diff line
@@ -5874,30 +5874,24 @@ public final class Settings {
                "unknown_sources_default_reversed";
                "unknown_sources_default_reversed";
        /**
        /**
         * Comma-separated list of location providers that activities may access. Do not rely on
         * Comma-separated list of location providers that are accessible. Do not rely on
         * this value being present in settings.db or on ContentObserver notifications on the
         * this value being present or correct, or on ContentObserver notifications on the
         * corresponding Uri.
         * corresponding Uri.
         *
         *
         * @deprecated Providers should not be controlled individually. See {@link #LOCATION_MODE}
         * @deprecated The preferred methods for checking provider status and listening for changes
          * documentation for information on reading/writing location information.
         * are via {@link LocationManager#isProviderEnabled(String)} and
         * {@link LocationManager#PROVIDERS_CHANGED_ACTION}.
         */
         */
        @Deprecated
        @Deprecated
        public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
        public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
        /**
        /**
         * The degree of location access enabled by the user.
         * The current location mode of the device. Do not rely on this value being present or on
         * <p>
         * ContentObserver notifications on the corresponding Uri.
         * When used with {@link #putInt(ContentResolver, String, int)}, must be one of {@link
         * #LOCATION_MODE_HIGH_ACCURACY}, {@link #LOCATION_MODE_SENSORS_ONLY}, {@link
         * #LOCATION_MODE_BATTERY_SAVING}, or {@link #LOCATION_MODE_OFF}. When used with {@link
         * #getInt(ContentResolver, String)}, the caller must gracefully handle additional location
         * modes that might be added in the future.
         * <p>
         * 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 mode, use {@link LocationManager#isLocationEnabled()}.
         * @deprecated The preferred methods for checking location mode and listening for changes
         * are via {@link LocationManager#isLocationEnabled()} and
         * {@link LocationManager#MODE_CHANGED_ACTION}.
         */
         */
        @Deprecated
        @Deprecated
        public static final String LOCATION_MODE = "location_mode";
        public static final String LOCATION_MODE = "location_mode";
@@ -5924,7 +5918,7 @@ public final class Settings {
        public static final int LOCATION_CHANGER_QUICK_SETTINGS = 2;
        public static final int LOCATION_CHANGER_QUICK_SETTINGS = 2;
        /**
        /**
         * Location access disabled.
         * Location mode is off.
         *
         *
         * @deprecated See {@link #LOCATION_MODE}.
         * @deprecated See {@link #LOCATION_MODE}.
         */
         */
@@ -5932,33 +5926,40 @@ public final class Settings {
        public static final int LOCATION_MODE_OFF = 0;
        public static final int LOCATION_MODE_OFF = 0;
        /**
        /**
         * Network Location Provider disabled, but GPS and other sensors enabled.
         * This mode no longer has any distinct meaning, but is interpreted as the location mode is
         * on.
         *
         *
         * @deprecated To check location status, use {@link LocationManager#isLocationEnabled()}. To
         * @deprecated See {@link #LOCATION_MODE_ON}.
         *             get the status of a location provider, use
         *             {@link LocationManager#isProviderEnabled(String)}.
         */
         */
        @Deprecated
        @Deprecated
        public static final int LOCATION_MODE_SENSORS_ONLY = 1;
        public static final int LOCATION_MODE_SENSORS_ONLY = 1;
        /**
        /**
         * Reduced power usage, such as limiting the number of GPS updates per hour. Requests
         * This mode no longer has any distinct meaning, but is interpreted as the location mode is
         * with {@link android.location.Criteria#POWER_HIGH} may be downgraded to
         * on.
         * {@link android.location.Criteria#POWER_MEDIUM}.
         *
         *
         * @deprecated See {@link #LOCATION_MODE}.
         * @deprecated See {@link #LOCATION_MODE_ON}.
         */
         */
        @Deprecated
        @Deprecated
        public static final int LOCATION_MODE_BATTERY_SAVING = 2;
        public static final int LOCATION_MODE_BATTERY_SAVING = 2;
        /**
        /**
         * Best-effort location computation allowed.
         * This mode no longer has any distinct meaning, but is interpreted as the location mode is
         * on.
         *
         *
         * @deprecated See {@link #LOCATION_MODE}.
         * @deprecated See {@link #LOCATION_MODE_ON}.
         */
         */
        @Deprecated
        @Deprecated
        public static final int LOCATION_MODE_HIGH_ACCURACY = 3;
        public static final int LOCATION_MODE_HIGH_ACCURACY = 3;
        /**
         * Location mode is on.
         *
         * @deprecated See {@link #LOCATION_MODE}.
         */
        @Deprecated
        public static final int LOCATION_MODE_ON = LOCATION_MODE_HIGH_ACCURACY;
        /**
        /**
         * A flag containing settings used for biometric weak
         * A flag containing settings used for biometric weak
         * @hide
         * @hide
+46 −62
Original line number Original line Diff line number Diff line
@@ -181,22 +181,14 @@ public class LocationManager {
        "android.location.GPS_ENABLED_CHANGE";
        "android.location.GPS_ENABLED_CHANGE";


    /**
    /**
     * Broadcast intent action when the configured location providers
     * Broadcast intent action when the set of enabled location providers changes. To check the
     * change. For use with {@link #isProviderEnabled(String)}. If you're interacting with the
     * status of a provider, use {@link #isProviderEnabled(String)}.
     * {@link android.provider.Settings.Secure#LOCATION_MODE} API, use {@link #MODE_CHANGED_ACTION}
     * instead.
     */
     */
    public static final String PROVIDERS_CHANGED_ACTION =
    public static final String PROVIDERS_CHANGED_ACTION = "android.location.PROVIDERS_CHANGED";
        "android.location.PROVIDERS_CHANGED";


    /**
    /**
     * Broadcast intent action when {@link android.provider.Settings.Secure#LOCATION_MODE} changes.
     * Broadcast intent action when the device location mode changes. To check the location mode,
     * For use with the {@link android.provider.Settings.Secure#LOCATION_MODE} API.
     * use {@link #isLocationEnabled()}.
     * If you're interacting with {@link #isProviderEnabled(String)}, use
     * {@link #PROVIDERS_CHANGED_ACTION} instead.
     *
     * In the future, there may be mode changes that do not result in
     * {@link #PROVIDERS_CHANGED_ACTION} broadcasts.
     */
     */
    public static final String MODE_CHANGED_ACTION = "android.location.MODE_CHANGED";
    public static final String MODE_CHANGED_ACTION = "android.location.MODE_CHANGED";


@@ -207,8 +199,10 @@ public class LocationManager {
     * If you're interacting with {@link #isProviderEnabled(String)}, use
     * If you're interacting with {@link #isProviderEnabled(String)}, use
     * {@link #PROVIDERS_CHANGED_ACTION} instead.
     * {@link #PROVIDERS_CHANGED_ACTION} instead.
     *
     *
     * @deprecated Do not use.
     * @hide
     * @hide
     */
     */
    @Deprecated
    public static final String MODE_CHANGING_ACTION = "com.android.settings.location.MODE_CHANGING";
    public static final String MODE_CHANGING_ACTION = "com.android.settings.location.MODE_CHANGING";


    /**
    /**
@@ -299,7 +293,7 @@ public class LocationManager {
            "com.android.settings.location.FOOTER_STRING";
            "com.android.settings.location.FOOTER_STRING";


    // Map from LocationListeners to their associated ListenerTransport objects
    // Map from LocationListeners to their associated ListenerTransport objects
    private HashMap<LocationListener,ListenerTransport> mListeners =
    private final HashMap<LocationListener, ListenerTransport> mListeners =
        new HashMap<LocationListener,ListenerTransport>();
        new HashMap<LocationListener,ListenerTransport>();


    private class ListenerTransport extends ILocationListener.Stub {
    private class ListenerTransport extends ILocationListener.Stub {
@@ -1264,39 +1258,20 @@ public class LocationManager {
    }
    }


    /**
    /**
     * Returns the current enabled/disabled status of location
     * Returns the current enabled/disabled state of location. To listen for changes, see
     * {@link #MODE_CHANGED_ACTION}.
     *
     *
     * @return true if location is enabled. false if location is disabled.
     * @return true if location is enabled and false if location is disabled.
     */
     */
    public boolean isLocationEnabled() {
    public boolean isLocationEnabled() {
        return isLocationEnabledForUser(Process.myUserHandle());
        return isLocationEnabledForUser(Process.myUserHandle());
    }
    }


    /**
    /**
     * Method for enabling or disabling location.
     * Returns the current enabled/disabled state of location.
     *
     * @param enabled true to enable location. false to disable location
     * @param userHandle the user to set
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(WRITE_SECURE_SETTINGS)
    public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
        Settings.Secure.putIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE,
                enabled
                        ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
                        : Settings.Secure.LOCATION_MODE_OFF,
                userHandle.getIdentifier());
    }

    /**
     * Returns the current enabled/disabled status of location
     *
     *
     * @param userHandle the user to query
     * @param userHandle the user to query
     * @return true location is enabled. false if location is disabled.
     * @return true if location is enabled and false if location is disabled.
     *
     *
     * @hide
     * @hide
     */
     */
@@ -1310,19 +1285,32 @@ public class LocationManager {
    }
    }


    /**
    /**
     * Returns the current enabled/disabled status of the given provider.
     * Enables or disables the location setting.
     *
     *
     * <p>If the user has enabled this provider in the Settings menu, true
     * @param enabled true to enable location and false to disable location.
     * is returned otherwise false is returned
     * @param userHandle the user to set
     *
     *
     * <p>Callers should instead use {@link #isLocationEnabled()}
     * @hide
     * unless they depend on provider-specific APIs such as
     */
     * {@link #requestLocationUpdates(String, long, float, LocationListener)}.
    @SystemApi
    @RequiresPermission(WRITE_SECURE_SETTINGS)
    public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
        Settings.Secure.putIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE,
                enabled
                        ? Settings.Secure.LOCATION_MODE_ON
                        : Settings.Secure.LOCATION_MODE_OFF,
                userHandle.getIdentifier());
    }

    /**
     * Returns the current enabled/disabled status of the given provider. To listen for changes, see
     * {@link #PROVIDERS_CHANGED_ACTION}.
     *
     *
     * <p>
     * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method would throw
     * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this
     * {@link SecurityException} if the location permissions were not sufficient to use the
     * method would throw {@link SecurityException} if the location permissions
     * specified provider.
     * were not sufficient to use the specified provider.
     *
     *
     * @param provider the name of the provider
     * @param provider the name of the provider
     * @return true if the provider exists and is enabled
     * @return true if the provider exists and is enabled
@@ -1334,19 +1322,13 @@ public class LocationManager {
    }
    }


    /**
    /**
     * Returns the current enabled/disabled status of the given provider and user.
     * Returns the current enabled/disabled status of the given provider and user. Callers should
     *
     * prefer {@link #isLocationEnabledForUser(UserHandle)} unless they depend on provider-specific
     * <p>If the user has enabled this provider in the Settings menu, true
     * APIs.
     * is returned otherwise false is returned
     *
     * <p>Callers should instead use {@link #isLocationEnabled()}
     * unless they depend on provider-specific APIs such as
     * {@link #requestLocationUpdates(String, long, float, LocationListener)}.
     *
     *
     * <p>
     * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method would throw
     * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this
     * {@link SecurityException} if the location permissions were not sufficient to use the
     * method would throw {@link SecurityException} if the location permissions
     * specified provider.
     * were not sufficient to use the specified provider.
     *
     *
     * @param provider the name of the provider
     * @param provider the name of the provider
     * @param userHandle the user to query
     * @param userHandle the user to query
@@ -1367,12 +1349,14 @@ public class LocationManager {
    }
    }


    /**
    /**
     * Method for enabling or disabling a single location provider.
     * Method for enabling or disabling a single location provider. This method is deprecated and
     * functions as a best effort. It should not be relied on in any meaningful sense as providers
     * may no longer be enabled or disabled by clients.
     *
     *
     * @param provider the name of the provider
     * @param provider the name of the provider
     * @param enabled true to enable the provider. false to disable the provider
     * @param enabled true to enable the provider. false to disable the provider
     * @param userHandle the user to set
     * @param userHandle the user to set
     * @return true if the value was set, false on database errors
     * @return true if the value was set, false otherwise
     *
     *
     * @throws IllegalArgumentException if provider is null
     * @throws IllegalArgumentException if provider is null
     * @deprecated Do not manipulate providers individually, use
     * @deprecated Do not manipulate providers individually, use
+1 −1
Original line number Original line Diff line number Diff line
@@ -4231,7 +4231,7 @@ public class SettingsProvider extends ContentProvider {


                        String defLocationMode = Integer.toString(
                        String defLocationMode = Integer.toString(
                                !TextUtils.isEmpty(locationProvidersAllowed.getValue())
                                !TextUtils.isEmpty(locationProvidersAllowed.getValue())
                                        ? Secure.LOCATION_MODE_HIGH_ACCURACY
                                        ? Secure.LOCATION_MODE_ON
                                        : Secure.LOCATION_MODE_OFF);
                                        : Secure.LOCATION_MODE_OFF);
                        secureSettings.insertSettingLocked(
                        secureSettings.insertSettingLocked(
                                Secure.LOCATION_MODE, defLocationMode,
                                Secure.LOCATION_MODE, defLocationMode,
+1 −1
Original line number Original line Diff line number Diff line
@@ -2200,7 +2200,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            return false;
            return false;
        }
        }


        if (mBackgroundThrottlePackageWhitelist.contains(record.mReceiver.mIdentity.mPackageName)) {
        if (mIgnoreSettingsPackageWhitelist.contains(record.mReceiver.mIdentity.mPackageName)) {
            return true;
            return true;
        }
        }