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

@@ -51,6 +51,7 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.accessibility.AccessibilityUtil;
import com.android.settings.accessibility.PreferredShortcuts;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -369,6 +370,50 @@ public class EditShortcutsPreferenceFragmentTest {
});
}
@Test
public void fragmentResumed_preferredShortcutsUpdated() {
mFragmentScenario = createFragScenario(/* isInSuw= */ false);
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
// Move the fragment to the background
mFragmentScenario.moveToState(Lifecycle.State.CREATED);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
// Update the chosen shortcut type to Volume keys while the fragment is in the background
ShortcutUtils.optInValueToSettings(
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET);
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
).isEqualTo(ShortcutConstants.UserShortcutType.HARDWARE);
}
@Test
public void onVolumeKeysShortcutSettingChanged_preferredShortcutsUpdated() {
mFragmentScenario = createFragScenario(/* isInSuw= */ false);
mFragmentScenario.moveToState(Lifecycle.State.CREATED);
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
).isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
ShortcutUtils.optInValueToSettings(
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET);
// Calls onFragment so that the change to Setting is notified to its observer
mFragmentScenario.onFragment(fragment ->
assertThat(
PreferredShortcuts.retrieveUserShortcutType(
mContext, TARGET, ShortcutConstants.UserShortcutType.SOFTWARE)
).isEqualTo(ShortcutConstants.UserShortcutType.HARDWARE)
);
}
private void assertLaunchSubSettingWithCurrentTargetComponents(
String componentName, boolean isInSuw) {
Intent intent = shadowOf(mActivity.getApplication()).getNextStartedActivity();