Loading packages/SettingsProvider/res/values/arrays.xml 0 → 100644 +36 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2024 The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- NOTE: if you change this, you must also add the corresponding scale key and lookup table to frameworks/base/core/java/android/content/res/FontScaleConverterFactory.java TODO(b/341235102): Remove font_scale array duplication --> <string-array name="entryvalues_font_size" translatable="false"> <item>0.85</item> <item>1.0</item> <item>1.15</item> <item>1.30</item> <item>1.50</item> <item>1.80</item> <item>2.0</item> </string-array> </resources> packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java +0 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ public class SystemSettings { Settings.System.WIFI_STATIC_DNS2, Settings.System.BLUETOOTH_DISCOVERABILITY, Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT, Settings.System.DEFAULT_DEVICE_FONT_SCALE, Settings.System.FONT_SCALE, Settings.System.DIM_SCREEN, Settings.System.SCREEN_OFF_TIMEOUT, Loading packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +57 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.providers.settings; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.backup.BackupAgentHelper; import android.app.backup.BackupDataInput; Loading Loading @@ -57,6 +59,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.internal.widget.LockPatternUtils; import com.android.settingslib.display.DisplayDensityConfiguration; import com.android.window.flags.Flags; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; Loading Loading @@ -88,6 +91,7 @@ public class SettingsBackupAgent extends BackupAgentHelper { private static final byte[] NULL_VALUE = new byte[0]; private static final int NULL_SIZE = -1; private static final float FONT_SCALE_DEF_VALUE = 1.0f; private static final String KEY_SYSTEM = "system"; private static final String KEY_SECURE = "secure"; Loading @@ -111,7 +115,6 @@ public class SettingsBackupAgent extends BackupAgentHelper { // Versioning of the Network Policies backup payload. private static final int NETWORK_POLICIES_BACKUP_VERSION = 1; // Slots in the checksum array. Never insert new items in the middle // of this array; new slots must be appended. private static final int STATE_SYSTEM = 0; Loading Loading @@ -208,10 +211,19 @@ public class SettingsBackupAgent extends BackupAgentHelper { // Populated in onRestore(). private int mRestoredFromSdkInt; // The available font scale for the current device @Nullable private String[] mAvailableFontScales; // The font_scale default value for this device. private float mDefaultFontScale; @Override public void onCreate() { if (DEBUG_BACKUP) Log.d(TAG, "onCreate() invoked"); mDefaultFontScale = getBaseContext().getResources().getFloat(R.dimen.def_device_font_scale); mAvailableFontScales = getBaseContext().getResources() .getStringArray(R.array.entryvalues_font_size); mSettingsHelper = new SettingsHelper(this); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); super.onCreate(); Loading Loading @@ -917,6 +929,23 @@ public class SettingsBackupAgent extends BackupAgentHelper { continue; } } if (Settings.System.FONT_SCALE.equals(key)) { // If the current value is different from the default it means that it's been // already changed for a11y reason. In that case we don't need to restore // the new value. final float currentValue = Settings.System.getFloat(cr, Settings.System.FONT_SCALE, mDefaultFontScale); if (currentValue != mDefaultFontScale) { Log.d(TAG, "Font scale not restored because changed for a11y reason."); continue; } final String toRestore = value; value = findClosestAllowedFontScale(value, mAvailableFontScales); Log.d(TAG, "Restored font scale from: " + toRestore + " to " + value); } settingsHelper.restoreValue(this, cr, contentValues, destination, key, value, mRestoredFromSdkInt); Loading @@ -924,6 +953,32 @@ public class SettingsBackupAgent extends BackupAgentHelper { } } @VisibleForTesting static String findClosestAllowedFontScale(@NonNull String requestedFontScale, @NonNull String[] availableFontScales) { if (Flags.configurableFontScaleDefault()) { final float requestedValue = Float.parseFloat(requestedFontScale); // Whatever is the requested value, we search the closest allowed value which is // equals or larger. Note that if the requested value is the previous default, // and this is still available, the value will be preserved. float candidate = 0.0f; boolean fontScaleFound = false; for (int i = 0; !fontScaleFound && i < availableFontScales.length; i++) { final float fontScale = Float.parseFloat(availableFontScales[i]); if (fontScale >= requestedValue) { candidate = fontScale; fontScaleFound = true; } } // If the current value is greater than all the allowed ones, we return the // largest possible. return fontScaleFound ? String.valueOf(candidate) : String.valueOf( availableFontScales[availableFontScales.length - 1]); } return requestedFontScale; } @VisibleForTesting SettingsBackupWhitelist getBackupWhitelist(Uri contentUri) { // Figure out the white list and redirects to the global table. We restore anything Loading packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +1 −2 Original line number Diff line number Diff line Loading @@ -386,6 +386,7 @@ public class SettingsHelper { // it means that the user has performed a global gesture to enable accessibility or set // these settings in the Accessibility portion of the Setup Wizard, and definitely needs // these features working after the restore. // Note: Settings.Secure.FONT_SCALE is already handled in the caller class. switch (name) { case Settings.Secure.ACCESSIBILITY_ENABLED: case Settings.Secure.TOUCH_EXPLORATION_ENABLED: Loading @@ -405,8 +406,6 @@ public class SettingsHelper { float currentScale = Settings.Secure.getFloat( mContext.getContentResolver(), name, defaultScale); return Math.abs(currentScale - defaultScale) >= FLOAT_TOLERANCE; case Settings.System.FONT_SCALE: return Settings.System.getFloat(mContext.getContentResolver(), name, 1.0f) != 1.0f; default: return false; } Loading packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -907,6 +907,7 @@ public class SettingsBackupTest { Settings.System.APPEND_FOR_LAST_AUDIBLE, // suffix deprecated since API 2 Settings.System.EGG_MODE, // I am the lolrus Settings.System.END_BUTTON_BEHAVIOR, // bug? Settings.System.DEFAULT_DEVICE_FONT_SCALE, // Non configurable Settings.System .HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, // candidate for backup? Loading Loading
packages/SettingsProvider/res/values/arrays.xml 0 → 100644 +36 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- /* ** ** Copyright 2024 The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ --> <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- NOTE: if you change this, you must also add the corresponding scale key and lookup table to frameworks/base/core/java/android/content/res/FontScaleConverterFactory.java TODO(b/341235102): Remove font_scale array duplication --> <string-array name="entryvalues_font_size" translatable="false"> <item>0.85</item> <item>1.0</item> <item>1.15</item> <item>1.30</item> <item>1.50</item> <item>1.80</item> <item>2.0</item> </string-array> </resources>
packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java +0 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ public class SystemSettings { Settings.System.WIFI_STATIC_DNS2, Settings.System.BLUETOOTH_DISCOVERABILITY, Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT, Settings.System.DEFAULT_DEVICE_FONT_SCALE, Settings.System.FONT_SCALE, Settings.System.DIM_SCREEN, Settings.System.SCREEN_OFF_TIMEOUT, Loading
packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +57 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.providers.settings; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.backup.BackupAgentHelper; import android.app.backup.BackupDataInput; Loading Loading @@ -57,6 +59,7 @@ import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.ArrayUtils; import com.android.internal.widget.LockPatternUtils; import com.android.settingslib.display.DisplayDensityConfiguration; import com.android.window.flags.Flags; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; Loading Loading @@ -88,6 +91,7 @@ public class SettingsBackupAgent extends BackupAgentHelper { private static final byte[] NULL_VALUE = new byte[0]; private static final int NULL_SIZE = -1; private static final float FONT_SCALE_DEF_VALUE = 1.0f; private static final String KEY_SYSTEM = "system"; private static final String KEY_SECURE = "secure"; Loading @@ -111,7 +115,6 @@ public class SettingsBackupAgent extends BackupAgentHelper { // Versioning of the Network Policies backup payload. private static final int NETWORK_POLICIES_BACKUP_VERSION = 1; // Slots in the checksum array. Never insert new items in the middle // of this array; new slots must be appended. private static final int STATE_SYSTEM = 0; Loading Loading @@ -208,10 +211,19 @@ public class SettingsBackupAgent extends BackupAgentHelper { // Populated in onRestore(). private int mRestoredFromSdkInt; // The available font scale for the current device @Nullable private String[] mAvailableFontScales; // The font_scale default value for this device. private float mDefaultFontScale; @Override public void onCreate() { if (DEBUG_BACKUP) Log.d(TAG, "onCreate() invoked"); mDefaultFontScale = getBaseContext().getResources().getFloat(R.dimen.def_device_font_scale); mAvailableFontScales = getBaseContext().getResources() .getStringArray(R.array.entryvalues_font_size); mSettingsHelper = new SettingsHelper(this); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); super.onCreate(); Loading Loading @@ -917,6 +929,23 @@ public class SettingsBackupAgent extends BackupAgentHelper { continue; } } if (Settings.System.FONT_SCALE.equals(key)) { // If the current value is different from the default it means that it's been // already changed for a11y reason. In that case we don't need to restore // the new value. final float currentValue = Settings.System.getFloat(cr, Settings.System.FONT_SCALE, mDefaultFontScale); if (currentValue != mDefaultFontScale) { Log.d(TAG, "Font scale not restored because changed for a11y reason."); continue; } final String toRestore = value; value = findClosestAllowedFontScale(value, mAvailableFontScales); Log.d(TAG, "Restored font scale from: " + toRestore + " to " + value); } settingsHelper.restoreValue(this, cr, contentValues, destination, key, value, mRestoredFromSdkInt); Loading @@ -924,6 +953,32 @@ public class SettingsBackupAgent extends BackupAgentHelper { } } @VisibleForTesting static String findClosestAllowedFontScale(@NonNull String requestedFontScale, @NonNull String[] availableFontScales) { if (Flags.configurableFontScaleDefault()) { final float requestedValue = Float.parseFloat(requestedFontScale); // Whatever is the requested value, we search the closest allowed value which is // equals or larger. Note that if the requested value is the previous default, // and this is still available, the value will be preserved. float candidate = 0.0f; boolean fontScaleFound = false; for (int i = 0; !fontScaleFound && i < availableFontScales.length; i++) { final float fontScale = Float.parseFloat(availableFontScales[i]); if (fontScale >= requestedValue) { candidate = fontScale; fontScaleFound = true; } } // If the current value is greater than all the allowed ones, we return the // largest possible. return fontScaleFound ? String.valueOf(candidate) : String.valueOf( availableFontScales[availableFontScales.length - 1]); } return requestedFontScale; } @VisibleForTesting SettingsBackupWhitelist getBackupWhitelist(Uri contentUri) { // Figure out the white list and redirects to the global table. We restore anything Loading
packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +1 −2 Original line number Diff line number Diff line Loading @@ -386,6 +386,7 @@ public class SettingsHelper { // it means that the user has performed a global gesture to enable accessibility or set // these settings in the Accessibility portion of the Setup Wizard, and definitely needs // these features working after the restore. // Note: Settings.Secure.FONT_SCALE is already handled in the caller class. switch (name) { case Settings.Secure.ACCESSIBILITY_ENABLED: case Settings.Secure.TOUCH_EXPLORATION_ENABLED: Loading @@ -405,8 +406,6 @@ public class SettingsHelper { float currentScale = Settings.Secure.getFloat( mContext.getContentResolver(), name, defaultScale); return Math.abs(currentScale - defaultScale) >= FLOAT_TOLERANCE; case Settings.System.FONT_SCALE: return Settings.System.getFloat(mContext.getContentResolver(), name, 1.0f) != 1.0f; default: return false; } Loading
packages/SettingsProvider/test/src/android/provider/SettingsBackupTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -907,6 +907,7 @@ public class SettingsBackupTest { Settings.System.APPEND_FOR_LAST_AUDIBLE, // suffix deprecated since API 2 Settings.System.EGG_MODE, // I am the lolrus Settings.System.END_BUTTON_BEHAVIOR, // bug? Settings.System.DEFAULT_DEVICE_FONT_SCALE, // Non configurable Settings.System .HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, // candidate for backup? Loading