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

Commit 5c91870f authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Stopped starting and killing processes directly from ATMS (27/n)

Post messages to have processes started and killed instead which
should be okay.

Bug: 80414790
Test: Existing tests pass
Change-Id: Ia435aa815c36a84947ae0f76291b1d1f9222231d
parent 2ea36d45
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -262,4 +262,18 @@ public abstract class ActivityManagerInternal {
     * flags.
     */
    public abstract void broadcastCloseSystemDialogs(String reason);

    /**
     * Kills all background processes, except those matching any of the specified properties.
     *
     * @param minTargetSdk the target SDK version at or above which to preserve processes,
     *                     or {@code -1} to ignore the target SDK
     * @param maxProcState the process state at or below which to preserve processes,
     *                     or {@code -1} to ignore the process state
     */
    public abstract void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState);

    /** Starts a given process. */
    public abstract void startProcess(String processName, ApplicationInfo info,
            boolean knownToBeDead, String hostingType, ComponentName hostingName);
}
+18 −0
Original line number Diff line number Diff line
@@ -20402,6 +20402,24 @@ public class ActivityManagerService extends IActivityManager.Stub
                        OP_NONE, null, false, false, -1, SYSTEM_UID, UserHandle.USER_ALL);
            }
        }
        @Override
        public void killAllBackgroundProcessesExcept(int minTargetSdk, int maxProcState) {
            synchronized (ActivityManagerService.this) {
                ActivityManagerService.this.killAllBackgroundProcessesExcept(
                        minTargetSdk, maxProcState);
            }
        }
        @Override
        public void startProcess(String processName, ApplicationInfo info,
                boolean knownToBeDead, String hostingType, ComponentName hostingName) {
            synchronized (ActivityManagerService.this) {
                startProcessLocked(processName, info, knownToBeDead, 0 /* intentFlags */,
                        hostingType, hostingName, false /* allowWhileBooting */,
                        false /* isolated */, true /* keepIfLarge */);
            }
        }
    }
    long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
+6 −2
Original line number Diff line number Diff line
@@ -1660,8 +1660,12 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            // restart the application.
        }

        mService.mAm.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,
                "activity", r.intent.getComponent(), false, false, true);
        // Post message to start process to avoid possible deadlock of calling into AMS with the
        // ATMS lock held.
        final Message msg = PooledLambda.obtainMessage(
                ActivityManagerInternal::startProcess, mService.mAmInternal, r.processName,
                r.info.applicationInfo, true, "activity", r.intent.getComponent());
        mService.mH.sendMessage(msg);
    }

    void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) {
+6 −2
Original line number Diff line number Diff line
@@ -4841,8 +4841,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            if (isDensityChange && displayId == DEFAULT_DISPLAY) {
                mAppWarnings.onDensityChanged();

                mAm.killAllBackgroundProcessesExcept(N,
                        ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
                // Post message to start process to avoid possible deadlock of calling into AMS with
                // the ATMS lock held.
                final Message msg = PooledLambda.obtainMessage(
                        ActivityManagerInternal::killAllBackgroundProcessesExcept, mAmInternal,
                        N, ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE);
                mH.sendMessage(msg);
            }
        }