OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
6 | 6 |
7 import android.app.Notification; | 7 import android.app.Notification; |
8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 * notification will replace the previous notification with the s
ame tag and origin, | 414 * notification will replace the previous notification with the s
ame tag and origin, |
415 * if present. If no matching previous notification is present, t
he new one will just | 415 * if present. If no matching previous notification is present, t
he new one will just |
416 * be added. | 416 * be added. |
417 * @param title Title to be displayed in the notification. | 417 * @param title Title to be displayed in the notification. |
418 * @param body Message to be displayed in the notification. Will be trimmed
to one line of | 418 * @param body Message to be displayed in the notification. Will be trimmed
to one line of |
419 * text by the Android notification system. | 419 * text by the Android notification system. |
420 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to | 420 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to |
421 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. | 421 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. |
422 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. | 422 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. |
423 * @param timestamp The timestamp of the event for which the notification is
being shown. | 423 * @param timestamp The timestamp of the event for which the notification is
being shown. |
| 424 * @param renotify Whether the sound, vibration, and lights should be replay
ed if the |
| 425 * notification is replacing another notification. |
424 * @param silent Whether the default sound, vibration and lights should be s
uppressed. | 426 * @param silent Whether the default sound, vibration and lights should be s
uppressed. |
425 * @param actionTitles Titles of actions to display alongside the notificati
on. | 427 * @param actionTitles Titles of actions to display alongside the notificati
on. |
426 * @see https://developer.android.com/reference/android/app/Notification.htm
l | 428 * @see https://developer.android.com/reference/android/app/Notification.htm
l |
427 */ | 429 */ |
428 @CalledByNative | 430 @CalledByNative |
429 private void displayNotification(long persistentNotificationId, String origi
n, String profileId, | 431 private void displayNotification(long persistentNotificationId, String origi
n, String profileId, |
430 boolean incognito, String tag, String title, String body, Bitmap ico
n, | 432 boolean incognito, String tag, String title, String body, Bitmap ico
n, |
431 int[] vibrationPattern, long timestamp, boolean silent, String[] act
ionTitles) { | 433 int[] vibrationPattern, long timestamp, boolean renotify, boolean si
lent, |
| 434 String[] actionTitles) { |
432 Resources res = mAppContext.getResources(); | 435 Resources res = mAppContext.getResources(); |
433 | 436 |
434 // Record whether it's known whether notifications can be shown to the u
ser at all. | 437 // Record whether it's known whether notifications can be shown to the u
ser at all. |
435 RecordHistogram.recordEnumeratedHistogram( | 438 RecordHistogram.recordEnumeratedHistogram( |
436 "Notifications.AppNotificationStatus", | 439 "Notifications.AppNotificationStatus", |
437 NotificationSystemStatusUtil.determineAppNotificationStatus(mApp
Context), | 440 NotificationSystemStatusUtil.determineAppNotificationStatus(mApp
Context), |
438 NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY); | 441 NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY); |
439 | 442 |
440 // Set up a pending intent for going to the settings screen for |origin|
. | 443 // Set up a pending intent for going to the settings screen for |origin|
. |
441 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( | 444 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( |
(...skipping 16 matching lines...) Expand all Loading... |
458 NotificationBuilderBase notificationBuilder = | 461 NotificationBuilderBase notificationBuilder = |
459 createNotificationBuilder() | 462 createNotificationBuilder() |
460 .setTitle(title) | 463 .setTitle(title) |
461 .setBody(body) | 464 .setBody(body) |
462 .setLargeIcon(ensureNormalizedIcon(icon, origin)) | 465 .setLargeIcon(ensureNormalizedIcon(icon, origin)) |
463 .setSmallIcon(R.drawable.ic_chrome) | 466 .setSmallIcon(R.drawable.ic_chrome) |
464 .setContentIntent(clickIntent) | 467 .setContentIntent(clickIntent) |
465 .setDeleteIntent(closeIntent) | 468 .setDeleteIntent(closeIntent) |
466 .setTicker(createTickerText(title, body)) | 469 .setTicker(createTickerText(title, body)) |
467 .setTimestamp(timestamp) | 470 .setTimestamp(timestamp) |
| 471 .setRenotify(renotify) |
468 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( | 472 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( |
469 origin, false /* showScheme */)); | 473 origin, false /* showScheme */)); |
470 | 474 |
471 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex
++) { | 475 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex
++) { |
472 notificationBuilder.addAction(0 /* actionIcon */, actionTitles[actio
nIndex], | 476 notificationBuilder.addAction(0 /* actionIcon */, actionTitles[actio
nIndex], |
473 makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFIC
ATION, | 477 makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFIC
ATION, |
474 persistentNotificationId, orig
in, profileId, | 478 persistentNotificationId, orig
in, profileId, |
475 incognito, tag, actionIndex)); | 479 incognito, tag, actionIndex)); |
476 } | 480 } |
477 | 481 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 656 |
653 private static native void nativeInitializeNotificationUIManager(); | 657 private static native void nativeInitializeNotificationUIManager(); |
654 | 658 |
655 private native void nativeOnNotificationClicked(long nativeNotificationUIMan
agerAndroid, | 659 private native void nativeOnNotificationClicked(long nativeNotificationUIMan
agerAndroid, |
656 long persistentNotificationId, String origin, String profileId, bool
ean incognito, | 660 long persistentNotificationId, String origin, String profileId, bool
ean incognito, |
657 String tag, int actionIndex); | 661 String tag, int actionIndex); |
658 private native void nativeOnNotificationClosed(long nativeNotificationUIMana
gerAndroid, | 662 private native void nativeOnNotificationClosed(long nativeNotificationUIMana
gerAndroid, |
659 long persistentNotificationId, String origin, String profileId, bool
ean incognito, | 663 long persistentNotificationId, String origin, String profileId, bool
ean incognito, |
660 String tag, boolean byUser); | 664 String tag, boolean byUser); |
661 } | 665 } |
OLD | NEW |