summaryrefslogtreecommitdiffstats
path: root/customtabs
diff options
context:
space:
mode:
authorYusuf Ozuysal <yusufo@google.com>2015-08-24 22:20:29 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-24 22:20:29 +0000
commit9e7466f6a2897f03d4bdabba67d589bd44c6b2ee (patch)
tree50dae92443fc2b141632a56ae4d584c443feb80d /customtabs
parentadf67683ff1724100b862a95bb5a2a0dc705276a (diff)
parentccf4675e0c12bb4765222529341ce2ab479e50ba (diff)
downloadandroid_frameworks_support-9e7466f6a2897f03d4bdabba67d589bd44c6b2ee.tar.gz
android_frameworks_support-9e7466f6a2897f03d4bdabba67d589bd44c6b2ee.tar.bz2
android_frameworks_support-9e7466f6a2897f03d4bdabba67d589bd44c6b2ee.zip
am ccf4675e: am d5cb7b5a: am 914c8c87: Merge "Revert "Add a way of generating a CustomTabsSessionToken from an intent"" into mnc-dev
* commit 'ccf4675e0c12bb4765222529341ce2ab479e50ba': Revert "Add a way of generating a CustomTabsSessionToken from an intent"
Diffstat (limited to 'customtabs')
-rw-r--r--customtabs/Android.mk3
-rw-r--r--customtabs/api/current.txt1
-rw-r--r--customtabs/build.gradle1
-rw-r--r--customtabs/src/android/support/customtabs/CustomTabsIntent.java37
-rw-r--r--customtabs/src/android/support/customtabs/CustomTabsService.java2
-rw-r--r--customtabs/src/android/support/customtabs/CustomTabsSessionToken.java17
6 files changed, 36 insertions, 25 deletions
diff --git a/customtabs/Android.mk b/customtabs/Android.mk
index 4b68227eca..be4cc43e44 100644
--- a/customtabs/Android.mk
+++ b/customtabs/Android.mk
@@ -24,8 +24,7 @@ LOCAL_SDK_VERSION := current
LOCAL_AIDL_INCLUDES := $LOCAL_PATH/src
LOCAL_SRC_FILES := $(call all-java-files-under, src) \
$(call all-Iaidl-files-under, src)
-LOCAL_JAVA_LIBRARIES := android-support-annotations \
-android-support-v4
+LOCAL_JAVA_LIBRARIES := android-support-annotations
include $(BUILD_STATIC_JAVA_LIBRARY)
# API Check
diff --git a/customtabs/api/current.txt b/customtabs/api/current.txt
index 73431634e5..9f67246c2c 100644
--- a/customtabs/api/current.txt
+++ b/customtabs/api/current.txt
@@ -79,7 +79,6 @@ package android.support.customtabs {
public class CustomTabsSessionToken {
method public android.support.customtabs.CustomTabsCallback getCallback();
- method public static android.support.customtabs.CustomTabsSessionToken getSessionTokenFromIntent(android.content.Intent);
}
}
diff --git a/customtabs/build.gradle b/customtabs/build.gradle
index 317dd9dab7..66e77b612c 100644
--- a/customtabs/build.gradle
+++ b/customtabs/build.gradle
@@ -3,7 +3,6 @@ apply plugin: 'android-library'
archivesBaseName = 'customtabs'
dependencies {
- compile project(':support-v4')
compile project(':support-annotations')
}
diff --git a/customtabs/src/android/support/customtabs/CustomTabsIntent.java b/customtabs/src/android/support/customtabs/CustomTabsIntent.java
index ab3685f8b2..9a8573869a 100644
--- a/customtabs/src/android/support/customtabs/CustomTabsIntent.java
+++ b/customtabs/src/android/support/customtabs/CustomTabsIntent.java
@@ -24,13 +24,16 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
+import android.os.IBinder;
import android.support.annotation.AnimRes;
-import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
+import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
-import android.support.v4.app.BundleCompat;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
/**
@@ -199,8 +202,7 @@ public final class CustomTabsIntent {
public Builder(@Nullable CustomTabsSession session) {
if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
Bundle bundle = new Bundle();
- BundleCompat.putBinder(
- bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
+ safePutBinder(bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
mIntent.putExtras(bundle);
}
@@ -325,5 +327,32 @@ public final class CustomTabsIntent {
}
return new CustomTabsIntent(mIntent, mStartAnimationBundle);
}
+
+ /**
+ * A convenience method to handle putting an {@link IBinder} inside a {@link Bundle} for all
+ * Android version.
+ * @param bundle The bundle to insert the {@link IBinder}.
+ * @param key The key to use while putting the {@link IBinder}.
+ * @param binder The {@link IBinder} to put.
+ * @return Whether the operation was successful.
+ */
+ private boolean safePutBinder(Bundle bundle, String key, IBinder binder) {
+ try {
+ // {@link Bundle#putBinder} exists since JB MR2, but we have
+ // {@link Bundle#putIBinder} which is the same method since the dawn of time. Use
+ // reflection when necessary to call it.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ bundle.putBinder(key, binder);
+ } else {
+ Method putBinderMethod =
+ Bundle.class.getMethod("putIBinder", String.class, IBinder.class);
+ putBinderMethod.invoke(bundle, key, binder);
+ }
+ } catch (InvocationTargetException | IllegalAccessException
+ | IllegalArgumentException | NoSuchMethodException e) {
+ return false;
+ }
+ return true;
+ }
}
}
diff --git a/customtabs/src/android/support/customtabs/CustomTabsService.java b/customtabs/src/android/support/customtabs/CustomTabsService.java
index 56940e2335..f0e7ea7d4d 100644
--- a/customtabs/src/android/support/customtabs/CustomTabsService.java
+++ b/customtabs/src/android/support/customtabs/CustomTabsService.java
@@ -23,7 +23,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.RemoteException;
-import android.support.v4.util.ArrayMap;
+import android.util.ArrayMap;
import java.util.List;
import java.util.Map;
diff --git a/customtabs/src/android/support/customtabs/CustomTabsSessionToken.java b/customtabs/src/android/support/customtabs/CustomTabsSessionToken.java
index 189d6fa421..479d1d9c7c 100644
--- a/customtabs/src/android/support/customtabs/CustomTabsSessionToken.java
+++ b/customtabs/src/android/support/customtabs/CustomTabsSessionToken.java
@@ -16,11 +16,10 @@
package android.support.customtabs;
-import android.content.Intent;
+import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
-import android.support.v4.app.BundleCompat;
import android.util.Log;
/**
@@ -32,20 +31,6 @@ public class CustomTabsSessionToken {
private final ICustomTabsCallback mCallbackBinder;
private final CustomTabsCallback mCallback;
- /**
- * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
- * for ways to generate an intent for custom tabs.
- * @param intent The intent to generate the token from. This has to include an extra for
- * {@link CustomTabsIntent#EXTRA_SESSION}.
- * @return The token that was generated.
- */
- public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
- Bundle b = intent.getExtras();
- IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
- if (binder == null) return null;
- return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder));
- }
-
/**@hide*/
CustomTabsSessionToken(ICustomTabsCallback callbackBinder) {
mCallbackBinder = callbackBinder;