diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 1837fb860b737..6553b61ebbc2b 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -260,8 +260,6 @@ public final class NotificationChannel implements Parcelable { private boolean mDemoted = false; private boolean mImportantConvo = false; private long mDeletedTime = DEFAULT_DELETION_TIME_MS; - // If the sound for this channel is missing, e.g. after restore. - private boolean mIsSoundMissing; /** * Creates a notification channel. @@ -716,13 +714,6 @@ public final class NotificationChannel implements Parcelable { return mSound; } - /** - * @hide - */ - public boolean isSoundMissing() { - return mIsSoundMissing; - } - /** * Returns the audio attributes for sound played by notifications posted to this channel. */ @@ -1007,9 +998,8 @@ public final class NotificationChannel implements Parcelable { // according to the docs because canonicalize method has to handle canonical uris as well. Uri canonicalizedUri = contentResolver.canonicalize(uri); if (canonicalizedUri == null) { - // We got a null because the uri in the backup does not exist here. - mIsSoundMissing = true; - return null; + // We got a null because the uri in the backup does not exist here, so we return default + return Settings.System.DEFAULT_NOTIFICATION_URI; } return contentResolver.uncanonicalize(canonicalizedUri); } diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java index 96bde3df1e685..e8a3a81503770 100644 --- a/services/core/java/com/android/server/notification/PreferencesHelper.java +++ b/services/core/java/com/android/server/notification/PreferencesHelper.java @@ -330,8 +330,7 @@ public class PreferencesHelper implements RankingConfig { } } - if (isShortcutOk(channel) && isDeletionOk(channel) - && !channel.isSoundMissing()) { + if (isShortcutOk(channel) && isDeletionOk(channel)) { r.channels.put(id, channel); } } 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 bf0ed713e4c30..66d157708332c 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -91,6 +91,7 @@ import android.os.RemoteCallback; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; +import android.provider.Settings; import android.provider.Settings.Global; import android.provider.Settings.Secure; import android.service.notification.ConversationChannelWrapper; @@ -376,27 +377,19 @@ public class PreferencesHelperTest extends UiServiceTestCase { when(mPm.getPackageUidAsUser(eq(packageName), anyInt())).thenReturn(uid); } - private static NotificationChannel createNotificationChannel(String id, String name, - int importance) { - NotificationChannel channel = new NotificationChannel(id, name, importance); - channel.setSound(SOUND_URI, Notification.AUDIO_ATTRIBUTES_DEFAULT); - return channel; - } - @Test public void testWriteXml_onlyBackupsTargetUser() throws Exception { // Setup package notifications. String package0 = "test.package.user0"; int uid0 = 1001; setUpPackageWithUid(package0, uid0); - NotificationChannel channel0 = createNotificationChannel("id0", "name0", IMPORTANCE_HIGH); + NotificationChannel channel0 = new NotificationChannel("id0", "name0", IMPORTANCE_HIGH); assertTrue(mHelper.createNotificationChannel(package0, uid0, channel0, true, false)); String package10 = "test.package.user10"; int uid10 = 1001001; setUpPackageWithUid(package10, uid10); - NotificationChannel channel10 = createNotificationChannel("id10", "name10", - IMPORTANCE_HIGH); + NotificationChannel channel10 = new NotificationChannel("id10", "name10", IMPORTANCE_HIGH); assertTrue(mHelper.createNotificationChannel(package10, uid10, channel10, true, false)); ByteArrayOutputStream baos = writeXmlAndPurge(package10, uid10, true, 10); @@ -421,7 +414,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { String package0 = "test.package.user0"; int uid0 = 1001; setUpPackageWithUid(package0, uid0); - NotificationChannel channel0 = createNotificationChannel("id0", "name0", IMPORTANCE_HIGH); + NotificationChannel channel0 = new NotificationChannel("id0", "name0", IMPORTANCE_HIGH); assertTrue(mHelper.createNotificationChannel(package0, uid0, channel0, true, false)); ByteArrayOutputStream baos = writeXmlAndPurge(package0, uid0, true, 0); @@ -514,8 +507,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannelGroup ncg = new NotificationChannelGroup("1", "bye"); NotificationChannelGroup ncg2 = new NotificationChannelGroup("2", "hello"); NotificationChannel channel1 = - createNotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); - NotificationChannel channel2 = createNotificationChannel("id2", "name2", IMPORTANCE_LOW); + new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); + NotificationChannel channel2 = + new NotificationChannel("id2", "name2", IMPORTANCE_LOW); channel2.setDescription("descriptions for all"); channel2.setSound(SOUND_URI, mAudioAttributes); channel2.enableLights(true); @@ -524,7 +518,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.enableVibration(false); channel2.setGroup(ncg.getId()); channel2.setLightColor(Color.BLUE); - NotificationChannel channel3 = createNotificationChannel("id3", "NAM3", IMPORTANCE_HIGH); + NotificationChannel channel3 = new NotificationChannel("id3", "NAM3", IMPORTANCE_HIGH); channel3.enableVibration(true); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncg, true); @@ -631,8 +625,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { } @Test - public void testRestoreXml_withNonExistentCanonicalizedSoundUri_ignoreChannel() - throws Exception { + public void testRestoreXml_withNonExistentCanonicalizedSoundUri() throws Exception { Thread.sleep(3000); doReturn(null) .when(mTestIContentProvider).canonicalize(any(), eq(CANONICAL_SOUND_URI)); @@ -650,7 +643,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannel actualChannel = mHelper.getNotificationChannel( PKG_N_MR1, UID_N_MR1, channel.getId(), false); - assertNull(actualChannel); + assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, actualChannel.getSound()); } @@ -659,8 +652,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { * handle its restore properly. */ @Test - public void testRestoreXml_withUncanonicalizedNonLocalSoundUri_ignoreChannel() - throws Exception { + public void testRestoreXml_withUncanonicalizedNonLocalSoundUri() throws Exception { // Not a local uncanonicalized uri, simulating that it fails to exist locally doReturn(null) .when(mTestIContentProvider).canonicalize(any(), eq(SOUND_URI)); @@ -679,7 +671,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { backupWithUncanonicalizedSoundUri.getBytes(), true, UserHandle.USER_SYSTEM); NotificationChannel actualChannel = mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, id, false); - assertNull(actualChannel); + assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, actualChannel.getSound()); } @Test @@ -703,11 +695,11 @@ public class PreferencesHelperTest extends UiServiceTestCase { NotificationChannelGroup ncg = new NotificationChannelGroup("1", "bye"); NotificationChannelGroup ncg2 = new NotificationChannelGroup("2", "hello"); NotificationChannel channel1 = - createNotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); + new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); NotificationChannel channel2 = - createNotificationChannel("id2", "name2", IMPORTANCE_HIGH); + new NotificationChannel("id2", "name2", IMPORTANCE_HIGH); NotificationChannel channel3 = - createNotificationChannel("id3", "name3", IMPORTANCE_LOW); + new NotificationChannel("id3", "name3", IMPORTANCE_LOW); channel3.setGroup(ncg.getId()); mHelper.createNotificationChannelGroup(PKG_N_MR1, UID_N_MR1, ncg, true); @@ -3062,7 +3054,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { @Test public void testChannelXml_backupDefaultApp() throws Exception { NotificationChannel channel1 = - createNotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); + new NotificationChannel("id1", "name1", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG_O, UID_O, channel1, true, false); @@ -3343,7 +3335,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( - PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false); + PKG_P, UID_P, new NotificationChannel("id", "id", 2), true, false); assertTrue(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); assertFalse(mHelper.deleteNotificationChannel(PKG_P, UID_P, "id")); } @@ -3354,7 +3346,7 @@ public class PreferencesHelperTest extends UiServiceTestCase { mAppOpsManager, mStatsEventBuilderFactory); mHelper.createNotificationChannel( - PKG_P, UID_P, createNotificationChannel("id", "id", 2), true, false); + PKG_P, UID_P, new NotificationChannel("id", "id", 2), true, false); mHelper.deleteNotificationChannel(PKG_P, UID_P, "id"); NotificationChannel nc1 = mHelper.getNotificationChannel(PKG_P, UID_P, "id", true); assertTrue(DateUtils.isToday(nc1.getDeletedTimeMs()));