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

Commit d22e8b14 authored by wilsonshih's avatar wilsonshih
Browse files

Fix setApplicationNightMode crash due to permission denial.

Test activity crash when calling UiModeManager#setApplicationNightMode.
There should call clearCallingIdentity before updating configuration in
system server.
Also clear some code around those methods.

Fixes: 189166288
Test: atest SplashscreenTests#testSetApplicationNightMode
Change-Id: I163919927030f81739aa3d9520e2012a92028793
parent 127ea4fa
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ interface IUiModeManager {
     *   1 - notnight mode
     *   2 - night mode
     *   3 - automatic mode switching
     * @throws RemoteException
     */
    void setApplicationNightMode(in int mode);

+5 −10
Original line number Diff line number Diff line
@@ -754,8 +754,7 @@ final class UiModeManagerService extends SystemService {
        }

        @Override
        public void setApplicationNightMode(@UiModeManager.NightMode int mode)
                throws RemoteException {
        public void setApplicationNightMode(@UiModeManager.NightMode int mode) {
            switch (mode) {
                case UiModeManager.MODE_NIGHT_NO:
                case UiModeManager.MODE_NIGHT_YES:
@@ -776,14 +775,10 @@ final class UiModeManagerService extends SystemService {
                default:
                    configNightMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
            }
            try {
            final ActivityTaskManagerInternal.PackageConfigurationUpdater updater =
                    mActivityTaskManager.createPackageConfigurationUpdater();
            updater.setNightMode(configNightMode);
            updater.commit();
            } catch (RemoteException e) {
                throw e;
            }
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -618,7 +618,7 @@ public abstract class ActivityTaskManagerInternal {
        /**
         * Commit changes.
         */
        void commit() throws RemoteException;
        void commit();
    }

    /**
+20 −20
Original line number Diff line number Diff line
@@ -6390,10 +6390,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

        @Override
        public PackageConfigurationUpdater createPackageConfigurationUpdater() {
            synchronized (mGlobalLock) {
            return new PackageConfigurationUpdaterImpl(Binder.getCallingPid());
        }
        }

        @Override
        public boolean hasSystemAlertWindowPermission(int callingUid, int callingPid,
@@ -6405,7 +6403,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {

    final class PackageConfigurationUpdaterImpl implements
            ActivityTaskManagerInternal.PackageConfigurationUpdater {
        private int mPid;
        private final int mPid;
        private int mNightMode;

        PackageConfigurationUpdaterImpl(int pid) {
@@ -6419,14 +6417,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }

        @Override
        public void commit() throws RemoteException {
            if (mPid == 0) {
                throw new RemoteException("Invalid process");
            }
        public void commit() {
            synchronized (mGlobalLock) {
                final long ident = Binder.clearCallingIdentity();
                try {
                    final WindowProcessController wpc = mProcessMap.getProcess(mPid);
                    if (wpc == null) {
                    Slog.w(TAG, "Override application configuration: cannot find application");
                        Slog.w(TAG, "Override application configuration: cannot find pid " + mPid);
                        return;
                    }
                    if (wpc.getNightMode() == mNightMode) {
@@ -6437,6 +6434,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    }
                    wpc.updateNightModeForAllActivities(mNightMode);
                    mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            }
        }