@@ -3425,6 +3425,15 @@ private final void startProcessLocked(ProcessRecord app, String hostingType,
34253425 app.killedByAm = false;
34263426 checkTime(startTime, "startProcess: starting to update pids map");
34273427 synchronized (mPidsSelfLocked) {
3428+ ProcessRecord oldApp;
3429+ // If there is already an app occupying that pid that hasn't been cleaned up
3430+ if ((oldApp = mPidsSelfLocked.get(startResult.pid)) != null && !app.isolated) {
3431+ // Clean up anything relating to this pid first
3432+ Slog.w(TAG, "Reusing pid " + startResult.pid
3433+ + " while app is still mapped to it");
3434+ cleanUpApplicationRecordLocked(oldApp, false, false, -1,
3435+ true /*replacingPid*/);
3436+ }
34283437 this.mPidsSelfLocked.put(startResult.pid, app);
34293438 if (isActivityProcess) {
34303439 Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
@@ -4565,7 +4574,8 @@ public void overridePendingTransition(IBinder token, String packageName,
45654574 private final void handleAppDiedLocked(ProcessRecord app,
45664575 boolean restarting, boolean allowRestart) {
45674576 int pid = app.pid;
4568- boolean kept = cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1);
4577+ boolean kept = cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1,
4578+ false /*replacingPid*/);
45694579 if (!kept && !restarting) {
45704580 removeLruProcessLocked(app);
45714581 if (pid > 0) {
@@ -15507,7 +15517,8 @@ private final boolean removeDyingProviderLocked(ProcessRecord proc,
1550715517 * app that was passed in must remain on the process lists.
1550815518 */
1550915519 private final boolean cleanUpApplicationRecordLocked(ProcessRecord app,
15510- boolean restarting, boolean allowRestart, int index) {
15520+ boolean restarting, boolean allowRestart, int index, boolean replacingPid) {
15521+ Slog.d(TAG, "cleanUpApplicationRecord -- " + app.pid);
1551115522 if (index >= 0) {
1551215523 removeLruProcessLocked(app);
1551315524 ProcessList.remove(app.pid);
@@ -15637,7 +15648,9 @@ private final boolean cleanUpApplicationRecordLocked(ProcessRecord app,
1563715648 if (!app.persistent || app.isolated) {
1563815649 if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG_CLEANUP,
1563915650 "Removing non-persistent process during cleanup: " + app);
15640- removeProcessNameLocked(app.processName, app.uid);
15651+ if (!replacingPid) {
15652+ removeProcessNameLocked(app.processName, app.uid);
15653+ }
1564115654 if (mHeavyWeightProcess == app) {
1564215655 mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
1564315656 mHeavyWeightProcess.userId, 0));
@@ -19489,7 +19502,7 @@ final void trimApplications() {
1948919502 // Ignore exceptions.
1949019503 }
1949119504 }
19492- cleanUpApplicationRecordLocked(app, false, true, -1);
19505+ cleanUpApplicationRecordLocked(app, false, true, -1, false /*replacingPid*/ );
1949319506 mRemovedProcesses.remove(i);
1949419507
1949519508 if (app.persistent) {
0 commit comments