OSDN Git Service

Getting ephemeral flag from PackageManager when UidRecord is null
authorSuprabh Shukla <suprabh@google.com>
Thu, 16 Mar 2017 22:37:36 +0000 (15:37 -0700)
committerSuprabh Shukla <suprabh@google.com>
Fri, 17 Mar 2017 21:29:08 +0000 (14:29 -0700)
When a user switches off background running for an app that was already
stopped, UidRecord is null when passed in to
AcitivityManager#doStopUidLocked resulting in an NPE. We need to get
ephemeral state flag from package manager in such cases.

Test: Manual

Bug: 36158380
Change-Id: Id77848c252cc0ff0c803113ac2c7c19aa0dcf254

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

index 5a6d9aa..b90f34d 100644 (file)
@@ -21482,6 +21482,15 @@ public class ActivityManagerService extends IActivityManager.Stub
         return success;
     }
 
+    private boolean isEphemeralLocked(int uid) {
+        String packages[] = mContext.getPackageManager().getPackagesForUid(uid);
+        if (packages == null || packages.length != 1) { // Ephemeral apps cannot share uid
+            return false;
+        }
+        return getPackageManagerInternalLocked().isPackageEphemeral(UserHandle.getUserId(uid),
+                packages[0]);
+    }
+
     private final void enqueueUidChangeLocked(UidRecord uidRec, int uid, int change) {
         final UidRecord.ChangeItem pendingChange;
         if (uidRec == null || uidRec.pendingChange == null) {
@@ -21522,7 +21531,7 @@ public class ActivityManagerService extends IActivityManager.Stub
         pendingChange.change = change;
         pendingChange.processState = uidRec != null
                 ? uidRec.setProcState : ActivityManager.PROCESS_STATE_NONEXISTENT;
-        pendingChange.ephemeral = uidRec.ephemeral;
+        pendingChange.ephemeral = uidRec != null ? uidRec.ephemeral : isEphemeralLocked(uid);
         pendingChange.procStateSeq = uidRec != null ? uidRec.curProcStateSeq : 0;
 
         // Directly update the power manager, since we sit on top of it and it is critical