Bug 1411968 - Only try launching BrowserApp when handling notifications; r=nechen
☠☠ backed out by 964e27d56a7a ☠ ☠
authorJim Chen <nchen@mozilla.com>
Fri, 10 Nov 2017 18:26:18 -0500
changeset 436112 ca5529c5b2324352734feddb9c928192b8350a56
parent 436111 2af71f8e9ca31859edc5dae64bbffa856d00194f
child 436113 0dc2628668b2d815a14e9f4d644d83868a9e85d0
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersnechen
bugs1411968
milestone59.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");