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
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user