🛃 Use older API when new one isn't needed. Providers relying on the older version of the Custom Tabs Service don't support newSessionWithExtras, therefore use newSession when possible. Change-Id: I4b1adcf20f6ecdc29d7b89bb8407373a48732cc9 Reviewed-on: https://chromium-review.googlesource.com/c/custom-tabs-client/+/1720773 Reviewed-by: Pavel Shmakov <pshmakov@chromium.org> Commit-Queue: Peter Conn <peconn@chromium.org>
diff --git a/customtabs/src/android/support/customtabs/CustomTabsClient.java b/customtabs/src/android/support/customtabs/CustomTabsClient.java index b8a780e..aad08c8 100644 --- a/customtabs/src/android/support/customtabs/CustomTabsClient.java +++ b/customtabs/src/android/support/customtabs/CustomTabsClient.java
@@ -231,10 +231,19 @@ private @Nullable CustomTabsSession newSessionInternal(final CustomTabsCallback callback, @Nullable PendingIntent sessionId) { ICustomTabsCallback.Stub wrapper = createCallbackWrapper(callback); - Bundle extras = new Bundle(); - if (sessionId != null) extras.putParcelable(CustomTabsIntent.EXTRA_SESSION_ID, sessionId); + try { - if (!mService.newSessionWithExtras(wrapper, extras)) return null; + boolean success; + + if (sessionId != null) { + Bundle extras = new Bundle(); + extras.putParcelable(CustomTabsIntent.EXTRA_SESSION_ID, sessionId); + success = mService.newSessionWithExtras(wrapper, extras); + } else { + success = mService.newSession(wrapper); + } + + if (!success) return null; } catch (RemoteException e) { return null; }