Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java

Issue 2132023002: Store the notification id as a string for Android notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@event_api
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 5c20a3cd205fbad809b1d98858cb7d211649be22..d330d4bb5fc86bcc2e309b7462db24e53b9d21b1 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
@@ -191,8 +191,8 @@ public class NotificationPlatformBridge {
}
}
- long persistentNotificationId =
- intent.getLongExtra(NotificationConstants.EXTRA_PERSISTENT_NOTIFICATION_ID, -1);
+ String notificationId = intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_ID);
+
String origin = intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_ORIGIN);
String profileId =
intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_ID);
@@ -200,7 +200,7 @@ public class NotificationPlatformBridge {
NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_INCOGNITO, false);
String tag = intent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_TAG);
- Log.i(TAG, "Dispatching notification event to native: " + persistentNotificationId);
+ Log.i(TAG, "Dispatching notification event to native: " + notificationId);
if (NotificationConstants.ACTION_CLICK_NOTIFICATION.equals(intent.getAction())) {
String webApkPackage = "";
@@ -215,15 +215,14 @@ public class NotificationPlatformBridge {
int actionIndex = intent.getIntExtra(
NotificationConstants.EXTRA_NOTIFICATION_INFO_ACTION_INDEX, -1);
sInstance.onNotificationClicked(
- persistentNotificationId, origin, profileId, incognito, tag, webApkPackage,
- actionIndex);
+ notificationId, origin, profileId, incognito, tag, webApkPackage, actionIndex);
return true;
} else if (NotificationConstants.ACTION_CLOSE_NOTIFICATION.equals(intent.getAction())) {
// Notification deleteIntent is executed only "when the notification is explicitly
// dismissed by the user, either with the 'Clear All' button or by swiping it away
// individually" (though a third-party NotificationListenerService may also trigger it).
sInstance.onNotificationClosed(
- persistentNotificationId, origin, profileId, incognito, tag, true /* byUser */);
+ notificationId, origin, profileId, incognito, tag, true /* byUser */);
return true;
}
@@ -301,13 +300,12 @@ public class NotificationPlatformBridge {
* Without this, the pending intents derived from the intent may be reused, because extras are
* not taken into account for the filterEquals comparison.
*
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin The origin to whom the notification belongs.
* @param actionIndex The zero-based index of the action button, or -1 if not applicable.
*/
- private Uri makeIntentData(long persistentNotificationId, String origin, int actionIndex) {
- return Uri.parse(origin).buildUpon().fragment(
- persistentNotificationId + "," + actionIndex).build();
+ private Uri makeIntentData(String notificationId, String origin, int actionIndex) {
+ return Uri.parse(origin).buildUpon().fragment(notificationId + "," + actionIndex).build();
}
/**
@@ -315,7 +313,7 @@ public class NotificationPlatformBridge {
* in the other parameters.
*
* @param action The action this pending intent will represent.
- * @param persistentNotificationId The persistent id of the notification.
+ * @paramn notificationId The id of the notification.
* @param origin The origin to whom the notification belongs.
* @param profileId Id of the profile to which the notification belongs.
* @param incognito Whether the profile was in incognito mode.
@@ -324,15 +322,14 @@ public class NotificationPlatformBridge {
* the notification is not associated with a WebAPK.
* @param actionIndex The zero-based index of the action button, or -1 if not applicable.
*/
- private PendingIntent makePendingIntent(String action, long persistentNotificationId,
- String origin, String profileId, boolean incognito, @Nullable String tag,
- String webApkPackage, int actionIndex) {
- Uri intentData = makeIntentData(persistentNotificationId, origin, actionIndex);
+ private PendingIntent makePendingIntent(String action, String notificationId, String origin,
+ String profileId, boolean incognito, @Nullable String tag, String webApkPackage,
+ int actionIndex) {
+ Uri intentData = makeIntentData(notificationId, origin, actionIndex);
Intent intent = new Intent(action, intentData);
intent.setClass(mAppContext, NotificationService.Receiver.class);
- intent.putExtra(NotificationConstants.EXTRA_PERSISTENT_NOTIFICATION_ID,
- persistentNotificationId);
+ intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_ID, notificationId);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_ORIGIN, origin);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_ID, profileId);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_INCOGNITO, incognito);
@@ -358,14 +355,13 @@ public class NotificationPlatformBridge {
* If the input tag is empty the output is PREFIX + SEPARATOR + ORIGIN + SEPARATOR +
* NOTIFICATION_ID.
*
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin The origin for which the notification is shown.
* @param tag A string identifier for this notification.
* @return The generated platform tag.
*/
@VisibleForTesting
- static String makePlatformTag(
- long persistentNotificationId, String origin, @Nullable String tag) {
+ static String makePlatformTag(String notificationId, String origin, @Nullable String tag) {
// The given tag may contain the separator character, so add it last to make reading the
// preceding origin token reliable. If no tag was specified (it is the default empty
// string), make the platform tag unique by appending the notification id.
@@ -376,7 +372,7 @@ public class NotificationPlatformBridge {
.append(NotificationConstants.NOTIFICATION_TAG_SEPARATOR);
if (TextUtils.isEmpty(tag)) {
- builder.append(persistentNotificationId);
+ builder.append(notificationId);
} else {
builder.append(tag);
}
@@ -460,7 +456,7 @@ public class NotificationPlatformBridge {
/**
* Displays a notification with the given details.
*
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin Full text of the origin, including the protocol, owning this notification.
* @param profileId Id of the profile that showed the notification.
* @param incognito if the session of the profile is an off the record one.
@@ -487,7 +483,7 @@ public class NotificationPlatformBridge {
* @see https://developer.android.com/reference/android/app/Notification.html
*/
@CalledByNative
- private void displayNotification(long persistentNotificationId, String origin, String profileId,
+ private void displayNotification(String notificationId, String origin, String profileId,
boolean incognito, String tag, String webApkPackage, String title, String body,
Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp, boolean renotify,
boolean silent, String[] actionTitles, Bitmap[] actionIcons) {
@@ -506,20 +502,19 @@ public class NotificationPlatformBridge {
// Set up a pending intent for going to the settings screen for |origin|.
Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
mAppContext, SingleWebsitePreferences.class.getName());
- settingsIntent.setData(
- makeIntentData(persistentNotificationId, origin, -1 /* actionIndex */));
+ settingsIntent.setData(makeIntentData(notificationId, origin, -1 /* actionIndex */));
settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
SingleWebsitePreferences.createFragmentArgsForSite(origin));
PendingIntent pendingSettingsIntent = PendingIntent.getActivity(mAppContext,
PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
- PendingIntent clickIntent = makePendingIntent(
- NotificationConstants.ACTION_CLICK_NOTIFICATION, persistentNotificationId, origin,
- profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
- PendingIntent closeIntent = makePendingIntent(
- NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotificationId, origin,
- profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
+ PendingIntent clickIntent =
+ makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION, notificationId,
+ origin, profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
+ PendingIntent closeIntent =
+ makePendingIntent(NotificationConstants.ACTION_CLOSE_NOTIFICATION, notificationId,
+ origin, profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
NotificationBuilderBase notificationBuilder =
createNotificationBuilder()
@@ -539,8 +534,8 @@ public class NotificationPlatformBridge {
for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex++) {
notificationBuilder.addAction(actionIcons[actionIndex], actionTitles[actionIndex],
makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION,
- persistentNotificationId, origin, profileId,
- incognito, tag, webApkPackage, actionIndex));
+ notificationId, origin, profileId, incognito, tag,
+ webApkPackage, actionIndex));
}
// If action buttons are displayed, there isn't room for the full Site Settings button
@@ -567,7 +562,7 @@ public class NotificationPlatformBridge {
makeDefaults(vibrationPattern.length, silent, vibrateEnabled));
notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern));
- String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
+ String platformTag = makePlatformTag(notificationId, origin, tag);
if (webApkPackage.isEmpty()) {
mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
} else {
@@ -676,17 +671,16 @@ public class NotificationPlatformBridge {
* Closes the notification associated with the given parameters.
*
* @param profileId of the profile whose notification this is for.
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin The origin to which the notification belongs.
* @param tag The tag of the notification. May be NULL.
* @param webApkPackage The package of the WebAPK associated with the notification.
* Empty if the notification is not associated with a WebAPK.
*/
@CalledByNative
- private void closeNotification(String profileId, long persistentNotificationId, String origin,
+ private void closeNotification(String profileId, String notificationId, String origin,
String tag, String webApkPackage) {
- // TODO(miguelg) make profile_id part of the tag.
Peter Beverloo 2016/07/08 16:14:38 Why is this not relevant anymore? (All this code s
Miguel Garcia 2016/07/08 16:43:09 Yeah I removed it by mistake. Still relevant indee
- String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
+ String platformTag = makePlatformTag(notificationId, origin, tag);
if (webApkPackage.isEmpty()) {
mNotificationManager.cancel(platformTag, PLATFORM_ID);
@@ -699,7 +693,7 @@ public class NotificationPlatformBridge {
* Calls NotificationPlatformBridgeAndroid::OnNotificationClicked in native code to indicate
* that the notification with the given parameters has been clicked on.
*
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin The origin of the notification.
* @param profileId Id of the profile that showed the notification.
* @param incognito if the profile session was an off the record one.
@@ -708,37 +702,36 @@ public class NotificationPlatformBridge {
* Empty if the notification is not associated with a WebAPK.
* @param actionIndex
*/
- private void onNotificationClicked(long persistentNotificationId, String origin,
- String profileId, boolean incognito, String tag, String webApkPackage,
- int actionIndex) {
+ private void onNotificationClicked(String notificationId, String origin, String profileId,
+ boolean incognito, String tag, String webApkPackage, int actionIndex) {
mLastNotificationClickMs = System.currentTimeMillis();
- nativeOnNotificationClicked(mNativeNotificationPlatformBridge, persistentNotificationId,
- origin, profileId, incognito, tag, webApkPackage, actionIndex);
+ nativeOnNotificationClicked(mNativeNotificationPlatformBridge, notificationId, origin,
+ profileId, incognito, tag, webApkPackage, actionIndex);
}
/**
* Calls NotificationPlatformBridgeAndroid::OnNotificationClosed in native code to indicate that
* the notification with the given parameters has been closed.
*
- * @param persistentNotificationId The persistent id of the notification.
+ * @param notificationId The id of the notification.
* @param origin The origin of the notification.
* @param profileId Id of the profile that showed the notification.
* @param incognito if the profile session was an off the record one.
* @param tag The tag of the notification. May be NULL.
* @param byUser Whether the notification was closed by a user gesture.
*/
- private void onNotificationClosed(long persistentNotificationId, String origin,
- String profileId, boolean incognito, String tag, boolean byUser) {
- nativeOnNotificationClosed(mNativeNotificationPlatformBridge, persistentNotificationId,
- origin, profileId, incognito, tag, byUser);
+ private void onNotificationClosed(String notificationId, String origin, String profileId,
+ boolean incognito, String tag, boolean byUser) {
+ nativeOnNotificationClosed(mNativeNotificationPlatformBridge, notificationId, origin,
+ profileId, incognito, tag, byUser);
}
private static native void nativeInitializeNotificationPlatformBridge();
private native void nativeOnNotificationClicked(long nativeNotificationPlatformBridgeAndroid,
- long persistentNotificationId, String origin, String profileId, boolean incognito,
- String tag, String webApkPackage, int actionIndex);
+ String notificationId, String origin, String profileId, boolean incognito, String tag,
+ String webApkPackage, int actionIndex);
private native void nativeOnNotificationClosed(long nativeNotificationPlatformBridgeAndroid,
- long persistentNotificationId, String origin, String profileId, boolean incognito,
- String tag, boolean byUser);
+ String notificationId, String origin, String profileId, boolean incognito, String tag,
+ boolean byUser);
}

Powered by Google App Engine
This is Rietveld 408576698