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

Commit 00bf6da8 authored by Jing Ji's avatar Jing Ji
Browse files

Fix the processgroup creation failure due to race conditions

...between creating the process and attaching the process.

The webview/app zygote process creation consists two steps:
a) Fork the process; b) Create the processgroup.
Betwen a) and b), if the app process has started and attaches
itself to the system_server, and also dies before b), we'd
end up killing its processgroup before creating it. This CL
fixed this issue.

Bug: 283391058
Test: Manual
Change-Id: I2c68f43ac921621bf0a3b0b2b399118518c60ca1
parent d28b311a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3393,7 +3393,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                mProcessList.noteAppKill(app, ApplicationExitInfo.REASON_OTHER,
                        ApplicationExitInfo.SUBREASON_UNKNOWN, reason);
            }
            ProcessList.killProcessGroup(app.uid, pid);
            app.killProcessGroupIfNecessaryLocked(true);
            synchronized (mProcLock) {
                app.setKilled(true);
            }
+25 −20
Original line number Diff line number Diff line
@@ -1197,6 +1197,23 @@ class ProcessRecord implements WindowProcessListener {
                EventLog.writeEvent(EventLogTags.AM_KILL,
                        userId, mPid, processName, mState.getSetAdj(), reason);
                Process.killProcessQuiet(mPid);
                killProcessGroupIfNecessaryLocked(asyncKPG);
            } else {
                mPendingStart = false;
            }
            if (!mPersistent) {
                synchronized (mProcLock) {
                    mKilled = true;
                    mKilledByAm = true;
                    mKillTime = SystemClock.uptimeMillis();
                }
            }
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
    }

    @GuardedBy("mService")
    void killProcessGroupIfNecessaryLocked(boolean async) {
        final boolean killProcessGroup;
        if (mHostingRecord != null
                && (mHostingRecord.usesWebviewZygote() || mHostingRecord.usesAppZygote())) {
@@ -1211,24 +1228,12 @@ class ProcessRecord implements WindowProcessListener {
            killProcessGroup = true;
        }
        if (killProcessGroup) {
                    if (asyncKPG) {
            if (async) {
                ProcessList.killProcessGroup(uid, mPid);
            } else {
                Process.sendSignalToProcessGroup(uid, mPid, OsConstants.SIGKILL);
            }
        }
            } else {
                mPendingStart = false;
            }
            if (!mPersistent) {
                synchronized (mProcLock) {
                    mKilled = true;
                    mKilledByAm = true;
                    mKillTime = SystemClock.uptimeMillis();
                }
            }
            Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
        }
    }

    @Override