Save the user preferred shortcut on Edit A11yShortcut screen

We saved the user preferred shortcut in the a11y feature's detail page.
Since now the Edit A11yShortcut screen is a standalone screen, we might
want to keep the existing behavior to update the user preferred shortcut
types when the edit screen is shown or when the shortcut settings are
updated.

Bug: 300302098
Test: atest
Test: manual
    - Go to an a11y feature page and open the Edit shortcut screen
    - Remove all selected shortcut option
    - Select volume key shortcut option, and deselect volume key
      shortcut option
    - Go to home page and close the Settings app
    - Go to the same a11y feature page and click on the shortcut toggle
    - Expect the volume key shortcut is turned on
Flag: ACONFIG
com.android.settings.accessibility.edit_shortcuts_in_full_screen
TRUNKFOOD

Change-Id: I2c92ec56d6e45317406f3a4b8ef8f076c398df7f
This commit is contained in:
Chun-Ku Lin
2024-01-25 01:22:35 +00:00
parent 8eb26342de
commit f9ae13a73d
4 changed files with 202 additions and 1 deletions

View File

@@ -16,17 +16,30 @@
package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import static com.google.common.truth.Truth.assertThat;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.util.ShortcutUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Set;
/** Tests for {@link PreferredShortcuts} */
@RunWith(AndroidJUnit4.class)
public class PreferredShortcutsTest {
@@ -39,8 +52,20 @@ public class PreferredShortcutsTest {
private static final String CLASS_NAME_2 = PACKAGE_NAME_2 + ".test2";
private static final ComponentName COMPONENT_NAME_2 = new ComponentName(PACKAGE_NAME_2,
CLASS_NAME_2);
private static final ContentResolver sContentResolver =
ApplicationProvider.getApplicationContext().getContentResolver();
private Context mContext = ApplicationProvider.getApplicationContext();
private final Context mContext = ApplicationProvider.getApplicationContext();
@Before
public void setUp() {
clearShortcuts();
}
@AfterClass
public static void cleanUp() {
clearShortcuts();
}
@Test
public void retrieveUserShortcutType_fromSingleData_matchSavedType() {
@@ -71,4 +96,88 @@ public class PreferredShortcutsTest {
assertThat(retrieveType).isEqualTo(type1);
}
@Test
public void updatePreferredShortcutsFromSetting_magnificationWithTripleTapAndVolumeKeyShortcuts_preferredShortcutsMatches() {
ShortcutUtils.optInValueToSettings(mContext, ShortcutConstants.UserShortcutType.HARDWARE,
MAGNIFICATION_CONTROLLER_NAME);
Settings.Secure.putInt(
sContentResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
AccessibilityUtil.State.ON);
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext,
Set.of(MAGNIFICATION_CONTROLLER_NAME));
int expectedShortcutTypes = ShortcutConstants.UserShortcutType.HARDWARE
| ShortcutConstants.UserShortcutType.TRIPLETAP;
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, MAGNIFICATION_CONTROLLER_NAME,
ShortcutConstants.UserShortcutType.SOFTWARE))
.isEqualTo(expectedShortcutTypes);
}
@Test
public void updatePreferredShortcutsFromSetting_magnificationWithNoActiveShortcuts_noChangesOnPreferredShortcutTypes() {
int expectedShortcutTypes = ShortcutConstants.UserShortcutType.HARDWARE
| ShortcutConstants.UserShortcutType.SOFTWARE;
PreferredShortcuts.saveUserShortcutType(mContext,
new PreferredShortcut(MAGNIFICATION_CONTROLLER_NAME, expectedShortcutTypes));
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext,
Set.of(MAGNIFICATION_CONTROLLER_NAME));
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, MAGNIFICATION_CONTROLLER_NAME,
ShortcutConstants.UserShortcutType.SOFTWARE))
.isEqualTo(expectedShortcutTypes);
}
@Test
public void updatePreferredShortcutsFromSetting_multipleComponents_preferredShortcutsMatches() {
String target1 = COLOR_INVERSION_COMPONENT_NAME.flattenToString();
String target2 = DALTONIZER_COMPONENT_NAME.flattenToString();
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, target1);
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
target1 + ShortcutConstants.SERVICES_SEPARATOR + target2);
int target1ShortcutTypes = ShortcutConstants.UserShortcutType.HARDWARE
| ShortcutConstants.UserShortcutType.SOFTWARE;
int target2ShortcutTypes = ShortcutConstants.UserShortcutType.HARDWARE;
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext, Set.of(target1, target2));
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, target1,
ShortcutConstants.UserShortcutType.SOFTWARE))
.isEqualTo(target1ShortcutTypes);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, target2,
ShortcutConstants.UserShortcutType.SOFTWARE))
.isEqualTo(target2ShortcutTypes);
}
private static void clearShortcuts() {
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "");
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "");
Settings.Secure.putInt(
sContentResolver,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
AccessibilityUtil.State.OFF);
Settings.Secure.putInt(
sContentResolver,
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
AccessibilityUtil.State.OFF);
}
}