Loading services/core/java/com/android/server/notification/NotificationManagerService.java +23 −4 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static android.content.Context.BIND_AUTO_CREATE; import static android.content.Context.BIND_FOREGROUND_SERVICE; import static android.content.pm.PackageManager.FEATURE_LEANBACK; import static android.content.pm.PackageManager.FEATURE_TELEVISION; import static android.content.pm.PackageManager.MATCH_ALL; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; import static android.content.pm.PackageManager.PERMISSION_GRANTED; Loading Loading @@ -191,6 +192,7 @@ import android.util.ArraySet; import android.util.AtomicFile; import android.util.IntArray; import android.util.Log; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; import android.util.Xml; Loading Loading @@ -1880,7 +1882,7 @@ public class NotificationManagerService extends SystemService { mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mZenModeHelper.onSystemReady(); mRoleObserver = new RoleObserver(getContext().getSystemService(RoleManager.class), getContext().getMainExecutor()); mPackageManager, getContext().getMainExecutor()); mRoleObserver.init(); } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { // This observer will force an update when observe is called, causing us to Loading Loading @@ -8219,11 +8221,14 @@ public class NotificationManagerService extends SystemService { private ArrayMap<String, ArrayMap<Integer, ArraySet<String>>> mNonBlockableDefaultApps; private final RoleManager mRm; private final IPackageManager mPm; private final Executor mExecutor; RoleObserver(@NonNull RoleManager roleManager, @NonNull IPackageManager pkgMgr, @NonNull @CallbackExecutor Executor executor) { mRm = roleManager; mPm = pkgMgr; mExecutor = executor; } Loading @@ -8237,8 +8242,12 @@ public class NotificationManagerService extends SystemService { Integer userId = users.get(j).getUserHandle().getIdentifier(); ArraySet<String> approvedForUserId = new ArraySet<>(mRm.getRoleHoldersAsUser( NON_BLOCKABLE_DEFAULT_ROLES[i], UserHandle.of(userId))); ArraySet<Pair<String, Integer>> approvedAppUids = new ArraySet<>(); for (String pkg : approvedForUserId) { approvedAppUids.add(new Pair(pkg, getUidForPackage(pkg, userId))); } userToApprovedList.put(userId, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedAppUids); } } Loading Loading @@ -8281,7 +8290,7 @@ public class NotificationManagerService extends SystemService { prevApprovedForRole.getOrDefault(user.getIdentifier(), new ArraySet<>()); ArraySet<String> toRemove = new ArraySet<>(); ArraySet<String> toAdd = new ArraySet<>(); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); for (String previous : previouslyApproved) { if (!roleHolders.contains(previous)) { Loading @@ -8290,7 +8299,8 @@ public class NotificationManagerService extends SystemService { } for (String nowApproved : roleHolders) { if (!previouslyApproved.contains(nowApproved)) { toAdd.add(nowApproved); toAdd.add(new Pair(nowApproved, getUidForPackage(nowApproved, user.getIdentifier()))); } } Loading @@ -8304,6 +8314,15 @@ public class NotificationManagerService extends SystemService { // RoleManager is the source of truth for this data so we don't need to trigger a // write of the notification policy xml for this change } private int getUidForPackage(String pkg, int userId) { try { return mPm.getPackageUid(pkg, MATCH_ALL, userId); } catch (RemoteException e) { Slog.e(TAG, "role manager has bad default " + pkg + " " + userId); } return -1; } } public static final class DumpFilter { Loading services/core/java/com/android/server/notification/PreferencesHelper.java +31 −8 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.service.notification.RankingHelperProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.proto.ProtoOutputStream; Loading Loading @@ -236,6 +237,8 @@ public class PreferencesHelper implements RankingConfig { } else { channel.populateFromXml(parser); } channel.setImportanceLockedByCriticalDeviceFunction( r.defaultAppLockedImportance); r.channels.put(id, channel); } } Loading Loading @@ -882,7 +885,8 @@ public class PreferencesHelper implements RankingConfig { } } public void updateDefaultApps(int userId, ArraySet<String> toRemove, ArraySet<String> toAdd) { public void updateDefaultApps(int userId, ArraySet<String> toRemove, ArraySet<Pair<String, Integer>> toAdd) { synchronized (mPackagePreferences) { for (PackagePreferences p : mPackagePreferences.values()) { if (userId == UserHandle.getUserId(p.uid)) { Loading @@ -891,7 +895,13 @@ public class PreferencesHelper implements RankingConfig { for (NotificationChannel channel : p.channels.values()) { channel.setImportanceLockedByCriticalDeviceFunction(false); } } else if (toAdd != null && toAdd.contains(p.pkg)) { } } } if (toAdd != null) { for (Pair<String, Integer> approvedApp : toAdd) { PackagePreferences p = getOrCreatePackagePreferencesLocked(approvedApp.first, approvedApp.second); p.defaultAppLockedImportance = true; for (NotificationChannel channel : p.channels.values()) { channel.setImportanceLockedByCriticalDeviceFunction(true); Loading @@ -900,7 +910,6 @@ public class PreferencesHelper implements RankingConfig { } } } } public NotificationChannelGroup getNotificationChannelGroupWithChannels(String pkg, int uid, String groupId, boolean includeDeleted) { Loading Loading @@ -1426,8 +1435,22 @@ public class PreferencesHelper implements RankingConfig { pw.print(" visibility="); pw.print(Notification.visibilityToString(r.visibility)); } if (r.showBadge != DEFAULT_SHOW_BADGE) { pw.print(" showBadge="); pw.print(Boolean.toString(r.showBadge)); pw.print(r.showBadge); } if (r.defaultAppLockedImportance != DEFAULT_APP_LOCKED_IMPORTANCE) { pw.print(" defaultAppLocked="); pw.print(r.defaultAppLockedImportance); } if (r.oemLockedImportance != DEFAULT_OEM_LOCKED_IMPORTANCE) { pw.print(" oemLocked="); pw.print(r.oemLockedImportance); } if (!r.futureOemLockedChannels.isEmpty()) { pw.print(" futureLockedChannels="); pw.print(r.futureOemLockedChannels); } pw.println(); for (NotificationChannel channel : r.channels.values()) { pw.print(prefix); Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +58 −16 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.TestableContentResolver; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Pair; import android.util.Xml; import com.android.internal.util.FastXmlSerializer; Loading Loading @@ -1647,11 +1648,13 @@ public class PreferencesHelperTest extends UiServiceTestCase { public void testClearData() { ArraySet<String> pkg = new ArraySet<>(); pkg.add(PKG_O); ArraySet<Pair<String, Integer>> pkgPair = new ArraySet<>(); pkgPair.add(new Pair(PKG_O, UID_O)); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.createNotificationChannelGroup( PKG_O, UID_O, new NotificationChannelGroup("1", "bye"), true); mHelper.lockChannelsForOEM(pkg.toArray(new String[]{})); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, pkg); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, pkgPair); mHelper.setNotificationDelegate(PKG_O, UID_O, "", 1); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); mHelper.setBubblesAllowed(PKG_O, UID_O, false); Loading Loading @@ -2493,8 +2496,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, b, false, false); mHelper.createNotificationChannel(PKG_O, UserHandle.PER_USER_RANGE + 1, c, true, true); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2513,8 +2516,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); Loading @@ -2532,8 +2535,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_O, UID_O, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2558,8 +2561,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); Loading @@ -2572,7 +2575,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_O); toAdd = new ArraySet<>(); toAdd.add(PKG_N_MR1); toAdd.add(new Pair(PKG_N_MR1, UID_N_MR1)); mHelper.updateDefaultApps(USER.getIdentifier(), toRemove, toAdd); assertFalse(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2583,8 +2586,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUpdateDefaultApps_appDoesNotExist_noCrash() { ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_N_MR1); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), toRemove, toAdd); Loading @@ -2596,8 +2599,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannel b = new NotificationChannel("b", "b", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2612,8 +2615,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { public void testUpdateNotificationChannel_defaultAppLockedImportance() { NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE); Loading @@ -2631,4 +2634,43 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(IMPORTANCE_HIGH, mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); } @Test public void testDefaultApp_appHasNoSettingsYet() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); assertTrue(a.isImportanceLockedByCriticalDeviceFunction()); } @Test public void testChannelXml_backupDefaultApp() throws Exception { NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, channel1, true, false); // clear data ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, true, UserHandle.USER_SYSTEM, channel1.getId(), NotificationChannel.DEFAULT_CHANNEL_ID); mHelper.onPackagesChanged(true, UserHandle.myUserId(), new String[]{PKG_O}, new int[]{ UID_O}); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())), null); parser.nextTag(); mHelper.readXml(parser, true, UserHandle.USER_SYSTEM); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, channel1.getId(), false) .isImportanceLockedByCriticalDeviceFunction()); } } services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +43 −108 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +23 −4 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static android.content.Context.BIND_AUTO_CREATE; import static android.content.Context.BIND_FOREGROUND_SERVICE; import static android.content.pm.PackageManager.FEATURE_LEANBACK; import static android.content.pm.PackageManager.FEATURE_TELEVISION; import static android.content.pm.PackageManager.MATCH_ALL; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE; import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE; import static android.content.pm.PackageManager.PERMISSION_GRANTED; Loading Loading @@ -191,6 +192,7 @@ import android.util.ArraySet; import android.util.AtomicFile; import android.util.IntArray; import android.util.Log; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; import android.util.Xml; Loading Loading @@ -1880,7 +1882,7 @@ public class NotificationManagerService extends SystemService { mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); mZenModeHelper.onSystemReady(); mRoleObserver = new RoleObserver(getContext().getSystemService(RoleManager.class), getContext().getMainExecutor()); mPackageManager, getContext().getMainExecutor()); mRoleObserver.init(); } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { // This observer will force an update when observe is called, causing us to Loading Loading @@ -8219,11 +8221,14 @@ public class NotificationManagerService extends SystemService { private ArrayMap<String, ArrayMap<Integer, ArraySet<String>>> mNonBlockableDefaultApps; private final RoleManager mRm; private final IPackageManager mPm; private final Executor mExecutor; RoleObserver(@NonNull RoleManager roleManager, @NonNull IPackageManager pkgMgr, @NonNull @CallbackExecutor Executor executor) { mRm = roleManager; mPm = pkgMgr; mExecutor = executor; } Loading @@ -8237,8 +8242,12 @@ public class NotificationManagerService extends SystemService { Integer userId = users.get(j).getUserHandle().getIdentifier(); ArraySet<String> approvedForUserId = new ArraySet<>(mRm.getRoleHoldersAsUser( NON_BLOCKABLE_DEFAULT_ROLES[i], UserHandle.of(userId))); ArraySet<Pair<String, Integer>> approvedAppUids = new ArraySet<>(); for (String pkg : approvedForUserId) { approvedAppUids.add(new Pair(pkg, getUidForPackage(pkg, userId))); } userToApprovedList.put(userId, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedForUserId); mPreferencesHelper.updateDefaultApps(userId, null, approvedAppUids); } } Loading Loading @@ -8281,7 +8290,7 @@ public class NotificationManagerService extends SystemService { prevApprovedForRole.getOrDefault(user.getIdentifier(), new ArraySet<>()); ArraySet<String> toRemove = new ArraySet<>(); ArraySet<String> toAdd = new ArraySet<>(); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); for (String previous : previouslyApproved) { if (!roleHolders.contains(previous)) { Loading @@ -8290,7 +8299,8 @@ public class NotificationManagerService extends SystemService { } for (String nowApproved : roleHolders) { if (!previouslyApproved.contains(nowApproved)) { toAdd.add(nowApproved); toAdd.add(new Pair(nowApproved, getUidForPackage(nowApproved, user.getIdentifier()))); } } Loading @@ -8304,6 +8314,15 @@ public class NotificationManagerService extends SystemService { // RoleManager is the source of truth for this data so we don't need to trigger a // write of the notification policy xml for this change } private int getUidForPackage(String pkg, int userId) { try { return mPm.getPackageUid(pkg, MATCH_ALL, userId); } catch (RemoteException e) { Slog.e(TAG, "role manager has bad default " + pkg + " " + userId); } return -1; } } public static final class DumpFilter { Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +31 −8 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.service.notification.RankingHelperProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.proto.ProtoOutputStream; Loading Loading @@ -236,6 +237,8 @@ public class PreferencesHelper implements RankingConfig { } else { channel.populateFromXml(parser); } channel.setImportanceLockedByCriticalDeviceFunction( r.defaultAppLockedImportance); r.channels.put(id, channel); } } Loading Loading @@ -882,7 +885,8 @@ public class PreferencesHelper implements RankingConfig { } } public void updateDefaultApps(int userId, ArraySet<String> toRemove, ArraySet<String> toAdd) { public void updateDefaultApps(int userId, ArraySet<String> toRemove, ArraySet<Pair<String, Integer>> toAdd) { synchronized (mPackagePreferences) { for (PackagePreferences p : mPackagePreferences.values()) { if (userId == UserHandle.getUserId(p.uid)) { Loading @@ -891,7 +895,13 @@ public class PreferencesHelper implements RankingConfig { for (NotificationChannel channel : p.channels.values()) { channel.setImportanceLockedByCriticalDeviceFunction(false); } } else if (toAdd != null && toAdd.contains(p.pkg)) { } } } if (toAdd != null) { for (Pair<String, Integer> approvedApp : toAdd) { PackagePreferences p = getOrCreatePackagePreferencesLocked(approvedApp.first, approvedApp.second); p.defaultAppLockedImportance = true; for (NotificationChannel channel : p.channels.values()) { channel.setImportanceLockedByCriticalDeviceFunction(true); Loading @@ -900,7 +910,6 @@ public class PreferencesHelper implements RankingConfig { } } } } public NotificationChannelGroup getNotificationChannelGroupWithChannels(String pkg, int uid, String groupId, boolean includeDeleted) { Loading Loading @@ -1426,8 +1435,22 @@ public class PreferencesHelper implements RankingConfig { pw.print(" visibility="); pw.print(Notification.visibilityToString(r.visibility)); } if (r.showBadge != DEFAULT_SHOW_BADGE) { pw.print(" showBadge="); pw.print(Boolean.toString(r.showBadge)); pw.print(r.showBadge); } if (r.defaultAppLockedImportance != DEFAULT_APP_LOCKED_IMPORTANCE) { pw.print(" defaultAppLocked="); pw.print(r.defaultAppLockedImportance); } if (r.oemLockedImportance != DEFAULT_OEM_LOCKED_IMPORTANCE) { pw.print(" oemLocked="); pw.print(r.oemLockedImportance); } if (!r.futureOemLockedChannels.isEmpty()) { pw.print(" futureLockedChannels="); pw.print(r.futureOemLockedChannels); } pw.println(); for (NotificationChannel channel : r.channels.values()) { pw.print(prefix); Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +58 −16 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.TestableContentResolver; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Pair; import android.util.Xml; import com.android.internal.util.FastXmlSerializer; Loading Loading @@ -1647,11 +1648,13 @@ public class PreferencesHelperTest extends UiServiceTestCase { public void testClearData() { ArraySet<String> pkg = new ArraySet<>(); pkg.add(PKG_O); ArraySet<Pair<String, Integer>> pkgPair = new ArraySet<>(); pkgPair.add(new Pair(PKG_O, UID_O)); mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false); mHelper.createNotificationChannelGroup( PKG_O, UID_O, new NotificationChannelGroup("1", "bye"), true); mHelper.lockChannelsForOEM(pkg.toArray(new String[]{})); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, pkg); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, pkgPair); mHelper.setNotificationDelegate(PKG_O, UID_O, "", 1); mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE); mHelper.setBubblesAllowed(PKG_O, UID_O, false); Loading Loading @@ -2493,8 +2496,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, b, false, false); mHelper.createNotificationChannel(PKG_O, UserHandle.PER_USER_RANGE + 1, c, true, true); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2513,8 +2516,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); Loading @@ -2532,8 +2535,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_O, UID_O, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2558,8 +2561,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, b, false, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); Loading @@ -2572,7 +2575,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_O); toAdd = new ArraySet<>(); toAdd.add(PKG_N_MR1); toAdd.add(new Pair(PKG_N_MR1, UID_N_MR1)); mHelper.updateDefaultApps(USER.getIdentifier(), toRemove, toAdd); assertFalse(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2583,8 +2586,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testUpdateDefaultApps_appDoesNotExist_noCrash() { ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); ArraySet<String> toRemove = new ArraySet<>(); toRemove.add(PKG_N_MR1); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), toRemove, toAdd); Loading @@ -2596,8 +2599,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannel b = new NotificationChannel("b", "b", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false) Loading @@ -2612,8 +2615,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { public void testUpdateNotificationChannel_defaultAppLockedImportance() { NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); ArraySet<String> toAdd = new ArraySet<>(); toAdd.add(PKG_O); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE); Loading @@ -2631,4 +2634,43 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertEquals(IMPORTANCE_HIGH, mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance()); } @Test public void testDefaultApp_appHasNoSettingsYet() { ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); NotificationChannel a = new NotificationChannel("a", "a", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, a, true, false); assertTrue(a.isImportanceLockedByCriticalDeviceFunction()); } @Test public void testChannelXml_backupDefaultApp() throws Exception { NotificationChannel channel1 = new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, channel1, true, false); // clear data ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, true, UserHandle.USER_SYSTEM, channel1.getId(), NotificationChannel.DEFAULT_CHANNEL_ID); mHelper.onPackagesChanged(true, UserHandle.myUserId(), new String[]{PKG_O}, new int[]{ UID_O}); ArraySet<Pair<String, Integer>> toAdd = new ArraySet<>(); toAdd.add(new Pair(PKG_O, UID_O)); mHelper.updateDefaultApps(UserHandle.getUserId(UID_O), null, toAdd); XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())), null); parser.nextTag(); mHelper.readXml(parser, true, UserHandle.USER_SYSTEM); assertTrue(mHelper.getNotificationChannel(PKG_O, UID_O, channel1.getId(), false) .isImportanceLockedByCriticalDeviceFunction()); } }
services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +43 −108 File changed.Preview size limit exceeded, changes collapsed. Show changes