Bug 1392224 - Make Fennec the default handler for Leanplum Push Notification. r?maliu draft
authorNevin Chen <cnevinchen@gmail.com>
Tue, 22 Aug 2017 13:40:17 +0800
changeset 650955 b38314a6d8c2e4e04ddfd1496568d58c5970ea54
parent 650272 d39c88e4dcb10224dbed8f9a346cdc82882a6eb9
child 727536 8ccde5edee2314c3ece216ebc5a13a7a25c2a212
push id75536
push userbmo:cnevinchen@gmail.com
push dateWed, 23 Aug 2017 02:18:01 +0000
reviewersmaliu
bugs1392224
milestone56.0a1
Bug 1392224 - Make Fennec the default handler for Leanplum Push Notification. r?maliu MozReview-Commit-ID: GiXHPvcPhgp
mobile/android/thirdparty/com/leanplum/LeanplumPushService.java
--- a/mobile/android/thirdparty/com/leanplum/LeanplumPushService.java
+++ b/mobile/android/thirdparty/com/leanplum/LeanplumPushService.java
@@ -470,23 +470,31 @@ public class LeanplumPushService {
     }
     return null;
   }
 
   /**
    * Checks if there is some activity that can handle intent.
    */
   private static Boolean activityHasIntent(Context context, Intent deepLinkIntent) {
+    final int flag;
+    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
+      flag = PackageManager.MATCH_ALL;
+    } else {
+      flag = 0;
+    }
     List<ResolveInfo> resolveInfoList =
-        context.getPackageManager().queryIntentActivities(deepLinkIntent, 0);
+            context.getPackageManager().queryIntentActivities(deepLinkIntent, flag);
     if (resolveInfoList != null && !resolveInfoList.isEmpty()) {
       for (ResolveInfo resolveInfo : resolveInfoList) {
         if (resolveInfo != null && resolveInfo.activityInfo != null &&
             resolveInfo.activityInfo.name != null) {
-          if (resolveInfo.activityInfo.name.contains(context.getPackageName())) {
+          // In local build, Fennec's activityInfo.packagename is org.mozilla.fennec_<device_name>
+          // But activityInfo.name is org.mozilla.Gecko.App. Thus we should use packagename here.
+          if (resolveInfo.activityInfo.packageName.equals(context.getPackageName())) {
             // If url can be handled by current app - set package name to intent, so url will be
             // open by current app. Skip chooser dialog.
             deepLinkIntent.setPackage(resolveInfo.activityInfo.packageName);
             return true;
           }
         }
       }
     }