Loading core/java/android/service/notification/StatusBarNotification.java +1 −1 Original line number Diff line number Diff line Loading @@ -436,7 +436,7 @@ public class StatusBarNotification implements Parcelable { try { ApplicationInfo ai = context.getPackageManager() .getApplicationInfoAsUser(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES, getUserId()); getNormalizedUserId()); mContext = context.createApplicationContext(ai, Context.CONTEXT_RESTRICTED); } catch (PackageManager.NameNotFoundException e) { Loading core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.service.notification; 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 org.junit.Assert.assertFalse; Loading Loading @@ -51,6 +53,7 @@ public class StatusBarNotificationTest { private final Context mMockContext = mock(Context.class); @Mock private Context mRealContext; private PackageManager mPm; private static final String PKG = "com.example.o"; Loading @@ -75,6 +78,8 @@ public class StatusBarNotificationTest { InstrumentationRegistry.getContext().getResources()); when(mMockContext.getPackageManager()).thenReturn(mPm); when(mMockContext.getApplicationInfo()).thenReturn(new ApplicationInfo()); mRealContext = InstrumentationRegistry.getContext(); } @Test Loading Loading @@ -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) { return getNotification(pkg, getNotificationBuilder(group, channelId)); } Loading Loading
core/java/android/service/notification/StatusBarNotification.java +1 −1 Original line number Diff line number Diff line Loading @@ -436,7 +436,7 @@ public class StatusBarNotification implements Parcelable { try { ApplicationInfo ai = context.getPackageManager() .getApplicationInfoAsUser(pkg, PackageManager.MATCH_UNINSTALLED_PACKAGES, getUserId()); getNormalizedUserId()); mContext = context.createApplicationContext(ai, Context.CONTEXT_RESTRICTED); } catch (PackageManager.NameNotFoundException e) { Loading
core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java +18 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.service.notification; 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 org.junit.Assert.assertFalse; Loading Loading @@ -51,6 +53,7 @@ public class StatusBarNotificationTest { private final Context mMockContext = mock(Context.class); @Mock private Context mRealContext; private PackageManager mPm; private static final String PKG = "com.example.o"; Loading @@ -75,6 +78,8 @@ public class StatusBarNotificationTest { InstrumentationRegistry.getContext().getResources()); when(mMockContext.getPackageManager()).thenReturn(mPm); when(mMockContext.getApplicationInfo()).thenReturn(new ApplicationInfo()); mRealContext = InstrumentationRegistry.getContext(); } @Test Loading Loading @@ -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) { return getNotification(pkg, getNotificationBuilder(group, channelId)); } Loading