diff --git a/api/current.txt b/api/current.txt index 6b8854779d312..0356306475c3d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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_HIGH_ACCURACY = 3; // 0x3 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 String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed"; field @Deprecated public static final String LOCK_PATTERN_ENABLED = "lock_pattern_autolock"; diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index ea00698f2001f..afa21100f0221 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -5874,30 +5874,24 @@ public final class Settings { "unknown_sources_default_reversed"; /** - * Comma-separated list of location providers that activities may access. Do not rely on - * this value being present in settings.db or on ContentObserver notifications on the + * Comma-separated list of location providers that are accessible. Do not rely on + * this value being present or correct, or on ContentObserver notifications on the * corresponding Uri. * - * @deprecated Providers should not be controlled individually. See {@link #LOCATION_MODE} - * documentation for information on reading/writing location information. + * @deprecated The preferred methods for checking provider status and listening for changes + * are via {@link LocationManager#isProviderEnabled(String)} and + * {@link LocationManager#PROVIDERS_CHANGED_ACTION}. */ @Deprecated public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed"; /** - * The degree of location access enabled by the user. - *
- * 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. - *
- * 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.
+ * The current location mode of the device. Do not rely on this value being present or on
+ * ContentObserver notifications on the corresponding Uri.
*
- * @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
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;
/**
- * Location access disabled.
+ * Location mode is off.
*
* @deprecated See {@link #LOCATION_MODE}.
*/
@@ -5932,32 +5926,39 @@ public final class Settings {
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
- * get the status of a location provider, use
- * {@link LocationManager#isProviderEnabled(String)}.
+ * @deprecated See {@link #LOCATION_MODE_ON}.
*/
@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}.
+ * 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
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_ON}.
+ */
+ @Deprecated
+ 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_HIGH_ACCURACY = 3;
+ public static final int LOCATION_MODE_ON = LOCATION_MODE_HIGH_ACCURACY;
/**
* A flag containing settings used for biometric weak
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index 59c6a0a21cd17..63b57d166f1f1 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -181,22 +181,14 @@ public class LocationManager {
"android.location.GPS_ENABLED_CHANGE";
/**
- * Broadcast intent action when the configured location providers
- * change. For use with {@link #isProviderEnabled(String)}. If you're interacting with the
- * {@link android.provider.Settings.Secure#LOCATION_MODE} API, use {@link #MODE_CHANGED_ACTION}
- * instead.
+ * Broadcast intent action when the set of enabled location providers changes. To check the
+ * status of a provider, use {@link #isProviderEnabled(String)}.
*/
- public static final String PROVIDERS_CHANGED_ACTION =
- "android.location.PROVIDERS_CHANGED";
+ public static final String PROVIDERS_CHANGED_ACTION = "android.location.PROVIDERS_CHANGED";
/**
- * Broadcast intent action when {@link android.provider.Settings.Secure#LOCATION_MODE} changes.
- * For use with the {@link android.provider.Settings.Secure#LOCATION_MODE} API.
- * 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.
+ * Broadcast intent action when the device location mode changes. To check the location mode,
+ * use {@link #isLocationEnabled()}.
*/
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
* {@link #PROVIDERS_CHANGED_ACTION} instead.
*
+ * @deprecated Do not use.
* @hide
*/
+ @Deprecated
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";
// Map from LocationListeners to their associated ListenerTransport objects
- private HashMap If the user has enabled this provider in the Settings menu, true
- * is returned otherwise false is returned
+ * @param enabled true to enable location and false to disable location.
+ * @param userHandle the user to set
*
- * Callers should instead use {@link #isLocationEnabled()}
- * unless they depend on provider-specific APIs such as
- * {@link #requestLocationUpdates(String, long, float, LocationListener)}.
+ * @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_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}.
*
- *
- * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this
- * method would throw {@link SecurityException} if the location permissions
- * were not sufficient to use the specified provider.
+ * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method would throw
+ * {@link SecurityException} if the location permissions were not sufficient to use the
+ * specified provider.
*
* @param provider the name of the provider
* @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
+ * APIs.
*
- * If the user has enabled this provider in the Settings menu, true
- * is returned otherwise false is returned
- *
- * Callers should instead use {@link #isLocationEnabled()}
- * unless they depend on provider-specific APIs such as
- * {@link #requestLocationUpdates(String, long, float, LocationListener)}.
- *
- *
- * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this
- * method would throw {@link SecurityException} if the location permissions
- * were not sufficient to use the specified provider.
+ * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method would throw
+ * {@link SecurityException} if the location permissions were not sufficient to use the
+ * specified provider.
*
* @param provider the name of the provider
* @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 enabled true to enable the provider. false to disable the provider
* @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
* @deprecated Do not manipulate providers individually, use
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 445312168ebaf..23e5f0eea46d3 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -4231,7 +4231,7 @@ public class SettingsProvider extends ContentProvider {
String defLocationMode = Integer.toString(
!TextUtils.isEmpty(locationProvidersAllowed.getValue())
- ? Secure.LOCATION_MODE_HIGH_ACCURACY
+ ? Secure.LOCATION_MODE_ON
: Secure.LOCATION_MODE_OFF);
secureSettings.insertSettingLocked(
Secure.LOCATION_MODE, defLocationMode,
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index d2c6354e91b8d..7eb8e938628e0 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -2200,7 +2200,7 @@ public class LocationManagerService extends ILocationManager.Stub {
return false;
}
- if (mBackgroundThrottlePackageWhitelist.contains(record.mReceiver.mIdentity.mPackageName)) {
+ if (mIgnoreSettingsPackageWhitelist.contains(record.mReceiver.mIdentity.mPackageName)) {
return true;
}