feat: route provider sessions to ABSDK and simulation

This commit is contained in:
2026-08-24 19:10:46 +08:00
parent d560a78b63
commit 45f768208f
6 changed files with 114 additions and 94 deletions
+12
View File
@@ -45,6 +45,15 @@ android {
kotlinOptions {
jvmTarget = "17"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
excludes += "/META-INF/DEPENDENCIES"
excludes += "/META-INF/LICENSE*"
excludes += "/META-INF/NOTICE*"
}
}
}
kapt {
@@ -55,6 +64,8 @@ dependencies {
implementation(project(":domain"))
implementation(project(":android:core:designsystem"))
implementation(project(":android:core:session"))
implementation(project(":absdk-bridge"))
implementation(project(":runtime:simulation"))
debugImplementation(project(":testing:fakes"))
implementation(platform(libs.compose.bom))
@@ -73,6 +84,7 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(project(":testing:fakes"))
androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.test.runner)
@@ -1,27 +0,0 @@
package com.flagship.abox.manager.di
import com.flagship.abox.manager.domain.SessionGateway
import com.flagship.abox.manager.testing.fakes.FakeSessionGateway
import com.flagship.abox.manager.ui.provider.Availability
import com.flagship.abox.manager.ui.provider.ProviderAvailability
import com.flagship.abox.manager.ui.provider.UnavailableReason
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object DebugSessionModule {
@Provides
@Singleton
fun provideRemoteSessionGateway(fake: FakeSessionGateway): SessionGateway = fake
@Provides
@Singleton
fun provideProviderAvailability(): ProviderAvailability = ProviderAvailability(
abox = Availability.Simulation,
compatible = Availability.Disabled(UnavailableReason.PROTOCOL_PENDING),
)
}
@@ -3,6 +3,8 @@ package com.flagship.abox.manager.di
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import com.flagship.abox.manager.absdk.bridge.AbsdkBridge
import com.flagship.abox.manager.absdk.bridge.CleartextAbsdkTransport
import com.flagship.abox.manager.domain.CredentialStore
import com.flagship.abox.manager.domain.LocalSessionGateway
import com.flagship.abox.manager.domain.ProviderProfileStore
@@ -11,9 +13,12 @@ import com.flagship.abox.manager.domain.SessionGateway
import com.flagship.abox.manager.session.credential.AndroidKeystoreCredentialCipher
import com.flagship.abox.manager.session.credential.CredentialCipher
import com.flagship.abox.manager.session.credential.KeystoreCredentialStore
import com.flagship.abox.manager.session.gateway.LocalSessionGatewayImpl
import com.flagship.abox.manager.session.profile.ProviderProfileStoreImpl
import com.flagship.abox.manager.session.profile.sessionDataStore
import com.flagship.abox.manager.simulation.SimulationSessionGateway
import com.flagship.abox.manager.ui.provider.Availability
import com.flagship.abox.manager.ui.provider.ProviderAvailability
import com.flagship.abox.manager.ui.provider.UnavailableReason
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -49,7 +54,25 @@ object SessionModule {
@Provides
@Singleton
fun provideLocalSessionGateway(): LocalSessionGateway = LocalSessionGatewayImpl()
@OptIn(CleartextAbsdkTransport::class)
fun provideAbsdkBridge(): AbsdkBridge = AbsdkBridge.create()
@Provides
@Singleton
fun provideRemoteSessionGateway(
bridge: AbsdkBridge,
): SessionGateway = bridge
@Provides
@Singleton
fun provideLocalSessionGateway(): LocalSessionGateway = SimulationSessionGateway()
@Provides
@Singleton
fun provideProviderAvailability(): ProviderAvailability = ProviderAvailability(
abox = Availability.Enabled,
compatible = Availability.Disabled(UnavailableReason.PROTOCOL_PENDING),
)
@Provides
@Singleton
@@ -1,27 +0,0 @@
package com.flagship.abox.manager.di
import com.flagship.abox.manager.domain.SessionGateway
import com.flagship.abox.manager.session.gateway.UnavailableRemoteSessionGateway
import com.flagship.abox.manager.ui.provider.Availability
import com.flagship.abox.manager.ui.provider.ProviderAvailability
import com.flagship.abox.manager.ui.provider.UnavailableReason
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object ReleaseSessionModule {
@Provides
@Singleton
fun provideRemoteSessionGateway(): SessionGateway = UnavailableRemoteSessionGateway()
@Provides
@Singleton
fun provideProviderAvailability(): ProviderAvailability = ProviderAvailability(
abox = Availability.Disabled(UnavailableReason.TRANSPORT_SECURITY_PENDING),
compatible = Availability.Disabled(UnavailableReason.PROTOCOL_PENDING),
)
}
@@ -1,38 +0,0 @@
package com.flagship.abox.manager.session.gateway
import com.flagship.abox.manager.domain.DomainResult
import com.flagship.abox.manager.domain.LocalSessionGateway
import com.flagship.abox.manager.domain.LoginCredentials
import com.flagship.abox.manager.domain.ProviderProfileId
import com.flagship.abox.manager.domain.Session
import com.flagship.abox.manager.domain.SessionValidity
import java.util.concurrent.ConcurrentHashMap
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
class LocalSessionGatewayImpl : LocalSessionGateway {
private val sessions = ConcurrentHashMap<ProviderProfileId, MutableStateFlow<Session?>>()
override fun observeSession(profileId: ProviderProfileId): Flow<Session?> = flow(profileId)
override suspend fun login(
profileId: ProviderProfileId,
credentials: LoginCredentials,
): DomainResult<Session> = DomainResult.Success(
Session(profileId, credentials.username).also { flow(profileId).value = it },
)
override suspend fun validateSession(
profileId: ProviderProfileId,
): DomainResult<SessionValidity> = DomainResult.Success(
if (flow(profileId).value == null) SessionValidity.INVALID else SessionValidity.VALID,
)
override suspend fun logout(profileId: ProviderProfileId): DomainResult<Unit> {
flow(profileId).value = null
return DomainResult.Success(Unit)
}
private fun flow(profileId: ProviderProfileId): MutableStateFlow<Session?> =
sessions.getOrPut(profileId) { MutableStateFlow(null) }
}