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
--- 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");