summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2017-04-12 13:27:58 -0400
committer Julia Reynolds <juliacr@google.com> 2017-04-13 11:03:57 -0400
commit184b86da382b8e24cdd0e5629e70d7057d418883 (patch)
treec0eae36d16ba6950a637bd98e7110c510307f48b
parent889280c4c3dde8b9454bf67faf2eab4ff99821b1 (diff)
Allow notification channels to be silent.
This better accomodates those apps that play their own sounds. Since most apps don't play their own sounds, update the documentation on notificationchannel to add guidance about when they should add a sound. Fixes: 37237013 Test: runtest systemui-notification Change-Id: If00b15b1b44da66d24dacb2895e9a6c0a06d1890
-rw-r--r--core/java/android/app/NotificationChannel.java8
-rw-r--r--services/core/java/com/android/server/notification/RankingHelper.java4
-rw-r--r--services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java2
-rw-r--r--services/tests/notification/src/com/android/server/notification/RankingHelperTest.java9
4 files changed, 7 insertions, 16 deletions
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java
index 92216d15ec95..e50bc136bc5a 100644
--- a/core/java/android/app/NotificationChannel.java
+++ b/core/java/android/app/NotificationChannel.java
@@ -26,6 +26,7 @@ import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
+import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
@@ -139,7 +140,7 @@ public final class NotificationChannel implements Parcelable {
private int mImportance = DEFAULT_IMPORTANCE;
private boolean mBypassDnd;
private int mLockscreenVisibility = DEFAULT_VISIBILITY;
- private Uri mSound;
+ private Uri mSound = Settings.System.DEFAULT_NOTIFICATION_URI;
private boolean mLights;
private int mLightColor = DEFAULT_LIGHT_COLOR;
private long[] mVibration;
@@ -330,7 +331,8 @@ public final class NotificationChannel implements Parcelable {
/**
* Sets the sound that should be played for notifications posted to this channel and its
- * audio attributes.
+ * audio attributes. Notification channels with an {@link #getImportance() importance} of at
+ * least {@link NotificationManager#IMPORTANCE_DEFAULT} should have a sound.
*
* Only modifiable before the channel is submitted to
* {@link NotificationManager#notify(String, int, Notification)}.
@@ -445,7 +447,7 @@ public final class NotificationChannel implements Parcelable {
}
/**
- * Returns the user specified importance {e.g. @link NotificationManager#IMPORTANCE_LOW} for
+ * Returns the user specified importance e.g. {@link NotificationManager#IMPORTANCE_LOW} for
* notifications posted to this channel.
*/
public int getImportance() {
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 9e12f919c417..44dc61de0ea9 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -570,10 +570,6 @@ 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);
MetricsLogger.action(getChannelLog(channel, pkg).setType(
MetricsProto.MetricsEvent.TYPE_OPEN));
diff --git a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
index e28566931d23..d383aea5a679 100644
--- a/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
+++ b/services/tests/notification/src/com/android/server/notification/BuzzBeepBlinkTest.java
@@ -215,6 +215,8 @@ public class BuzzBeepBlinkTest {
builder.setSound(CUSTOM_SOUND);
channel.setSound(CUSTOM_SOUND, CUSTOM_ATTRIBUTES);
}
+ } else {
+ channel.setSound(null, null);
}
if (buzzy) {
if (defaultVibration) {
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 885eb2ea235a..303054e77793 100644
--- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java
@@ -738,15 +738,6 @@ public class RankingHelperTest {
}
@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",