Skip to content

Commit c998deb

Browse files
Amith Yamasanigitbuildkicker
authored andcommitted
DO NOT MERGE: Clean up when recycling a pid with a pending launch
Fix for accidental launch of a broadcast receiver in an incorrect app instance. Bug: 30202481 Change-Id: I8ec8f19c633f3aec8da084dab5fd5b312443336f (cherry picked from commit d1eeb5b)
1 parent 90ea10c commit c998deb

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

services/core/java/com/android/server/am/ActivityManagerService.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

services/core/java/com/android/server/am/BroadcastQueue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ public boolean sendPendingBroadcastsLocked(ProcessRecord app) {
292292
boolean didSomething = false;
293293
final BroadcastRecord br = mPendingBroadcast;
294294
if (br != null && br.curApp.pid == app.pid) {
295+
if (br.curApp != app) {
296+
Slog.e(TAG, "App mismatch when sending pending broadcast to "
297+
+ app.processName + ", intended target is " + br.curApp.processName);
298+
return false;
299+
}
295300
try {
296301
mPendingBroadcast = null;
297302
processCurBroadcastLocked(br, app);

0 commit comments

Comments
 (0)