@@ -3424,6 +3424,15 @@ private final void startProcessLocked(ProcessRecord app, String hostingType,
34243424 app.killedByAm = false;
34253425 checkTime(startTime, "startProcess: starting to update pids map");
34263426 synchronized (mPidsSelfLocked) {
3427+ ProcessRecord oldApp;
3428+ // If there is already an app occupying that pid that hasn't been cleaned up
3429+ if ((oldApp = mPidsSelfLocked.get(startResult.pid)) != null && !app.isolated) {
3430+ // Clean up anything relating to this pid first
3431+ Slog.w(TAG, "Reusing pid " + startResult.pid
3432+ + " while app is still mapped to it");
3433+ cleanUpApplicationRecordLocked(oldApp, false, false, -1,
3434+ true /*replacingPid*/);
3435+ }
34273436 this.mPidsSelfLocked.put(startResult.pid, app);
34283437 if (isActivityProcess) {
34293438 Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
@@ -4564,7 +4573,8 @@ public void overridePendingTransition(IBinder token, String packageName,
45644573 private final void handleAppDiedLocked(ProcessRecord app,
45654574 boolean restarting, boolean allowRestart) {
45664575 int pid = app.pid;
4567- boolean kept = cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1);
4576+ boolean kept = cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1,
4577+ false /*replacingPid*/);
45684578 if (!kept && !restarting) {
45694579 removeLruProcessLocked(app);
45704580 if (pid > 0) {
@@ -15502,7 +15512,8 @@ private final boolean removeDyingProviderLocked(ProcessRecord proc,
1550215512 * app that was passed in must remain on the process lists.
1550315513 */
1550415514 private final boolean cleanUpApplicationRecordLocked(ProcessRecord app,
15505- boolean restarting, boolean allowRestart, int index) {
15515+ boolean restarting, boolean allowRestart, int index, boolean replacingPid) {
15516+ Slog.d(TAG, "cleanUpApplicationRecord -- " + app.pid);
1550615517 if (index >= 0) {
1550715518 removeLruProcessLocked(app);
1550815519 ProcessList.remove(app.pid);
@@ -15632,7 +15643,9 @@ private final boolean cleanUpApplicationRecordLocked(ProcessRecord app,
1563215643 if (!app.persistent || app.isolated) {
1563315644 if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG_CLEANUP,
1563415645 "Removing non-persistent process during cleanup: " + app);
15635- removeProcessNameLocked(app.processName, app.uid);
15646+ if (!replacingPid) {
15647+ removeProcessNameLocked(app.processName, app.uid);
15648+ }
1563615649 if (mHeavyWeightProcess == app) {
1563715650 mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
1563815651 mHeavyWeightProcess.userId, 0));
@@ -19473,7 +19486,7 @@ final void trimApplications() {
1947319486 // Ignore exceptions.
1947419487 }
1947519488 }
19476- cleanUpApplicationRecordLocked(app, false, true, -1);
19489+ cleanUpApplicationRecordLocked(app, false, true, -1, false /*replacingPid*/ );
1947719490 mRemovedProcesses.remove(i);
1947819491
1947919492 if (app.persistent) {
0 commit comments