| 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;
|
| + }
|
| + }
|
| }
|
|
|