Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 834b66c4 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Getting ephemeral flag from PackageManager when UidRecord is null

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
parent ca6d48f3
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -21482,6 +21482,15 @@ public class ActivityManagerService extends IActivityManager.Stub
        return success;
        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) {
    private final void enqueueUidChangeLocked(UidRecord uidRec, int uid, int change) {
        final UidRecord.ChangeItem pendingChange;
        final UidRecord.ChangeItem pendingChange;
        if (uidRec == null || uidRec.pendingChange == null) {
        if (uidRec == null || uidRec.pendingChange == null) {
@@ -21522,7 +21531,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        pendingChange.change = change;
        pendingChange.change = change;
        pendingChange.processState = uidRec != null
        pendingChange.processState = uidRec != null
                ? uidRec.setProcState : ActivityManager.PROCESS_STATE_NONEXISTENT;
                ? 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;
        pendingChange.procStateSeq = uidRec != null ? uidRec.curProcStateSeq : 0;
        // Directly update the power manager, since we sit on top of it and it is critical
        // Directly update the power manager, since we sit on top of it and it is critical