Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java

Issue 1224553003: customtabs: Convert to the new AIDL interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't prerender when we should not. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
index ae7f1182eb2fa21ca09529ce71cad562532e1398..7489a824afe02a16a8166d27f3c01ebc438fca11 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
@@ -8,11 +8,14 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
+import android.os.Build;
import android.os.Bundle;
+import android.os.IBinder;
import android.os.Parcelable;
import org.chromium.base.Log;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -167,4 +170,30 @@ public class IntentUtils {
return null;
}
}
+
+ /**
+ * @return a Binder from an Intent, or null.
+ *
+ * Creates a temporary copy of the extra Bundle, which is required as
+ * Intent#getBinderExtra() doesn't exist, but Bundle.getBinder() does.
+ */
+ public static IBinder safeGetBinderExtra(Intent intent, String name) {
+ if (!intent.hasExtra(name)) return null;
+ try {
+ Bundle extras = intent.getExtras();
+ // Bundle#getBinder() is public starting at API level 18, but exists
+ // in previous SDKs as a hidden method named "getIBinder" (which
+ // still exists as of L MR1 but is hidden and deprecated).
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ return extras.getBinder(name);
+ } else {
+ Method getBinderMethod = Bundle.class.getMethod("getIBinder", String.class);
+ return (IBinder) getBinderMethod.invoke(extras, name);
+ }
+ } catch (Throwable t) {
+ // Catches un-parceling exceptions.
+ Log.e(TAG, "getBinder failed on intent " + intent);
+ return null;
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698