Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java |
index fe71f72f5bb93f1bde5d77994f9734df79a08692..8f0fa2612eff9ea1c5e35700d46ce89b42b23506 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java |
@@ -30,6 +30,7 @@ |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
+import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
import org.chromium.chrome.browser.preferences.Preferences; |
import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences; |
@@ -411,25 +412,26 @@ static String getOriginFromTag(@Nullable String tag) { |
} |
/** |
- * Generates the notfiication defaults from vibrationPattern's size and silent. |
+ * Generates the notification defaults from vibrationPattern's size and silent. |
* |
* Use the system's default ringtone, vibration and indicator lights unless the notification |
* has been marked as being silent. |
* If a vibration pattern is set, the notification should use the provided pattern |
- * rather than the defaulting to system settings. |
+ * rather than defaulting to the system settings. |
* |
* @param vibrationPatternLength Vibration pattern's size for the Notification. |
* @param silent Whether the default sound, vibration and lights should be suppressed. |
+ * @param vibrateEnabled Whether vibration is enabled in preferences. |
* @return The generated notification's default value. |
*/ |
@VisibleForTesting |
- static int makeDefaults(int vibrationPatternLength, boolean silent) { |
+ static int makeDefaults(int vibrationPatternLength, boolean silent, boolean vibrateEnabled) { |
assert !silent || vibrationPatternLength == 0; |
if (silent) return 0; |
int defaults = Notification.DEFAULT_ALL; |
- if (vibrationPatternLength > 0) { |
+ if (vibrationPatternLength > 0 || !vibrateEnabled) { |
defaults &= ~Notification.DEFAULT_VIBRATE; |
} |
return defaults; |
@@ -552,10 +554,19 @@ private void displayNotification(long persistentNotificationId, String origin, S |
// one, so add it after the other actions. |
notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pendingSettingsIntent); |
- notificationBuilder.setDefaults(makeDefaults(vibrationPattern.length, silent)); |
- if (vibrationPattern.length > 0) { |
- notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern)); |
+ // The NotificationManagerService in the core Android framework has a fallback vibration |
+ // pattern. It is used when the device is in vibrate mode, there is no custom pattern, and |
+ // the vibration default has been disabled, but there is a sound to play. Effectively, it |
+ // plays the fallback pattern as fallback for the sound, even though the default vibration |
+ // has been turned off. So in order to truly prevent vibration, specify a custom empty |
+ // pattern. |
Peter Beverloo
2016/06/07 12:46:01
Can we make this significantly more concise? What
Michael van Ouwerkerk
2016/06/07 16:34:21
Sure, I did something shorter like that.
|
+ boolean vibrateEnabled = PrefServiceBridge.getInstance().isNotificationsVibrateEnabled(); |
+ if (!vibrateEnabled) { |
+ vibrationPattern = new int[0]; |
} |
+ notificationBuilder.setDefaults( |
+ makeDefaults(vibrationPattern.length, silent, vibrateEnabled)); |
+ notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern)); |
String platformTag = makePlatformTag(persistentNotificationId, origin, tag); |
if (webApkPackage.isEmpty()) { |