Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 299f21d4 authored by “riyaghai”'s avatar “riyaghai”
Browse files

Modify PackageConfigurationUpdater Commit function to return a boolean

Bug: 200672359
Bug: 202112084

Test: atest WmTests:ActivityTaskManagerServiceTests

Change-Id: Iac1d7eb92643e14248fc8b3c7e11832beff3e327
parent 7a7f3725
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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();
    }

    /**
+3 −2
Original line number Diff line number Diff line
@@ -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);
@@ -198,7 +198,7 @@ public class PackageConfigPersister {
                }

                if (!updateNightMode(record, writeRecord) && !updateLocales(record, writeRecord)) {
                    return;
                    return false;
                }

                if (DEBUG) {
@@ -206,6 +206,7 @@ public class PackageConfigPersister {
                }
                mPersisterQueue.addItem(new WriteProcessItem(writeRecord), false /* flush */);
            }
            return true;
        }
    }

+5 −4
Original line number Diff line number Diff line
@@ -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();
@@ -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;
@@ -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);
+3 −1
Original line number Diff line number Diff line
@@ -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
+24 −0
Original line number Diff line number Diff line
@@ -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);