Make QS shortcut type as default preferred shortcut for A11yService that

associate with a TileService

Bug: 322712028
Test: manual (Turn on the shortcut for the first time for various
feature with or without tile. Verify only the A11yService with tile
would show QS as the shortcut when directly turn on the main shortcut
toggle)
Test: atest com.android.settings.accessibility

Flag: aconfig android.view.accessibility.a11y_qs_shortcut
Change-Id: I569b417639d2db8b7eddd818a2b9037ed4be2509
This commit is contained in:
Chun-Ku Lin
2024-03-16 01:13:16 +00:00
parent 71ebe0f959
commit 5cdf972b50
5 changed files with 231 additions and 32 deletions

View File

@@ -42,7 +42,8 @@ public final class PreferredShortcuts {
/**
* Retrieves the user preferred shortcut types for the given {@code componentName} from
* SharedPreferences.
* SharedPreferences. If the user doesn't have a preferred shortcut,
* {@link ShortcutConstants.UserShortcutType.SOFTWARE} is returned.
*
* @param context {@link Context} to access the {@link SharedPreferences}
* @param componentName Name of the service or activity, should be the format of {@link
@@ -52,7 +53,26 @@ public final class PreferredShortcuts {
@ShortcutConstants.UserShortcutType
public static int retrieveUserShortcutType(
@NonNull Context context, @NonNull String componentName) {
final int defaultTypes = getDefaultPreferredShortcutTypesForTarget(componentName);
return retrieveUserShortcutType(
context, componentName, ShortcutConstants.UserShortcutType.SOFTWARE);
}
/**
* 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 defaultTypes The default shortcut types to use if the user doesn't have a
* preferred shortcut.
* @return {@link ShortcutConstants.UserShortcutType}
*/
@ShortcutConstants.UserShortcutType
public static int retrieveUserShortcutType(
@NonNull Context context,
@NonNull String componentName,
@ShortcutConstants.UserShortcutType int defaultTypes) {
// Create a mutable set to modify
final Set<String> info = new HashSet<>(getFromSharedPreferences(context));
@@ -150,14 +170,5 @@ public final class PreferredShortcuts {
getSharedPreferences(context).edit().clear().apply();
}
/**
* 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() {}
}