@@ -13,8 +13,6 @@ import android.content.pm.PackageManager.PackageInfoFlags
13
13
import android.net.Uri
14
14
import android.os.Build
15
15
import android.provider.Settings
16
- import android.view.WindowManager
17
- import androidx.annotation.RequiresApi
18
16
import androidx.browser.customtabs.CustomTabsIntent
19
17
import androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION
20
18
import io.flutter.Log
@@ -112,6 +110,7 @@ open class AmplifyAuthCognitoPlugin :
112
110
}
113
111
114
112
override fun onAttachedToEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
113
+ Log .d(TAG , " onAttachedToEngine" )
115
114
applicationContext = binding.applicationContext
116
115
nativePlugin = NativeAuthPlugin (binding.binaryMessenger)
117
116
NativeAuthBridge .setUp(
@@ -121,6 +120,7 @@ open class AmplifyAuthCognitoPlugin :
121
120
}
122
121
123
122
override fun onDetachedFromEngine (binding : FlutterPlugin .FlutterPluginBinding ) {
123
+ Log .d(TAG , " onDetachedFromEngine" )
124
124
applicationContext = null
125
125
cancelCurrentOperation()
126
126
nativePlugin = null
@@ -131,6 +131,7 @@ open class AmplifyAuthCognitoPlugin :
131
131
}
132
132
133
133
override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
134
+ Log .d(TAG , " onAttachedToActivity" )
134
135
mainActivity = binding.activity
135
136
activityBinding = binding
136
137
// Treat the launching intent the same as an intent created while the application was
@@ -141,20 +142,23 @@ open class AmplifyAuthCognitoPlugin :
141
142
}
142
143
143
144
override fun onDetachedFromActivityForConfigChanges () {
145
+ Log .d(TAG , " onDetachedFromActivityForConfigChanges" )
144
146
activityBinding?.removeActivityResultListener(this )
145
147
activityBinding?.removeOnNewIntentListener(this )
146
148
activityBinding = null
147
149
mainActivity = null
148
150
}
149
151
150
152
override fun onReattachedToActivityForConfigChanges (binding : ActivityPluginBinding ) {
153
+ Log .d(TAG , " onReattachedToActivityForConfigChanges" )
151
154
mainActivity = binding.activity
152
155
activityBinding = binding
153
156
binding.addOnNewIntentListener(this )
154
157
binding.addActivityResultListener(this )
155
158
}
156
159
157
160
override fun onDetachedFromActivity () {
161
+ Log .d(TAG , " onDetachedFromActivity" )
158
162
activityBinding?.removeActivityResultListener(this )
159
163
activityBinding?.removeOnNewIntentListener(this )
160
164
activityBinding = null
@@ -287,6 +291,7 @@ open class AmplifyAuthCognitoPlugin :
287
291
* Handles the result of a sign in redirect.
288
292
*/
289
293
private fun handleSignInResult (queryParameters : MutableMap <String , String >): Boolean {
294
+ Log .d(TAG , " handleSignInResult: $queryParameters (signInResult=$signInResult )" )
290
295
signInResult?.invoke(Result .success(queryParameters))
291
296
signInResult = null
292
297
return true
@@ -296,6 +301,7 @@ open class AmplifyAuthCognitoPlugin :
296
301
* Handles the result of a sign out redirect.
297
302
*/
298
303
private fun handleSignOutResult (): Boolean {
304
+ Log .d(TAG , " handleSignOutResult (signOutResult=$signOutResult )" )
299
305
signOutResult?.invoke(Result .success(Unit ))
300
306
signOutResult = null
301
307
return true
@@ -317,10 +323,12 @@ open class AmplifyAuthCognitoPlugin :
317
323
activityIntent,
318
324
MATCH_DEFAULT_ONLY
319
325
)
326
+ Log .d(TAG , " [browserPackageName] Resolved activity info: $defaultViewHandlerInfo " )
320
327
var defaultViewHandlerPackageName: String? = null
321
328
if (defaultViewHandlerInfo != null ) {
322
329
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName
323
330
}
331
+ Log .d(TAG , " [browserPackageName] Resolved default package: $defaultViewHandlerPackageName " )
324
332
325
333
// Get all apps that can handle VIEW intents.
326
334
val resolvedActivityList = packageManager.queryIntentActivities(activityIntent, MATCH_ALL )
@@ -334,6 +342,7 @@ open class AmplifyAuthCognitoPlugin :
334
342
packagesSupportingCustomTabs.add(info.activityInfo.packageName)
335
343
}
336
344
}
345
+ Log .d(TAG , " [browserPackageName] Resolved custom tabs handlers: $packagesSupportingCustomTabs " )
337
346
338
347
if (packagesSupportingCustomTabs.isEmpty()) {
339
348
null
@@ -360,6 +369,7 @@ open class AmplifyAuthCognitoPlugin :
360
369
val useBrowserPackage = browserPackageName
361
370
? : this .browserPackageName
362
371
? : throw HostedUiException .NOBROWSER ()
372
+ Log .d(TAG , " [launchUrl] Using browser package: $useBrowserPackage " )
363
373
intent.intent.`package` = useBrowserPackage
364
374
intent.intent.putExtra(
365
375
Intent .EXTRA_REFERRER ,
@@ -429,14 +439,15 @@ open class AmplifyAuthCognitoPlugin :
429
439
* on the final redirect to the user's custom URI.
430
440
*/
431
441
override fun onNewIntent (intent : Intent ): Boolean {
432
- Log .d(TAG , " onNewIntent: $intent " )
442
+ Log .d(TAG , " [ onNewIntent] Got intent : $intent " )
433
443
if (intent.action == Intent .ACTION_VIEW && intent.hasCategory(Intent .CATEGORY_BROWSABLE )) {
434
444
val uri = intent.data
435
445
if (uri == null ) {
436
446
Log .e(TAG , " No data associated with intent" )
437
447
return false
438
448
}
439
449
val queryParameters = uri.queryParameters
450
+ Log .d(TAG , " [onNewIntent] Handling intent with query parameters: $queryParameters (signInResult=$signInResult , signOutResult=$signOutResult )" )
440
451
return if (signInResult != null && signOutResult != null ) {
441
452
Log .e(TAG , " Inconsistent state. Pending sign in and sign out." )
442
453
false
@@ -451,6 +462,7 @@ open class AmplifyAuthCognitoPlugin :
451
462
true
452
463
}
453
464
}
465
+ Log .d(TAG , " [onNewIntent] Not handling intent" )
454
466
return false
455
467
}
456
468
@@ -463,7 +475,7 @@ open class AmplifyAuthCognitoPlugin :
463
475
* is a cancellation since otherwise, [handleSignInResult] would have set it to `null`.
464
476
*/
465
477
override fun onActivityResult (requestCode : Int , resultCode : Int , intent : Intent ? ): Boolean {
466
- Log .d(TAG , " onActivityResult: $requestCode , $resultCode " )
478
+ Log .d(TAG , " [ onActivityResult] Got result: requestCode= $requestCode , resultCode= $resultCode , intent= $intent " )
467
479
if (requestCode == CUSTOM_TAB_REQUEST_CODE ) {
468
480
scope.launch {
469
481
delay(1000L )
@@ -480,7 +492,7 @@ open class AmplifyAuthCognitoPlugin :
480
492
* Cancels the pending operation, if any.
481
493
*/
482
494
private fun cancelCurrentOperation () {
483
- Log .d(TAG , " cancelCurrentOperation" )
495
+ Log .d(TAG , " [ cancelCurrentOperation] Canceling with state: signInResult= $signInResult , signOutResult= $signOutResult " )
484
496
if (signInResult != null ) {
485
497
signInResult?.invoke(Result .failure(HostedUiException .CANCELLED ()))
486
498
} else if (signOutResult != null ) {
0 commit comments