From 3836e6e899a01abd67bb9f20ef8414ea4ee37ac2 Mon Sep 17 00:00:00 2001 From: Emerick Rogul Date: Mon, 16 Dec 2019 11:00:25 -0500 Subject: [PATCH] Foreground browser on Brave Ads notification event --- .../BraveNotificationPlatformBridge.java | 31 +++++++++++++++++++ ...tifications-NotificationService.java.patch | 13 ++++++++ 2 files changed, 44 insertions(+) create mode 100644 patches/chrome-android-java-src-org-chromium-chrome-browser-notifications-NotificationService.java.patch diff --git a/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java b/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java index ea860204951..2d887c45ce9 100644 --- a/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java +++ b/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java @@ -9,8 +9,11 @@ package org.chromium.chrome.browser.notifications; import android.app.Notification; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; +import org.chromium.base.ApplicationStatus; +import org.chromium.base.ContextUtils; import org.chromium.base.annotations.CalledByNative; public class BraveNotificationPlatformBridge extends NotificationPlatformBridge { @@ -31,6 +34,34 @@ public class BraveNotificationPlatformBridge extends NotificationPlatformBridge super(nativeNotificationPlatformBridge); } + static boolean dispatchNotificationEvent(Intent intent) { + if (NotificationPlatformBridge.dispatchNotificationEvent(intent)) { + @NotificationType + int notificationType = intent.getIntExtra( + NotificationConstants.EXTRA_NOTIFICATION_TYPE, NotificationType.WEB_PERSISTENT); + if (notificationType == NotificationType.BRAVE_ADS) { + bringToForeground(); + } + return true; + } + + return false; + } + + private static void bringToForeground() { + if (ApplicationStatus.hasVisibleActivities()) { + return; + } + Context context = ContextUtils.getApplicationContext(); + Intent launchIntent = + context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); + if (launchIntent != null) { + launchIntent.setFlags( + Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + context.startActivity(launchIntent); + } + } + @Override protected NotificationBuilderBase prepareNotificationBuilder(String notificationId, @NotificationType int notificationType, String origin, String scopeUrl, diff --git a/patches/chrome-android-java-src-org-chromium-chrome-browser-notifications-NotificationService.java.patch b/patches/chrome-android-java-src-org-chromium-chrome-browser-notifications-NotificationService.java.patch new file mode 100644 index 00000000000..6e194045654 --- /dev/null +++ b/patches/chrome-android-java-src-org-chromium-chrome-browser-notifications-NotificationService.java.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java +index 07cf0852a2707fad59f35e864a8a1814234eaebd..b8822f523ae05a93224416b961bb308cbb4883be 100644 +--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java ++++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationService.java +@@ -117,7 +117,7 @@ public class NotificationService extends IntentService { + + // Now that the browser process is initialized, we pass forward the call to the + // NotificationPlatformBridge which will take care of delivering the appropriate events. +- if (!NotificationPlatformBridge.dispatchNotificationEvent(intent)) { ++ if (!BraveNotificationPlatformBridge.dispatchNotificationEvent(intent)) { + Log.w(TAG, "Unable to dispatch the notification event to Chrome."); + } +