From ecbfeea93b7d59987282095725dc48704d8a8b61 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Tue, 23 Jan 2024 10:24:39 +1300 Subject: [PATCH] fix: custom tabs dismiss callback triggered before redirect --- .gitignore | 2 ++ .../com/immutable/unity/ImmutableActivity.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1da78762..9c7e4ee0 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/**/*.meta # WebView.bundle src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/WebView.bundle/**/*.meta + +*.idea diff --git a/src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/src/main/java/com/immutable/unity/ImmutableActivity.java b/src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/src/main/java/com/immutable/unity/ImmutableActivity.java index 8982d200..1ef84eab 100644 --- a/src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/src/main/java/com/immutable/unity/ImmutableActivity.java +++ b/src/Packages/Passport/Runtime/Assets/ImmutableAndroid.androidlib/src/main/java/com/immutable/unity/ImmutableActivity.java @@ -6,6 +6,8 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -95,7 +97,17 @@ private void launchCustomTabs() { @Override public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) { if (navigationEvent == CustomTabsCallback.TAB_HIDDEN && callbackInstance != null) { - callbackInstance.onCustomTabsDismissed(uri.toString()); + // Adding some delay before calling onCustomTabsDismissed as sometimes this gets called + // before the PKCE deeplink is triggered (by 100ms). This means pkceCompletionSource will be + // set to null before the SDK can use it to notify the consumer of the PKCE result. + // See PassportImpl.OnLoginPKCEDismissed and PassportImpl.OnDeepLinkActivated + final Handler handler = new Handler(Looper.getMainLooper()); + handler.postDelayed(new Runnable() { + @Override + public void run() { + callbackInstance.onCustomTabsDismissed(uri.toString()); + } + }, 1000); } } });