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

Commit 91998e96 authored by Cam Bickel's avatar Cam Bickel Committed by Camden Bickel
Browse files

Cleanup flag "migrate_enable_shortcuts"

Bug: b/332006721
Test: atest AccessibilityShortcutControllerTest InvisibleToggleAccessibilityServiceTargetTest
Flag: EXEMPT flag cleanup
Change-Id: Iab849b2f1e53e71e992009626d7161a2c8e5fddc
parent 40c99aa5
Loading
Loading
Loading
Loading
+39 −44
Original line number Diff line number Diff line
@@ -360,41 +360,42 @@ public class AccessibilityShortcutController {

        // Avoid non-a11y users accidentally turning shortcut on without reading this carefully.
        // Put "don't turn on" as the primary action.
        final AlertDialog alertDialog = mFrameworkObjectProvider.getAlertDialogBuilder(
                        // Use SystemUI context so we pick up any theme set in a vendor overlay
        final AlertDialog alertDialog =
                mFrameworkObjectProvider
                        .getAlertDialogBuilder(
                                // Use SystemUI context so we pick up any theme set in a vendor
                                // overlay
                                mFrameworkObjectProvider.getSystemUiContext())
                        .setTitle(getShortcutWarningTitle(targets))
                        .setMessage(getShortcutWarningMessage(targets))
                        .setCancelable(false)
                .setNegativeButton(R.string.accessibility_shortcut_on,
                        (DialogInterface d, int which) -> enableDefaultHardwareShortcut(userId))
                .setPositiveButton(R.string.accessibility_shortcut_off,
                        .setNegativeButton(
                                R.string.accessibility_shortcut_on,
                                (DialogInterface d, int which) ->
                                        enableDefaultHardwareShortcut(userId))
                        .setPositiveButton(
                                R.string.accessibility_shortcut_off,
                                (DialogInterface d, int which) -> {
                                    Set<String> targetServices =
                                            ShortcutUtils.getShortcutTargetsFromSettings(
                                            mContext,
                                            HARDWARE,
                                            userId);
                            if (Flags.migrateEnableShortcuts()) {
                                                    mContext, HARDWARE, userId);
                                    am.enableShortcutsForTargets(
                                            false, HARDWARE, targetServices, userId);
                            } else {
                                Settings.Secure.putStringForUser(mContext.getContentResolver(),
                                        Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "",
                                        userId);
                                ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState(
                                        mContext, targetServices, userId);
                            }
                                    // If canceled, treat as if the dialog has never been shown
                            Settings.Secure.putIntForUser(mContext.getContentResolver(),
                                    Settings.Secure.putIntForUser(
                                            mContext.getContentResolver(),
                                            Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                                    DialogStatus.NOT_SHOWN, userId);
                                            DialogStatus.NOT_SHOWN,
                                            userId);
                                })
                .setOnCancelListener((DialogInterface d) -> {
                        .setOnCancelListener(
                                (DialogInterface d) -> {
                                    // If canceled, treat as if the dialog has never been shown
                    Settings.Secure.putIntForUser(mContext.getContentResolver(),
                                    Settings.Secure.putIntForUser(
                                            mContext.getContentResolver(),
                                            Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                            DialogStatus.NOT_SHOWN, userId);
                                            DialogStatus.NOT_SHOWN,
                                            userId);
                                })
                        .create();
        return alertDialog;
@@ -531,14 +532,8 @@ public class AccessibilityShortcutController {
            // Default service is invalid, so nothing we can do here.
            return;
        }
        if (Flags.migrateEnableShortcuts()) {
        accessibilityManager.enableShortcutsForTargets(true, HARDWARE,
                Set.of(defaultServiceComponent.flattenToString()), userId);
        } else {
            Settings.Secure.putStringForUser(mContext.getContentResolver(),
                    Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
                    defaultServiceComponent.flattenToString(), userId);
        }
    }

    private boolean performTtsPrompt(AlertDialog alertDialog) {
+3 −15
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.internal.accessibility.dialog;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.GESTURE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import static com.android.internal.accessibility.util.ShortcutUtils.optInValueToSettings;
import static com.android.internal.accessibility.util.ShortcutUtils.optOutValueFromSettings;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -31,7 +29,6 @@ import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;

import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType;
@@ -118,18 +115,9 @@ public abstract class AccessibilityTarget implements TargetOperations, OnTargetS
    @Override
    public void onCheckedChanged(boolean isChecked) {
        setShortcutEnabled(isChecked);
        if (Flags.migrateEnableShortcuts()) {
            final AccessibilityManager am =
                    getContext().getSystemService(AccessibilityManager.class);
        final AccessibilityManager am = getContext().getSystemService(AccessibilityManager.class);
        am.enableShortcutsForTargets(
                isChecked, getShortcutType(), Set.of(mId), UserHandle.myUserId());
        } else {
            if (isChecked) {
                optInValueToSettings(getContext(), getShortcutType(), getId());
            } else {
                optOutValueFromSettings(getContext(), getShortcutType(), getId());
            }
        }
    }

    public void setStateDescription(CharSequence stateDescription) {
+1 −124
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.internal.accessibility;

import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN;
import static android.provider.Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
@@ -64,7 +63,6 @@ import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
@@ -423,7 +421,6 @@ public class AccessibilityShortcutControllerTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testClickingDisableButtonInDialog_shouldClearShortcutId() throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
        configureValidShortcutService();
@@ -445,58 +442,6 @@ public class AccessibilityShortcutControllerTest {
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testClickingDisableButtonInDialog_shouldClearShortcutId_old() throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
        configureValidShortcutService();
        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
        getController().performAccessibilityShortcut();

        ArgumentCaptor<DialogInterface.OnClickListener> captor =
                ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
        verify(mAlertDialogBuilder).setPositiveButton(eq(R.string.accessibility_shortcut_off),
                captor.capture());
        captor.getValue().onClick(null, DialogInterface.BUTTON_POSITIVE);

        assertThat(
                Settings.Secure.getString(mContentResolver, ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)
        ).isEmpty();
        assertThat(Settings.Secure.getInt(
                mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN)).isEqualTo(
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
    }

    @Test
    @EnableFlags(Flags.FLAG_UPDATE_ALWAYS_ON_A11Y_SERVICE)
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void turnOffVolumeShortcutForAlwaysOnA11yService_shouldTurnOffA11yService()
            throws Exception {
        configureApplicationTargetSdkVersion(Build.VERSION_CODES.R);
        turnOffVolumeKeyShortcutForA11yService(/* alwaysOnService= */ true);

        assertThat(
                Settings.Secure.getString(mContentResolver, ENABLED_ACCESSIBILITY_SERVICES)
        ).isEmpty();
    }

    @Test
    @EnableFlags(Flags.FLAG_UPDATE_ALWAYS_ON_A11Y_SERVICE)
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void turnOffVolumeShortcutForAlwaysOnA11yService_hasOtherTypesShortcut_shouldNotTurnOffA11yService()
            throws Exception {
        configureApplicationTargetSdkVersion(Build.VERSION_CODES.R);
        Settings.Secure.putString(
                mContentResolver, ACCESSIBILITY_BUTTON_TARGETS, SERVICE_NAME_STRING);

        turnOffVolumeKeyShortcutForA11yService(/* alwaysOnService= */ true);

        assertThat(
                Settings.Secure.getString(mContentResolver, ENABLED_ACCESSIBILITY_SERVICES)
        ).isEqualTo(SERVICE_NAME_STRING);
    }

    @Test
    public void turnOffVolumeShortcutForStandardA11yService_shouldNotTurnOffA11yService()
            throws Exception {
@@ -530,7 +475,6 @@ public class AccessibilityShortcutControllerTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testTurnOnDefaultA11yServiceInDialog_defaultServiceShortcutTurnsOn()
            throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
@@ -554,30 +498,6 @@ public class AccessibilityShortcutControllerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testTurnOnDefaultA11yServiceInDialog_defaultServiceShortcutTurnsOn_old()
            throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
        configureDefaultAccessibilityService();
        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
        getController().performAccessibilityShortcut();

        ArgumentCaptor<DialogInterface.OnClickListener> captor =
                ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
        verify(mAlertDialogBuilder).setNegativeButton(eq(R.string.accessibility_shortcut_on),
                captor.capture());
        captor.getValue().onClick(null, DialogInterface.BUTTON_NEGATIVE);

        assertThat(Settings.Secure.getString(mContentResolver,
                ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)).isEqualTo(SERVICE_NAME_STRING);
        assertThat(Settings.Secure.getInt(
                mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN)).isEqualTo(
                AccessibilityShortcutController.DialogStatus.SHOWN);
    }

    @Test
    @EnableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testTurnOffDefaultA11yServiceInDialog_defaultServiceShortcutTurnsOff()
            throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
@@ -600,29 +520,6 @@ public class AccessibilityShortcutControllerTest {
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testTurnOffDefaultA11yServiceInDialog_defaultServiceShortcutTurnsOff_old()
            throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
        configureDefaultAccessibilityService();
        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
        getController().performAccessibilityShortcut();

        ArgumentCaptor<DialogInterface.OnClickListener> captor =
                ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
        verify(mAlertDialogBuilder).setPositiveButton(eq(R.string.accessibility_shortcut_off),
                captor.capture());
        captor.getValue().onClick(null, DialogInterface.BUTTON_POSITIVE);

        assertThat(Settings.Secure.getString(mContentResolver,
                ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)).isEmpty();
        assertThat(Settings.Secure.getInt(
                mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN)).isEqualTo(
                AccessibilityShortcutController.DialogStatus.NOT_SHOWN);
    }

    @Test
    public void testOnAccessibilityShortcut_afterDialogShown_shouldCallServer() throws Exception {
        configureShortcutEnabled(ENABLED_EXCEPT_LOCK_SCREEN);
@@ -638,9 +535,7 @@ public class AccessibilityShortcutControllerTest {
    }

    @Test
    @EnableFlags({
            Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS,
            Flags.FLAG_RESTORE_A11Y_SHORTCUT_TARGET_SERVICE})
    @EnableFlags(Flags.FLAG_RESTORE_A11Y_SHORTCUT_TARGET_SERVICE)
    public void testOnAccessibilityShortcut_settingNull_dialogShown_enablesDefaultShortcut()
            throws Exception {
        configureDefaultAccessibilityService();
@@ -657,24 +552,6 @@ public class AccessibilityShortcutControllerTest {
                Display.DEFAULT_DISPLAY, HARDWARE, null);
    }

    @Test
    @EnableFlags(Flags.FLAG_RESTORE_A11Y_SHORTCUT_TARGET_SERVICE)
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void testOnAccessibilityShortcut_settingNull_dialogShown_writesDefaultSetting()
            throws Exception {
        configureDefaultAccessibilityService();
        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN,
                AccessibilityShortcutController.DialogStatus.SHOWN);
        // Setting is only `null` during SUW.
        Settings.Secure.putString(mContentResolver, ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, null);
        getController().performAccessibilityShortcut();

        assertThat(Settings.Secure.getString(mContentResolver,
                ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)).isEqualTo(SERVICE_NAME_STRING);
        verify(mAccessibilityManagerService).performAccessibilityShortcut(
                Display.DEFAULT_DISPLAY, HARDWARE, null);
    }

    @Test
    public void getFrameworkFeatureMap_shouldBeUnmodifiable() {
        final Map<ComponentName, AccessibilityShortcutController.FrameworkFeatureInfo>
+0 −91
Original line number Diff line number Diff line
@@ -33,12 +33,7 @@ import android.content.pm.ParceledListSlice;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import android.view.accessibility.IAccessibilityManager;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -67,8 +62,6 @@ import java.util.List;
 */
@RunWith(AndroidJUnit4.class)
public class InvisibleToggleAccessibilityServiceTargetTest {
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    @Rule
    public FakeSettingsProviderRule mSettingsProviderRule = FakeSettingsProvider.rule();
    @Mock
@@ -117,7 +110,6 @@ public class InvisibleToggleAccessibilityServiceTargetTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_true_callA11yManagerToUpdateShortcuts() throws Exception {
        mSut.onCheckedChanged(true);

@@ -130,7 +122,6 @@ public class InvisibleToggleAccessibilityServiceTargetTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_false_callA11yManagerToUpdateShortcuts() throws Exception {
        mSut.onCheckedChanged(false);
        verify(mAccessibilityManagerService).enableShortcutsForTargets(
@@ -140,86 +131,4 @@ public class InvisibleToggleAccessibilityServiceTargetTest {
                anyInt());
        assertThat(mListCaptor.getValue()).containsExactly(ALWAYS_ON_SERVICE_COMPONENT_NAME);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_turnOnShortcut_hasOtherShortcut_serviceKeepsOn() {
        enableA11yService(/* enable= */ true);
        addShortcutForA11yService(
                Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, /* add= */ false);
        addShortcutForA11yService(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, /* add= */ true);

        mSut.onCheckedChanged(/* isChecked= */ true);

        assertA11yServiceState(/* enabled= */ true);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_turnOnShortcut_noOtherShortcut_shouldTurnOnService() {
        enableA11yService(/* enable= */ false);
        addShortcutForA11yService(
                Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, /* add= */ false);
        addShortcutForA11yService(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, /* add= */ false);

        mSut.onCheckedChanged(/* isChecked= */ true);

        assertA11yServiceState(/* enabled= */ true);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_turnOffShortcut_hasOtherShortcut_serviceKeepsOn() {
        enableA11yService(/* enable= */ true);
        addShortcutForA11yService(
                Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, /* add= */ true);
        addShortcutForA11yService(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, /* add= */ true);

        mSut.onCheckedChanged(/* isChecked= */ false);

        assertA11yServiceState(/* enabled= */ true);
    }

    @Test
    @DisableFlags(Flags.FLAG_MIGRATE_ENABLE_SHORTCUTS)
    public void onCheckedChanged_turnOffShortcut_noOtherShortcut_shouldTurnOffService() {
        enableA11yService(/* enable= */ true);
        addShortcutForA11yService(
                Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, /* add= */ true);
        addShortcutForA11yService(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, /* add= */ false);

        mSut.onCheckedChanged(/* isChecked= */ false);

        assertA11yServiceState(/* enabled= */ false);
    }

    private void enableA11yService(boolean enable) {
        Settings.Secure.putString(
                mContextSpy.getContentResolver(),
                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                enable ? ALWAYS_ON_SERVICE_COMPONENT_NAME : "");
    }

    private void addShortcutForA11yService(String shortcutKey, boolean add) {
        Settings.Secure.putString(
                mContextSpy.getContentResolver(),
                shortcutKey,
                add ? ALWAYS_ON_SERVICE_COMPONENT_NAME : "");
    }

    private void assertA11yServiceState(boolean enabled) {
        if (enabled) {
            assertThat(
                    Settings.Secure.getString(
                            mContextSpy.getContentResolver(),
                            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES)
            ).contains(ALWAYS_ON_SERVICE_COMPONENT_NAME);
        } else {
            assertThat(
                    Settings.Secure.getString(
                            mContextSpy.getContentResolver(),
                            Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES)
            ).doesNotContain(ALWAYS_ON_SERVICE_COMPONENT_NAME);
        }
    }
}