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

Commit 6805730b authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Automerger Merge Worker
Browse files

Merge "Fix setApplicationNightMode crash due to permission denial." into sc-dev am: d42b8e2c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14702762

Change-Id: If69e153e70ece1a8cd3f72551e90cce056d4c47e
parents e0ad9e1a d42b8e2c
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
@@ -6404,10 +6404,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,
@@ -6419,7 +6417,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) {
@@ -6433,14 +6431,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) {
@@ -6451,6 +6448,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    }
                    wpc.updateNightModeForAllActivities(mNightMode);
                    mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
            }
        }