Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationUIManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationUIManager.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationUIManager.java |
index 476649c033582edc57650aacd2cff7e3363ef4ee..a02033f4ea3d0943881d916fd41e21b33cd1a42d 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationUIManager.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationUIManager.java |
@@ -290,6 +290,54 @@ public class NotificationUIManager { |
} |
/** |
+ * Generates the notfiication defaults from vibratePattern's size and silent. |
+ * |
+ * Use the system's default ringtone, vibration and indicator lights unless the notification |
+ * has been marked as being silent, for example because it's low priority. |
Peter Beverloo
2015/05/01 17:17:59
"for example because it's low priority." -> we don
Sanghyun Park
2015/05/04 07:00:43
Done.
|
+ * If a vibration pattern is set, the notification should use the provided pattern |
+ * rather than the defaulting to system settings. |
+ * |
+ * @param vibratePatternLength Vibration pattern's size for the Notification. |
+ * @param silent Whether the default sound, vibration and lights should be suppressed. |
+ * @return The generated notification's default value. |
+ * Returns 0 if silent is true. |
Peter Beverloo
2015/05/01 17:17:59
No need for lines 303-306 in the description, one
Sanghyun Park
2015/05/04 07:00:43
Okay, I'll remove these lines.
|
+ * Returns Notification.DEFAULT_ALL if silent is false and vibration's length is 0. |
+ * Returns Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE |
+ * if silent is false and vibration's length is greater than 0. |
+ */ |
+ @VisibleForTesting |
+ static int makeDefaults(int vibratePatternLength, boolean silent) { |
+ assert silent && vibratePatternLength == 0; |
+ |
+ if (silent) return 0; |
+ |
+ int defaults = Notification.DEFAULT_ALL; |
+ if (vibratePatternLength > 0) { |
+ defaults &= ~Notification.DEFAULT_VIBRATE; |
+ } |
+ return defaults; |
+ } |
+ |
+ /** |
+ * Generates the vibration pattern used in Android notification. |
+ * |
+ * In Android platform, the first value indicates the number of |
Peter Beverloo
2015/05/01 17:17:59
nit: the linebreaks are kind of odd in this commen
Sanghyun Park
2015/05/04 07:00:44
Done.
|
+ * milliseconds to wait before turning the vibrator on unlike Blink. |
+ * So, we need to insert any value at the beginning of vibrate value. |
+ * |
+ * @param vibratePattern Vibration pattern for the Notification. |
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Web Vibration
Sanghyun Park
2015/05/04 07:00:43
Done.
|
+ * @return The generated vibration pattern for Android. |
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Android syntax
Sanghyun Park
2015/05/04 07:00:43
Done.
|
+ */ |
+ @VisibleForTesting |
+ static long[] makeVibratePattern(int[] vibratePattern) { |
+ long[] pattern = new long[vibratePattern.length + 1]; |
+ for (int i = 0; i < vibratePattern.length; ++i) { |
+ pattern[i + 1] = vibratePattern[i]; |
+ } |
+ return pattern; |
+ } |
+ |
+ /** |
* Displays a notification with the given details. |
* |
* @param persistentNotificationId The persistent id of the notification. |
@@ -303,11 +351,13 @@ public class NotificationUIManager { |
* text by the Android notification system. |
* @param icon Icon to be displayed in the notification. When this isn't a valid Bitmap, a |
* default icon will be generated instead. |
+ * @param vibratePattern Vibration pattern for the Notification. |
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Web Vibration
Sanghyun Park
2015/05/04 07:00:43
Done.
|
* @param silent Whether the default sound, vibration and lights should be suppressed. |
+ * @see https://developer.android.com/reference/android/app/Notification.html |
*/ |
@CalledByNative |
private void displayNotification(long persistentNotificationId, String origin, String tag, |
- String title, String body, Bitmap icon, boolean silent) { |
+ String title, String body, Bitmap icon, int[] vibratePattern, boolean silent) { |
Peter Beverloo
2015/05/01 17:17:59
nit: rename this to vibrationPattern?
Sanghyun Park
2015/05/04 07:00:43
Done.
|
if (icon == null || icon.getWidth() == 0) { |
icon = getIconGenerator().generateIconForUrl(origin, true); |
} |
@@ -347,9 +397,10 @@ public class NotificationUIManager { |
pendingSettingsIntent) |
.setSubText(origin); |
- // Use the system's default ringtone, vibration and indicator lights unless the notification |
- // has been marked as being silent, for example because it's low priority. |
- if (!silent) notificationBuilder.setDefaults(Notification.DEFAULT_ALL); |
+ notificationBuilder.setDefaults(makeDefaults(vibratePattern.length, silent)); |
+ if (vibratePattern.length > 0) { |
+ notificationBuilder.setVibrate(makeVibratePattern(vibratePattern)); |
+ } |
String platformTag = makePlatformTag(persistentNotificationId, origin, tag); |
mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build()); |