Loading packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +20 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.net.Uri; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiManager; import android.os.Build; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.os.UserHandle; import android.provider.Settings; Loading Loading @@ -269,7 +270,7 @@ public class SettingsBackupAgent extends BackupAgentHelper { byte[] secureSettingsData = getSecureSettings(); byte[] globalSettingsData = getGlobalSettings(); byte[] lockSettingsData = getLockSettings(UserHandle.myUserId()); byte[] locale = mSettingsHelper.getLocaleData(); byte[] locale = getLocaleSettings(); byte[] softApConfigData = getSoftAPConfiguration(); byte[] netPoliciesData = getNetworkPolicies(); byte[] wifiFullConfigData = getNewWifiConfigData(); Loading Loading @@ -408,7 +409,12 @@ public class SettingsBackupAgent extends BackupAgentHelper { case KEY_LOCALE : byte[] localeData = new byte[size]; data.readEntityData(localeData, 0, size); mSettingsHelper.setLocaleData(localeData, size); mSettingsHelper .setLocaleData( localeData, size, mBackupRestoreEventLogger, KEY_LOCALE); break; case KEY_WIFI_CONFIG : Loading Loading @@ -545,7 +551,9 @@ public class SettingsBackupAgent extends BackupAgentHelper { if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of locale data"); if (nBytes > buffer.length) buffer = new byte[nBytes]; in.readFully(buffer, 0, nBytes); mSettingsHelper.setLocaleData(buffer, nBytes); mSettingsHelper .setLocaleData( buffer, nBytes, mBackupRestoreEventLogger, KEY_LOCALE); // Restore older backups performing the necessary migrations. if (version < FULL_BACKUP_ADDED_WIFI_NEW) { Loading Loading @@ -1410,6 +1418,15 @@ public class SettingsBackupAgent extends BackupAgentHelper { return mWifiManager.retrieveBackupData(); } private byte[] getLocaleSettings() { if (!areAgentMetricsEnabled) { return mSettingsHelper.getLocaleData(); } LocaleList localeList = mSettingsHelper.getLocaleList(); numberOfSettingsPerKey.put(KEY_LOCALE, localeList.size()); return localeList.toLanguageTags().getBytes(); } private void restoreNewWifiConfigData(byte[] bytes) { if (DEBUG_BACKUP) { Log.v(TAG, "Applying restored wifi data"); Loading packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +27 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.providers.settings; import android.annotation.NonNull; import android.app.ActivityManager; import android.app.IActivityManager; import android.app.backup.BackupRestoreEventLogger; import android.app.backup.IBackupManager; import android.content.ContentResolver; import android.content.ContentValues; Loading @@ -43,6 +44,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.LocalePicker; import com.android.server.backup.Flags; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; import java.io.FileNotFoundException; Loading @@ -68,6 +70,10 @@ public class SettingsHelper { /** See frameworks/base/core/res/res/values/config.xml#config_keyChordPowerVolumeUp **/ private static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2; // Error messages for logging metrics. private static final String ERROR_REMOTE_EXCEPTION_SETTING_LOCALE_DATA = "remote_exception_setting_locale_data"; private Context mContext; private AudioManager mAudioManager; private TelephonyManager mTelephonyManager; Loading Loading @@ -528,6 +534,11 @@ public class SettingsHelper { return conf.getLocales().toLanguageTags().getBytes(); } LocaleList getLocaleList() { Configuration conf = mContext.getResources().getConfiguration(); return conf.getLocales(); } private static Locale toFullLocale(@NonNull Locale locale) { if (locale.getScript().isEmpty() || locale.getCountry().isEmpty()) { return ULocale.addLikelySubtags(ULocale.forLocale(locale)).toLocale(); Loading Loading @@ -653,8 +664,12 @@ public class SettingsHelper { * code and {@code CC} is a two letter country code. * * @param data the comma separated BCP-47 language tags in bytes. * @param size the size of the data in bytes. * @param backupRestoreEventLogger the logger to log the restore event. * @param dataType the data type of the setting for logging purposes. */ /* package */ void setLocaleData(byte[] data, int size) { /* package */ void setLocaleData( byte[] data, int size, BackupRestoreEventLogger backupRestoreEventLogger, String dataType) { final Configuration conf = mContext.getResources().getConfiguration(); // Replace "_" with "-" to deal with older backups. Loading @@ -681,8 +696,18 @@ public class SettingsHelper { am.updatePersistentConfigurationWithAttribution(config, mContext.getOpPackageName(), mContext.getAttributionTag()); if (Flags.enableMetricsSettingsBackupAgents()) { backupRestoreEventLogger .logItemsRestored(dataType, localeList.size()); } } catch (RemoteException e) { // Intentionally left blank if (Flags.enableMetricsSettingsBackupAgents()) { backupRestoreEventLogger .logItemsRestoreFailed( dataType, localeList.size(), ERROR_REMOTE_EXCEPTION_SETTING_LOCALE_DATA); } } } Loading packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.AssetFileDescriptor; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; Loading Loading @@ -83,6 +84,9 @@ public class SettingsHelperTest { "content://media/internal/audio/media/30?title=DefaultAlarm&canonical=1"; private static final String VIBRATION_FILE_NAME = "haptics.xml"; private static final LocaleList LOCALE_LIST = LocaleList.forLanguageTags("en-US,en-UK"); private SettingsHelper mSettingsHelper; @Rule Loading Loading @@ -778,6 +782,15 @@ public class SettingsHelperTest { assertThat(getAutoRotationSettingValue()).isEqualTo(previousValue); } @Test public void getLocaleList_returnsLocaleList() { Configuration config = new Configuration(); config.setLocales(LOCALE_LIST); when(mResources.getConfiguration()).thenReturn(config); assertThat(mSettingsHelper.getLocaleList()).isEqualTo(LOCALE_LIST); } private int getAutoRotationSettingValue() { return Settings.System.getInt(mContentResolver, Settings.System.ACCELEROMETER_ROTATION, Loading Loading
packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java +20 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.net.Uri; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiManager; import android.os.Build; import android.os.LocaleList; import android.os.ParcelFileDescriptor; import android.os.UserHandle; import android.provider.Settings; Loading Loading @@ -269,7 +270,7 @@ public class SettingsBackupAgent extends BackupAgentHelper { byte[] secureSettingsData = getSecureSettings(); byte[] globalSettingsData = getGlobalSettings(); byte[] lockSettingsData = getLockSettings(UserHandle.myUserId()); byte[] locale = mSettingsHelper.getLocaleData(); byte[] locale = getLocaleSettings(); byte[] softApConfigData = getSoftAPConfiguration(); byte[] netPoliciesData = getNetworkPolicies(); byte[] wifiFullConfigData = getNewWifiConfigData(); Loading Loading @@ -408,7 +409,12 @@ public class SettingsBackupAgent extends BackupAgentHelper { case KEY_LOCALE : byte[] localeData = new byte[size]; data.readEntityData(localeData, 0, size); mSettingsHelper.setLocaleData(localeData, size); mSettingsHelper .setLocaleData( localeData, size, mBackupRestoreEventLogger, KEY_LOCALE); break; case KEY_WIFI_CONFIG : Loading Loading @@ -545,7 +551,9 @@ public class SettingsBackupAgent extends BackupAgentHelper { if (DEBUG_BACKUP) Log.d(TAG, nBytes + " bytes of locale data"); if (nBytes > buffer.length) buffer = new byte[nBytes]; in.readFully(buffer, 0, nBytes); mSettingsHelper.setLocaleData(buffer, nBytes); mSettingsHelper .setLocaleData( buffer, nBytes, mBackupRestoreEventLogger, KEY_LOCALE); // Restore older backups performing the necessary migrations. if (version < FULL_BACKUP_ADDED_WIFI_NEW) { Loading Loading @@ -1410,6 +1418,15 @@ public class SettingsBackupAgent extends BackupAgentHelper { return mWifiManager.retrieveBackupData(); } private byte[] getLocaleSettings() { if (!areAgentMetricsEnabled) { return mSettingsHelper.getLocaleData(); } LocaleList localeList = mSettingsHelper.getLocaleList(); numberOfSettingsPerKey.put(KEY_LOCALE, localeList.size()); return localeList.toLanguageTags().getBytes(); } private void restoreNewWifiConfigData(byte[] bytes) { if (DEBUG_BACKUP) { Log.v(TAG, "Applying restored wifi data"); Loading
packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java +27 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.providers.settings; import android.annotation.NonNull; import android.app.ActivityManager; import android.app.IActivityManager; import android.app.backup.BackupRestoreEventLogger; import android.app.backup.IBackupManager; import android.content.ContentResolver; import android.content.ContentValues; Loading @@ -43,6 +44,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.LocalePicker; import com.android.server.backup.Flags; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; import java.io.FileNotFoundException; Loading @@ -68,6 +70,10 @@ public class SettingsHelper { /** See frameworks/base/core/res/res/values/config.xml#config_keyChordPowerVolumeUp **/ private static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2; // Error messages for logging metrics. private static final String ERROR_REMOTE_EXCEPTION_SETTING_LOCALE_DATA = "remote_exception_setting_locale_data"; private Context mContext; private AudioManager mAudioManager; private TelephonyManager mTelephonyManager; Loading Loading @@ -528,6 +534,11 @@ public class SettingsHelper { return conf.getLocales().toLanguageTags().getBytes(); } LocaleList getLocaleList() { Configuration conf = mContext.getResources().getConfiguration(); return conf.getLocales(); } private static Locale toFullLocale(@NonNull Locale locale) { if (locale.getScript().isEmpty() || locale.getCountry().isEmpty()) { return ULocale.addLikelySubtags(ULocale.forLocale(locale)).toLocale(); Loading Loading @@ -653,8 +664,12 @@ public class SettingsHelper { * code and {@code CC} is a two letter country code. * * @param data the comma separated BCP-47 language tags in bytes. * @param size the size of the data in bytes. * @param backupRestoreEventLogger the logger to log the restore event. * @param dataType the data type of the setting for logging purposes. */ /* package */ void setLocaleData(byte[] data, int size) { /* package */ void setLocaleData( byte[] data, int size, BackupRestoreEventLogger backupRestoreEventLogger, String dataType) { final Configuration conf = mContext.getResources().getConfiguration(); // Replace "_" with "-" to deal with older backups. Loading @@ -681,8 +696,18 @@ public class SettingsHelper { am.updatePersistentConfigurationWithAttribution(config, mContext.getOpPackageName(), mContext.getAttributionTag()); if (Flags.enableMetricsSettingsBackupAgents()) { backupRestoreEventLogger .logItemsRestored(dataType, localeList.size()); } } catch (RemoteException e) { // Intentionally left blank if (Flags.enableMetricsSettingsBackupAgents()) { backupRestoreEventLogger .logItemsRestoreFailed( dataType, localeList.size(), ERROR_REMOTE_EXCEPTION_SETTING_LOCALE_DATA); } } } Loading
packages/SettingsProvider/test/src/com/android/providers/settings/SettingsHelperTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.content.ContentValues; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.res.AssetFileDescriptor; import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.database.MatrixCursor; Loading Loading @@ -83,6 +84,9 @@ public class SettingsHelperTest { "content://media/internal/audio/media/30?title=DefaultAlarm&canonical=1"; private static final String VIBRATION_FILE_NAME = "haptics.xml"; private static final LocaleList LOCALE_LIST = LocaleList.forLanguageTags("en-US,en-UK"); private SettingsHelper mSettingsHelper; @Rule Loading Loading @@ -778,6 +782,15 @@ public class SettingsHelperTest { assertThat(getAutoRotationSettingValue()).isEqualTo(previousValue); } @Test public void getLocaleList_returnsLocaleList() { Configuration config = new Configuration(); config.setLocales(LOCALE_LIST); when(mResources.getConfiguration()).thenReturn(config); assertThat(mSettingsHelper.getLocaleList()).isEqualTo(LOCALE_LIST); } private int getAutoRotationSettingValue() { return Settings.System.getInt(mContentResolver, Settings.System.ACCELEROMETER_ROTATION, Loading