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

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

Issue 2536313003: Implement GetDisplayed on android M+ (Closed)
Patch Set: review Created 4 years 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 0ca20263b419fef302c1a463aacb1ab55325fcd1..4e32ba0a39013c3ee66cb29b3ce868610a88dd4e 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
@@ -15,6 +15,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.service.notification.StatusBarNotification;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@@ -43,6 +44,8 @@ import org.chromium.webapk.lib.client.WebApkValidator;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
import javax.annotation.Nullable;
@@ -572,9 +575,19 @@ public class NotificationPlatformBridge {
makeDefaults(vibrationPattern.length, silent, vibrateEnabled));
notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern));
+ // The extras bundle is available from API 20 but it's currenlty only used to retrieve
+ // notifications which is only available from 23 (Marshmallow) onwards.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Bundle extras = new Bundle();
+ extras.putString(NotificationConstants.EXTRA_NOTIFICATION_ID, notificationId);
+ extras.putString(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_ID, profileId);
+ notificationBuilder.setExtras(extras);
+ }
+
String platformTag = makePlatformTag(notificationId, origin, tag);
if (webApkPackage.isEmpty()) {
- mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
+ Notification notification = notificationBuilder.build();
+ mNotificationManager.notify(platformTag, PLATFORM_ID, notification);
Peter Beverloo 2016/12/06 16:54:13 nit: why this change? revert? :)
Miguel Garcia 2016/12/14 15:47:32 Acknowledged.
} else {
WebApkNotificationClient.notifyNotification(
webApkPackage, notificationBuilder, platformTag, PLATFORM_ID);
@@ -675,6 +688,30 @@ public class NotificationPlatformBridge {
}
}
+ @CalledByNative
Peter Beverloo 2016/12/06 16:54:13 nit: please add a docblock for consistency
Miguel Garcia 2016/12/14 15:47:32 Done.
+ private String[] getNotificationsForProfile(String profileId) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
+ return null;
+ }
+
+ StatusBarNotification[] displayedNotifications =
+ mNotificationManager.getActiveNotifications();
+ List<String> notifications = new ArrayList<String>();
+ for (StatusBarNotification notification : displayedNotifications) {
+ Bundle extras = notification.getNotification().extras;
+ String notificationId = extras.getString(NotificationConstants.EXTRA_NOTIFICATION_ID);
+ String notificationProfileId =
+ extras.getString(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_ID);
+ if (notificationId != null && profileId.equals(notificationProfileId)) {
+ notifications.add(notificationId);
+ }
+ }
+ if (notifications.size() == 0) return null;
+
+ String[] result = new String[notifications.size()];
+ return notifications.toArray(result);
+ }
+
/**
* Calls NotificationPlatformBridgeAndroid::OnNotificationClicked in native code to indicate
* that the notification with the given parameters has been clicked on.

Powered by Google App Engine
This is Rietveld 408576698