Set default value of accessibility button mode

Set floating menu mode by default, but if the user uses accessibility button in the navigation bar to trigger their accessibility features before migration, then set it to keep the navigation button mode.

Cherry picked from commit a87f05d552

Bug: 173940304
Test: 1. Push old version of db and apk
      2. Enable/Disable accessibility features in navigation bar
      3. Push new version of db and apk
Change-Id: I465eb2190f0e1ca9a6a6be928752a07d5e9576da
Merged-In: I465eb2190f0e1ca9a6a6be928752a07d5e9576da
This commit is contained in:
jasonwshsu
2021-03-08 18:10:35 +08:00
parent e24d701f4c
commit 12e09d1017
2 changed files with 45 additions and 1 deletions

View File

@@ -252,4 +252,8 @@
<!-- Default for Settings.Global.DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW -->
<bool name="def_enable_non_resizable_multi_window">true</bool>
<!-- Default for Settings.Secure.ACCESSIBILITY_BUTTON_MODE -->
<integer name="def_accessibility_button_mode">1</integer>
</resources>

View File

@@ -3399,7 +3399,7 @@ public class SettingsProvider extends ContentProvider {
}
private final class UpgradeController {
private static final int SETTINGS_VERSION = 198;
private static final int SETTINGS_VERSION = 199;
private final int mUserId;
@@ -4897,6 +4897,36 @@ public class SettingsProvider extends ContentProvider {
currentVersion = 198;
}
if (currentVersion == 198) {
// Version 198: Set the default value for accessibility button. If the user
// uses accessibility button in the navigation bar to trigger their
// accessibility features (check if ACCESSIBILITY_BUTTON_TARGETS has value)
// then leave accessibility button mode in the navigation bar, otherwise, set it
// to the floating menu.
final SettingsState secureSettings = getSecureSettingsLocked(userId);
final Setting accessibilityButtonMode = secureSettings.getSettingLocked(
Secure.ACCESSIBILITY_BUTTON_MODE);
if (accessibilityButtonMode.isNull()) {
if (isAccessibilityButtonInNavigationBarOn(secureSettings)) {
secureSettings.insertSettingLocked(Secure.ACCESSIBILITY_BUTTON_MODE,
String.valueOf(
Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR),
/*tag= */ null, /* makeDefault= */ false,
SettingsState.SYSTEM_PACKAGE_NAME);
} else {
final int defAccessibilityButtonMode =
getContext().getResources().getInteger(
R.integer.def_accessibility_button_mode);
secureSettings.insertSettingLocked(Secure.ACCESSIBILITY_BUTTON_MODE,
String.valueOf(defAccessibilityButtonMode), /* tag= */
null, /* makeDefault= */ true,
SettingsState.SYSTEM_PACKAGE_NAME);
}
}
currentVersion = 199;
}
// vXXX: Add new settings above this point.
if (currentVersion != newVersion) {
@@ -5075,5 +5105,15 @@ public class SettingsProvider extends ContentProvider {
}
return items;
}
private boolean isAccessibilityButtonInNavigationBarOn(SettingsState secureSettings) {
final boolean hasValueInA11yBtnTargets = !TextUtils.isEmpty(
secureSettings.getSettingLocked(
Secure.ACCESSIBILITY_BUTTON_TARGETS).getValue());
final int navigationMode = getContext().getResources().getInteger(
com.android.internal.R.integer.config_navBarInteractionMode);
return hasValueInA11yBtnTargets && (navigationMode != NAV_BAR_MODE_GESTURAL);
}
}
}