From d4d2de2a7778b85f5af9959a5ebf07094727e672 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Wed, 14 Nov 2012 11:25:46 -0800 Subject: [PATCH] Do not vibe when the default notification sound is Silent. (This relates to the new vibration fallback behavior, where notifications that expect to make a sound should always vibrate in vibrate mode. We should not vibrate if the notification's sound is silent, but we should also not vibrate if the notification uses the default sound and the default is silent.) Bug: 7537077 Change-Id: I08e149c8c00ef2d2f61e418d88a086cb5e9cf241 --- .../server/NotificationManagerService.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index 70d37bfc82851..fa84f486ac595 100755 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -1077,16 +1077,27 @@ public class NotificationManagerService extends INotificationManager.Stub final AudioManager audioManager = (AudioManager) mContext .getSystemService(Context.AUDIO_SERVICE); + // sound final boolean useDefaultSound = (notification.defaults & Notification.DEFAULT_SOUND) != 0; - if (useDefaultSound || notification.sound != null) { - Uri uri; - if (useDefaultSound) { - uri = Settings.System.DEFAULT_NOTIFICATION_URI; - } else { - uri = notification.sound; - } + + Uri soundUri = null; + boolean hasValidSound = false; + + if (useDefaultSound) { + soundUri = Settings.System.DEFAULT_NOTIFICATION_URI; + + // check to see if the default notification sound is silent + ContentResolver resolver = mContext.getContentResolver(); + hasValidSound = Settings.System.getString(resolver, + Settings.System.NOTIFICATION_SOUND) != null; + } else if (notification.sound != null) { + soundUri = notification.sound; + hasValidSound = (soundUri != null); + } + + if (hasValidSound) { boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0; int audioStreamType; if (notification.audioStreamType >= 0) { @@ -1103,7 +1114,7 @@ public class NotificationManagerService extends INotificationManager.Stub try { final IRingtonePlayer player = mAudioService.getRingtonePlayer(); if (player != null) { - player.playAsync(uri, user, looping, audioStreamType); + player.playAsync(soundUri, user, looping, audioStreamType); } } catch (RemoteException e) { } finally { @@ -1120,7 +1131,7 @@ public class NotificationManagerService extends INotificationManager.Stub // and no other vibration is specified, we apply the default vibration anyway final boolean convertSoundToVibration = !hasCustomVibrate - && (useDefaultSound || notification.sound != null) + && hasValidSound && (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE); // The DEFAULT_VIBRATE flag trumps any custom vibration.