Fix Magnification Settings didn't restore via D2D transfer

ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED is replaced
with ButtonTargets setting value. We address it in data migration but
not in D2D

Consider D2D, we restore it to ButtonTargets value when the restored
sdk version of the received intent is below R.

Bug: 155943759
Test: manual test
     1. prepare an Android Q device and an Android R device
     2. backup settings value of Android Q device by the google account.
     3. Launch setupwizard to restore it by the google account.
Change-Id: I5df070dd1ef880ac1ee5c0867b42e88782348a1b
This commit is contained in:
ryanlwlin
2020-05-28 18:42:50 +08:00
parent 0a62017612
commit 779b7a09c5
3 changed files with 50 additions and 3 deletions

View File

@@ -80,6 +80,7 @@ public class SettingsHelper {
sBroadcastOnRestore.add(Settings.Secure.UI_NIGHT_MODE);
sBroadcastOnRestore.add(Settings.Secure.DARK_THEME_CUSTOM_START_TIME);
sBroadcastOnRestore.add(Settings.Secure.DARK_THEME_CUSTOM_END_TIME);
sBroadcastOnRestore.add(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
}
private interface SettingsLookup {

View File

@@ -31,6 +31,7 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
/**
* Tests for {@link SettingsHelper#restoreValue(Context, ContentResolver, ContentValues, Uri,
@@ -89,7 +90,7 @@ public class SettingsHelperRestoreTest {
float restoreSettingValue = defaultSettingValue + 0.5f;
mSettingsHelper.restoreValue(
mContext,
Mockito.mock(Context.class),
mContentResolver,
new ContentValues(2),
Settings.Secure.getUriFor(settingName),
@@ -132,7 +133,7 @@ public class SettingsHelperRestoreTest {
Settings.Secure.putInt(mContentResolver, settingName, configuredSettingValue);
mSettingsHelper.restoreValue(
mContext,
Mockito.mock(Context.class),
mContentResolver,
new ContentValues(2),
Settings.Secure.getUriFor(settingName),
@@ -154,7 +155,7 @@ public class SettingsHelperRestoreTest {
int restoreSettingValue = 1;
mSettingsHelper.restoreValue(
mContext,
Mockito.mock(Context.class),
mContentResolver,
new ContentValues(2),
Settings.Secure.getUriFor(settingName),

View File

@@ -16,6 +16,7 @@
package com.android.server.accessibility;
import static android.provider.Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;
import static android.view.accessibility.AccessibilityManager.ShortcutType;
@@ -542,12 +543,56 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE),
intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE));
}
} else if (ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(which)) {
synchronized (mLock) {
restoreLegacyDisplayMagnificationNavBarIfNeededLocked(
intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE),
intent.getIntExtra(Intent.EXTRA_SETTING_RESTORED_FROM_SDK_INT,
0));
}
}
}
}
}, UserHandle.ALL, intentFilter, null, null);
}
// Called only during settings restore; currently supports only the owner user
// TODO: b/22388012
private void restoreLegacyDisplayMagnificationNavBarIfNeededLocked(String newSetting,
int restoreFromSdkInt) {
if (restoreFromSdkInt >= Build.VERSION_CODES.R) {
return;
}
boolean displayMagnificationNavBarEnabled;
try {
displayMagnificationNavBarEnabled = Integer.parseInt(newSetting) == 1;
} catch (NumberFormatException e) {
Slog.w(LOG_TAG, "number format is incorrect" + e);
return;
}
final AccessibilityUserState userState = getUserStateLocked(UserHandle.USER_SYSTEM);
final Set<String> targetsFromSetting = new ArraySet<>();
readColonDelimitedSettingToSet(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
userState.mUserId, targetsFromSetting, str -> str);
final boolean targetsContainMagnification = targetsFromSetting.contains(
MAGNIFICATION_CONTROLLER_NAME);
if (targetsContainMagnification == displayMagnificationNavBarEnabled) {
return;
}
if (displayMagnificationNavBarEnabled) {
targetsFromSetting.add(MAGNIFICATION_CONTROLLER_NAME);
} else {
targetsFromSetting.remove(MAGNIFICATION_CONTROLLER_NAME);
}
persistColonDelimitedSetToSettingLocked(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
userState.mUserId, targetsFromSetting, str -> str);
readAccessibilityButtonTargetsLocked(userState);
onUserStateChangedLocked(userState);
}
@Override
public long addClient(IAccessibilityManagerClient callback, int userId) {
synchronized (mLock) {