Chromium Code Reviews| 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..cd115632bcf55faaa4cf1fc787410dfbd9dfe0ad 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,16 @@ 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 Android framework applies a fallback vibration pattern for the sound when the device |
| + // is in vibrate mode, there is no custom pattern, and the vibration default has been |
| + // disabled. To truly prevent vibration, provide a custom empty pattern. |
| + boolean vibrateEnabled = PrefServiceBridge.getInstance().isNotificationsVibrateEnabled(); |
| + if (!vibrateEnabled) { |
| + vibrationPattern = new int[0]; |
|
gone
2016/06/07 17:32:54
Might it be clearer to add a
private static final
Michael van Ouwerkerk
2016/06/08 13:28:13
Done.
|
| } |
| + notificationBuilder.setDefaults( |
| + makeDefaults(vibrationPattern.length, silent, vibrateEnabled)); |
| + notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern)); |
| String platformTag = makePlatformTag(persistentNotificationId, origin, tag); |
| if (webApkPackage.isEmpty()) { |