Skip to content

Commit 00fad46

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 5a110cf commit 00fad46

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
@@ -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) {

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)