Loading core/java/android/app/INotificationManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,8 @@ interface INotificationManager NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(String pkg, int uid, String groupId, boolean includeDeleted); void updateNotificationChannelGroupForPackage(String pkg, int uid, in NotificationChannelGroup group); void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel); void unlockNotificationChannel(String pkg, int uid, String channelId); void unlockAllNotificationChannels(); NotificationChannel getNotificationChannel(String callingPkg, int userId, String pkg, String channelId); NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String pkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId); void createConversationNotificationChannelForPackage(String pkg, int uid, in NotificationChannel parentChannel, String conversationId); Loading services/core/java/com/android/server/notification/NotificationManagerService.java +14 −0 Original line number Diff line number Diff line Loading @@ -3525,6 +3525,20 @@ public class NotificationManagerService extends SystemService { updateNotificationChannelInt(pkg, uid, channel, false); } @Override public void unlockNotificationChannel(String pkg, int uid, String channelId) { checkCallerIsSystemOrSystemUiOrShell("Caller not system or sysui or shell"); mPreferencesHelper.unlockNotificationChannelImportance(pkg, uid, channelId); handleSavePolicyFile(); } @Override public void unlockAllNotificationChannels() { checkCallerIsSystem(); mPreferencesHelper.unlockAllNotificationChannels(); handleSavePolicyFile(); } @Override public ParceledListSlice<NotificationChannel> getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted) { Loading services/core/java/com/android/server/notification/PreferencesHelper.java +30 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.notification; import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.IMPORTANCE_NONE; Loading Loading @@ -955,6 +956,23 @@ public class PreferencesHelper implements RankingConfig { channel.unlockFields(channel.getUserLockedFields()); } void unlockNotificationChannelImportance(String pkg, int uid, String updatedChannelId) { Objects.requireNonNull(updatedChannelId); synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); if (r == null) { throw new IllegalArgumentException("Invalid package"); } NotificationChannel channel = r.channels.get(updatedChannelId); if (channel == null || channel.isDeleted()) { throw new IllegalArgumentException("Channel does not exist"); } channel.unlockFields(USER_LOCKED_IMPORTANCE); } } @Override public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel, boolean fromUser) { Loading Loading @@ -2389,6 +2407,18 @@ public class PreferencesHelper implements RankingConfig { return mBadgingEnabled.get(userId, DEFAULT_SHOW_BADGE); } public void unlockAllNotificationChannels() { synchronized (mPackagePreferences) { final int numPackagePreferences = mPackagePreferences.size(); for (int i = 0; i < numPackagePreferences; i++) { final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannel channel : r.channels.values()) { channel.unlockFields(USER_LOCKED_IMPORTANCE); } } } } private void updateConfig() { mRankingHandler.requestSort(); } Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; import static android.app.NotificationChannel.CONVERSATION_CHANNEL_ID_FORMAT; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; Loading Loading @@ -3796,4 +3797,40 @@ public class PreferencesHelperTest extends UiServiceTestCase { } } } @Test public void testUnlockNotificationChannelImportance() { NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false); channel.lockFields(USER_LOCKED_IMPORTANCE); assertTrue((channel.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); mHelper.unlockNotificationChannelImportance(PKG_O, UID_O, channel.getId()); assertTrue((channel.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } @Test public void testUnlockAllNotificationChannels() { NotificationChannel channelA = new NotificationChannel("a", "a", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, channelA, true, false); NotificationChannel channelB = new NotificationChannel("b", "b", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel(PKG_P, UID_P, channelB, true, false); NotificationChannel channelC = new NotificationChannel("c", "c", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_P, UID_O, channelC, false, false); channelA.lockFields(USER_LOCKED_IMPORTANCE); channelB.lockFields(USER_LOCKED_IMPORTANCE); channelC.lockFields(USER_LOCKED_IMPORTANCE); assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); mHelper.unlockAllNotificationChannels(); assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } } Loading
core/java/android/app/INotificationManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,8 @@ interface INotificationManager NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(String pkg, int uid, String groupId, boolean includeDeleted); void updateNotificationChannelGroupForPackage(String pkg, int uid, in NotificationChannelGroup group); void updateNotificationChannelForPackage(String pkg, int uid, in NotificationChannel channel); void unlockNotificationChannel(String pkg, int uid, String channelId); void unlockAllNotificationChannels(); NotificationChannel getNotificationChannel(String callingPkg, int userId, String pkg, String channelId); NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String pkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId); void createConversationNotificationChannelForPackage(String pkg, int uid, in NotificationChannel parentChannel, String conversationId); Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +14 −0 Original line number Diff line number Diff line Loading @@ -3525,6 +3525,20 @@ public class NotificationManagerService extends SystemService { updateNotificationChannelInt(pkg, uid, channel, false); } @Override public void unlockNotificationChannel(String pkg, int uid, String channelId) { checkCallerIsSystemOrSystemUiOrShell("Caller not system or sysui or shell"); mPreferencesHelper.unlockNotificationChannelImportance(pkg, uid, channelId); handleSavePolicyFile(); } @Override public void unlockAllNotificationChannels() { checkCallerIsSystem(); mPreferencesHelper.unlockAllNotificationChannels(); handleSavePolicyFile(); } @Override public ParceledListSlice<NotificationChannel> getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted) { Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +30 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.notification; import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.IMPORTANCE_NONE; Loading Loading @@ -955,6 +956,23 @@ public class PreferencesHelper implements RankingConfig { channel.unlockFields(channel.getUserLockedFields()); } void unlockNotificationChannelImportance(String pkg, int uid, String updatedChannelId) { Objects.requireNonNull(updatedChannelId); synchronized (mPackagePreferences) { PackagePreferences r = getOrCreatePackagePreferencesLocked(pkg, uid); if (r == null) { throw new IllegalArgumentException("Invalid package"); } NotificationChannel channel = r.channels.get(updatedChannelId); if (channel == null || channel.isDeleted()) { throw new IllegalArgumentException("Channel does not exist"); } channel.unlockFields(USER_LOCKED_IMPORTANCE); } } @Override public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel, boolean fromUser) { Loading Loading @@ -2389,6 +2407,18 @@ public class PreferencesHelper implements RankingConfig { return mBadgingEnabled.get(userId, DEFAULT_SHOW_BADGE); } public void unlockAllNotificationChannels() { synchronized (mPackagePreferences) { final int numPackagePreferences = mPackagePreferences.size(); for (int i = 0; i < numPackagePreferences; i++) { final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannel channel : r.channels.values()) { channel.unlockFields(USER_LOCKED_IMPORTANCE); } } } } private void updateConfig() { mRankingHandler.requestSort(); } Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static android.app.AppOpsManager.MODE_ALLOWED; import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; import static android.app.NotificationChannel.CONVERSATION_CHANNEL_ID_FORMAT; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; Loading Loading @@ -3796,4 +3797,40 @@ public class PreferencesHelperTest extends UiServiceTestCase { } } } @Test public void testUnlockNotificationChannelImportance() { NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false); channel.lockFields(USER_LOCKED_IMPORTANCE); assertTrue((channel.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); mHelper.unlockNotificationChannelImportance(PKG_O, UID_O, channel.getId()); assertTrue((channel.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } @Test public void testUnlockAllNotificationChannels() { NotificationChannel channelA = new NotificationChannel("a", "a", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG_O, UID_O, channelA, true, false); NotificationChannel channelB = new NotificationChannel("b", "b", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel(PKG_P, UID_P, channelB, true, false); NotificationChannel channelC = new NotificationChannel("c", "c", IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_P, UID_O, channelC, false, false); channelA.lockFields(USER_LOCKED_IMPORTANCE); channelB.lockFields(USER_LOCKED_IMPORTANCE); channelC.lockFields(USER_LOCKED_IMPORTANCE); assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0); mHelper.unlockAllNotificationChannels(); assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } }