Move the default shortcut types in a separate utility method.
Bug: 322701168
Test: atest
Flag: N/A (Strict mechanical refactors, no behavior change)
Change-Id: I1beb36e5aeeec0f303228b57baf034a000a72b75
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 81f3fa8..09a691e 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -272,7 +272,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
+ getComponentName().flattenToString());
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
getComponentName());
@@ -449,7 +449,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
- getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
+ getComponentName().flattenToString());
final List<CharSequence> list = new ArrayList<>();
@@ -477,8 +477,8 @@
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
- getPrefContext(), getComponentName().flattenToString(),
- AccessibilityUtil.UserShortcutType.SOFTWARE);
+ getPrefContext(), getComponentName().flattenToString()
+ );
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: AccessibilityUtil.UserShortcutType.EMPTY;
}
@@ -519,7 +519,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- getComponentName().flattenToString(), AccessibilityUtil.UserShortcutType.SOFTWARE);
+ getComponentName().flattenToString());
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
getComponentName()));
diff --git a/src/com/android/settings/accessibility/PreferredShortcuts.java b/src/com/android/settings/accessibility/PreferredShortcuts.java
index d4e8e0c..e76bc9b 100644
--- a/src/com/android/settings/accessibility/PreferredShortcuts.java
+++ b/src/com/android/settings/accessibility/PreferredShortcuts.java
@@ -39,27 +39,25 @@
private static final String USER_SHORTCUT_TYPE = "user_shortcut_type";
/**
- * Retrieves {@link UserShortcutType} for the given {@code componentName} from
+ * Retrieves the user preferred shortcut types for the given {@code componentName} from
* SharedPreferences.
*
* @param context {@link Context} to access the {@link SharedPreferences}
* @param componentName Name of the service or activity, should be the format of {@link
* ComponentName#flattenToString()}.
- * @param defaultType See {@link UserShortcutType}
- * @return {@link UserShortcutType}
+ * @return {@link ShortcutConstants.UserShortcutType}
*/
- public static int retrieveUserShortcutType(Context context, String componentName,
- int defaultType) {
- if (componentName == null) {
- return defaultType;
- }
+ @ShortcutConstants.UserShortcutType
+ public static int retrieveUserShortcutType(
+ @NonNull Context context, @NonNull String componentName) {
+ final int defaultTypes = getDefaultPreferredShortcutTypesForTarget(componentName);
// Create a mutable set to modify
final Set<String> info = new HashSet<>(getFromSharedPreferences(context));
info.removeIf(str -> !str.contains(componentName));
if (info.isEmpty()) {
- return defaultType;
+ return defaultTypes;
}
final String str = info.stream().findFirst().get();
@@ -140,5 +138,14 @@
return context.getSharedPreferences(ACCESSIBILITY_PERF, Context.MODE_PRIVATE);
}
+ /**
+ * Returns the default shortcut types for the given accessibility feature.
+ */
+ @ShortcutConstants.UserShortcutType
+ private static int getDefaultPreferredShortcutTypesForTarget(@NonNull String componentName) {
+ // TODO (b/322712028): return different default shortcut types for the given component
+ return ShortcutConstants.UserShortcutType.SOFTWARE;
+ }
+
private PreferredShortcuts() {}
}
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index f312098..0b5ad3e 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -47,7 +47,6 @@
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
-import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragment;
import com.android.settingslib.accessibility.AccessibilityUtils;
@@ -331,7 +330,7 @@
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
- mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mComponentName.flattenToString());
if (preference.isChecked()) {
final boolean isWarningRequired;
if (android.view.accessibility.Flags.cleanupAccessibilityWarningDialog()) {
@@ -508,7 +507,7 @@
mShortcutPreference.setChecked(true);
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
- mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mComponentName.flattenToString());
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mIsDialogShown.set(false);
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index fc0acfe..e7835f8 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -658,7 +658,7 @@
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
- getPrefContext(), mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ getPrefContext(), mComponentName.flattenToString());
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -708,7 +708,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
- mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mComponentName.flattenToString());
final List<CharSequence> list = new ArrayList<>();
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
@@ -801,7 +801,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mComponentName.flattenToString());
mShortcutPreference.setChecked(
AccessibilityUtil.hasValuesInSettings(getPrefContext(), shortcutTypes,
mComponentName));
@@ -819,7 +819,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mComponentName.flattenToString());
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName);
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index b948194..023556c 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -386,7 +386,7 @@
int value = restoreOnConfigChangedValue();
if (value == NOT_SET) {
final int lastNonEmptyUserShortcutType = PreferredShortcuts.retrieveUserShortcutType(
- getPrefContext(), MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ getPrefContext(), MAGNIFICATION_CONTROLLER_NAME);
value = mShortcutPreference.isChecked() ? lastNonEmptyUserShortcutType
: UserShortcutType.EMPTY;
}
@@ -460,7 +460,7 @@
}
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(context,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
final List<CharSequence> list = new ArrayList<>();
if (hasShortcutType(shortcutTypes, UserShortcutType.SOFTWARE)) {
@@ -574,7 +574,7 @@
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
@@ -629,7 +629,7 @@
@Override
protected void updateShortcutPreference() {
final int shortcutTypes = PreferredShortcuts.retrieveUserShortcutType(getPrefContext(),
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
index 179c647..4607a59 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
@@ -110,7 +110,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.getComponentName().flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.getComponentName().flattenToString());
// Compare to default UserShortcutType
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE);
}
@@ -123,7 +123,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.getComponentName().flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.getComponentName().flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE);
}
@@ -136,7 +136,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.getComponentName().flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.getComponentName().flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE);
}
@@ -201,7 +201,7 @@
mFragment.saveNonEmptyUserShortcutType(value);
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.getComponentName().flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.getComponentName().flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index 2c59c26..70c7cd6 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -169,7 +169,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.mComponentName.flattenToString());
// Compare to default UserShortcutType
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE);
}
@@ -185,7 +185,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.mComponentName.flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE);
}
@@ -199,7 +199,7 @@
mFragment.updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.mComponentName.flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE);
}
@@ -281,7 +281,7 @@
mFragment.saveNonEmptyUserShortcutType(value);
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- mFragment.mComponentName.flattenToString(), UserShortcutType.SOFTWARE);
+ mFragment.mComponentName.flattenToString());
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
index 05dc8fa..4c49395 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
@@ -374,7 +374,7 @@
mFragController.get().updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
// Compare to default UserShortcutType
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE);
}
@@ -388,7 +388,7 @@
mFragController.get().updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(expectedType).isEqualTo(UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP);
}
@@ -402,7 +402,7 @@
mFragController.get().updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(expectedType).isEqualTo(UserShortcutType.TRIPLETAP);
}
@@ -416,7 +416,7 @@
mFragController.get().updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
}
@@ -431,7 +431,7 @@
mFragController.get().updateShortcutPreferenceData();
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
}
@@ -507,7 +507,7 @@
fragment.saveNonEmptyUserShortcutType(value);
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(value).isEqualTo(6);
assertThat(expectedType).isEqualTo(UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP);
}
@@ -529,7 +529,7 @@
fragment.saveNonEmptyUserShortcutType(value);
final int expectedType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- MAGNIFICATION_CONTROLLER_NAME, UserShortcutType.SOFTWARE);
+ MAGNIFICATION_CONTROLLER_NAME);
assertThat(value).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
assertThat(expectedType).isEqualTo(UserShortcutType.TWOFINGERTRIPLETAP);
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragmentTest.java
index 7586954..13f0b24 100644
--- a/tests/robotests/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/shortcuts/EditShortcutsPreferenceFragmentTest.java
@@ -378,7 +378,7 @@
mFragmentScenario.moveToState(Lifecycle.State.CREATED);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
+ mContext, TARGET)
).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
// Update the chosen shortcut type to Volume keys while the fragment is in the background
ShortcutUtils.optInValueToSettings(
@@ -388,7 +388,7 @@
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
+ mContext, TARGET)
).isEqualTo(ShortcutConstants.UserShortcutType.HARDWARE);
}
@@ -398,7 +398,7 @@
mFragmentScenario.moveToState(Lifecycle.State.CREATED);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
+ mContext, TARGET)
).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
ShortcutUtils.optInValueToSettings(
@@ -408,7 +408,7 @@
mFragmentScenario.onFragment(fragment ->
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
+ mContext, TARGET)
).isEqualTo(ShortcutConstants.UserShortcutType.HARDWARE)
);
diff --git a/tests/unit/src/com/android/settings/accessibility/PreferredShortcutsTest.java b/tests/unit/src/com/android/settings/accessibility/PreferredShortcutsTest.java
index e7dfb5b..e3c07ef 100644
--- a/tests/unit/src/com/android/settings/accessibility/PreferredShortcutsTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/PreferredShortcutsTest.java
@@ -75,7 +75,7 @@
PreferredShortcuts.saveUserShortcutType(mContext, shortcut);
final int retrieveType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- COMPONENT_NAME_1.flattenToString(), 0);
+ COMPONENT_NAME_1.flattenToString());
assertThat(retrieveType).isEqualTo(type);
}
@@ -92,7 +92,7 @@
PreferredShortcuts.saveUserShortcutType(mContext, shortcut1);
PreferredShortcuts.saveUserShortcutType(mContext, shortcut2);
final int retrieveType = PreferredShortcuts.retrieveUserShortcutType(mContext,
- COMPONENT_NAME_1.flattenToString(), 0);
+ COMPONENT_NAME_1.flattenToString());
assertThat(retrieveType).isEqualTo(type1);
}
@@ -113,8 +113,8 @@
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, MAGNIFICATION_CONTROLLER_NAME,
- ShortcutConstants.UserShortcutType.SOFTWARE))
+ mContext, MAGNIFICATION_CONTROLLER_NAME
+ ))
.isEqualTo(expectedShortcutTypes);
}
@@ -132,8 +132,8 @@
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, MAGNIFICATION_CONTROLLER_NAME,
- ShortcutConstants.UserShortcutType.SOFTWARE))
+ mContext, MAGNIFICATION_CONTROLLER_NAME
+ ))
.isEqualTo(expectedShortcutTypes);
}
@@ -156,13 +156,13 @@
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, target1,
- ShortcutConstants.UserShortcutType.SOFTWARE))
+ mContext, target1
+ ))
.isEqualTo(target1ShortcutTypes);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
- mContext, target2,
- ShortcutConstants.UserShortcutType.SOFTWARE))
+ mContext, target2
+ ))
.isEqualTo(target2ShortcutTypes);
}