Loading services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2824,6 +2824,12 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), true); mPreferencesHelper.updateNotificationChannel(pkg, uid, channel, true); if (mEnableAppSettingMigration) { if (mPreferencesHelper.onlyHasDefaultChannel(pkg, uid)) { mPermissionHelper.setNotificationPermission(pkg, UserHandle.getUserId(uid), channel.getImportance() != IMPORTANCE_NONE, true); } } maybeNotifyChannelOwner(pkg, uid, preUpdate, channel); if (!fromListener) { Loading services/core/java/com/android/server/notification/PreferencesHelper.java +5 −3 Original line number Diff line number Diff line Loading @@ -1043,9 +1043,11 @@ public class PreferencesHelper implements RankingConfig { r.channels.put(updatedChannel.getId(), updatedChannel); if (onlyHasDefaultChannel(pkg, uid)) { if (!mPermissionHelper.isMigrationEnabled()) { // copy settings to app level so they are inherited by new channels // when the app migrates r.importance = updatedChannel.getImportance(); } r.priority = updatedChannel.canBypassDnd() ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT; r.visibility = updatedChannel.getLockscreenVisibility(); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -3708,6 +3708,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(IMPORTANCE_LOW, mService.getNotificationRecord(sbn.getKey()).getImportance()); assertEquals(IMPORTANCE_UNSPECIFIED, mBinderService.getPackageImportance( sbn.getPackageName())); nb = new Notification.Builder(mContext) .setContentTitle("foo") Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.app.AppOpsManager.MODE_IGNORED; import static android.app.NotificationManager.EXTRA_BLOCKED_STATE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static android.content.pm.PackageManager.FEATURE_WATCH; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.UserHandle.USER_SYSTEM; Loading Loading @@ -123,6 +124,7 @@ import com.android.server.wm.ActivityTaskManagerInternal; import com.android.server.wm.WindowManagerInternal; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -663,4 +665,17 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { verify(mWorkerHandler, never()).post( any(NotificationManagerService.EnqueueNotificationRunnable.class)); } @Test public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception { final NotificationChannel defaultChannel = mBinderService.getNotificationChannel( PKG_N_MR1, ActivityManager.getCurrentUser(), PKG_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID); defaultChannel.setImportance(IMPORTANCE_NONE); mBinderService.updateNotificationChannelForPackage(PKG_N_MR1, mUid, defaultChannel); verify(mPermissionHelper).setNotificationPermission( PKG_N_MR1, ActivityManager.getCurrentUser(), false, true); } } services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -4072,6 +4072,28 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } @Test public void testDefaultChannelUpdatesApp_preMigrationToPermissions() throws Exception { final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID, false); defaultChannel.setImportance(IMPORTANCE_NONE); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true); assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_N_MR1, UID_N_MR1)); } @Test public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception { when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID, false); defaultChannel.setImportance(IMPORTANCE_NONE); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true); assertEquals(IMPORTANCE_UNSPECIFIED, mHelper.getImportance(PKG_N_MR1, UID_N_MR1)); } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2824,6 +2824,12 @@ public class NotificationManagerService extends SystemService { mPreferencesHelper.getNotificationChannel(pkg, uid, channel.getId(), true); mPreferencesHelper.updateNotificationChannel(pkg, uid, channel, true); if (mEnableAppSettingMigration) { if (mPreferencesHelper.onlyHasDefaultChannel(pkg, uid)) { mPermissionHelper.setNotificationPermission(pkg, UserHandle.getUserId(uid), channel.getImportance() != IMPORTANCE_NONE, true); } } maybeNotifyChannelOwner(pkg, uid, preUpdate, channel); if (!fromListener) { Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +5 −3 Original line number Diff line number Diff line Loading @@ -1043,9 +1043,11 @@ public class PreferencesHelper implements RankingConfig { r.channels.put(updatedChannel.getId(), updatedChannel); if (onlyHasDefaultChannel(pkg, uid)) { if (!mPermissionHelper.isMigrationEnabled()) { // copy settings to app level so they are inherited by new channels // when the app migrates r.importance = updatedChannel.getImportance(); } r.priority = updatedChannel.canBypassDnd() ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT; r.visibility = updatedChannel.getLockscreenVisibility(); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +2 −0 Original line number Diff line number Diff line Loading @@ -3708,6 +3708,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(IMPORTANCE_LOW, mService.getNotificationRecord(sbn.getKey()).getImportance()); assertEquals(IMPORTANCE_UNSPECIFIED, mBinderService.getPackageImportance( sbn.getPackageName())); nb = new Notification.Builder(mContext) .setContentTitle("foo") Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import static android.app.AppOpsManager.MODE_IGNORED; import static android.app.NotificationManager.EXTRA_BLOCKED_STATE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static android.content.pm.PackageManager.FEATURE_WATCH; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.UserHandle.USER_SYSTEM; Loading Loading @@ -123,6 +124,7 @@ import com.android.server.wm.ActivityTaskManagerInternal; import com.android.server.wm.WindowManagerInternal; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -663,4 +665,17 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { verify(mWorkerHandler, never()).post( any(NotificationManagerService.EnqueueNotificationRunnable.class)); } @Test public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception { final NotificationChannel defaultChannel = mBinderService.getNotificationChannel( PKG_N_MR1, ActivityManager.getCurrentUser(), PKG_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID); defaultChannel.setImportance(IMPORTANCE_NONE); mBinderService.updateNotificationChannelForPackage(PKG_N_MR1, mUid, defaultChannel); verify(mPermissionHelper).setNotificationPermission( PKG_N_MR1, ActivityManager.getCurrentUser(), false, true); } }
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -4072,6 +4072,28 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue((channelA.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelB.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); assertTrue((channelC.getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0); } @Test public void testDefaultChannelUpdatesApp_preMigrationToPermissions() throws Exception { final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID, false); defaultChannel.setImportance(IMPORTANCE_NONE); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true); assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_N_MR1, UID_N_MR1)); } @Test public void testDefaultChannelDoesNotUpdateApp_postMigrationToPermissions() throws Exception { when(mPermissionHelper.isMigrationEnabled()).thenReturn(true); final NotificationChannel defaultChannel = mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, NotificationChannel.DEFAULT_CHANNEL_ID, false); defaultChannel.setImportance(IMPORTANCE_NONE); mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, defaultChannel, true); assertEquals(IMPORTANCE_UNSPECIFIED, mHelper.getImportance(PKG_N_MR1, UID_N_MR1)); } }