From c5865d6f1bc9cca1ed09ec42f4dd35a62218d29f Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Fri, 2 Mar 2018 16:00:43 -0800 Subject: [PATCH] Change a11y shortcut default lockscreen behavior If the user hasn't chosen a preference, the shortcut will not work on the lockscreen until the user agrees to use the shortcut. After the user so agrees, the shortcut will also work on the shortcut. Bug: 70944865 Test: Adding a test for the new behavior Change-Id: I41e1238fad43a4432cd341c6808e26ad6e155506 --- .../AccessibilityShortcutController.java | 9 ++++++++- .../AccessibilityShortcutControllerTest.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java index 293471c686e57..08763580fc882 100644 --- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java +++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java @@ -143,6 +143,9 @@ public class AccessibilityShortcutController { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN), false, co, UserHandle.USER_ALL); + mContext.getContentResolver().registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN), + false, co, UserHandle.USER_ALL); setCurrentUser(mUserId); } @@ -168,8 +171,12 @@ public class AccessibilityShortcutController { 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, 0, mUserId); mEnabledOnLockScreen = Settings.Secure.getIntForUser( - cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, 0, mUserId) == 1; + cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, + dialogAlreadyShown, mUserId) == 1; mIsShortcutEnabled = enabled && haveValidService; } 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 449e3743e3aab..4e957e3631b62 100644 --- a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java @@ -213,6 +213,20 @@ public class AccessibilityShortcutControllerTest { assertTrue(getController().isAccessibilityShortcutAvailable(true)); } + @Test + public void testShortcutAvailable_onLockScreenAndLockScreenPreferenceUnset() { + // When the user hasn't specified a lock screen preference, we allow from the lock screen + // as long as the user has agreed to enable the shortcut + configureValidShortcutService(); + configureShortcutEnabled(ENABLED_INCLUDING_LOCK_SCREEN); + Settings.Secure.putString( + mContentResolver, ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, null); + Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 0); + assertFalse(getController().isAccessibilityShortcutAvailable(true)); + Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 1); + assertTrue(getController().isAccessibilityShortcutAvailable(true)); + } + @Test public void testShortcutAvailable_whenServiceIdBecomesNull_shouldReturnFalse() { configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);