From 77b5f6dad2569919e01ab824709f02e2eacf8d02 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Thu, 15 Dec 2022 14:09:02 -0600 Subject: [PATCH 1/4] Fix for when loading credentials the success/error is fired twice --- .../auth/cognito/CredentialStoreClient.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt index f44d415462..c7fe7863c5 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt @@ -56,9 +56,9 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context: ) { var capturedSuccess: Result? = null var capturedError: Exception? = null - val token = StateChangeListenerToken() + var token: StateChangeListenerToken? = StateChangeListenerToken() credentialStoreStateMachine.listen( - token, + token as StateChangeListenerToken, { storeState -> logger.verbose("Credential Store State Change: $storeState") @@ -72,11 +72,12 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context: is CredentialStoreState.Idle -> { val success = capturedSuccess val error = capturedError - if (success != null) { - credentialStoreStateMachine.cancel(token) + if (success != null && token != null) { + credentialStoreStateMachine.cancel(token as StateChangeListenerToken) + token = null onSuccess(success) - } else if (error != null) { - credentialStoreStateMachine.cancel(token) + } else if (error != null && token != null) { + credentialStoreStateMachine.cancel(token as StateChangeListenerToken) onError(error) } } From 780b16bd3686924e4065f196cb727702affa8fe7 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Fri, 16 Dec 2022 10:23:51 -0600 Subject: [PATCH 2/4] Addressed comments: --- .../amplifyframework/auth/cognito/CredentialStoreClient.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt index c7fe7863c5..1354dead92 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/CredentialStoreClient.kt @@ -61,7 +61,6 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context: token as StateChangeListenerToken, { storeState -> logger.verbose("Credential Store State Change: $storeState") - when (storeState) { is CredentialStoreState.Success -> { capturedSuccess = Result.success(storeState.storedCredentials) @@ -73,11 +72,12 @@ internal class CredentialStoreClient(configuration: AuthConfiguration, context: val success = capturedSuccess val error = capturedError if (success != null && token != null) { - credentialStoreStateMachine.cancel(token as StateChangeListenerToken) + credentialStoreStateMachine.cancel(token!!) token = null onSuccess(success) } else if (error != null && token != null) { - credentialStoreStateMachine.cancel(token as StateChangeListenerToken) + credentialStoreStateMachine.cancel(token!!) + token = null onError(error) } } From 93d999551bc11714a04bb6a036bef0f633ac2693 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Tue, 20 Dec 2022 15:28:55 -0600 Subject: [PATCH 3/4] Reverting changes to synchronous auth and adding logging --- .../pinpoint/PinpointAnalyticsInstrumentationTest.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index a7f89824e1..bfb2957c98 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -34,18 +34,20 @@ import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin import com.amplifyframework.core.Amplify import com.amplifyframework.hub.HubChannel import com.amplifyframework.hub.HubEvent +import com.amplifyframework.logging.AndroidLoggingPlugin +import com.amplifyframework.logging.LogLevel import com.amplifyframework.testutils.HubAccumulator import com.amplifyframework.testutils.Resources import com.amplifyframework.testutils.Sleep import com.amplifyframework.testutils.sync.SynchronousAuth -import java.util.UUID -import java.util.concurrent.TimeUnit import kotlinx.coroutines.runBlocking import org.json.JSONException import org.junit.Assert import org.junit.Before import org.junit.BeforeClass import org.junit.Test +import java.util.UUID +import java.util.concurrent.TimeUnit class PinpointAnalyticsInstrumentationTest { @Before @@ -388,9 +390,11 @@ class PinpointAnalyticsInstrumentationTest { setUniqueId() Amplify.Auth.addPlugin(AWSCognitoAuthPlugin() as AuthPlugin<*>) Amplify.addPlugin(AWSPinpointAnalyticsPlugin()) + Amplify.Logging.addPlugin(AndroidLoggingPlugin(LogLevel.DEBUG)) Amplify.configure(context) Sleep.milliseconds(COGNITO_CONFIGURATION_TIMEOUT) synchronousAuth = SynchronousAuth.delegatingTo(Amplify.Auth) + } private fun setUniqueId() { From 5f9badf5aa6e768b42b8edf7ba367fec941c90b8 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Tue, 20 Dec 2022 15:31:40 -0600 Subject: [PATCH 4/4] lint fix --- .../pinpoint/PinpointAnalyticsInstrumentationTest.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt index bfb2957c98..6be6288414 100644 --- a/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt +++ b/aws-analytics-pinpoint/src/androidTest/java/com/amplifyframework/analytics/pinpoint/PinpointAnalyticsInstrumentationTest.kt @@ -40,14 +40,14 @@ import com.amplifyframework.testutils.HubAccumulator import com.amplifyframework.testutils.Resources import com.amplifyframework.testutils.Sleep import com.amplifyframework.testutils.sync.SynchronousAuth +import java.util.UUID +import java.util.concurrent.TimeUnit import kotlinx.coroutines.runBlocking import org.json.JSONException import org.junit.Assert import org.junit.Before import org.junit.BeforeClass import org.junit.Test -import java.util.UUID -import java.util.concurrent.TimeUnit class PinpointAnalyticsInstrumentationTest { @Before @@ -394,7 +394,6 @@ class PinpointAnalyticsInstrumentationTest { Amplify.configure(context) Sleep.milliseconds(COGNITO_CONFIGURATION_TIMEOUT) synchronousAuth = SynchronousAuth.delegatingTo(Amplify.Auth) - } private fun setUniqueId() {