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

Commit 390f8f9b authored by menghanli's avatar menghanli
Browse files

Accessibility Service & Shortcut Redesign - Remove “volume key shortcut” setting (5/n)

- 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
parent 962946c9
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -6560,13 +6560,6 @@ public final class Settings {
         */
         */
        public static final String ACCESSIBILITY_ENABLED = "accessibility_enabled";
        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.
         * Setting specifying if the accessibility shortcut is enabled.
         * @hide
         * @hide
+1 −6
Original line number Original line Diff line number Diff line
@@ -143,9 +143,6 @@ public class AccessibilityShortcutController {
        mContext.getContentResolver().registerContentObserver(
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE),
                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE),
                false, co, UserHandle.USER_ALL);
                false, co, UserHandle.USER_ALL);
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED),
                false, co, UserHandle.USER_ALL);
        mContext.getContentResolver().registerContentObserver(
        mContext.getContentResolver().registerContentObserver(
                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN),
                Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN),
                false, co, UserHandle.USER_ALL);
                false, co, UserHandle.USER_ALL);
@@ -174,8 +171,6 @@ public class AccessibilityShortcutController {
    public void onSettingsChanged() {
    public void onSettingsChanged() {
        final boolean hasShortcutTarget = hasShortcutTarget();
        final boolean hasShortcutTarget = hasShortcutTarget();
        final ContentResolver cr = mContext.getContentResolver();
        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
        // Enable the shortcut from the lockscreen by default if the dialog has been shown
        final int dialogAlreadyShown = Settings.Secure.getIntForUser(
        final int dialogAlreadyShown = Settings.Secure.getIntForUser(
                cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, DialogStaus.NOT_SHOWN,
                cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, DialogStaus.NOT_SHOWN,
@@ -183,7 +178,7 @@ public class AccessibilityShortcutController {
        mEnabledOnLockScreen = Settings.Secure.getIntForUser(
        mEnabledOnLockScreen = Settings.Secure.getIntForUser(
                cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
                cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
                dialogAlreadyShown, mUserId) == 1;
                dialogAlreadyShown, mUserId) == 1;
        mIsShortcutEnabled = enabled && hasShortcutTarget;
        mIsShortcutEnabled = hasShortcutTarget;
    }
    }


    /**
    /**
+0 −35
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.accessibility;
package com.android.internal.accessibility;


import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN;
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_ON_LOCK_SCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;
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};
    private static final long[] VIBRATOR_PATTERN_LONG = {VIBRATOR_PATTERN_1, VIBRATOR_PATTERN_2};


    // Convenience values for enabling/disabling to make code more readable
    // 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_EXCEPT_LOCK_SCREEN = 1;
    private static final int ENABLED_INCLUDING_LOCK_SCREEN = 2;
    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 Context mContext;
    private @Mock FrameworkObjectProvider mFrameworkObjectProvider;
    private @Mock FrameworkObjectProvider mFrameworkObjectProvider;
@@ -224,14 +221,6 @@ public class AccessibilityShortcutControllerTest {
        assertTrue(getController().isAccessibilityShortcutAvailable(false));
        assertTrue(getController().isAccessibilityShortcutAvailable(false));
    }
    }


    @Test
    public void testShortcutAvailable_disabledWithValidServiceWhenCreated_shouldReturnFalse()
            throws Exception {
        configureValidShortcutService();
        configureShortcutEnabled(DISABLED_BUT_LOCK_SCREEN_ON);
        assertFalse(getController().isAccessibilityShortcutAvailable(false));
    }

    @Test
    @Test
    public void testShortcutAvailable_onLockScreenButDisabledThere_shouldReturnFalse()
    public void testShortcutAvailable_onLockScreenButDisabledThere_shouldReturnFalse()
            throws Exception {
            throws Exception {
@@ -284,21 +273,9 @@ public class AccessibilityShortcutControllerTest {
        assertTrue(accessibilityShortcutController.isAccessibilityShortcutAvailable(false));
        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
    @Test
    public void testShortcutAvailable_whenShortcutBecomesEnabled_shouldReturnTrue()
    public void testShortcutAvailable_whenShortcutBecomesEnabled_shouldReturnTrue()
            throws Exception {
            throws Exception {
        configureShortcutEnabled(DISABLED);
        configureValidShortcutService();
        configureValidShortcutService();
        AccessibilityShortcutController accessibilityShortcutController = getController();
        AccessibilityShortcutController accessibilityShortcutController = getController();
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
@@ -594,31 +571,19 @@ public class AccessibilityShortcutControllerTest {
    }
    }


    private void configureShortcutEnabled(int enabledValue) {
    private void configureShortcutEnabled(int enabledValue) {
        final boolean enabled;
        final boolean lockscreen;
        final boolean lockscreen;


        switch (enabledValue) {
        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:
            case ENABLED_INCLUDING_LOCK_SCREEN:
                enabled = true;
                lockscreen = true;
                lockscreen = true;
                break;
                break;
            case ENABLED_EXCEPT_LOCK_SCREEN:
            case ENABLED_EXCEPT_LOCK_SCREEN:
                enabled = true;
                lockscreen = false;
                lockscreen = false;
                break;
                break;
            default:
            default:
                throw new IllegalArgumentException();
                throw new IllegalArgumentException();
        }
        }


        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_ENABLED, enabled ? 1 : 0);
        Settings.Secure.putInt(
        Settings.Secure.putInt(
                mContentResolver, ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, lockscreen ? 1 : 0);
                mContentResolver, ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, lockscreen ? 1 : 0);
    }
    }
+0 −13
Original line number Original line Diff line number Diff line
@@ -189,19 +189,6 @@ public class AccessibilityUtils {
        return context.getString(R.string.config_defaultAccessibilityService);
        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<ComponentName> getInstalledServices(Context context) {
    private static Set<ComponentName> getInstalledServices(Context context) {
        final Set<ComponentName> installedServices = new HashSet<>();
        final Set<ComponentName> installedServices = new HashSet<>();
        installedServices.clear();
        installedServices.clear();
+0 −1
Original line number Original line Diff line number Diff line
@@ -48,7 +48,6 @@ public class SecureSettings {
        Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
        Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT,
        Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
        Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
        Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
        Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
        Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET,
        Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET,
Loading