Bug 1337771 - Let ActionButton works in some apps draft
authorJulian_Chu <walkingice0204@gmail.com>
Fri, 10 Feb 2017 15:47:56 +0800
changeset 481632 2c84df99a42265ac4b68b3a9b82e81828580a87f
parent 480508 3a95aa4246653a7863914ffec032897d13359fb0
child 545259 f13524c7226956de872890e2fbc7c69146be0509
push id44888
push userbmo:walkingice0204@gmail.com
push dateFri, 10 Feb 2017 08:06:43 +0000
bugs1337771
milestone54.0a1
Bug 1337771 - Let ActionButton works in some apps If the intent from 3rd-party app doesn't have data url, directly call PendingIntent.send() will perform nothing. To use current url as polyfill to fix it. MozReview-Commit-ID: IIP7hGd1cBH
mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko.customtabs;
 import android.app.PendingIntent;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.annotation.NonNull;
 import android.support.annotation.VisibleForTesting;
 import android.support.v4.view.MenuItemCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.widget.Toolbar;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -265,17 +266,25 @@ public class CustomTabsActivity extends 
 
         final Window window = getWindow();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
             window.setStatusBarColor(ColorUtil.darken(toolbarColor, 0.25));
         }
     }
 
+    private void performPendingIntent(@NonNull PendingIntent pendingIntent) {
+        // bug 1337771: If intent-creator haven't set data url, call send() directly won't work.
+        final Intent additional = new Intent();
+        final Tab tab = Tabs.getInstance().getSelectedTab();
+        additional.setData(Uri.parse(tab.getURL()));
+        try {
+            pendingIntent.send(this, 0, additional);
+        } catch (PendingIntent.CanceledException e) {
+            Log.w(LOGTAG, "Performing a canceled pending intent", e);
+        }
+    }
+
     private void onActionButtonClicked() {
         PendingIntent pendingIntent = IntentUtil.getActionButtonPendingIntent(getIntent());
-        try {
-            pendingIntent.send();
-        } catch (PendingIntent.CanceledException e) {
-            Log.w(LOGTAG, "Action Button clicked, but pending intent was canceled", e);
-        }
+        performPendingIntent(pendingIntent);
     }
 }