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

Commit a937c5b7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix wrong use if "!UserHandle.isApp()""

parents 39937d4b 9cc471ce
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -573,6 +573,14 @@ public class Process {
        return UserHandle.of(UserHandle.getUserId(myUid()));
    }

    /**
     * Returns whether the given uid belongs to a system core component or not.
     * @hide
     */
    public static boolean isCoreUid(int uid) {
        return UserHandle.isCore(uid);
    }

    /**
     * Returns whether the given uid belongs to an application.
     * @param uid A kernel uid.
+22 −2
Original line number Diff line number Diff line
@@ -126,7 +126,10 @@ public final class UserHandle implements Parcelable {
        return getAppId(uid1) == getAppId(uid2);
    }

    /** @hide */
    /**
     * Whether a UID is an "isolated" UID.
     * @hide
     */
    public static boolean isIsolated(int uid) {
        if (uid > 0) {
            final int appId = getAppId(uid);
@@ -136,7 +139,11 @@ public final class UserHandle implements Parcelable {
        }
    }

    /** @hide */
    /**
     * Whether a UID belongs to a regular app. *Note* "Not a regular app" does not mean
     * "it's system", because of isolated UIDs. Use {@link #isCore} for that.
     * @hide
     */
    public static boolean isApp(int uid) {
        if (uid > 0) {
            final int appId = getAppId(uid);
@@ -146,6 +153,19 @@ public final class UserHandle implements Parcelable {
        }
    }

    /**
     * Whether a UID belongs to a system core component or not.
     * @hide
     */
    public static boolean isCore(int uid) {
        if (uid > 0) {
            final int appId = getAppId(uid);
            return appId < Process.FIRST_APPLICATION_UID;
        } else {
            return false;
        }
    }

    /**
     * Returns the user for a given uid.
     * @param uid A uid for an application running in a particular user.
+3 −3
Original line number Diff line number Diff line
@@ -504,7 +504,7 @@ public class ForceAppStandbyTracker {
     */
    void uidToForeground(int uid) {
        synchronized (mLock) {
            if (!UserHandle.isApp(uid)) {
            if (UserHandle.isCore(uid)) {
                return;
            }
            // TODO This can be optimized by calling indexOfKey and sharing the index for get and
@@ -522,7 +522,7 @@ public class ForceAppStandbyTracker {
     */
    void uidToBackground(int uid, boolean remove) {
        synchronized (mLock) {
            if (!UserHandle.isApp(uid)) {
            if (UserHandle.isCore(uid)) {
                return;
            }
            // TODO This can be optimized by calling indexOfKey and sharing the index for get and
@@ -864,7 +864,7 @@ public class ForceAppStandbyTracker {
     * Note clients normally shouldn't need to access it. It's only for dumpsys.
     */
    public boolean isInForeground(int uid) {
        if (!UserHandle.isApp(uid)) {
        if (UserHandle.isCore(uid)) {
            return true;
        }
        synchronized (mLock) {
+2 −3
Original line number Diff line number Diff line
@@ -428,7 +428,6 @@ import com.android.server.SystemServiceManager;
import com.android.server.ThreadPriorityBooster;
import com.android.server.Watchdog;
import com.android.server.am.ActivityStack.ActivityState;
import com.android.server.am.EventLogTags;
import com.android.server.am.proto.ActivityManagerServiceProto;
import com.android.server.am.proto.BroadcastProto;
import com.android.server.am.proto.GrantUriProto;
@@ -8849,7 +8848,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            case AppOpsManager.MODE_ALLOWED:
                // If force-background-check is enabled, restrict all apps that aren't whitelisted.
                if (mForceBackgroundCheck &&
                        UserHandle.isApp(uid) &&
                        !UserHandle.isCore(uid) &&
                        !isOnDeviceIdleWhitelistLocked(uid)) {
                    if (DEBUG_BACKGROUND_CHECK) {
                        Slog.i(TAG, "Force background check: " +
@@ -24120,7 +24119,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        final int size = mActiveUids.size();
        for (int i = 0; i < size; i++) {
            final int uid = mActiveUids.keyAt(i);
            if (!UserHandle.isApp(uid)) {
            if (UserHandle.isCore(uid)) {
                continue;
            }
            final UidRecord uidRec = mActiveUids.valueAt(i);