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

Commit d347205e authored by Christopher Tate's avatar Christopher Tate
Browse files

Fix #37305009 : Beam crash in secondary users

The background-policy check for a-priori app uids needs to be an appId
check rather than nominal uid.

Along the way, even though the code is not invoked after the boot
sequence currently, make the "is this uid on the a-priori list?"
check thread safe.

Bug 37305009
Test: manual

Change-Id: I7c2525f86e73b213057cd4b7f327191ec20c4a6d
parent 106527e2
Loading
Loading
Loading
Loading
+10 −8
Original line number Original line Diff line number Diff line
@@ -832,9 +832,9 @@ public class ActivityManagerService extends IActivityManager.Stub
    ProcessRecord mHeavyWeightProcess = null;
    ProcessRecord mHeavyWeightProcess = null;
    /**
    /**
     * Non-persistent app uid whitelist for background restrictions
     * Non-persistent appId whitelist for background restrictions
     */
     */
    int[] mBackgroundUidWhitelist = new int[] {
    int[] mBackgroundAppIdWhitelist = new int[] {
            BLUETOOTH_UID
            BLUETOOTH_UID
    };
    };
@@ -12102,9 +12102,11 @@ public class ActivityManagerService extends IActivityManager.Stub
    }
    }
    private boolean uidOnBackgroundWhitelist(final int uid) {
    private boolean uidOnBackgroundWhitelist(final int uid) {
        final int N = mBackgroundUidWhitelist.length;
        final int appId = UserHandle.getAppId(uid);
        final int[] whitelist = mBackgroundAppIdWhitelist;
        final int N = whitelist.length;
        for (int i = 0; i < N; i++) {
        for (int i = 0; i < N; i++) {
            if (uid == mBackgroundUidWhitelist[i]) {
            if (appId == whitelist[i]) {
                return true;
                return true;
            }
            }
        }
        }
@@ -12121,11 +12123,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            Slog.i(TAG, "Adding uid " + uid + " to bg uid whitelist");
            Slog.i(TAG, "Adding uid " + uid + " to bg uid whitelist");
        }
        }
        synchronized (this) {
        synchronized (this) {
            final int N = mBackgroundUidWhitelist.length;
            final int N = mBackgroundAppIdWhitelist.length;
            int[] newList = new int[N+1];
            int[] newList = new int[N+1];
            System.arraycopy(mBackgroundUidWhitelist, 0, newList, 0, N);
            System.arraycopy(mBackgroundAppIdWhitelist, 0, newList, 0, N);
            newList[N] = uid;
            newList[N] = UserHandle.getAppId(uid);
            mBackgroundUidWhitelist = newList;
            mBackgroundAppIdWhitelist = newList;
        }
        }
    }
    }