From 224377b12ec4756e54b225646356ed9a36bca6da Mon Sep 17 00:00:00 2001 From: Serg Date: Fri, 14 Oct 2022 16:08:33 -0400 Subject: [PATCH] Adds a few null checks and handling an exception inside RetentionNotificationPublisher on Android --- .../RetentionNotificationPublisher.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotificationPublisher.java b/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotificationPublisher.java index 29a75b3b7ff..037ba2f6b88 100644 --- a/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotificationPublisher.java +++ b/android/java/org/chromium/chrome/browser/notifications/retention/RetentionNotificationPublisher.java @@ -112,11 +112,17 @@ public class RetentionNotificationPublisher extends BroadcastReceiver { case RetentionNotificationUtil.DAY_30: case RetentionNotificationUtil.DAY_35: // Can't check for rewards code in background - if (braveActivity != null - && !BraveAdsNativeHelper.nativeIsBraveAdsEnabled( - Profile.getLastUsedRegularProfile()) - && ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS)) { - createNotification(context, intent); + try { + if (braveActivity != null + && !BraveAdsNativeHelper.nativeIsBraveAdsEnabled( + Profile.getLastUsedRegularProfile()) + && ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS)) { + createNotification(context, intent); + } + } catch (IllegalStateException exc) { + // We can receive 'Browser hasn't finished initialization yet!' if + // Profile.getLastUsedRegularProfile is called to early. Just ignore it, + // that's better comparing to crashing } break; case RetentionNotificationUtil.EVERY_SUNDAY: @@ -184,7 +190,8 @@ public class RetentionNotificationPublisher extends BroadcastReceiver { public static void backgroundNotificationAction(Context context, Intent intent) { String notificationType = intent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE); - if (ApplicationStatus.hasVisibleActivities()) { + if (ApplicationStatus.hasVisibleActivities() || context == null + || context.getPackageManager() == null) { return; } Intent launchIntent =