Only set locale in config for updating locale

To update locale, it doesn't need a full configuration because
system only applied the diff of config from non-undefined fields.

IActivityManager#getConfiguration actually gets the configuration
according to the pid, which is process configuration. And process
configuration can be overridden by the activity running in its
process. So the returned value shouldn't be used to update the
system persistent configuration.

Therefore it is enough to use a new Configuration instance with
setting the necessary fields. This is also more efficient that
saves a binder call to system.

Bug: 253386061
Test: atest LocaleManagerTests
Change-Id: Icdce437fcf1a3bef0562cfc4dd5ad3ba52ea08ef
This commit is contained in:
Riddle Hsu
2022-10-20 22:03:49 +08:00
parent 241b46e657
commit 03f0f57e6b
3 changed files with 3 additions and 4 deletions

View File

@@ -173,7 +173,7 @@ public class LocaleManager {
@TestApi
public void setSystemLocales(@NonNull LocaleList locales) {
try {
Configuration conf = ActivityManager.getService().getConfiguration();
Configuration conf = new Configuration();
conf.setLocales(locales);
ActivityManager.getService().updatePersistentConfiguration(conf);
} catch (RemoteException e) {

View File

@@ -311,8 +311,7 @@ public class LocalePicker extends ListFragment {
try {
final IActivityManager am = ActivityManager.getService();
final Configuration config = am.getConfiguration();
final Configuration config = new Configuration();
config.setLocales(locales);
config.userSetLocale = true;

View File

@@ -549,7 +549,7 @@ public class SettingsHelper {
try {
IActivityManager am = ActivityManager.getService();
Configuration config = am.getConfiguration();
final Configuration config = new Configuration();
config.setLocales(merged);
// indicate this isn't some passing default - the user wants this remembered
config.userSetLocale = true;