From 390f8f9be923554b7f0ad043e0412e3c2053c5ad Mon Sep 17 00:00:00 2001 From: menghanli Date: Wed, 11 Mar 2020 20:52:47 +0800 Subject: [PATCH] =?UTF-8?q?Accessibility=20Service=20&=20Shortcut=20Redesi?= =?UTF-8?q?gn=20-=20Remove=20=E2=80=9Cvolume=20key=20shortcut=E2=80=9D=20s?= =?UTF-8?q?etting=20(5/n)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Target to fix migration issue to support a user revoked the accessibility shortcut before upgrading to R, but wants to to apply new hardware shortcut design in R. - The switchbar of accessibility_shortcut_enabled was removed in (1/n), so we should also remove related checker in controller. Bug: 142529032 Test: atest AccessibilityShortcutControllerTest Change-Id: I48f8d88c4192e894b9e210221e5dc7e701344623 --- core/java/android/provider/Settings.java | 7 ---- .../AccessibilityShortcutController.java | 7 +--- .../AccessibilityShortcutControllerTest.java | 35 ------------------- .../accessibility/AccessibilityUtils.java | 13 ------- .../settings/backup/SecureSettings.java | 1 - .../validators/SecureSettingsValidators.java | 3 +- .../settings/SettingsProtoDumpUtil.java | 3 -- .../providers/settings/SettingsProvider.java | 19 +++++++++- .../AccessibilityManagerService.java | 11 ------ 9 files changed, 20 insertions(+), 79 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index a28ea899694cf..bd06cee7df9fb 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -6560,13 +6560,6 @@ public final class Settings { */ public static final String ACCESSIBILITY_ENABLED = "accessibility_enabled"; - /** - * Setting specifying if the accessibility shortcut is enabled. - * @hide - */ - public static final String ACCESSIBILITY_SHORTCUT_ENABLED = - "accessibility_shortcut_enabled"; - /** * Setting specifying if the accessibility shortcut is enabled. * @hide diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java index 54ea57a6cae4b..d64b5f1118dc1 100644 --- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java +++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java @@ -143,9 +143,6 @@ public class AccessibilityShortcutController { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE), false, co, UserHandle.USER_ALL); - mContext.getContentResolver().registerContentObserver( - Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED), - false, co, UserHandle.USER_ALL); mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN), false, co, UserHandle.USER_ALL); @@ -174,8 +171,6 @@ public class AccessibilityShortcutController { public void onSettingsChanged() { final boolean hasShortcutTarget = hasShortcutTarget(); final ContentResolver cr = mContext.getContentResolver(); - final boolean enabled = Settings.Secure.getIntForUser( - cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1, mUserId) == 1; // Enable the shortcut from the lockscreen by default if the dialog has been shown final int dialogAlreadyShown = Settings.Secure.getIntForUser( cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, DialogStaus.NOT_SHOWN, @@ -183,7 +178,7 @@ public class AccessibilityShortcutController { mEnabledOnLockScreen = Settings.Secure.getIntForUser( cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogAlreadyShown, mUserId) == 1; - mIsShortcutEnabled = enabled && hasShortcutTarget; + mIsShortcutEnabled = hasShortcutTarget; } /** diff --git a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java index 9af0ed0ab8261..4a33da6805857 100644 --- a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java @@ -17,7 +17,6 @@ package com.android.internal.accessibility; import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN; -import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED; import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN; import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE; import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY; @@ -102,10 +101,8 @@ public class AccessibilityShortcutControllerTest { private static final long[] VIBRATOR_PATTERN_LONG = {VIBRATOR_PATTERN_1, VIBRATOR_PATTERN_2}; // Convenience values for enabling/disabling to make code more readable - private static final int DISABLED = 0; private static final int ENABLED_EXCEPT_LOCK_SCREEN = 1; private static final int ENABLED_INCLUDING_LOCK_SCREEN = 2; - private static final int DISABLED_BUT_LOCK_SCREEN_ON = 3; private @Mock Context mContext; private @Mock FrameworkObjectProvider mFrameworkObjectProvider; @@ -224,14 +221,6 @@ public class AccessibilityShortcutControllerTest { assertTrue(getController().isAccessibilityShortcutAvailable(false)); } - @Test - public void testShortcutAvailable_disabledWithValidServiceWhenCreated_shouldReturnFalse() - throws Exception { - configureValidShortcutService(); - configureShortcutEnabled(DISABLED_BUT_LOCK_SCREEN_ON); - assertFalse(getController().isAccessibilityShortcutAvailable(false)); - } - @Test public void testShortcutAvailable_onLockScreenButDisabledThere_shouldReturnFalse() throws Exception { @@ -284,21 +273,9 @@ public class AccessibilityShortcutControllerTest { assertTrue(accessibilityShortcutController.isAccessibilityShortcutAvailable(false)); } - @Test - public void testShortcutAvailable_whenShortcutBecomesDisabled_shouldReturnFalse() - throws Exception { - configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN); - configureValidShortcutService(); - AccessibilityShortcutController accessibilityShortcutController = getController(); - configureShortcutEnabled(DISABLED); - accessibilityShortcutController.onSettingsChanged(); - assertFalse(accessibilityShortcutController.isAccessibilityShortcutAvailable(false)); - } - @Test public void testShortcutAvailable_whenShortcutBecomesEnabled_shouldReturnTrue() throws Exception { - configureShortcutEnabled(DISABLED); configureValidShortcutService(); AccessibilityShortcutController accessibilityShortcutController = getController(); configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN); @@ -594,31 +571,19 @@ public class AccessibilityShortcutControllerTest { } private void configureShortcutEnabled(int enabledValue) { - final boolean enabled; final boolean lockscreen; switch (enabledValue) { - case DISABLED: - enabled = false; - lockscreen = false; - break; - case DISABLED_BUT_LOCK_SCREEN_ON: - enabled = false; - lockscreen = true; - break; case ENABLED_INCLUDING_LOCK_SCREEN: - enabled = true; lockscreen = true; break; case ENABLED_EXCEPT_LOCK_SCREEN: - enabled = true; lockscreen = false; break; default: throw new IllegalArgumentException(); } - Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_ENABLED, enabled ? 1 : 0); Settings.Secure.putInt( mContentResolver, ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, lockscreen ? 1 : 0); } diff --git a/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java b/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java index 2b841967d4a8d..59735f413f9db 100644 --- a/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/accessibility/AccessibilityUtils.java @@ -189,19 +189,6 @@ public class AccessibilityUtils { return context.getString(R.string.config_defaultAccessibilityService); } - /** - * Check if the accessibility shortcut is enabled for a user - * - * @param context A valid context - * @param userId The user of interest - * @return {@code true} if the shortcut is enabled for the user. {@code false} otherwise. - * Note that the shortcut may be enabled, but no action associated with it. - */ - public static boolean isShortcutEnabled(Context context, int userId) { - return Settings.Secure.getIntForUser(context.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1, userId) == 1; - } - private static Set getInstalledServices(Context context) { final Set installedServices = new HashSet<>(); installedServices.clear(); diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index d350d9df37b8c..d320df9c24ba5 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -48,7 +48,6 @@ public class SecureSettings { Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, - Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET, diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index 4d33b627f4e20..8801a9c32a364 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -25,10 +25,10 @@ import static android.provider.settings.validators.SettingsValidators.COMMA_SEPA import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.JSON_OBJECT_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.LOCALE_VALIDATOR; +import static android.provider.settings.validators.SettingsValidators.NONE_NEGATIVE_LONG_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NON_NEGATIVE_INTEGER_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.NULLABLE_COMPONENT_NAME_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.PACKAGE_NAME_VALIDATOR; -import static android.provider.settings.validators.SettingsValidators.NONE_NEGATIVE_LONG_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TILE_LIST_VALIDATOR; import static android.provider.settings.validators.SettingsValidators.TTS_LIST_VALIDATOR; @@ -82,7 +82,6 @@ public class SecureSettingsValidators { Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT, ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR); VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, BOOLEAN_VALIDATOR); - VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, BOOLEAN_VALIDATOR); VALIDATORS.put(Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, BOOLEAN_VALIDATOR); VALIDATORS.put( diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java index af74121a11c98..b22caf0edc666 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java @@ -1780,9 +1780,6 @@ class SettingsProtoDumpUtil { dumpSetting(s, p, Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, SecureSettingsProto.Accessibility.LARGE_POINTER_ICON); - dumpSetting(s, p, - Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, - SecureSettingsProto.Accessibility.SHORTCUT_ENABLED); dumpSetting(s, p, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, SecureSettingsProto.Accessibility.SHORTCUT_ON_LOCK_SCREEN); diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 5a9d7497b6411..2fde87c08ad59 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -3436,7 +3436,7 @@ public class SettingsProvider extends ContentProvider { } private final class UpgradeController { - private static final int SETTINGS_VERSION = 188; + private static final int SETTINGS_VERSION = 189; private final int mUserId; @@ -4759,6 +4759,23 @@ public class SettingsProvider extends ContentProvider { currentVersion = 188; } + if (currentVersion == 188) { + // Deprecate ACCESSIBILITY_SHORTCUT_ENABLED, and migrate it + // to ACCESSIBILITY_SHORTCUT_TARGET_SERVICE. + final SettingsState secureSettings = getSecureSettingsLocked(userId); + final Setting shortcutEnabled = secureSettings.getSettingLocked( + "accessibility_shortcut_enabled"); + if ("0".equals(shortcutEnabled.getValue())) { + // Clear shortcut key targets list setting. + secureSettings.insertSettingLocked( + Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, + "", null /* tag */, false /* makeDefault */, + SettingsState.SYSTEM_PACKAGE_NAME); + } + secureSettings.deleteSettingLocked("accessibility_shortcut_enabled"); + currentVersion = 189; + } + // vXXX: Add new settings above this point. if (currentVersion != newVersion) { diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 60c3d7859984e..1b180e3357d7d 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -2001,17 +2001,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, userState.mUserId, currentTargets, str -> str); scheduleNotifyClientsOfServicesStateChangeLocked(userState); - - // Disable accessibility shortcut key if there's no shortcut installed. - if (currentTargets.isEmpty()) { - final long identity = Binder.clearCallingIdentity(); - try { - Settings.Secure.putIntForUser(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 0, userState.mUserId); - } finally { - Binder.restoreCallingIdentity(identity); - } - } } private boolean canRequestAndRequestsTouchExplorationLocked(