Pass user preferred shortcut types when launching the

AccessibilityShortcutsTutorial.

**Root cause**
When toggle the shortcut, it asks the AccessibilityManager to turn on
the shortcut and update the Settings data. Internally, the
AccessibilityManager delegate the work to AccessibilityManagerService
via a oneway binder call.

In the past, when launching the AccessibilityShortcutsTutorial, we
assume the shortcut selection are saved in the Settings before launching
the AccessibilityShortcutsTutorial. So we pass whatever are in the
Settings as what the user has selected to the tutorial.
This is not true anymore since we use the oneway AIDL call to do the
updates. The data in Settings may not yet be  updated before we use it to
launch the tutorial.

Since the user preferred shortcuts are always set before we attempt to
launch the AccessibilityShortcutsTutorial, we can rely on it instead of
the Settings value to launch the AccessibilityShortcutsTutorial for the
selected shortcut options.

**Changes in this cl**
- Mechanical refactor to extract the lines to get the user preferred
  shortcut into a method.

- Use the new method to grab the shortcut options to pass to the
  AccessibilityShortcutsTutorial to prevent the crash.

Bug: 341176890
Test: manual
    - Modify the AccessibilityManagerService locally to delay processing
      the request to update the shortcut options in Settings data
    - Turn on the shortcut toggle, and verify the app won't crash

Test: atest com.android.settings.accessibility
Flag: EXEMPT bugfix (low risk + mechanical refactor)
Change-Id: Id3cc4cc5f6667061545955881632544472aedd95
This commit is contained in:
Chun-Ku Lin
2024-05-21 23:33:55 +00:00
parent f60595d0d5
commit 09efbe453c
4 changed files with 42 additions and 30 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
import static com.android.settings.accessibility.PreferredShortcuts.retrieveUserShortcutType;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.AlertDialog;
@@ -327,8 +326,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override
public void onToggleClicked(ShortcutPreference preference) {
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
if (preference.isChecked()) {
final boolean isWarningRequired =
getPrefContext().getSystemService(AccessibilityManager.class)
@@ -507,8 +505,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
void onAllowButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(true);
final int shortcutTypes = retrieveUserShortcutType(getPrefContext(),
mComponentName.flattenToString(), getDefaultShortcutTypes());
final int shortcutTypes = getUserPreferredShortcutTypes();
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
mIsDialogShown.set(false);