Foreground browser on Brave Ads notification event
This commit is contained in:
+31
@@ -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,
|
||||
|
||||
+13
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user