diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b69af890..ceb53178a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,14 @@ ### Features - **storage:** Add support for S3 acceleration mode ([#2304](https://github.com/aws-amplify/amplify-android/issues/2304)) - **aws-datastore:** Make the reachability component configurable ([#2307](https://github.com/aws-amplify/amplify-android/issues/2307)) +- **aws-api,aws-datastore:** WebSocket improvements ([#2283](https://github.com/aws-amplify/amplify-android/issues/2283)) ### Bug Fixes - **datastore:** Fix aliasing of column names ([#2312](https://github.com/aws-amplify/amplify-android/issues/2312)) +- **auth:** Delete user invalid state fixes ([#2326](https://github.com/aws-amplify/amplify-android/issues/2326)) + +### Miscellaneous +- Restore publishing sources jar ([#2329](https://github.com/aws-amplify/amplify-android/issues/2329)) [See all changes between 2.2.2 and 2.3.0](https://github.com/aws-amplify/amplify-android/compare/release_v2.2.2...release_v2.3.0) diff --git a/README.md b/README.md index fb8d14f167..f1b496f341 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Amplify for Android (Developer Preview) +## Amplify for Android AWS Amplify [![DiscordChat](https://img.shields.io/discord/308323056592486420?logo=discord)](https://discord.gg/jWVbPfC) diff --git a/annotations/.gitignore b/annotations/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/annotations/.gitignore @@ -0,0 +1 @@ +/build diff --git a/annotations/build.gradle.kts b/annotations/build.gradle.kts new file mode 100644 index 0000000000..0b85f37c56 --- /dev/null +++ b/annotations/build.gradle.kts @@ -0,0 +1,46 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +plugins { + id("com.android.library") + id("kotlin-android") +} + +apply(from = rootProject.file("configuration/checkstyle.gradle")) +apply(from = rootProject.file("configuration/publishing.gradle")) + +group = properties["POM_GROUP"].toString() + +android { + kotlinOptions { + moduleName = "com.amplifyframework.annotations" + } +} + +dependencies { + implementation(dependency.kotlin.stdlib) +} + +afterEvaluate { + // Disables this warning: + // warning: listOf(classfile) MethodParameters attribute + // introduced in version 52.0 class files is ignored in + // version 51.0 class files + // Root project has -Werror, so this warning + // would fail the build, otherwise. + tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:-classfile") + } +} diff --git a/annotations/gradle.properties b/annotations/gradle.properties new file mode 100644 index 0000000000..13ed609b9e --- /dev/null +++ b/annotations/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=annotations +POM_NAME=Amplify Framework for Android - Annotations +POM_DESCRIPTION=Amplify Framework for Android - Annotations for AWS Amplify Libraries +POM_PACKAGING=aar diff --git a/annotations/src/main/AndroidManifest.xml b/annotations/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..1f1387a5dc --- /dev/null +++ b/annotations/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt b/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt new file mode 100644 index 0000000000..63058ac08b --- /dev/null +++ b/annotations/src/main/java/com/amplifyframework/annotations/InternalApiWarning.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amplifyframework.annotations + +/** + * API marked with this annotation is internal to Amplify, and it is not intended to be used outside. + * It could be modified or removed without any notice. + * + * We strongly recommend to not use such API. + */ +@Suppress("DEPRECATION") +@RequiresOptIn( + level = RequiresOptIn.Level.WARNING, + message = "This API is internal to Amplify and should not be used. It could be removed or changed without notice.", +) +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.TYPEALIAS, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY, + AnnotationTarget.FIELD, + AnnotationTarget.CONSTRUCTOR, +) +public annotation class InternalApiWarning diff --git a/aws-analytics-pinpoint/build.gradle.kts b/aws-analytics-pinpoint/build.gradle.kts index 2f209e9f4a..db1438ac52 100644 --- a/aws-analytics-pinpoint/build.gradle.kts +++ b/aws-analytics-pinpoint/build.gradle.kts @@ -26,6 +26,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(project(":aws-pinpoint-core")) implementation(dependency.androidx.appcompat) diff --git a/aws-api-appsync/build.gradle.kts b/aws-api-appsync/build.gradle.kts index 093f53b53c..0a0da660e8 100644 --- a/aws-api-appsync/build.gradle.kts +++ b/aws-api-appsync/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.annotation) implementation(dependency.androidx.core) diff --git a/aws-api/build.gradle.kts b/aws-api/build.gradle.kts index e5a1da97d1..72799ee46e 100644 --- a/aws-api/build.gradle.kts +++ b/aws-api/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { api(project(":core")) + api(project(":aws-core")) implementation(project(":aws-api-appsync")) implementation(dependency.androidx.appcompat) diff --git a/aws-auth-cognito/build.gradle.kts b/aws-auth-cognito/build.gradle.kts index 0d4db7c918..c8a8d4cc73 100644 --- a/aws-auth-cognito/build.gradle.kts +++ b/aws-auth-cognito/build.gradle.kts @@ -26,6 +26,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.kotlin.coroutines) implementation(dependency.kotlin.serializationJson) implementation(dependency.androidx.appcompat) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt index 929179d318..1ffa276ee0 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPlugin.kt @@ -18,6 +18,7 @@ package com.amplifyframework.auth.cognito import android.app.Activity import android.content.Context import android.content.Intent +import androidx.annotation.RestrictTo import androidx.annotation.VisibleForTesting import com.amplifyframework.AmplifyException import com.amplifyframework.auth.AuthCodeDeliveryDetails @@ -91,6 +92,13 @@ class AWSCognitoAuthPlugin : AuthPlugin() { } } + private lateinit var pluginConfigurationJSON: JSONObject + + @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + fun getPluginConfiguration(): JSONObject { + return pluginConfigurationJSON + } + private fun Exception.toAuthException(): AuthException { return if (this is AuthException) { this @@ -105,6 +113,7 @@ class AWSCognitoAuthPlugin : AuthPlugin() { @Throws(AmplifyException::class) override fun configure(pluginConfiguration: JSONObject, context: Context) { + pluginConfigurationJSON = pluginConfiguration try { val configuration = AuthConfiguration.fromJson(pluginConfiguration) val credentialStoreClient = CredentialStoreClient(configuration, context, logger) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt index 85b03cce2e..0688a51fef 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/AWSCognitoAuthService.kt @@ -17,8 +17,8 @@ package com.amplifyframework.auth.cognito import aws.sdk.kotlin.services.cognitoidentity.CognitoIdentityClient import aws.sdk.kotlin.services.cognitoidentityprovider.CognitoIdentityProviderClient -import aws.sdk.kotlin.services.cognitoidentityprovider.endpoints.EndpointProvider import aws.smithy.kotlin.runtime.client.endpoints.Endpoint +import aws.smithy.kotlin.runtime.client.endpoints.EndpointProvider import com.amplifyframework.statemachine.codegen.data.AuthConfiguration interface AWSCognitoAuthService { diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt index bef2b979ba..c45ab2bfbb 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt @@ -833,7 +833,8 @@ internal class RealAWSCognitoAuthPlugin( when (val authNState = it.authNState) { is AuthenticationState.SigningOut -> { (authNState.signOutState as? SignOutState.SigningOutHostedUI)?.let { signOutState -> - if (callbackUri == null && signOutState.signedInData.signInMethod != + if (callbackUri == null && !signOutState.bypassCancel && + signOutState.signedInData.signInMethod != SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.UNKNOWN) ) { authStateMachine.send( @@ -1734,40 +1735,35 @@ internal class RealAWSCognitoAuthPlugin( private fun _deleteUser(token: String, onSuccess: Action, onError: Consumer) { val listenerToken = StateChangeListenerToken() + var deleteUserException: Exception? = null authStateMachine.listen( listenerToken, { authState -> - when (val authNState = authState.authNState) { - is AuthenticationState.SignedOut -> { - val event = DeleteUserEvent(DeleteUserEvent.EventType.SignOutDeletedUser()) - authStateMachine.send(event) - } - is AuthenticationState.Error -> { - val event = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(authNState.exception)) - authStateMachine.send(event) - } - else -> { - // No-op - } - } - val authZState = authState.authZState as? AuthorizationState.DeletingUser - when (val deleteUserState = authZState?.deleteUserState) { - is DeleteUserState.UserDeleted -> { - onSuccess.call() - sendHubEvent(AuthChannelEventName.USER_DELETED.toString()) - authStateMachine.cancel(listenerToken) - } - is DeleteUserState.Error -> { - authStateMachine.cancel(listenerToken) - onError.accept( - CognitoAuthExceptionConverter.lookup( - deleteUserState.exception, - "Request to delete user may have failed. Please check exception stack" + if (authState is AuthState.Configured) { + val (authNState, authZState) = authState + val exception = deleteUserException + when { + authZState is AuthorizationState.DeletingUser && + authZState.deleteUserState is DeleteUserState.Error -> { + deleteUserException = authZState.deleteUserState.exception + } + authNState is AuthenticationState.SignedOut && authZState is AuthorizationState.Configured -> { + sendHubEvent(AuthChannelEventName.USER_DELETED.toString()) + authStateMachine.cancel(listenerToken) + onSuccess.call() + } + authZState is AuthorizationState.SessionEstablished && exception != null -> { + authStateMachine.cancel(listenerToken) + onError.accept( + CognitoAuthExceptionConverter.lookup( + exception, + "Request to delete user may have failed. Please check exception stack" + ) ) - ) - } - else -> { - // No-op + } + else -> { + // No - op + } } } }, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt index 9e65f1652d..0f3fa8621c 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/DeleteUserCognitoActions.kt @@ -22,31 +22,48 @@ import com.amplifyframework.statemachine.Action import com.amplifyframework.statemachine.codegen.actions.DeleteUserActions import com.amplifyframework.statemachine.codegen.data.SignOutData import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent +import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent import com.amplifyframework.statemachine.codegen.events.DeleteUserEvent internal object DeleteUserCognitoActions : DeleteUserActions { override fun initDeleteUserAction(accessToken: String): Action = Action("DeleteUser") { id, dispatcher -> logger.verbose("$id Starting execution") - val evt = try { + try { cognitoAuthService.cognitoIdentityProviderClient?.deleteUser( DeleteUserRequest.invoke { this.accessToken = accessToken } ) - AuthenticationEvent(AuthenticationEvent.EventType.SignOutRequested(SignOutData(globalSignOut = false))) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.UserDeleted()) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) } catch (e: Exception) { logger.warn("Failed to delete user.", e) if (e is UserNotFoundException) { // The user could have been remotely deleted, clear local session - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested( - SignOutData(globalSignOut = false) - ) - ) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e, true)) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) } else { - DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e)) + val evt = DeleteUserEvent(DeleteUserEvent.EventType.ThrowError(e, false)) + logger.verbose("$id Sending event ${evt.type}") + dispatcher.send(evt) + val evt2 = AuthorizationEvent(AuthorizationEvent.EventType.ThrowError(e)) + logger.verbose("$id Sending event ${evt2.type}") + dispatcher.send(evt2) } } + } + + override fun initiateSignOut(): Action = + Action("Sign Out Deleted User") { id, dispatcher -> + logger.verbose("$id Starting execution") + val evt = AuthorizationEvent(AuthorizationEvent.EventType.UserDeleted()) + val evt2 = AuthenticationEvent( + AuthenticationEvent.EventType.SignOutRequested(SignOutData(globalSignOut = true, bypassCancel = true)) + ) logger.verbose("$id Sending event ${evt.type}") dispatcher.send(evt) + logger.verbose("$id Sending event ${evt2.type}") + dispatcher.send(evt2) } } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt index 7097a3363a..78f3fdbea3 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/DeleteUserActions.kt @@ -19,4 +19,5 @@ import com.amplifyframework.statemachine.Action internal interface DeleteUserActions { fun initDeleteUserAction(accessToken: String): Action + fun initiateSignOut(): Action } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt index 427ff7cad6..05f925d2be 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/data/SignOutData.kt @@ -18,4 +18,5 @@ package com.amplifyframework.statemachine.codegen.data internal data class SignOutData( val globalSignOut: Boolean = false, val browserPackage: String? = null, + val bypassCancel: Boolean = false // When user deleted, even if sign out is cancelled, proceed to sign out locally ) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt index 78a27bae84..dddfead926 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/DeleteUserEvent.kt @@ -24,9 +24,8 @@ internal class DeleteUserEvent( ) : StateMachineEvent { sealed class EventType { data class DeleteUser(val accessToken: String) : EventType() - data class UserSignedOutAndDeleted(val id: String = "") : EventType() - data class SignOutDeletedUser(val id: String = "") : EventType() - data class ThrowError(val exception: Exception) : EventType() + data class UserDeleted(val id: String = "") : EventType() + data class ThrowError(val exception: Exception, val signOutUser: Boolean) : EventType() } override val type: String = eventType.javaClass.simpleName diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt index 4add2c4860..bdfb3775e7 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthenticationState.kt @@ -130,7 +130,8 @@ internal sealed class AuthenticationState : State { StateResolution(SigningIn(), listOf(action)) } authenticationEvent is AuthenticationEvent.EventType.SignOutRequested -> { - val action = authenticationActions.initiateSignOutAction(authenticationEvent, null) + val action = authenticationActions + .initiateSignOutAction(authenticationEvent, null) StateResolution(SigningOut(), listOf(action)) } authorizationEvent is AuthorizationEvent.EventType.StartFederationToIdentityPool -> { diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt index ce74b24b07..c3e3bd7af7 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/AuthorizationState.kt @@ -51,7 +51,10 @@ internal sealed class AuthorizationState : State { val refreshSessionState: RefreshSessionState ) : AuthorizationState() - data class DeletingUser(val deleteUserState: DeleteUserState) : AuthorizationState() + data class DeletingUser( + val deleteUserState: DeleteUserState, + val amplifyCredential: AmplifyCredential + ) : AuthorizationState() data class StoringCredentials(val amplifyCredential: AmplifyCredential) : AuthorizationState() data class SessionEstablished(val amplifyCredential: AmplifyCredential) : AuthorizationState() data class FederatingToIdentityPool( @@ -231,9 +234,22 @@ internal sealed class AuthorizationState : State { ) } } - is DeletingUser -> { - val resolution = deleteUserResolver.resolve(oldState.deleteUserState, event) - StateResolution(DeletingUser(resolution.newState), resolution.actions) + is DeletingUser -> when (authorizationEvent) { + is AuthorizationEvent.EventType.UserDeleted -> { + StateResolution( + SigningOut(oldState.amplifyCredential), + listOf() + ) + } + is AuthorizationEvent.EventType.ThrowError -> { + StateResolution(SessionEstablished(oldState.amplifyCredential)) + } + else -> { + val resolution = deleteUserResolver.resolve(oldState.deleteUserState, event) + StateResolution( + DeletingUser(resolution.newState, oldState.amplifyCredential), resolution.actions + ) + } } is SessionEstablished -> when { authenticationEvent is AuthenticationEvent.EventType.SignInRequested -> StateResolution(SigningIn()) @@ -242,7 +258,7 @@ internal sealed class AuthorizationState : State { StateResolution(SigningOut(oldState.amplifyCredential)) } deleteUserEvent is DeleteUserEvent.EventType.DeleteUser -> StateResolution( - DeletingUser(DeleteUserState.NotStarted()), + DeletingUser(DeleteUserState.NotStarted(), oldState.amplifyCredential), listOf(authorizationActions.initiateDeleteUser(deleteUserEvent)) ) authorizationEvent is AuthorizationEvent.EventType.RefreshSession -> { @@ -305,7 +321,7 @@ internal sealed class AuthorizationState : State { } deleteUserEvent is DeleteUserEvent.EventType.DeleteUser -> { StateResolution( - DeletingUser(DeleteUserState.NotStarted()), + DeletingUser(DeleteUserState.NotStarted(), AmplifyCredential.Empty), listOf(authorizationActions.initiateDeleteUser(deleteUserEvent)) ) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt index f722c48093..2d7570781d 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/DeleteUserState.kt @@ -26,7 +26,6 @@ import java.lang.Exception internal sealed class DeleteUserState : State { data class NotStarted(val id: String = "") : DeleteUserState() data class DeletingUser(val id: String = "") : DeleteUserState() - data class SigningOut(val id: String = "") : DeleteUserState() data class UserDeleted(val id: String = "") : DeleteUserState() data class Error(val exception: Exception) : DeleteUserState() @@ -54,14 +53,21 @@ internal sealed class DeleteUserState : State { } is DeletingUser -> { when (deleteUserEvent) { - is DeleteUserEvent.EventType.SignOutDeletedUser -> StateResolution(UserDeleted()) + is DeleteUserEvent.EventType.UserDeleted -> { + val action = deleteUserActions.initiateSignOut() + StateResolution(UserDeleted(), listOf(action)) + } is DeleteUserEvent.EventType.ThrowError -> { - StateResolution(Error(deleteUserEvent.exception)) + if (deleteUserEvent.signOutUser) { + val action = deleteUserActions.initiateSignOut() + StateResolution(UserDeleted(), listOf(action)) + } else { + StateResolution(Error(deleteUserEvent.exception)) + } } else -> StateResolution(oldState) } - } - else -> StateResolution(oldState) + } else -> StateResolution(oldState) } } } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt index d8ad161bef..376c3ef0ed 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignOutState.kt @@ -29,7 +29,11 @@ import com.amplifyframework.statemachine.codegen.events.SignOutEvent internal sealed class SignOutState : State { data class NotStarted(val id: String = "") : SignOutState() - data class SigningOutHostedUI(val signedInData: SignedInData, val globalSignOut: Boolean) : SignOutState() + data class SigningOutHostedUI( + val signedInData: SignedInData, + val globalSignOut: Boolean, + val bypassCancel: Boolean + ) : SignOutState() data class SigningOutGlobally(val id: String = "") : SignOutState() data class RevokingToken(val id: String = "") : SignOutState() data class BuildingRevokeTokenError(val id: String = "") : SignOutState() @@ -49,7 +53,11 @@ internal sealed class SignOutState : State { is SignOutEvent.EventType.InvokeHostedUISignOut -> { val action = signOutActions.hostedUISignOutAction(signOutEvent) StateResolution( - SigningOutHostedUI(signOutEvent.signedInData, signOutEvent.signOutData.globalSignOut), + SigningOutHostedUI( + signOutEvent.signedInData, + signOutEvent.signOutData.globalSignOut, + signOutEvent.signOutData.bypassCancel + ), listOf(action) ) } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt index 2db28e2a71..4c55943360 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPluginTest.kt @@ -40,6 +40,7 @@ import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttribute import aws.sdk.kotlin.services.cognitoidentityprovider.model.VerifyUserAttributeResponse import com.amplifyframework.auth.AuthCodeDeliveryDetails import com.amplifyframework.auth.AuthException +import com.amplifyframework.auth.AuthSession import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.auth.AuthUserAttributeKey import com.amplifyframework.auth.cognito.exceptions.configuration.InvalidUserPoolConfigurationException @@ -199,6 +200,26 @@ class RealAWSCognitoAuthPluginTest { verify { onError.accept(expectedAuthError) } } + @Test + fun testFetchAuthSessionSucceedsIfSignedOut() { + // GIVEN + val onSuccess = mockk>() + val onError = mockk>(relaxed = true) + val currentAuthState = mockk { + every { authNState } returns AuthenticationState.SignedOut(mockk()) + every { authZState } returns AuthorizationState.Configured() + } + every { authStateMachine.getCurrentState(captureLambda()) } answers { + lambda<(AuthState) -> Unit>().invoke(currentAuthState) + } + + // WHEN + plugin.fetchAuthSession(onSuccess, onError) + + // THEN + verify(exactly = 0) { onSuccess.accept(any()) } + } + @Test fun testConfirmSignUpFailsIfNotConfigured() { // GIVEN diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt index a6c01e7b26..b6341d623a 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt @@ -37,9 +37,7 @@ import com.amplifyframework.statemachine.codegen.data.AuthConfiguration import com.amplifyframework.statemachine.codegen.data.CognitoUserPoolTokens import com.amplifyframework.statemachine.codegen.data.DeviceMetadata import com.amplifyframework.statemachine.codegen.data.LoginsMapProvider -import com.amplifyframework.statemachine.codegen.data.SignInData import com.amplifyframework.statemachine.codegen.data.SignInMethod -import com.amplifyframework.statemachine.codegen.data.SignOutData import com.amplifyframework.statemachine.codegen.data.SignedInData import com.amplifyframework.statemachine.codegen.data.SignedOutData import com.amplifyframework.statemachine.codegen.events.AuthEvent @@ -68,9 +66,6 @@ open class StateTransitionTestBase { fun uninitialized(): T = null as T } - @Mock - internal lateinit var signInData: SignInData - @Mock internal lateinit var signedInData: SignedInData @@ -485,19 +480,4 @@ open class StateTransitionTestBase { } ) } - - internal fun setupDeleteAction() { - Mockito.`when`( - mockDeleteUserActions.initDeleteUserAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested(SignOutData(true)) - ) - ) - } - ) - } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt index 48dba44b10..f8a09bbbb3 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt @@ -24,7 +24,6 @@ import com.amplifyframework.statemachine.codegen.data.SignedOutData import com.amplifyframework.statemachine.codegen.events.AuthEvent import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent -import com.amplifyframework.statemachine.codegen.events.DeleteUserEvent import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent import com.amplifyframework.statemachine.codegen.events.SignInEvent import com.amplifyframework.statemachine.codegen.events.SignOutEvent @@ -78,7 +77,6 @@ class StateTransitionTests : StateTransitionTestBase() { setupSRPActions() setupSignOutActions() setupFetchAuthActions() - setupDeleteAction() setupStateMachine() Dispatchers.setMain(mainThreadSurrogate) } @@ -682,56 +680,4 @@ class StateTransitionTests : StateTransitionTestBase() { assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } assertTrue { testLatch.await(5, TimeUnit.SECONDS) } } - - @Test - fun testDeleteUser() { - setupConfigureSignedIn() - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val testLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { it -> - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn } - authState?.run { - configureLatch.countDown() - stateMachine.send( - DeleteUserEvent( - DeleteUserEvent.EventType.DeleteUser("TOKEN-123") - ) - ) - } - val signoutState = it.takeIf { it.authNState is AuthenticationState.SignedOut } - signoutState?.run { - stateMachine.send( - DeleteUserEvent( - DeleteUserEvent.EventType.SignOutDeletedUser() - ) - ) - } - val deleteUserState = (it.authZState as? AuthorizationState.DeletingUser)?.deleteUserState - val userDeletedSuccess = deleteUserState?.takeIf { - it is DeleteUserState.UserDeleted - } - - userDeletedSuccess?.run { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } } diff --git a/aws-core/.gitignore b/aws-core/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/aws-core/.gitignore @@ -0,0 +1 @@ +/build diff --git a/aws-core/build.gradle.kts b/aws-core/build.gradle.kts new file mode 100644 index 0000000000..eb799fb7f8 --- /dev/null +++ b/aws-core/build.gradle.kts @@ -0,0 +1,50 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +plugins { + id("com.android.library") + id("kotlin-android") +} + +apply(from = rootProject.file("configuration/checkstyle.gradle")) +apply(from = rootProject.file("configuration/publishing.gradle")) + +group = properties["POM_GROUP"].toString() + +android { + kotlinOptions { + moduleName = "com.amplifyframework.aws-core" + } +} + +dependencies { + implementation(project(":core")) + implementation(dependency.kotlin.stdlib) + implementation(dependency.kotlin.coroutines) + + implementation(dependency.aws.credentials) +} + +afterEvaluate { + // Disables this warning: + // warning: listOf(classfile) MethodParameters attribute + // introduced in version 52.0 class files is ignored in + // version 51.0 class files + // Root project has -Werror, so this warning + // would fail the build, otherwise. + tasks.withType().configureEach { + options.compilerArgs.add("-Xlint:-classfile") + } +} diff --git a/aws-core/gradle.properties b/aws-core/gradle.properties new file mode 100644 index 0000000000..f5cda23871 --- /dev/null +++ b/aws-core/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=aws-core +POM_NAME=Amplify Framework for Android - AWS Core +POM_DESCRIPTION=Amplify Framework for Android - AWS Core components and utilities for AWS Amplify Libraries +POM_PACKAGING=aar diff --git a/aws-core/src/main/AndroidManifest.xml b/aws-core/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..a2c4ba9f7a --- /dev/null +++ b/aws-core/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt similarity index 93% rename from core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt index 33cb2dccf8..7b98a4c56c 100644 --- a/core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSAuthSessionInternal.kt @@ -14,8 +14,10 @@ */ package com.amplifyframework.auth +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.auth.result.AuthSessionResult +@InternalApiWarning open class AWSAuthSessionInternal( @get:JvmName("getSignedIn") open val isSignedIn: Boolean, diff --git a/core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt similarity index 100% rename from core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSCognitoUserPoolTokens.kt diff --git a/core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt similarity index 86% rename from core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt index 31276197eb..8135bd4eaf 100644 --- a/core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentials.kt @@ -15,6 +15,7 @@ package com.amplifyframework.auth +import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials import aws.smithy.kotlin.runtime.time.Instant /** @@ -85,3 +86,12 @@ class AWSTemporaryCredentials( */ val expiration: Instant ) : AWSCredentials(accessKeyId, secretAccessKey) + +internal fun AWSCredentials.toSdkCredentials(): Credentials { + return Credentials( + accessKeyId = this.accessKeyId, + secretAccessKey = this.secretAccessKey, + sessionToken = (this as? AWSTemporaryCredentials)?.sessionToken, + expiration = (this as? AWSTemporaryCredentials)?.expiration + ) +} diff --git a/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt new file mode 100644 index 0000000000..34c9555bdb --- /dev/null +++ b/aws-core/src/main/java/com/amplifyframework/auth/AWSCredentialsProvider.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amplifyframework.auth + +import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials +import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider +import com.amplifyframework.core.Consumer +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException +import kotlin.coroutines.suspendCoroutine + +/** + * Customer provided CredentialsProvider implementation that fetches and returns AWSCredentials or a subclass such + * as AWSTemporaryCredentials. For example: + * + * class AWSTemporaryCredentialsProvider: AWSCredentialsProvider { + * override fun fetchAWSCredentials( + * onSuccess: Consumer, + * onError: Consumer + * ) { + * // customer provided fetch implementation + * } + * } + */ +interface AWSCredentialsProvider { + + fun fetchAWSCredentials( + onSuccess: Consumer<@UnsafeVariance T>, + onError: Consumer + ) +} + +fun convertToSdkCredentialsProvider( + awsCredentialsProvider: AWSCredentialsProvider +): CredentialsProvider { + + return object : CredentialsProvider { + override suspend fun getCredentials(): Credentials { + return suspendCoroutine { continuation -> + awsCredentialsProvider.fetchAWSCredentials( + { continuation.resume(it.toSdkCredentials()) }, + { continuation.resumeWithException(it) } + ) + } + } + } +} diff --git a/core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt similarity index 93% rename from core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt rename to aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt index ec898cc843..21657259b9 100644 --- a/core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/AuthCredentialsProvider.kt @@ -16,8 +16,10 @@ package com.amplifyframework.auth import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.core.Consumer +@InternalApiWarning interface AuthCredentialsProvider : CredentialsProvider { /** * Get the identity ID of the currently logged in user if they are registered in identity pools. diff --git a/core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt b/aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt similarity index 90% rename from core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt rename to aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt index 6da1ee0839..a807afd05e 100644 --- a/core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt +++ b/aws-core/src/main/java/com/amplifyframework/auth/CognitoCredentialsProvider.kt @@ -36,7 +36,7 @@ open class CognitoCredentialsProvider : AuthCredentialsProvider { Amplify.Auth.fetchAuthSession( { authSession -> authSession.toAWSAuthSession()?.awsCredentialsResult?.value?.let { - continuation.resume(it.toCredentials()) + continuation.resume(it.toSdkCredentials()) } ?: continuation.resumeWithException( AuthException( "Failed to get credentials. " + @@ -98,12 +98,3 @@ open class CognitoCredentialsProvider : AuthCredentialsProvider { private fun AuthSession.toAWSAuthSession(): AWSAuthSessionInternal? { return this as? AWSAuthSessionInternal } - -private fun AWSCredentials.toCredentials(): Credentials { - return Credentials( - accessKeyId = this.accessKeyId, - secretAccessKey = this.secretAccessKey, - sessionToken = (this as? AWSTemporaryCredentials)?.sessionToken, - expiration = (this as? AWSTemporaryCredentials)?.expiration - ) -} diff --git a/aws-datastore/build.gradle.kts b/aws-datastore/build.gradle.kts index 38a8e73535..b5cd1ee15f 100644 --- a/aws-datastore/build.gradle.kts +++ b/aws-datastore/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(project(":aws-api-appsync")) implementation(dependency.androidx.appcompat) diff --git a/aws-geo-location/build.gradle.kts b/aws-geo-location/build.gradle.kts index 5e72d4a9b6..cd0a88b81b 100644 --- a/aws-geo-location/build.gradle.kts +++ b/aws-geo-location/build.gradle.kts @@ -24,6 +24,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.aws.location) testImplementation(project(":testutils")) diff --git a/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt b/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt index 5519cda7c2..2f20108069 100644 --- a/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt +++ b/aws-geo-location/src/main/java/com/amplifyframework/geo/location/AWSLocationGeoPlugin.kt @@ -19,6 +19,7 @@ import android.content.Context import aws.sdk.kotlin.services.location.LocationClient import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider import com.amplifyframework.AmplifyException +import com.amplifyframework.annotations.InternalApiWarning import com.amplifyframework.auth.AuthCategory import com.amplifyframework.auth.CognitoCredentialsProvider import com.amplifyframework.core.Amplify @@ -64,6 +65,7 @@ class AWSLocationGeoPlugin( configuration.searchIndices!!.default } + @InternalApiWarning val credentialsProvider: CredentialsProvider by lazy { CognitoCredentialsProvider() } diff --git a/aws-predictions-tensorflow/build.gradle.kts b/aws-predictions-tensorflow/build.gradle.kts index 8e0b5dec62..25cef8c9c1 100644 --- a/aws-predictions-tensorflow/build.gradle.kts +++ b/aws-predictions-tensorflow/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.tensorflow) diff --git a/aws-predictions/build.gradle.kts b/aws-predictions/build.gradle.kts index 3648bdec72..f2ec25cf9a 100644 --- a/aws-predictions/build.gradle.kts +++ b/aws-predictions/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.aws.comprehend) implementation(dependency.aws.polly) diff --git a/aws-push-notifications-pinpoint/build.gradle.kts b/aws-push-notifications-pinpoint/build.gradle.kts index 8afac0069b..e4153e9bfa 100644 --- a/aws-push-notifications-pinpoint/build.gradle.kts +++ b/aws-push-notifications-pinpoint/build.gradle.kts @@ -25,7 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) - implementation(project(":aws-auth-cognito")) + implementation(project(":aws-core")) implementation(project(":aws-pinpoint-core")) api(project(":aws-push-notifications-pinpoint-utils")) diff --git a/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml b/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml index 61b6d00aae..4effc86390 100644 --- a/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml +++ b/aws-push-notifications-pinpoint/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ --> + package="com.amplifyframework.pushnotifications.pinpoint"> diff --git a/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt b/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt index fd5e097605..7b57bf70db 100644 --- a/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt +++ b/aws-push-notifications-pinpoint/src/main/java/com/amplifyframework/pushnotifications/pinpoint/AWSPinpointPushNotificationsPlugin.kt @@ -26,7 +26,6 @@ import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor import com.amplifyframework.AmplifyException import com.amplifyframework.analytics.UserProfile import com.amplifyframework.auth.CognitoCredentialsProvider -import com.amplifyframework.auth.cognito.BuildConfig import com.amplifyframework.core.Action import com.amplifyframework.core.Amplify import com.amplifyframework.core.Consumer diff --git a/aws-storage-s3/build.gradle.kts b/aws-storage-s3/build.gradle.kts index 601506f988..3ebe967e09 100644 --- a/aws-storage-s3/build.gradle.kts +++ b/aws-storage-s3/build.gradle.kts @@ -25,6 +25,7 @@ group = properties["POM_GROUP"].toString() dependencies { implementation(project(":core")) + implementation(project(":aws-core")) implementation(dependency.androidx.appcompat) implementation(dependency.aws.s3) diff --git a/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java b/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java index 4f354a6fd4..8f47e082c8 100644 --- a/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java +++ b/aws-storage-s3/src/main/java/com/amplifyframework/storage/s3/AWSS3StoragePlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -17,8 +17,10 @@ import android.content.Context; import androidx.annotation.NonNull; +import androidx.annotation.OptIn; import androidx.annotation.VisibleForTesting; +import com.amplifyframework.annotations.InternalApiWarning; import com.amplifyframework.auth.AuthCredentialsProvider; import com.amplifyframework.auth.CognitoCredentialsProvider; import com.amplifyframework.core.Consumer; @@ -107,6 +109,7 @@ public final class AWSS3StoragePlugin extends StoragePlugin { * Constructs the AWS S3 Storage Plugin initializing the executor service. */ @SuppressWarnings("unused") // This is a public API. + @OptIn(markerClass = InternalApiWarning.class) public AWSS3StoragePlugin() { this(new CognitoCredentialsProvider()); } @@ -117,6 +120,7 @@ public AWSS3StoragePlugin() { * @param awsS3StoragePluginConfiguration storage plugin configuration */ @SuppressWarnings("unused") // This is a public API. + @OptIn(markerClass = InternalApiWarning.class) public AWSS3StoragePlugin(AWSS3StoragePluginConfiguration awsS3StoragePluginConfiguration) { this(new CognitoCredentialsProvider(), awsS3StoragePluginConfiguration); } diff --git a/build.gradle.kts b/build.gradle.kts index 5144d811ba..fc0deb7197 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,6 +15,7 @@ import com.android.build.gradle.LibraryExtension import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { repositories { @@ -64,6 +65,10 @@ tasks.register("clean").configure { delete(rootProject.buildDir) } +val optInAnnotations = listOf( + "com.amplifyframework.annotations.InternalApiWarning" +) + subprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") @@ -100,6 +105,14 @@ subprojects { failOnPassedAfterRetry.set(true) } } + + tasks.withType { + kotlinOptions { + optInAnnotations.forEach { + freeCompilerArgs += "-opt-in=$it" + } + } + } } @Suppress("ExpiredTargetSdkVersion") diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 38539d51d7..8cfdddfbef 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -31,6 +31,7 @@ android { } dependencies { + api(project(":annotations")) implementation(dependency.androidx.v4support) implementation(dependency.androidx.annotation) implementation(dependency.androidx.nav.fragment) @@ -38,8 +39,6 @@ dependencies { implementation(dependency.androidx.security) implementation(dependency.kotlin.serializationJson) - implementation(dependency.aws.credentials) - testImplementation(project(":aws-api-appsync")) // Used to reference Temporal types in tests. testImplementation(project(":testmodels")) diff --git a/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java b/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java index d2bde4e990..82d7254ca7 100644 --- a/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java +++ b/core/src/main/java/com/amplifyframework/auth/AuthCategoryBehavior.java @@ -48,7 +48,6 @@ * Specifies the behavior for the Auth category. */ public interface AuthCategoryBehavior { - /** * Creates a new user account with the specified username and password. * Can also pass in user attributes to associate with the user through diff --git a/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt b/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt index 17dd22d442..31a9a74f2d 100644 --- a/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt +++ b/core/src/main/java/com/amplifyframework/notifications/pushnotifications/NotificationPayload.kt @@ -16,7 +16,6 @@ package com.amplifyframework.notifications.pushnotifications import android.os.Parcelable -import java.util.UUID import kotlinx.parcelize.Parcelize @Parcelize diff --git a/settings.gradle.kts b/settings.gradle.kts index 2e00855fb3..e847b9393d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -138,7 +138,9 @@ dependencyResolutionManagement { } } +include(":annotations") include(":core") +include(":aws-core") // Plugin Modules include(":aws-analytics-pinpoint")