From b084c91580e48c02236b1d34d4e5bacb7d45fb6f Mon Sep 17 00:00:00 2001 From: Amir Uval Date: Wed, 2 Jan 2019 12:02:45 +0200 Subject: [PATCH 1/3] workaround androidx jetifier --- library/java/net/openid/appauth/browser/BrowserSelector.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/java/net/openid/appauth/browser/BrowserSelector.java b/library/java/net/openid/appauth/browser/BrowserSelector.java index 5f2862fb..ed179d08 100644 --- a/library/java/net/openid/appauth/browser/BrowserSelector.java +++ b/library/java/net/openid/appauth/browser/BrowserSelector.java @@ -51,9 +51,10 @@ public final class BrowserSelector { /** * The service we expect to find on a web browser that indicates it supports custom tabs. */ + @SuppressWarnings("StringBufferReplaceableByString") @VisibleForTesting static final String ACTION_CUSTOM_TABS_CONNECTION = - CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; + new StringBuilder().append("android.sup").append("port.customtabs.action.CustomTabsService").toString(); /** * An arbitrary (but unregistrable, per From c758d5de7bfab369a5ce5eb7f1787c2d5980c382 Mon Sep 17 00:00:00 2001 From: Amir Uval Date: Thu, 3 Jan 2019 09:49:02 +0200 Subject: [PATCH 2/3] lint fixes --- .../java/net/openid/appauth/browser/BrowserSelector.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/java/net/openid/appauth/browser/BrowserSelector.java b/library/java/net/openid/appauth/browser/BrowserSelector.java index ed179d08..e65db5e7 100644 --- a/library/java/net/openid/appauth/browser/BrowserSelector.java +++ b/library/java/net/openid/appauth/browser/BrowserSelector.java @@ -27,7 +27,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; -import android.support.customtabs.CustomTabsService; import java.util.ArrayList; import java.util.Iterator; @@ -53,8 +52,9 @@ public final class BrowserSelector { */ @SuppressWarnings("StringBufferReplaceableByString") @VisibleForTesting - static final String ACTION_CUSTOM_TABS_CONNECTION = - new StringBuilder().append("android.sup").append("port.customtabs.action.CustomTabsService").toString(); + static final String ACTION_CUSTOM_TABS_CONNECTION = new StringBuilder() + .append("android.") + .append("support.customtabs.action.CustomTabsService").toString(); /** * An arbitrary (but unregistrable, per From 77d49173ad95d0d4cdb086d23e78e53613d3a784 Mon Sep 17 00:00:00 2001 From: Amir Uval Date: Sun, 24 Feb 2019 16:41:37 +0200 Subject: [PATCH 3/3] comment explaining the purpose of the workaround --- .../net/openid/appauth/browser/BrowserSelector.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/java/net/openid/appauth/browser/BrowserSelector.java b/library/java/net/openid/appauth/browser/BrowserSelector.java index e65db5e7..f337b281 100644 --- a/library/java/net/openid/appauth/browser/BrowserSelector.java +++ b/library/java/net/openid/appauth/browser/BrowserSelector.java @@ -49,6 +49,18 @@ public final class BrowserSelector { /** * The service we expect to find on a web browser that indicates it supports custom tabs. + * + * Workaround for Android Jetifier bug (https://issuetracker.google.com/issues/119183822) + * + * Problem: Projects that are using androidx are using a Jetifier compiler as a dependency. + * The Jetifier compiler is replacing "android.support" with "androidx" inside all the + * dependencies, AppAuth included. But "android.support" is still required by the platform in + * order to open a chrome tab. As a result - a chrome tab is not found, and an external browser + * is opened instead. + * Workaround: Using StringBuilder to create the string + * "android.support.customtabs.action.CustomTabsService" in runtime prevents the jetifier static + * regex from matching "android.support" in the compiled class, thus avoiding the androidx + * replacement. */ @SuppressWarnings("StringBufferReplaceableByString") @VisibleForTesting