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

Commit 177d5bb1 authored by Austin Borger's avatar Austin Borger
Browse files

Modify UidRecord.CHANGE_PROCSTATE such that it behaves like a bit mask.

UidRecord.CHANGE_PROCSTATE was allocated the value 0, since it is
assumed that if there is any change to a UidRecord it includes a proc
state change. This is a valid assumption, but is not an unusual design
for a bitmask. This change adds a bit specifically for proc state
changes.

At the time of this change, CHANGE_PROCSTATE should always be set.
However the intention is to pre-empt change
I68d964f474d20f819f54b614a4e314ce00aac8fb, which breaks the assumption
that all UidRecord changes will include proc state. To avoid verbosity,
additional constants have been defined which combine the other change
bits with CHANGE_PROCSTATE for external users to reference.

Change-Id: Iae7e6601938d1b3ee5c4c9b339ae06029eb598e6
Bug: 124224342
Test: -- ActivityManagerServiceTest
      -- ActivityManagerProcessStateTest
      -- ActivityManagerFgsBgStartTest
      -- UidObserverControllerTest
      -- CtsAppTestCases
parent 329ed6ef
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -779,6 +779,7 @@ message UidRecordProto {
        CHANGE_CACHED = 3;
        CHANGE_UNCACHED = 4;
        CHANGE_CAPABILITY = 5;
        CHANGE_PROCSTATE = 6;
    }
    repeated Change last_reported_changes = 8;
    optional int32 num_procs = 9;
+1 −1
Original line number Diff line number Diff line
@@ -15528,7 +15528,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    @GuardedBy("this")
    final void doStopUidLocked(int uid, final UidRecord uidRec) {
        mServices.stopInBackgroundLocked(uid);
        enqueueUidChangeLocked(uidRec, uid, UidRecord.CHANGE_IDLE);
        enqueueUidChangeLocked(uidRec, uid, UidRecord.CHANGE_IDLE | UidRecord.CHANGE_PROCSTATE);
    }
    /**
+6 −3
Original line number Diff line number Diff line
@@ -1191,7 +1191,7 @@ public class OomAdjuster {
        }
        for (int i = activeUids.size() - 1; i >= 0; i--) {
            final UidRecord uidRec = activeUids.valueAt(i);
            int uidChange = UidRecord.CHANGE_PROCSTATE;
            int uidChange = 0;
            if (uidRec.getCurProcState() != PROCESS_STATE_NONEXISTENT
                    && (uidRec.getSetProcState() != uidRec.getCurProcState()
                    || uidRec.getSetCapability() != uidRec.getCurCapability()
@@ -1219,12 +1219,12 @@ public class OomAdjuster {
                        }
                    }
                    if (uidRec.isIdle() && !uidRec.isSetIdle()) {
                        uidChange = UidRecord.CHANGE_IDLE;
                        uidChange |= UidRecord.CHANGE_IDLE;
                        becameIdle.add(uidRec);
                    }
                } else {
                    if (uidRec.isIdle()) {
                        uidChange = UidRecord.CHANGE_ACTIVE;
                        uidChange |= UidRecord.CHANGE_ACTIVE;
                        EventLogTags.writeAmUidActive(uidRec.getUid());
                        uidRec.setIdle(false);
                    }
@@ -1241,6 +1241,9 @@ public class OomAdjuster {
                if (uidRec.getSetCapability() != uidRec.getCurCapability()) {
                    uidChange |= UidRecord.CHANGE_CAPABILITY;
                }
                if (uidRec.getSetProcState() != uidRec.getCurProcState()) {
                    uidChange |= UidRecord.CHANGE_PROCSTATE;
                }
                uidRec.setSetProcState(uidRec.getCurProcState());
                uidRec.setSetCapability(uidRec.getCurCapability());
                uidRec.setSetAllowListed(uidRec.isCurAllowListed());
+1 −1
Original line number Diff line number Diff line
@@ -3031,7 +3031,7 @@ public final class ProcessList {
                            Slog.i(TAG_UID_OBSERVERS, "No more processes in " + uidRecord);
                        }
                        mService.enqueueUidChangeLocked(uidRecord, -1,
                                UidRecord.CHANGE_GONE);
                                UidRecord.CHANGE_GONE | UidRecord.CHANGE_PROCSTATE);
                        EventLogTags.writeAmUidStopped(uid);
                        mActiveUids.remove(uid);
                        mService.mFgsStartTempAllowList.removeUid(record.info.uid);
+3 −0
Original line number Diff line number Diff line
@@ -154,6 +154,9 @@ public class UidObserverController {
        if ((pendingChange & UidRecord.CHANGE_CAPABILITY) != 0) {
            currentChange |= UidRecord.CHANGE_CAPABILITY;
        }
        if ((pendingChange & UidRecord.CHANGE_PROCSTATE) != 0) {
            currentChange |= UidRecord.CHANGE_PROCSTATE;
        }
        return currentChange;
    }

Loading