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

Commit 9576b5a2 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Allow clients to register for listening to changes in capabilities." into sc-dev

parents 9759067e ce7fc422
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -794,6 +794,9 @@ public class ActivityManager {
    /** @hide Flag for registerUidObserver: report uid cached state has changed. */
    public static final int UID_OBSERVER_CACHED = 1<<4;

    /** @hide Flag for registerUidObserver: report uid capability has changed. */
    public static final int UID_OBSERVER_CAPABILITY = 1<<5;

    /** @hide Mode for {@link IActivityManager#isAppStartModeDisabled}: normal free-to-run operation. */
    public static final int APP_START_MODE_NORMAL = 0;

+2 −0
Original line number Diff line number Diff line
@@ -33,4 +33,6 @@ enum UidObserverFlag {
    UID_OBSERVER_FLAG_ACTIVE = 4;
    // report uid cached state has changed, original value is 1 << 4
    UID_OBSERVER_FLAG_CACHED = 5;
    // report uid capability has changed, original value is 1 << 5
    UID_OBSERVER_FLAG_CAPABILITY = 6;
}
+1 −0
Original line number Diff line number Diff line
@@ -778,6 +778,7 @@ message UidRecordProto {
        CHANGE_ACTIVE = 2;
        CHANGE_CACHED = 3;
        CHANGE_UNCACHED = 4;
        CHANGE_CAPABILITY = 5;
    }
    repeated Change last_reported_changes = 8;
    optional int32 num_procs = 9;
+3 −0
Original line number Diff line number Diff line
@@ -1328,6 +1328,9 @@ public final class OomAdjuster {
                        || uidRec.getSetProcState() == PROCESS_STATE_NONEXISTENT) {
                    uidChange |= isCached ? UidRecord.CHANGE_CACHED : UidRecord.CHANGE_UNCACHED;
                }
                if (uidRec.getSetCapability() != uidRec.getCurCapability()) {
                    uidChange |= UidRecord.CHANGE_CAPABILITY;
                }
                uidRec.setSetProcState(uidRec.getCurProcState());
                uidRec.setSetCapability(uidRec.getCurCapability());
                uidRec.setSetAllowListed(uidRec.isCurAllowListed());
+23 −11
Original line number Diff line number Diff line
@@ -147,6 +147,9 @@ public class UidObserverController {
        if ((currentChange & UidRecord.CHANGE_GONE) != 0) {
            currentChange &= ~(UidRecord.CHANGE_ACTIVE | UidRecord.CHANGE_CACHED);
        }
        if ((pendingChange & UidRecord.CHANGE_CAPABILITY) != 0) {
            currentChange |= UidRecord.CHANGE_CAPABILITY;
        }
        return currentChange;
    }

@@ -285,12 +288,9 @@ public class UidObserverController {
                        reg.mLastProcStates.delete(item.uid);
                    }
                } else {
                    boolean doReport = false;
                    if ((reg.mWhich & ActivityManager.UID_OBSERVER_PROCSTATE) != 0) {
                        if (DEBUG_UID_OBSERVERS) {
                            Slog.i(TAG_UID_OBSERVERS, "UID CHANGED uid=" + item.uid
                                    + ": " + item.procState + ": " + item.capability);
                        }
                        boolean doReport = true;
                        doReport = true;
                        if (reg.mCutpoint >= ActivityManager.MIN_PROCESS_STATE) {
                            final int lastState = reg.mLastProcStates.get(item.uid,
                                    ActivityManager.PROCESS_STATE_UNKNOWN);
@@ -302,7 +302,15 @@ public class UidObserverController {
                                doReport = item.procState != PROCESS_STATE_NONEXISTENT;
                            }
                        }
                    }
                    if ((reg.mWhich & ActivityManager.UID_OBSERVER_CAPABILITY) != 0) {
                        doReport |= (change & UidRecord.CHANGE_CAPABILITY) != 0;
                    }
                    if (doReport) {
                        if (DEBUG_UID_OBSERVERS) {
                            Slog.i(TAG_UID_OBSERVERS, "UID CHANGED uid=" + item.uid
                                    + ": " + item.procState + ": " + item.capability);
                        }
                        if (reg.mLastProcStates != null) {
                            reg.mLastProcStates.put(item.uid, item.procState);
                        }
@@ -310,7 +318,6 @@ public class UidObserverController {
                                item.procStateSeq, item.capability);
                    }
                }
                }
                final int duration = (int) (SystemClock.uptimeMillis() - start);
                if (reg.mMaxDispatchTime < duration) {
                    reg.mMaxDispatchTime = duration;
@@ -428,12 +435,14 @@ public class UidObserverController {
                ActivityManager.UID_OBSERVER_ACTIVE,
                ActivityManager.UID_OBSERVER_GONE,
                ActivityManager.UID_OBSERVER_PROCSTATE,
                ActivityManager.UID_OBSERVER_CAPABILITY,
        };
        private static final int[] PROTO_ENUMS = new int[]{
                ActivityManagerProto.UID_OBSERVER_FLAG_IDLE,
                ActivityManagerProto.UID_OBSERVER_FLAG_ACTIVE,
                ActivityManagerProto.UID_OBSERVER_FLAG_GONE,
                ActivityManagerProto.UID_OBSERVER_FLAG_PROCSTATE,
                ActivityManagerProto.UID_OBSERVER_FLAG_CAPABILITY,
        };

        UidObserverRegistration(int uid, @NonNull String pkg, int which, int cutpoint) {
@@ -462,6 +471,9 @@ public class UidObserverController {
            if ((mWhich & ActivityManager.UID_OBSERVER_GONE) != 0) {
                pw.print(" GONE");
            }
            if ((mWhich & ActivityManager.UID_OBSERVER_CAPABILITY) != 0) {
                pw.print(" CAP");
            }
            if ((mWhich & ActivityManager.UID_OBSERVER_PROCSTATE) != 0) {
                pw.print(" STATE");
                pw.print(" (cut=");
Loading