Loading services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +11 −1 Original line number Diff line number Diff line Loading @@ -663,13 +663,23 @@ public abstract class ActivityTaskManagerInternal { * This setting is persisted and will overlay on top of the system locales for * the said application. * @return the current {@link PackageConfigurationUpdater} updated with the provided locale. * * <p>NOTE: This method should not be called by clients directly to set app locales, * instead use the {@link LocaleManagerService#setApplicationLocales} */ PackageConfigurationUpdater setLocales(LocaleList locales); /** * Commit changes. */ void commit(); * @return true if the configuration changes were persisted, * false if there were no changes, or if erroneous inputs were provided, such as: * <ui> * <li>Invalid packageName</li> * <li>Invalid userId</li> * <li>no WindowProcessController found for the package</li> * </ui> */ boolean commit(); } /** Loading services/core/java/com/android/server/wm/PackageConfigPersister.java +3 −2 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ public class PackageConfigPersister { } @GuardedBy("mLock") void updateFromImpl(String packageName, int userId, boolean updateFromImpl(String packageName, int userId, PackageConfigurationUpdaterImpl impl) { synchronized (mLock) { PackageConfigRecord record = findRecordOrCreate(mModified, packageName, userId); Loading @@ -198,7 +198,7 @@ public class PackageConfigPersister { } if (!updateNightMode(record, writeRecord) && !updateLocales(record, writeRecord)) { return; return false; } if (DEBUG) { Loading @@ -206,6 +206,7 @@ public class PackageConfigPersister { } mPersisterQueue.addItem(new WriteProcessItem(writeRecord), false /* flush */); } return true; } } Loading services/core/java/com/android/server/wm/PackageConfigurationUpdaterImpl.java +5 −4 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ final class PackageConfigurationUpdaterImpl implements } @Override public void commit() { public boolean commit() { synchronized (this) { synchronized (mAtm.mGlobalLock) { final long ident = Binder.clearCallingIdentity(); Loading @@ -79,7 +79,7 @@ final class PackageConfigurationUpdaterImpl implements if (wpc == null) { Slog.w(TAG, "commit: Override application configuration failed: " + "cannot find pid " + mPid); return; return false; } uid = wpc.mUid; mUserId = wpc.mUserId; Loading @@ -90,11 +90,12 @@ final class PackageConfigurationUpdaterImpl implements if (uid < 0) { Slog.w(TAG, "commit: update of application configuration failed: " + "userId or packageName not valid " + mUserId); return; return false; } } updateConfig(uid, mPackageName); mAtm.mPackageConfigPersister.updateFromImpl(mPackageName, mUserId, this); return mAtm.mPackageConfigPersister .updateFromImpl(mPackageName, mUserId, this); } finally { Binder.restoreCallingIdentity(ident); Loading services/tests/servicestests/src/com/android/server/locales/FakePackageConfigurationUpdater.java +3 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,9 @@ class FakePackageConfigurationUpdater implements PackageConfigurationUpdater { } @Override public void commit() {} public boolean commit() { return mLocales != null; } /** * Returns the locales that were stored during the test run. Returns {@code null} if no locales Loading services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java +24 −0 Original line number Diff line number Diff line Loading @@ -839,6 +839,30 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase { wpc.getConfiguration().getLocales()); } @Test public void testPackageConfigUpdate_commitConfig_configSuccessfullyApplied() { Configuration config = mAtm.getGlobalConfiguration(); config.setLocales(LocaleList.forLanguageTags("en-XC")); mAtm.updateGlobalConfigurationLocked(config, true, true, DEFAULT_USER_ID); WindowProcessController wpc = createWindowProcessController( DEFAULT_PACKAGE_NAME, DEFAULT_USER_ID); mAtm.mProcessMap.put(Binder.getCallingPid(), wpc); mAtm.mInternal.onProcessAdded(wpc); ActivityTaskManagerInternal.PackageConfigurationUpdater packageConfigUpdater = mAtm.mInternal.createPackageConfigurationUpdater(DEFAULT_PACKAGE_NAME, DEFAULT_USER_ID); // committing new configuration returns true; assertTrue(packageConfigUpdater.setLocales(LocaleList.forLanguageTags("en-XA,ar-XB")) .commit()); // applying the same configuration returns false. assertFalse(packageConfigUpdater.setLocales(LocaleList.forLanguageTags("en-XA,ar-XB")) .commit()); assertTrue(packageConfigUpdater.setLocales(LocaleList.getEmptyLocaleList()) .setNightMode(Configuration.UI_MODE_NIGHT_UNDEFINED).commit()); } private WindowProcessController createWindowProcessController(String packageName, int userId) { WindowProcessListener mMockListener = Mockito.mock(WindowProcessListener.class); Loading Loading
services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +11 −1 Original line number Diff line number Diff line Loading @@ -663,13 +663,23 @@ public abstract class ActivityTaskManagerInternal { * This setting is persisted and will overlay on top of the system locales for * the said application. * @return the current {@link PackageConfigurationUpdater} updated with the provided locale. * * <p>NOTE: This method should not be called by clients directly to set app locales, * instead use the {@link LocaleManagerService#setApplicationLocales} */ PackageConfigurationUpdater setLocales(LocaleList locales); /** * Commit changes. */ void commit(); * @return true if the configuration changes were persisted, * false if there were no changes, or if erroneous inputs were provided, such as: * <ui> * <li>Invalid packageName</li> * <li>Invalid userId</li> * <li>no WindowProcessController found for the package</li> * </ui> */ boolean commit(); } /** Loading
services/core/java/com/android/server/wm/PackageConfigPersister.java +3 −2 Original line number Diff line number Diff line Loading @@ -172,7 +172,7 @@ public class PackageConfigPersister { } @GuardedBy("mLock") void updateFromImpl(String packageName, int userId, boolean updateFromImpl(String packageName, int userId, PackageConfigurationUpdaterImpl impl) { synchronized (mLock) { PackageConfigRecord record = findRecordOrCreate(mModified, packageName, userId); Loading @@ -198,7 +198,7 @@ public class PackageConfigPersister { } if (!updateNightMode(record, writeRecord) && !updateLocales(record, writeRecord)) { return; return false; } if (DEBUG) { Loading @@ -206,6 +206,7 @@ public class PackageConfigPersister { } mPersisterQueue.addItem(new WriteProcessItem(writeRecord), false /* flush */); } return true; } } Loading
services/core/java/com/android/server/wm/PackageConfigurationUpdaterImpl.java +5 −4 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ final class PackageConfigurationUpdaterImpl implements } @Override public void commit() { public boolean commit() { synchronized (this) { synchronized (mAtm.mGlobalLock) { final long ident = Binder.clearCallingIdentity(); Loading @@ -79,7 +79,7 @@ final class PackageConfigurationUpdaterImpl implements if (wpc == null) { Slog.w(TAG, "commit: Override application configuration failed: " + "cannot find pid " + mPid); return; return false; } uid = wpc.mUid; mUserId = wpc.mUserId; Loading @@ -90,11 +90,12 @@ final class PackageConfigurationUpdaterImpl implements if (uid < 0) { Slog.w(TAG, "commit: update of application configuration failed: " + "userId or packageName not valid " + mUserId); return; return false; } } updateConfig(uid, mPackageName); mAtm.mPackageConfigPersister.updateFromImpl(mPackageName, mUserId, this); return mAtm.mPackageConfigPersister .updateFromImpl(mPackageName, mUserId, this); } finally { Binder.restoreCallingIdentity(ident); Loading
services/tests/servicestests/src/com/android/server/locales/FakePackageConfigurationUpdater.java +3 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,9 @@ class FakePackageConfigurationUpdater implements PackageConfigurationUpdater { } @Override public void commit() {} public boolean commit() { return mLocales != null; } /** * Returns the locales that were stored during the test run. Returns {@code null} if no locales Loading
services/tests/wmtests/src/com/android/server/wm/ActivityTaskManagerServiceTests.java +24 −0 Original line number Diff line number Diff line Loading @@ -839,6 +839,30 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase { wpc.getConfiguration().getLocales()); } @Test public void testPackageConfigUpdate_commitConfig_configSuccessfullyApplied() { Configuration config = mAtm.getGlobalConfiguration(); config.setLocales(LocaleList.forLanguageTags("en-XC")); mAtm.updateGlobalConfigurationLocked(config, true, true, DEFAULT_USER_ID); WindowProcessController wpc = createWindowProcessController( DEFAULT_PACKAGE_NAME, DEFAULT_USER_ID); mAtm.mProcessMap.put(Binder.getCallingPid(), wpc); mAtm.mInternal.onProcessAdded(wpc); ActivityTaskManagerInternal.PackageConfigurationUpdater packageConfigUpdater = mAtm.mInternal.createPackageConfigurationUpdater(DEFAULT_PACKAGE_NAME, DEFAULT_USER_ID); // committing new configuration returns true; assertTrue(packageConfigUpdater.setLocales(LocaleList.forLanguageTags("en-XA,ar-XB")) .commit()); // applying the same configuration returns false. assertFalse(packageConfigUpdater.setLocales(LocaleList.forLanguageTags("en-XA,ar-XB")) .commit()); assertTrue(packageConfigUpdater.setLocales(LocaleList.getEmptyLocaleList()) .setNightMode(Configuration.UI_MODE_NIGHT_UNDEFINED).commit()); } private WindowProcessController createWindowProcessController(String packageName, int userId) { WindowProcessListener mMockListener = Mockito.mock(WindowProcessListener.class); Loading