Loading services/core/java/com/android/server/notification/NotificationManagerService.java +9 −6 Original line number Diff line number Diff line Loading @@ -4515,6 +4515,9 @@ public class NotificationManagerService extends SystemService { */ @Override public boolean areNotificationsEnabledForPackage(String pkg, int uid) { if (Process.isSdkSandboxUid(uid)) { return false; } enforceSystemOrSystemUIOrSamePackage(pkg, "Caller not system or systemui or same package"); if (UserHandle.getCallingUserId() != UserHandle.getUserId(uid)) { Loading Loading @@ -5184,8 +5187,8 @@ public class NotificationManagerService extends SystemService { public NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String targetPkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallerSystemOrSystemUiOrShell()) { if (isCallerSystemOrSystemUiOrShell() || canNotifyAsPackage(callingPkg, targetPkg, userId)) { int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); Loading Loading @@ -6601,7 +6604,7 @@ public class NotificationManagerService extends SystemService { String wellbeingPackage = getContext().getResources().getString( com.android.internal.R.string.config_systemWellbeing); boolean isCallerWellbeing = !TextUtils.isEmpty(wellbeingPackage) && mPackageManagerInternal.isSameApp(wellbeingPackage, uid, userId); && isCallerSameApp(wellbeingPackage, uid, userId); if (!isCallerWellbeing) { throw new IllegalArgumentException( "Only the 'Wellbeing' package can use AutomaticZenRules with " Loading Loading @@ -6886,7 +6889,7 @@ public class NotificationManagerService extends SystemService { ? mEffectsSuppressors.get(0) : null; if (isCallerSystemOrSystemUiOrShell() || suppressor == null || mPackageManagerInternal.isSameApp(suppressor.getPackageName(), || isCallerSameApp(suppressor.getPackageName(), Binder.getCallingUid(), UserHandle.getUserId(Binder.getCallingUid()))) { return suppressor; } Loading Loading @@ -9437,7 +9440,7 @@ public class NotificationManagerService extends SystemService { int resolveNotificationUid(String callingPkg, String targetPkg, int callingUid, int userId) throws NameNotFoundException { if (userId == USER_ALL) { userId = USER_SYSTEM; userId = UserHandle.getUserId(callingUid); } // posted from app A on behalf of app A if (isCallerSameApp(targetPkg, callingUid, userId) Loading Loading @@ -12292,7 +12295,7 @@ public class NotificationManagerService extends SystemService { if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) { return; } if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) { if (!UserHandle.isSameApp(uid, mPackageManagerInternal.getPackageUid(pkg, 0L, userId))) { throw new SecurityException("Package " + pkg + " is not owned by uid " + uid); } } services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java +12 −6 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ package com.android.server; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; Loading Loading @@ -50,11 +52,6 @@ public class UiServiceTestCase { protected static final String PKG_P = "com.example.p"; protected static final String PKG_R = "com.example.r"; protected static final int UID_N_MR1 = 10001; protected static final int UID_O = 10002; protected static final int UID_P = 10003; protected static final int UID_R = 10004; @Rule public TestableContext mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); Loading @@ -63,6 +60,10 @@ public class UiServiceTestCase { protected final @UserIdInt int mUserId = UserHandle.getUserId(mUid); protected final UserHandle mUser = UserHandle.of(mUserId); protected final String mPkg = mContext.getPackageName(); protected final int UID_N_MR1 = UserHandle.getUid(mUserId, 1); protected final int UID_O = UserHandle.getUid(mUserId, 2); protected final int UID_P = UserHandle.getUid(mUserId, 3); protected final int UID_R = UserHandle.getUid(mUserId, 4); protected TestableContext getContext() { return mContext; Loading Loading @@ -93,7 +94,12 @@ public class UiServiceTestCase { return Build.VERSION_CODES.CUR_DEVELOPMENT; } }); when(mPmi.getPackageUid(eq(PKG_N_MR1), anyLong(), eq(mUserId))).thenReturn(UID_N_MR1); when(mPmi.getPackageUid(eq(PKG_O), anyLong(), eq(mUserId))).thenReturn(UID_O); when(mPmi.getPackageUid(eq(PKG_P), anyLong(), eq(mUserId))).thenReturn(UID_P); when(mPmi.getPackageUid(eq(PKG_R), anyLong(), eq(mUserId))).thenReturn(UID_R); when(mPmi.getPackageUid(eq(mContext.getPackageName()), anyLong(), eq(mUserId))) .thenReturn(mUid); LocalServices.removeServiceForTest(UserManagerInternal.class); LocalServices.addService(UserManagerInternal.class, mUmi); LocalServices.removeServiceForTest(UriGrantsManagerInternal.class); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +185 −120 File changed.Preview size limit exceeded, changes collapsed. Show changes services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +50 −29 Original line number Diff line number Diff line Loading @@ -1220,19 +1220,21 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, false, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"com.example.o\" show_badge=\"true\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; String expected_o = "<package name=\"com.example.o\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\" uid=\"10002\">\n" + "=\"false\" uid=\"" + UID_O + "\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" + "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "</package>\n"; String expected_n = "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\" uid=\"10001\">\n" + "=\"false\" uid=\"" + UID_N_MR1 + "\">\n" + "<channelGroup id=\"1\" name=\"bye\" blocked=\"false\" locked=\"0\" />\n" + "<channelGroup id=\"2\" name=\"hello\" blocked=\"false\" locked=\"0\" />\n" + "<channel id=\"id1\" name=\"name1\" importance=\"4\" show_badge=\"true\" " Loading @@ -1247,11 +1249,16 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "<package name=\"com.example.p\" show_badge=\"true\" " + "</package>\n"; String expected_p = "<package name=\"com.example.p\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\"10003\""; assertThat(baos.toString()).contains(expected); + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\""+ UID_P + "\" />"; String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); } @Test Loading Loading @@ -1305,18 +1312,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; String expected_o = // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" + "</package>\n"; String expected_n = // Importance default because on in permission helper + "<package name=\"com.example.n_mr1\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.n_mr1\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" Loading @@ -1334,15 +1343,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "</package>\n"; String expected_p = // Importance default because on in permission helper + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\""; assertThat(baos.toString()).contains(expected); String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); // Packages that exist solely in permissionhelper assertThat(baos.toString()).contains("<package name=\"first\" importance=\"3\""); assertThat(baos.toString()).contains("<package name=\"third\" importance=\"0\""); assertThat(actual).contains("<package name=\"first\" importance=\"3\""); assertThat(actual).contains("<package name=\"third\" importance=\"0\""); } @Test Loading Loading @@ -1382,7 +1396,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, false, false, SYSTEM_UID, true); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false, UID_N_MR1, false); UID_O, false); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setInvalidMessageSent(PKG_P, UID_P); Loading @@ -1392,18 +1406,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " String expected_o = "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" // Importance 0 because missing from permission helper + "<package name=\"com.example.n_mr1\" importance=\"0\" show_badge=\"true\" " + "</package>\n"; String expected_n = // Importance missing because missing from permission helper "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" Loading @@ -1421,12 +1437,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "</package>\n"; String expected_p = // Importance default because on in permission helper + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\""; assertThat(baos.toString()).contains(expected); String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); } @Test Loading Loading @@ -3897,7 +3918,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { String dump = dumpToString(mHelper); assertThat(dump).contains( "AppSettings: com.example.p (10003)\n" "AppSettings: com.example.p (" + UID_P + ")\n" + " Delegate: the.delegate.package (456) enabled=true"); } Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +9 −6 Original line number Diff line number Diff line Loading @@ -4515,6 +4515,9 @@ public class NotificationManagerService extends SystemService { */ @Override public boolean areNotificationsEnabledForPackage(String pkg, int uid) { if (Process.isSdkSandboxUid(uid)) { return false; } enforceSystemOrSystemUIOrSamePackage(pkg, "Caller not system or systemui or same package"); if (UserHandle.getCallingUserId() != UserHandle.getUserId(uid)) { Loading Loading @@ -5184,8 +5187,8 @@ public class NotificationManagerService extends SystemService { public NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String targetPkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId) { if (canNotifyAsPackage(callingPkg, targetPkg, userId) || isCallerSystemOrSystemUiOrShell()) { if (isCallerSystemOrSystemUiOrShell() || canNotifyAsPackage(callingPkg, targetPkg, userId)) { int targetUid = INVALID_UID; try { targetUid = mPackageManagerClient.getPackageUidAsUser(targetPkg, userId); Loading Loading @@ -6601,7 +6604,7 @@ public class NotificationManagerService extends SystemService { String wellbeingPackage = getContext().getResources().getString( com.android.internal.R.string.config_systemWellbeing); boolean isCallerWellbeing = !TextUtils.isEmpty(wellbeingPackage) && mPackageManagerInternal.isSameApp(wellbeingPackage, uid, userId); && isCallerSameApp(wellbeingPackage, uid, userId); if (!isCallerWellbeing) { throw new IllegalArgumentException( "Only the 'Wellbeing' package can use AutomaticZenRules with " Loading Loading @@ -6886,7 +6889,7 @@ public class NotificationManagerService extends SystemService { ? mEffectsSuppressors.get(0) : null; if (isCallerSystemOrSystemUiOrShell() || suppressor == null || mPackageManagerInternal.isSameApp(suppressor.getPackageName(), || isCallerSameApp(suppressor.getPackageName(), Binder.getCallingUid(), UserHandle.getUserId(Binder.getCallingUid()))) { return suppressor; } Loading Loading @@ -9437,7 +9440,7 @@ public class NotificationManagerService extends SystemService { int resolveNotificationUid(String callingPkg, String targetPkg, int callingUid, int userId) throws NameNotFoundException { if (userId == USER_ALL) { userId = USER_SYSTEM; userId = UserHandle.getUserId(callingUid); } // posted from app A on behalf of app A if (isCallerSameApp(targetPkg, callingUid, userId) Loading Loading @@ -12292,7 +12295,7 @@ public class NotificationManagerService extends SystemService { if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) { return; } if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) { if (!UserHandle.isSameApp(uid, mPackageManagerInternal.getPackageUid(pkg, 0L, userId))) { throw new SecurityException("Package " + pkg + " is not owned by uid " + uid); } }
services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java +12 −6 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ package com.android.server; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; Loading Loading @@ -50,11 +52,6 @@ public class UiServiceTestCase { protected static final String PKG_P = "com.example.p"; protected static final String PKG_R = "com.example.r"; protected static final int UID_N_MR1 = 10001; protected static final int UID_O = 10002; protected static final int UID_P = 10003; protected static final int UID_R = 10004; @Rule public TestableContext mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); Loading @@ -63,6 +60,10 @@ public class UiServiceTestCase { protected final @UserIdInt int mUserId = UserHandle.getUserId(mUid); protected final UserHandle mUser = UserHandle.of(mUserId); protected final String mPkg = mContext.getPackageName(); protected final int UID_N_MR1 = UserHandle.getUid(mUserId, 1); protected final int UID_O = UserHandle.getUid(mUserId, 2); protected final int UID_P = UserHandle.getUid(mUserId, 3); protected final int UID_R = UserHandle.getUid(mUserId, 4); protected TestableContext getContext() { return mContext; Loading Loading @@ -93,7 +94,12 @@ public class UiServiceTestCase { return Build.VERSION_CODES.CUR_DEVELOPMENT; } }); when(mPmi.getPackageUid(eq(PKG_N_MR1), anyLong(), eq(mUserId))).thenReturn(UID_N_MR1); when(mPmi.getPackageUid(eq(PKG_O), anyLong(), eq(mUserId))).thenReturn(UID_O); when(mPmi.getPackageUid(eq(PKG_P), anyLong(), eq(mUserId))).thenReturn(UID_P); when(mPmi.getPackageUid(eq(PKG_R), anyLong(), eq(mUserId))).thenReturn(UID_R); when(mPmi.getPackageUid(eq(mContext.getPackageName()), anyLong(), eq(mUserId))) .thenReturn(mUid); LocalServices.removeServiceForTest(UserManagerInternal.class); LocalServices.addService(UserManagerInternal.class, mUmi); LocalServices.removeServiceForTest(UriGrantsManagerInternal.class); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +185 −120 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +50 −29 Original line number Diff line number Diff line Loading @@ -1220,19 +1220,21 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, false, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "<package name=\"com.example.o\" show_badge=\"true\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; String expected_o = "<package name=\"com.example.o\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\" uid=\"10002\">\n" + "=\"false\" uid=\"" + UID_O + "\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" + "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "</package>\n"; String expected_n = "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\" uid=\"10001\">\n" + "=\"false\" uid=\"" + UID_N_MR1 + "\">\n" + "<channelGroup id=\"1\" name=\"bye\" blocked=\"false\" locked=\"0\" />\n" + "<channelGroup id=\"2\" name=\"hello\" blocked=\"false\" locked=\"0\" />\n" + "<channel id=\"id1\" name=\"name1\" importance=\"4\" show_badge=\"true\" " Loading @@ -1247,11 +1249,16 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "<package name=\"com.example.p\" show_badge=\"true\" " + "</package>\n"; String expected_p = "<package name=\"com.example.p\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\"10003\""; assertThat(baos.toString()).contains(expected); + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\""+ UID_P + "\" />"; String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); } @Test Loading Loading @@ -1305,18 +1312,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; String expected_o = // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" + "</package>\n"; String expected_n = // Importance default because on in permission helper + "<package name=\"com.example.n_mr1\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.n_mr1\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" Loading @@ -1334,15 +1343,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "</package>\n"; String expected_p = // Importance default because on in permission helper + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\""; assertThat(baos.toString()).contains(expected); String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); // Packages that exist solely in permissionhelper assertThat(baos.toString()).contains("<package name=\"first\" importance=\"3\""); assertThat(baos.toString()).contains("<package name=\"third\" importance=\"0\""); assertThat(actual).contains("<package name=\"first\" importance=\"3\""); assertThat(actual).contains("<package name=\"third\" importance=\"0\""); } @Test Loading Loading @@ -1382,7 +1396,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel3, false, false, SYSTEM_UID, true); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false, UID_N_MR1, false); UID_O, false); mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true); mHelper.setInvalidMessageSent(PKG_P, UID_P); Loading @@ -1392,18 +1406,20 @@ public class PreferencesHelperTest extends UiServiceTestCase { ByteArrayOutputStream baos = writeXmlAndPurge( PKG_N_MR1, UID_N_MR1, true, USER_SYSTEM); String expected = "<ranking version=\"4\" " + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n" + "last_bubbles_version_upgrade=\"" + Build.VERSION.SDK_INT + "\">\n"; // Importance 0 because off in permissionhelper + "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " String expected_o = "<package name=\"com.example.o\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" // Importance 0 because missing from permission helper + "<package name=\"com.example.n_mr1\" importance=\"0\" show_badge=\"true\" " + "</package>\n"; String expected_n = // Importance missing because missing from permission helper "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" Loading @@ -1421,12 +1437,17 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<channel id=\"miscellaneous\" name=\"Uncategorized\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + "</package>\n"; String expected_p = // Importance default because on in permission helper + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\""; assertThat(baos.toString()).contains(expected); String actual = baos.toString(); assertThat(actual).contains(expected); assertThat(actual).contains(expected_o); assertThat(actual).contains(expected_n); assertThat(actual).contains(expected_p); } @Test Loading Loading @@ -3897,7 +3918,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { String dump = dumpToString(mHelper); assertThat(dump).contains( "AppSettings: com.example.p (10003)\n" "AppSettings: com.example.p (" + UID_P + ")\n" + " Delegate: the.delegate.package (456) enabled=true"); } Loading