diff options
| author | 2021-10-25 13:38:51 +0000 | |
|---|---|---|
| committer | 2021-10-25 13:38:51 +0000 | |
| commit | 50936e9b7abfdf9bf9d259f21f2352128f5ac52e (patch) | |
| tree | c8d730cd50c5f3ac4283bf936e56717d9072f81c | |
| parent | 59e5fa40f8b1e2decf2c4f4662c087c463929ae8 (diff) | |
| parent | 808d3a582d4dc1e5e93a473eabe4659dd352c4c0 (diff) | |
Merge "Migrate pre-Oreo app handling to permissions"
5 files changed, 50 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index f14f769548ac..f701c2abe0c6 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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) { diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index b94721afee00..c74813aec410 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -1043,9 +1043,11 @@ public class PreferencesHelper implements RankingConfig { r.channels.put(updatedChannel.getId(), updatedChannel); if (onlyHasDefaultChannel(pkg, uid)) { - // copy settings to app level so they are inherited by new channels - // when the app migrates - r.importance = updatedChannel.getImportance(); + 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(); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index f61d3000f97d..5694e599edc3 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -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") diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java index 3ec87291cc32..016b57953131 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java @@ -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; @@ -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; @@ -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); + } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index 5324ec5f900e..d90f91a4e84a 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -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)); } } |