Skip to content

Commit 3ecbd98

Browse files
committed
chore(auth): Improve native Android logs (#3469)
1 parent bc772e6 commit 3ecbd98

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import android.content.pm.PackageManager.PackageInfoFlags
1313
import android.net.Uri
1414
import android.os.Build
1515
import android.provider.Settings
16-
import android.view.WindowManager
17-
import androidx.annotation.RequiresApi
1816
import androidx.browser.customtabs.CustomTabsIntent
1917
import androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION
2018
import io.flutter.Log
@@ -112,6 +110,7 @@ open class AmplifyAuthCognitoPlugin :
112110
}
113111

114112
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
113+
Log.d(TAG, "onAttachedToEngine")
115114
applicationContext = binding.applicationContext
116115
nativePlugin = NativeAuthPlugin(binding.binaryMessenger)
117116
NativeAuthBridge.setUp(
@@ -121,6 +120,7 @@ open class AmplifyAuthCognitoPlugin :
121120
}
122121

123122
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
123+
Log.d(TAG, "onDetachedFromEngine")
124124
applicationContext = null
125125
cancelCurrentOperation()
126126
nativePlugin = null
@@ -131,6 +131,7 @@ open class AmplifyAuthCognitoPlugin :
131131
}
132132

133133
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
134+
Log.d(TAG, "onAttachedToActivity")
134135
mainActivity = binding.activity
135136
activityBinding = binding
136137
// Treat the launching intent the same as an intent created while the application was
@@ -141,20 +142,23 @@ open class AmplifyAuthCognitoPlugin :
141142
}
142143

143144
override fun onDetachedFromActivityForConfigChanges() {
145+
Log.d(TAG, "onDetachedFromActivityForConfigChanges")
144146
activityBinding?.removeActivityResultListener(this)
145147
activityBinding?.removeOnNewIntentListener(this)
146148
activityBinding = null
147149
mainActivity = null
148150
}
149151

150152
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
153+
Log.d(TAG, "onReattachedToActivityForConfigChanges")
151154
mainActivity = binding.activity
152155
activityBinding = binding
153156
binding.addOnNewIntentListener(this)
154157
binding.addActivityResultListener(this)
155158
}
156159

157160
override fun onDetachedFromActivity() {
161+
Log.d(TAG, "onDetachedFromActivity")
158162
activityBinding?.removeActivityResultListener(this)
159163
activityBinding?.removeOnNewIntentListener(this)
160164
activityBinding = null
@@ -287,6 +291,7 @@ open class AmplifyAuthCognitoPlugin :
287291
* Handles the result of a sign in redirect.
288292
*/
289293
private fun handleSignInResult(queryParameters: MutableMap<String, String>): Boolean {
294+
Log.d(TAG, "handleSignInResult: $queryParameters (signInResult=$signInResult)")
290295
signInResult?.invoke(Result.success(queryParameters))
291296
signInResult = null
292297
return true
@@ -296,6 +301,7 @@ open class AmplifyAuthCognitoPlugin :
296301
* Handles the result of a sign out redirect.
297302
*/
298303
private fun handleSignOutResult(): Boolean {
304+
Log.d(TAG, "handleSignOutResult (signOutResult=$signOutResult)")
299305
signOutResult?.invoke(Result.success(Unit))
300306
signOutResult = null
301307
return true
@@ -317,10 +323,12 @@ open class AmplifyAuthCognitoPlugin :
317323
activityIntent,
318324
MATCH_DEFAULT_ONLY
319325
)
326+
Log.d(TAG, "[browserPackageName] Resolved activity info: $defaultViewHandlerInfo")
320327
var defaultViewHandlerPackageName: String? = null
321328
if (defaultViewHandlerInfo != null) {
322329
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName
323330
}
331+
Log.d(TAG, "[browserPackageName] Resolved default package: $defaultViewHandlerPackageName")
324332

325333
// Get all apps that can handle VIEW intents.
326334
val resolvedActivityList = packageManager.queryIntentActivities(activityIntent, MATCH_ALL)
@@ -334,6 +342,7 @@ open class AmplifyAuthCognitoPlugin :
334342
packagesSupportingCustomTabs.add(info.activityInfo.packageName)
335343
}
336344
}
345+
Log.d(TAG, "[browserPackageName] Resolved custom tabs handlers: $packagesSupportingCustomTabs")
337346

338347
if (packagesSupportingCustomTabs.isEmpty()) {
339348
null
@@ -360,6 +369,7 @@ open class AmplifyAuthCognitoPlugin :
360369
val useBrowserPackage = browserPackageName
361370
?: this.browserPackageName
362371
?: throw HostedUiException.NOBROWSER()
372+
Log.d(TAG, "[launchUrl] Using browser package: $useBrowserPackage")
363373
intent.intent.`package` = useBrowserPackage
364374
intent.intent.putExtra(
365375
Intent.EXTRA_REFERRER,
@@ -429,14 +439,15 @@ open class AmplifyAuthCognitoPlugin :
429439
* on the final redirect to the user's custom URI.
430440
*/
431441
override fun onNewIntent(intent: Intent): Boolean {
432-
Log.d(TAG, "onNewIntent: $intent")
442+
Log.d(TAG, "[onNewIntent] Got intent: $intent")
433443
if (intent.action == Intent.ACTION_VIEW && intent.hasCategory(Intent.CATEGORY_BROWSABLE)) {
434444
val uri = intent.data
435445
if (uri == null) {
436446
Log.e(TAG, "No data associated with intent")
437447
return false
438448
}
439449
val queryParameters = uri.queryParameters
450+
Log.d(TAG, "[onNewIntent] Handling intent with query parameters: $queryParameters (signInResult=$signInResult, signOutResult=$signOutResult)")
440451
return if (signInResult != null && signOutResult != null) {
441452
Log.e(TAG, "Inconsistent state. Pending sign in and sign out.")
442453
false
@@ -451,6 +462,7 @@ open class AmplifyAuthCognitoPlugin :
451462
true
452463
}
453464
}
465+
Log.d(TAG, "[onNewIntent] Not handling intent")
454466
return false
455467
}
456468

@@ -463,7 +475,7 @@ open class AmplifyAuthCognitoPlugin :
463475
* is a cancellation since otherwise, [handleSignInResult] would have set it to `null`.
464476
*/
465477
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")
467479
if (requestCode == CUSTOM_TAB_REQUEST_CODE) {
468480
scope.launch {
469481
delay(1000L)
@@ -480,7 +492,7 @@ open class AmplifyAuthCognitoPlugin :
480492
* Cancels the pending operation, if any.
481493
*/
482494
private fun cancelCurrentOperation() {
483-
Log.d(TAG, "cancelCurrentOperation")
495+
Log.d(TAG, "[cancelCurrentOperation] Canceling with state: signInResult=$signInResult, signOutResult=$signOutResult")
484496
if (signInResult != null) {
485497
signInResult?.invoke(Result.failure(HostedUiException.CANCELLED()))
486498
} else if (signOutResult != null) {

0 commit comments

Comments
 (0)