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

Commit 668495d7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Ensure package context used by System UI has a valid userId." into...

Merge "Ensure package context used by System UI has a valid userId." into sc-qpr1-dev am: e7f5a375

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15584842

Change-Id: Ief73f955c719d82ca6c5bbe446f6da71af639551
parents 4fe50aa8 e7f5a375
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -436,7 +436,7 @@ public class StatusBarNotification implements Parcelable {
            try {
            try {
                ApplicationInfo ai = context.getPackageManager()
                ApplicationInfo ai = context.getPackageManager()
                        .getApplicationInfoAsUser(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES,
                        .getApplicationInfoAsUser(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES,
                                getUserId());
                                getNormalizedUserId());
                mContext = context.createApplicationContext(ai,
                mContext = context.createApplicationContext(ai,
                        Context.CONTEXT_RESTRICTED);
                        Context.CONTEXT_RESTRICTED);
            } catch (PackageManager.NameNotFoundException e) {
            } catch (PackageManager.NameNotFoundException e) {
+18 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
package android.service.notification;
package android.service.notification;


import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertNull;


import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
@@ -51,6 +53,7 @@ public class StatusBarNotificationTest {


    private final Context mMockContext = mock(Context.class);
    private final Context mMockContext = mock(Context.class);
    @Mock
    @Mock
    private Context mRealContext;
    private PackageManager mPm;
    private PackageManager mPm;


    private static final String PKG = "com.example.o";
    private static final String PKG = "com.example.o";
@@ -75,6 +78,8 @@ public class StatusBarNotificationTest {
                InstrumentationRegistry.getContext().getResources());
                InstrumentationRegistry.getContext().getResources());
        when(mMockContext.getPackageManager()).thenReturn(mPm);
        when(mMockContext.getPackageManager()).thenReturn(mPm);
        when(mMockContext.getApplicationInfo()).thenReturn(new ApplicationInfo());
        when(mMockContext.getApplicationInfo()).thenReturn(new ApplicationInfo());

        mRealContext = InstrumentationRegistry.getContext();
    }
    }


    @Test
    @Test
@@ -199,6 +204,19 @@ public class StatusBarNotificationTest {


    }
    }


    @Test
    public void testGetPackageContext_worksWithUserAll() {
        String pkg = "com.android.systemui";
        int uid = 1000;
        Notification notification = getNotificationBuilder(GROUP_ID_1, CHANNEL_ID).build();
        StatusBarNotification sbn = new StatusBarNotification(
                pkg, pkg, ID, TAG, uid, uid, notification, UserHandle.ALL, null, UID);
        Context resultContext = sbn.getPackageContext(mRealContext);
        assertNotNull(resultContext);
        assertNotSame(mRealContext, resultContext);
        assertEquals(pkg, resultContext.getPackageName());
    }

    private StatusBarNotification getNotification(String pkg, String group, String channelId) {
    private StatusBarNotification getNotification(String pkg, String group, String channelId) {
        return getNotification(pkg, getNotificationBuilder(group, channelId));
        return getNotification(pkg, getNotificationBuilder(group, channelId));
    }
    }