Bug 1411968 - Only try launching BrowserApp when handling notifications; r?nechen draft
authorJim Chen <nchen@mozilla.com>
Fri, 10 Nov 2017 18:26:18 -0500
changeset 696694 98e666e36efd55007d4e4fdb24b711b9d9448b36
parent 695787 277e2ae05f747e257eaa73e36f1bc31b98a21af9
child 739903 22778c2fa0190eb67634662227ce47e41ec1d5f9
push id88765
push userbmo:nchen@mozilla.com
push dateFri, 10 Nov 2017 23:26:32 +0000
reviewersnechen
bugs1411968
milestone58.0a1
Bug 1411968 - Only try launching BrowserApp when handling notifications; r?nechen Usually when we handle notification events, we try to launch whatever Activity showed the notification so that the user can see results. However, only BrowserApp supports being launched this way, so we should restrict launching Activites to BrowserApp. For others like CustomTabsActivity, we should just handle the notification event directly. Currently, only download notifications are supported for these other Activities, so it's okay if we don't display the Activity. MozReview-Commit-ID: CNVRSEWBOQ6
mobile/android/base/java/org/mozilla/gecko/notifications/NotificationReceiver.java
--- a/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationReceiver.java
+++ b/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationReceiver.java
@@ -1,15 +1,16 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.notifications;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.mozglue.SafeIntent;
 
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
@@ -57,17 +58,27 @@ public class NotificationReceiver extend
             client.onNotificationClose(data.getQueryParameter(NotificationHelper.ID_ATTR));
             return;
         }
 
         forwardMessageToActivity(intent, context);
     }
 
     private void forwardMessageToActivity(final Intent intent, final Context context) {
-        final ComponentName name = intent.getExtras().getParcelable(NotificationHelper.ORIGINAL_EXTRA_COMPONENT);
+        final ComponentName name =
+                intent.getExtras().getParcelable(NotificationHelper.ORIGINAL_EXTRA_COMPONENT);
+
+        if (!AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS.equals(
+                name != null ? name.getClassName() : null)) {
+            // Don't try to start anything other than the browser Activity.
+            NotificationHelper.getInstance(context.getApplicationContext())
+                              .handleNotificationIntent(new SafeIntent(intent));
+            return;
+        }
+
         intent.setComponent(name);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(intent);
     }
 
     private void onNotificationClientAction(final Context context, final String action,
                                             final Uri data, final Intent intent) {
         final String name = data.getQueryParameter("name");