6
6
import android .net .Uri ;
7
7
import android .os .Build ;
8
8
import android .os .Bundle ;
9
- import android .os .Handler ;
10
- import android .os .Looper ;
11
9
12
10
import androidx .annotation .NonNull ;
13
11
import androidx .annotation .Nullable ;
@@ -61,6 +59,16 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
61
59
@ Override
62
60
protected void onResume () {
63
61
super .onResume ();
62
+ Uri uri = getUri ();
63
+ // Determine whether user returned to this activity from a redirect or because the user cancelled
64
+ // the auth flow. If there is no response data (from RedirectActivity), it's because the
65
+ // user dismissed custom tabs, pressed the back button, or the auth flow finished without invoking
66
+ // RedirectActivity.
67
+ if (customTabsLaunched && uri != null && getIntent ().getData () == null && callbackInstance != null ) {
68
+ // User cancelled auth flow
69
+ callbackInstance .onCustomTabsDismissed (uri .toString ());
70
+ }
71
+
64
72
Intent authenticationIntent = getIntent ();
65
73
if (!customTabsLaunched && authenticationIntent .getExtras () == null ) {
66
74
// This activity was launched in an unexpected way
@@ -85,34 +93,29 @@ protected void onDestroy() {
85
93
}
86
94
}
87
95
88
- private void launchCustomTabs () {
96
+ @ Nullable
97
+ private Uri getUri () {
89
98
Bundle extras = getIntent ().getExtras ();
90
- Uri uri ;
91
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
92
- uri = extras .getParcelable (EXTRA_URI , Uri .class );
99
+ if (extras != null ) {
100
+ Uri uri ;
101
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
102
+ uri = extras .getParcelable (EXTRA_URI , Uri .class );
103
+ } else {
104
+ uri = extras .getParcelable (EXTRA_URI );
105
+ }
106
+ return uri ;
93
107
} else {
94
- uri = extras .getParcelable (EXTRA_URI );
108
+ return null ;
109
+ }
110
+ }
111
+
112
+ private void launchCustomTabs () {
113
+ Uri uri = getUri ();
114
+ if (uri != null ) {
115
+ customTabsController = new CustomTabsController (this , new CustomTabsCallback ());
116
+ customTabsController .bindService ();
117
+ customTabsController .launch (uri );
95
118
}
96
- customTabsController = new CustomTabsController (this , new CustomTabsCallback () {
97
- @ Override
98
- public void onNavigationEvent (int navigationEvent , @ Nullable Bundle extras ) {
99
- if (navigationEvent == CustomTabsCallback .TAB_HIDDEN && callbackInstance != null ) {
100
- // Adding some delay before calling onCustomTabsDismissed as sometimes this gets called
101
- // before the PKCE deeplink is triggered (by 100ms). This means pkceCompletionSource will be
102
- // set to null before the SDK can use it to notify the consumer of the PKCE result.
103
- // See PassportImpl.OnLoginPKCEDismissed and PassportImpl.OnDeepLinkActivated
104
- final Handler handler = new Handler (Looper .getMainLooper ());
105
- handler .postDelayed (new Runnable () {
106
- @ Override
107
- public void run () {
108
- callbackInstance .onCustomTabsDismissed (uri .toString ());
109
- }
110
- }, 1000 );
111
- }
112
- }
113
- });
114
- customTabsController .bindService ();
115
- customTabsController .launch (uri );
116
119
}
117
120
118
121
private void onDeeplinkResult (@ Nullable Intent intent ) {
0 commit comments