From 9540ca4fc47ac5448826c43912aa573caecc746c Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 2 May 2016 12:33:22 -0600 Subject: [PATCH] When fork() fails, clean up data structures. There are a number of different conditions that could cause ActivityManager to fail to fork() a process. One of the most common ones is a package being "frozen" during a PackageManager operation. When this happens, use the common forceStopPackageLocked() method to cleanup any internal bookkeeping structures. (It's slightly misnamed, since it doesn't actually "force stop" the app.) It's also the same method that we called moments earlier when the package was first frozen through KILL_APPLICATION_MSG. Bug: 28395549 Change-Id: I7b1623c5f66fc1de24cad5360c977ea764d09244 --- .../android/server/am/ActivityManagerService.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index ddb9b8af1befb..30dd33fab3929 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -3724,13 +3724,16 @@ public final class ActivityManagerService extends ActivityManagerNative } checkTime(startTime, "startProcess: done updating pids map"); } catch (RuntimeException e) { - // XXX do better error recovery. - app.setPid(0); - mBatteryStatsService.noteProcessFinish(app.processName, app.info.uid); - if (app.isolated) { - mBatteryStatsService.removeIsolatedUid(app.uid, app.info.uid); - } Slog.e(TAG, "Failure starting process " + app.processName, e); + + // Something went very wrong while trying to start this process; one + // common case is when the package is frozen due to an active + // upgrade. To recover, clean up any active bookkeeping related to + // starting this process. (We already invoked this method once when + // the package was initially frozen through KILL_APPLICATION_MSG, so + // it doesn't hurt to use it again.) + forceStopPackageLocked(app.info.packageName, UserHandle.getAppId(app.uid), false, + false, true, false, false, UserHandle.getUserId(app.userId), "start failure"); } }