From 31b2baac8d121bfd2bc9785b17fc385a8d282438 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 22 Feb 2017 12:18:45 -0500 Subject: [PATCH] Add missing sound to important channels. Test: runtest systemui-notification Change-Id: I7b091d312220e3830f2cd613b7ac08f75c5f0a8c --- .../server/notification/RankingHelper.java | 5 +++++ .../notification/RankingHelperTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 76890b1dc79db..867af9a4dd2fa 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -32,6 +32,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ParceledListSlice; import android.os.Build; import android.os.UserHandle; +import android.provider.Settings; import android.service.notification.NotificationListenerService.Ranking; import android.text.TextUtils; import android.util.ArrayMap; @@ -516,6 +517,10 @@ public class RankingHelper implements RankingConfig { if (!r.showBadge) { channel.setShowBadge(false); } + if (channel.getSound() == null) { + channel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, + Notification.AUDIO_ATTRIBUTES_DEFAULT); + } r.channels.put(channel.getId(), channel); updateConfig(); } diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java index 9ea9ce9e1d2b6..8210072139931 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -775,6 +775,26 @@ public class RankingHelperTest { mHelper.getNotificationChannel(pkg, uid, newChannel.getId(), false)); } + @Test + public void testCreateChannel_addMissingSound() throws Exception { + final NotificationChannel channel = + new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + mHelper.createNotificationChannel(pkg, uid, channel, true); + assertNotNull(mHelper.getNotificationChannel( + pkg, uid, channel.getId(), false).getSound()); + } + + @Test + public void testCreateChannel_noOverrideSound() throws Exception { + Uri sound = new Uri.Builder().scheme("test").build(); + final NotificationChannel channel = new NotificationChannel("id2", "name2", + NotificationManager.IMPORTANCE_DEFAULT); + channel.setSound(sound, mAudioAttributes); + mHelper.createNotificationChannel(pkg, uid, channel, true); + assertEquals(sound, mHelper.getNotificationChannel( + pkg, uid, channel.getId(), false).getSound()); + } + @Test public void testPermanentlyDeleteChannels() throws Exception { NotificationChannel channel1 =