Show QS shortcut option if the a11y feature provides a tile.
Bug: 314852953 Test: atest com.android.settings.accessibility Test: atest com.android.settings.accessibility.shortcuts Test: manual Flag: ACONFIG android.view.accessibility.a11y_qs_shortcut STAGING Change-Id: Id7a6b3adfd4c4f3cb2b9f7fe15269b57a3d00543
This commit is contained in:
@@ -18,6 +18,10 @@ package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -25,20 +29,30 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
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 androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.internal.accessibility.util.ShortcutUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.testutils.AccessibilityTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -55,14 +69,18 @@ public final class AccessibilityUtilTest {
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
|
||||
private static final String HARDWARE_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||
private static final String QUICK_SETTINGS_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_QS_TARGETS;
|
||||
|
||||
private static final String PLACEHOLDER_SETTING_FEATURE = "placeholderSettingFeature";
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,11 +169,12 @@ public final class AccessibilityUtilTest {
|
||||
public void getUserShortcutTypeFromSettings_putOneValue_hasValue() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
MOCK_COMPONENT_NAME);
|
||||
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
||||
assertThat(shortcutTypes).isEqualTo(
|
||||
UserShortcutType.SOFTWARE
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,16 +182,34 @@ public final class AccessibilityUtilTest {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
final int shortcutType = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
MOCK_COMPONENT_NAME);
|
||||
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE).isTrue();
|
||||
assertThat(
|
||||
(shortcutType & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE).isTrue();
|
||||
assertThat(shortcutTypes).isEqualTo(
|
||||
UserShortcutType.SOFTWARE
|
||||
| UserShortcutType.HARDWARE
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void getUserShortcutTypeFromSettings_threeShortcutTypesChosen() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
setShortcut(UserShortcutType.QUICK_SETTINGS, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
final int shortcutTypes = AccessibilityUtil.getUserShortcutTypesFromSettings(mContext,
|
||||
MOCK_COMPONENT_NAME);
|
||||
|
||||
assertThat(shortcutTypes).isEqualTo(
|
||||
UserShortcutType.SOFTWARE
|
||||
| UserShortcutType.HARDWARE
|
||||
| UserShortcutType.QUICK_SETTINGS
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||
clearShortcuts();
|
||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
||||
@@ -187,6 +224,24 @@ public final class AccessibilityUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optInAllValuesToSettings_optInValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE
|
||||
| UserShortcutType.QUICK_SETTINGS;
|
||||
|
||||
AccessibilityUtil.optInAllValuesToSettings(mContext, shortcutTypes, MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ true, shortcutTypes,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optInValueToSettings_optInValue_haveMatchString() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
@@ -199,6 +254,23 @@ public final class AccessibilityUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optInValueToSettings_optInValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME2.flattenToString());
|
||||
|
||||
AccessibilityUtil.optInValueToSettings(
|
||||
mContext, UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME2);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ true, UserShortcutType.HARDWARE,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optInValueToSettings_optInTwoValues_haveMatchString() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
@@ -213,6 +285,7 @@ public final class AccessibilityUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
setShortcut(UserShortcutType.HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
@@ -227,6 +300,27 @@ public final class AccessibilityUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optOutAllValuesToSettings_optOutValue_callsA1yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
int shortcutTypes =
|
||||
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE
|
||||
| UserShortcutType.QUICK_SETTINGS;
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(mContext, shortcutTypes,
|
||||
MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ false,
|
||||
shortcutTypes,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optOutValueFromSettings_optOutValue_emptyString() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
@@ -237,6 +331,7 @@ public final class AccessibilityUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optOutValueFromSettings_optOutValue_haveMatchString() {
|
||||
setShortcut(UserShortcutType.SOFTWARE, MOCK_COMPONENT_NAME.flattenToString(),
|
||||
MOCK_COMPONENT_NAME2.flattenToString());
|
||||
@@ -248,6 +343,55 @@ public final class AccessibilityUtilTest {
|
||||
MOCK_COMPONENT_NAME.flattenToString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void optOutValueFromSettings_optOutValue_callsA11yManager() {
|
||||
AccessibilityManager a11yManager =
|
||||
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
|
||||
Set<String> shortcutTargets = Set.of(MOCK_COMPONENT_NAME.flattenToString());
|
||||
|
||||
AccessibilityUtil.optOutValueFromSettings(
|
||||
mContext, UserShortcutType.QUICK_SETTINGS, MOCK_COMPONENT_NAME);
|
||||
|
||||
verify(a11yManager).enableShortcutsForTargets(
|
||||
/* enable= */ false, UserShortcutType.QUICK_SETTINGS,
|
||||
shortcutTargets, UserHandle.myUserId());
|
||||
verifyNoMoreInteractions(a11yManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertKeyFromSettings_shortcutTypeSoftware() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.SOFTWARE))
|
||||
.isEqualTo(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertKeyFromSettings_shortcutTypeHardware() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.HARDWARE))
|
||||
.isEqualTo(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertKeyFromSettings_shortcutTypeTripleTap() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.TRIPLETAP))
|
||||
.isEqualTo(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void convertKeyFromSettings_shortcutTypeMultiFingersMultiTap() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.TWOFINGER_DOUBLETAP))
|
||||
.isEqualTo(
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
|
||||
public void convertKeyFromSettings_shortcutTypeQuickSettings() {
|
||||
assertThat(AccessibilityUtil.convertKeyFromSettings(UserShortcutType.QUICK_SETTINGS))
|
||||
.isEqualTo(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
|
||||
}
|
||||
|
||||
private AccessibilityServiceInfo getMockAccessibilityServiceInfo() {
|
||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
final ServiceInfo serviceInfo = new ServiceInfo();
|
||||
@@ -287,12 +431,12 @@ public final class AccessibilityUtilTest {
|
||||
shortcutComponents.add(componentName);
|
||||
}
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
shortcutType == UserShortcutType.SOFTWARE ? SOFTWARE_SHORTCUT_KEY
|
||||
: HARDWARE_SHORTCUT_KEY, shortcutComponents.toString());
|
||||
ShortcutUtils.convertToKey(shortcutType), shortcutComponents.toString());
|
||||
}
|
||||
|
||||
private void clearShortcuts() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(), SOFTWARE_SHORTCUT_KEY, "");
|
||||
Settings.Secure.putString(mContext.getContentResolver(), HARDWARE_SHORTCUT_KEY, "");
|
||||
Settings.Secure.putString(mContext.getContentResolver(), QUICK_SETTINGS_SHORTCUT_KEY, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user