summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Jiang <eejiang@google.com>2020-02-12 00:48:58 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-02-12 00:48:58 +0000
commit5040954f68b17f34ba90ecc427f1b9d2aefb1b96 (patch)
treed68250a4af0712052661900cba7eac7d122d656d
parentbe020f681f577e704ea113274bf4d09783129cf4 (diff)
parent38f5a0683b7c161b080237492ad96a21eeb8ce32 (diff)
Merge "Moves Adaptive Sleep's settings from Settings.System to Settings.Secure"
-rw-r--r--core/java/android/provider/Settings.java9
-rw-r--r--core/proto/android/providers/settings/secure.proto7
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java1
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java2
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java1
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java1
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java6
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java19
-rw-r--r--services/core/java/com/android/server/power/AttentionDetector.java12
-rw-r--r--services/tests/servicestests/src/com/android/server/power/AttentionDetectorTest.java20
10 files changed, 57 insertions, 21 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 44c2fbbd9ce7..2a457f76fa8e 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2997,6 +2997,7 @@ public final class Settings {
private static final HashSet<String> MOVED_TO_SECURE;
static {
MOVED_TO_SECURE = new HashSet<>(30);
+ MOVED_TO_SECURE.add(Secure.ADAPTIVE_SLEEP);
MOVED_TO_SECURE.add(Secure.ANDROID_ID);
MOVED_TO_SECURE.add(Secure.HTTP_PROXY);
MOVED_TO_SECURE.add(Secure.LOCATION_PROVIDERS_ALLOWED);
@@ -3952,6 +3953,7 @@ public final class Settings {
/**
* Control whether to enable adaptive sleep mode.
+ * @deprecated Use {@link android.provider.Settings.Secure#ADAPTIVE_SLEEP} instead.
* @hide
*/
public static final String ADAPTIVE_SLEEP = "adaptive_sleep";
@@ -4744,7 +4746,6 @@ public final class Settings {
PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_FOR_VR);
PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_FOR_VR_FLOAT);
PUBLIC_SETTINGS.add(SCREEN_BRIGHTNESS_MODE);
- PUBLIC_SETTINGS.add(ADAPTIVE_SLEEP);
PUBLIC_SETTINGS.add(MODE_RINGER_STREAMS_AFFECTED);
PUBLIC_SETTINGS.add(MUTE_STREAMS_AFFECTED);
PUBLIC_SETTINGS.add(VIBRATE_ON);
@@ -5798,6 +5799,12 @@ public final class Settings {
}
/**
+ * Control whether to enable adaptive sleep mode.
+ * @hide
+ */
+ public static final String ADAPTIVE_SLEEP = "adaptive_sleep";
+
+ /**
* @deprecated Use {@link android.provider.Settings.Global#DEVELOPMENT_SETTINGS_ENABLED}
* instead
*/
diff --git a/core/proto/android/providers/settings/secure.proto b/core/proto/android/providers/settings/secure.proto
index 77d4e87cec56..6d9e8ab776b7 100644
--- a/core/proto/android/providers/settings/secure.proto
+++ b/core/proto/android/providers/settings/secure.proto
@@ -80,6 +80,11 @@ message SecureSettingsProto {
}
optional Accessibility accessibility = 2;
+ message AdaptiveSleep {
+ optional SettingProto enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+ }
+ optional AdaptiveSleep adaptive_sleep = 78;
+
// Origins for which browsers should allow geolocation by default.
// The value is a space-separated list of origins.
optional SettingProto allowed_geolocation_origins = 3;
@@ -574,5 +579,5 @@ message SecureSettingsProto {
// Please insert fields in alphabetical order and group them into messages
// if possible (to avoid reaching the method limit).
- // Next tag = 78;
+ // Next tag = 79;
}
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
index de4817cc4c49..2431381f3033 100644
--- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
+++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
@@ -37,6 +37,7 @@ public class SecureSettings {
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
+ Settings.Secure.ADAPTIVE_SLEEP,
Settings.Secure.AUTOFILL_SERVICE,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java
index 3f5b0daa06a7..c4330e16d236 100644
--- a/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java
+++ b/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java
@@ -46,7 +46,7 @@ public class SystemSettings {
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
- Settings.System.ADAPTIVE_SLEEP,
+ Settings.System.ADAPTIVE_SLEEP, // moved to secure
Settings.System.VIBRATE_INPUT_DEVICES,
Settings.System.MODE_RINGER_STREAMS_AFFECTED,
Settings.System.TEXT_AUTO_REPLACE,
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
index 849f22f7e0a2..5553469b0420 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
@@ -59,6 +59,7 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, BOOLEAN_VALIDATOR);
VALIDATORS.put(
Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, BOOLEAN_VALIDATOR);
+ VALIDATORS.put(Secure.ADAPTIVE_SLEEP, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.AUTOFILL_SERVICE, NULLABLE_COMPONENT_NAME_VALIDATOR);
VALIDATORS.put(
Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
index c5d4fa9f1b40..8037266ac92f 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java
@@ -126,7 +126,6 @@ public class SystemSettingsValidators {
VALIDATORS.put(System.SCREEN_OFF_TIMEOUT, NON_NEGATIVE_INTEGER_VALIDATOR);
VALIDATORS.put(System.SCREEN_BRIGHTNESS_FOR_VR, new InclusiveIntegerRangeValidator(0, 255));
VALIDATORS.put(System.SCREEN_BRIGHTNESS_MODE, BOOLEAN_VALIDATOR);
- VALIDATORS.put(System.ADAPTIVE_SLEEP, BOOLEAN_VALIDATOR);
VALIDATORS.put(System.MODE_RINGER_STREAMS_AFFECTED, NON_NEGATIVE_INTEGER_VALIDATOR);
VALIDATORS.put(System.MUTE_STREAMS_AFFECTED, NON_NEGATIVE_INTEGER_VALIDATOR);
VALIDATORS.put(System.VIBRATE_ON, BOOLEAN_VALIDATOR);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index 66d8306932e0..d6776879254d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -1813,6 +1813,12 @@ class SettingsProtoDumpUtil {
SecureSettingsProto.Accessibility.ACCESSIBILITY_MAGNIFICATION_MODE);
p.end(accessibilityToken);
+ final long adaptiveSleepToken = p.start(SecureSettingsProto.ADAPTIVE_SLEEP);
+ dumpSetting(s, p,
+ Settings.Secure.ADAPTIVE_SLEEP,
+ SecureSettingsProto.AdaptiveSleep.ENABLED);
+ p.end(adaptiveSleepToken);
+
dumpSetting(s, p,
Settings.Secure.ALLOWED_GEOLOCATION_ORIGINS,
SecureSettingsProto.ALLOWED_GEOLOCATION_ORIGINS);
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 7b518a6167b7..aad46e9f0959 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -3426,7 +3426,7 @@ public class SettingsProvider extends ContentProvider {
}
private final class UpgradeController {
- private static final int SETTINGS_VERSION = 187;
+ private static final int SETTINGS_VERSION = 188;
private final int mUserId;
@@ -4732,6 +4732,23 @@ public class SettingsProvider extends ContentProvider {
currentVersion = 187;
}
+ if (currentVersion == 187) {
+ // Migrate adaptive sleep setting from System to Secure.
+ if (userId == UserHandle.USER_OWNER) {
+ // Remove from the system settings.
+ SettingsState systemSettings = getSystemSettingsLocked(userId);
+ String name = Settings.System.ADAPTIVE_SLEEP;
+ Setting setting = systemSettings.getSettingLocked(name);
+ systemSettings.deleteSettingLocked(name);
+
+ // Add to the secure settings.
+ SettingsState secureSettings = getSecureSettingsLocked(userId);
+ secureSettings.insertSettingLocked(name, setting.getValue(), null /* tag */,
+ false /* makeDefault */, SettingsState.SYSTEM_PACKAGE_NAME);
+ }
+ currentVersion = 188;
+ }
+
// vXXX: Add new settings above this point.
if (currentVersion != newVersion) {
diff --git a/services/core/java/com/android/server/power/AttentionDetector.java b/services/core/java/com/android/server/power/AttentionDetector.java
index cc72dd69a5fa..1ab6adee2320 100644
--- a/services/core/java/com/android/server/power/AttentionDetector.java
+++ b/services/core/java/com/android/server/power/AttentionDetector.java
@@ -17,7 +17,7 @@
package com.android.server.power;
import static android.provider.DeviceConfig.NAMESPACE_ATTENTION_MANAGER_SERVICE;
-import static android.provider.Settings.System.ADAPTIVE_SLEEP;
+import static android.provider.Settings.Secure.ADAPTIVE_SLEEP;
import android.Manifest;
import android.app.ActivityManager;
@@ -152,8 +152,8 @@ public class AttentionDetector {
@VisibleForTesting
void updateEnabledFromSettings(Context context) {
- mIsSettingEnabled = Settings.System.getIntForUser(context.getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT) == 1;
+ mIsSettingEnabled = Settings.Secure.getIntForUser(context.getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT) == 1;
}
public void systemReady(Context context) {
@@ -173,8 +173,8 @@ public class AttentionDetector {
// Shouldn't happen since in-process.
}
- context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
- Settings.System.ADAPTIVE_SLEEP),
+ context.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
+ Settings.Secure.ADAPTIVE_SLEEP),
false, new ContentObserver(new Handler(context.getMainLooper())) {
@Override
public void onChange(boolean selfChange) {
@@ -194,7 +194,7 @@ public class AttentionDetector {
if (!isAttentionServiceSupported() || !serviceHasSufficientPermissions()) {
// Turns off adaptive sleep in settings for all users if attention service is not
// available. The setting itself should also be grayed out in this case.
- Settings.System.putInt(mContentResolver, ADAPTIVE_SLEEP, 0);
+ Settings.Secure.putInt(mContentResolver, ADAPTIVE_SLEEP, 0);
return nextScreenDimming;
}
diff --git a/services/tests/servicestests/src/com/android/server/power/AttentionDetectorTest.java b/services/tests/servicestests/src/com/android/server/power/AttentionDetectorTest.java
index 642cedb4c852..c4289efe1839 100644
--- a/services/tests/servicestests/src/com/android/server/power/AttentionDetectorTest.java
+++ b/services/tests/servicestests/src/com/android/server/power/AttentionDetectorTest.java
@@ -92,18 +92,18 @@ public class AttentionDetectorTest extends AndroidTestCase {
mNextDimming = SystemClock.uptimeMillis() + 3000L;
// Save the existing state.
- mIsSettingEnabled = Settings.System.getIntForUser(getContext().getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT);
+ mIsSettingEnabled = Settings.Secure.getIntForUser(getContext().getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT);
- Settings.System.putIntForUser(getContext().getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, 1, UserHandle.USER_CURRENT);
+ Settings.Secure.putIntForUser(getContext().getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, 1, UserHandle.USER_CURRENT);
mAttentionDetector.updateEnabledFromSettings(getContext());
}
@After
public void tearDown() {
- Settings.System.putIntForUser(getContext().getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, mIsSettingEnabled, UserHandle.USER_CURRENT);
+ Settings.Secure.putIntForUser(getContext().getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, mIsSettingEnabled, UserHandle.USER_CURRENT);
DeviceConfig.setProperty(NAMESPACE_ATTENTION_MANAGER_SERVICE,
KEY_PRE_DIM_CHECK_DURATION_MILLIS,
@@ -122,8 +122,8 @@ public class AttentionDetectorTest extends AndroidTestCase {
@Test
public void testOnUserActivity_doesntCheckIfNotEnabled() {
- Settings.System.putIntForUser(getContext().getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT);
+ Settings.Secure.putIntForUser(getContext().getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT);
mAttentionDetector.updateEnabledFromSettings(getContext());
long when = registerAttention();
verify(mAttentionManagerInternal, never()).checkAttention(anyLong(), any());
@@ -163,8 +163,8 @@ public class AttentionDetectorTest extends AndroidTestCase {
PackageManager.PERMISSION_DENIED);
registerAttention();
- boolean enabled = Settings.System.getIntForUser(getContext().getContentResolver(),
- Settings.System.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT) == 1;
+ boolean enabled = Settings.Secure.getIntForUser(getContext().getContentResolver(),
+ Settings.Secure.ADAPTIVE_SLEEP, 0, UserHandle.USER_CURRENT) == 1;
assertFalse(enabled);
}