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

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

Merge "Use UserHandle.isSameApp to determine if the uids are the same app" into main

parents 6b378155 fd4e20ec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -244,7 +244,7 @@ class PackageMonitorCallbackHelper {
                return;
            }
            int registerUid = registerUser.getUid();
            if (allowUids != null && registerUid != Process.SYSTEM_UID
            if (allowUids != null && !UserHandle.isSameApp(registerUid, Process.SYSTEM_UID)
                    && !ArrayUtils.contains(allowUids, registerUid)) {
                if (DEBUG) {
                    Slog.w(TAG, "Skip invoke PackageMonitorCallback for " + intent.getAction()
+19 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.Handler;
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Process;
import android.os.UserHandle;
import android.util.SparseArray;

import org.junit.After;
@@ -340,6 +341,24 @@ public class PackageMonitorCallbackHelperTest {
        verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any());
    }

    @Test
    public void registerPackageMonitor_callbackNotInAllowListSystemUidSecondUser_callbackIsCalled()
            throws Exception {
        IRemoteCallback callback = createMockPackageMonitorCallback();
        int userId = 10;
        int fakeAppId = 12345;
        SparseArray<int[]> broadcastAllowList = new SparseArray<>();
        broadcastAllowList.put(userId, new int[]{UserHandle.getUid(userId, fakeAppId)});

        mPackageMonitorCallbackHelper.registerPackageMonitorCallback(callback, userId,
                UserHandle.getUid(userId, Process.SYSTEM_UID));
        mPackageMonitorCallbackHelper.notifyPackageMonitor(Intent.ACTION_PACKAGE_ADDED,
                FAKE_PACKAGE_NAME, createFakeBundle(), new int[]{userId},
                null /* instantUserIds */, broadcastAllowList, mHandler, null /* filterExtras */);

        verify(callback, after(WAIT_CALLBACK_CALLED_IN_MS).times(1)).sendResult(any());
    }

    private IRemoteCallback createMockPackageMonitorCallback() {
        return spy(new IRemoteCallback.Stub() {
            @Override