Write default accessibility service only when user enter into corresponding page.

Based on ag/17463205, to help users not to mis-triggered
volume-key-accessibility shortcut, we will only write default
accessibility service when user enter into corresponding service page.

Fix: 228562075
Fix: 226866175
Test: manual test ->
      1. Do not enter into default config accessibility service page during setup wizard then finish setup wizard.
      2. Observe settings value of shortcut targets. It should be null.
Change-Id: I4f26598d646c8e6b312debd03eaaa9d2cd7010ea
This commit is contained in:
jasonwshsu
2022-04-08 17:33:31 +08:00
parent ca73aa40ef
commit 2f2f0e982f

View File

@@ -157,7 +157,6 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
}
}
setupDefaultShortcutIfNecessary(getPrefContext());
final int resId = getPreferenceScreenResId();
if (resId <= 0) {
final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
@@ -226,6 +225,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
if (mNeedsQSTooltipReshow) {
getView().post(this::showQuickSettingsTooltipIfNeeded);
}
writeDefaultShortcutTargetServiceToSettingsIfNeeded(getPrefContext());
}
@Override
@@ -788,8 +789,22 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
/**
* Setups a configurable default if the setting has never been set.
*
* TODO(b/228562075): Remove this function when correcting the format in config file
* `config_defaultAccessibilityService`.
*/
private static void setupDefaultShortcutIfNecessary(Context context) {
private void writeDefaultShortcutTargetServiceToSettingsIfNeeded(Context context) {
if (mComponentName == null) {
return;
}
final ComponentName defaultService = ComponentName.unflattenFromString(context.getString(
com.android.internal.R.string.config_defaultAccessibilityService));
// write default accessibility service only when user enter into corresponding page.
if (!mComponentName.equals(defaultService)) {
return;
}
final String targetKey = Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
String targetString = Settings.Secure.getString(context.getContentResolver(), targetKey);
if (!TextUtils.isEmpty(targetString)) {