diff --git a/Plugins/Android/ImmutableAndroid/ImmutableAndroid/src/main/java/com/immutable/unity/ImmutableActivity.java b/Plugins/Android/ImmutableAndroid/ImmutableAndroid/src/main/java/com/immutable/unity/ImmutableActivity.java index 1ef84eab..dcacfd60 100644 --- a/Plugins/Android/ImmutableAndroid/ImmutableAndroid/src/main/java/com/immutable/unity/ImmutableActivity.java +++ b/Plugins/Android/ImmutableAndroid/ImmutableAndroid/src/main/java/com/immutable/unity/ImmutableActivity.java @@ -6,8 +6,6 @@ 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; @@ -61,6 +59,16 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onResume() { super.onResume(); + Uri uri = getUri(); + // Determine whether user returned to this activity from a redirect or because the user cancelled + // the auth flow. If there is no response data (from RedirectActivity), it's because the + // user dismissed custom tabs, pressed the back button, or the auth flow finished without invoking + // RedirectActivity. + if (customTabsLaunched && uri != null && getIntent().getData() == null && callbackInstance != null) { + // User cancelled auth flow + callbackInstance.onCustomTabsDismissed(uri.toString()); + } + Intent authenticationIntent = getIntent(); if (!customTabsLaunched && authenticationIntent.getExtras() == null) { // This activity was launched in an unexpected way @@ -85,34 +93,29 @@ protected void onDestroy() { } } - private void launchCustomTabs() { + @Nullable + private Uri getUri() { Bundle extras = getIntent().getExtras(); - Uri uri; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - uri = extras.getParcelable(EXTRA_URI, Uri.class); + if (extras != null) { + Uri uri; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + uri = extras.getParcelable(EXTRA_URI, Uri.class); + } else { + uri = extras.getParcelable(EXTRA_URI); + } + return uri; } else { - uri = extras.getParcelable(EXTRA_URI); + return null; + } + } + + private void launchCustomTabs() { + Uri uri = getUri(); + if (uri != null) { + customTabsController = new CustomTabsController(this, new CustomTabsCallback()); + customTabsController.bindService(); + customTabsController.launch(uri); } - customTabsController = new CustomTabsController(this, new CustomTabsCallback() { - @Override - public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) { - if (navigationEvent == CustomTabsCallback.TAB_HIDDEN && callbackInstance != null) { - // 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); - } - } - }); - customTabsController.bindService(); - customTabsController.launch(uri); } private void onDeeplinkResult(@Nullable Intent intent) { diff --git a/src/Packages/Passport/Runtime/Assets/Plugins/Android/ImmutableAndroid.aar b/src/Packages/Passport/Runtime/Assets/Plugins/Android/ImmutableAndroid.aar index 4e3e1f1f..c2da52af 100644 Binary files a/src/Packages/Passport/Runtime/Assets/Plugins/Android/ImmutableAndroid.aar and b/src/Packages/Passport/Runtime/Assets/Plugins/Android/ImmutableAndroid.aar differ