mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1395 Auth | Fix | Set metrics for mw library (#74)
This commit is contained in:
parent
444ffe3a1b
commit
0f37c3ea69
20 changed files with 134 additions and 16 deletions
|
@ -0,0 +1,21 @@
|
|||
package com.anytypeio.anytype.app
|
||||
|
||||
import com.anytypeio.anytype.BuildConfig
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
|
||||
class DefaultMetricsProvider : MetricsProvider {
|
||||
override fun getVersion(): String {
|
||||
return if (BuildConfig.DEBUG)
|
||||
BuildConfig.VERSION_NAME + DEV_PREFIX
|
||||
else {
|
||||
return BuildConfig.VERSION_NAME
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPlatform(): String = PLATFORM_NAME
|
||||
|
||||
companion object {
|
||||
const val PLATFORM_NAME = "kotlin"
|
||||
const val DEV_PREFIX = "-dev"
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.anytypeio.anytype.di.feature
|
||||
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import com.anytypeio.anytype.CrashReporter
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerFeature
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
|
@ -13,13 +14,13 @@ import com.anytypeio.anytype.domain.auth.interactor.SelectAccount
|
|||
import com.anytypeio.anytype.domain.auth.interactor.SetupWallet
|
||||
import com.anytypeio.anytype.domain.auth.interactor.StartLoadingAccounts
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.config.FeaturesConfigProvider
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.CrashReporter
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.`object`.SetupMobileUseCaseSkip
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
||||
|
@ -243,11 +244,13 @@ object SetupNewAccountModule {
|
|||
fun provideCreateAccountUseCase(
|
||||
repository: AuthRepository,
|
||||
configStorage: ConfigStorage,
|
||||
workspaceManager: WorkspaceManager
|
||||
workspaceManager: WorkspaceManager,
|
||||
metricsProvider: MetricsProvider
|
||||
): CreateAccount = CreateAccount(
|
||||
repository = repository,
|
||||
configStorage = configStorage,
|
||||
workspaceManager = workspaceManager
|
||||
workspaceManager = workspaceManager,
|
||||
metricsProvider = metricsProvider
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.anytypeio.anytype.di.feature
|
||||
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.anytypeio.anytype.CrashReporter
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
|
||||
|
@ -18,9 +19,9 @@ import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
|||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.launch.SetDefaultEditorType
|
||||
import com.anytypeio.anytype.CrashReporter
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.templates.GetTemplates
|
||||
|
@ -70,13 +71,15 @@ object SplashModule {
|
|||
pathProvider: PathProvider,
|
||||
featuresConfigProvider: FeaturesConfigProvider,
|
||||
configStorage: ConfigStorage,
|
||||
workspaceManager: WorkspaceManager
|
||||
workspaceManager: WorkspaceManager,
|
||||
metricsProvider: MetricsProvider
|
||||
): LaunchAccount = LaunchAccount(
|
||||
repository = authRepository,
|
||||
pathProvider = pathProvider,
|
||||
featuresConfigProvider = featuresConfigProvider,
|
||||
configStorage = configStorage,
|
||||
workspaceManager = workspaceManager
|
||||
workspaceManager = workspaceManager,
|
||||
metricsProvider = metricsProvider
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
@ -173,4 +176,5 @@ interface SplashDependencies : ComponentDependencies {
|
|||
fun userSettingsRepository(): UserSettingsRepository
|
||||
fun dispatchers(): AppCoroutineDispatchers
|
||||
fun crashReporter(): CrashReporter
|
||||
fun metricsProvider(): MetricsProvider
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.anytypeio.anytype.domain.auth.interactor.SetupWallet
|
|||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
||||
|
@ -50,11 +51,13 @@ object OnboardingAuthModule {
|
|||
fun provideCreateAccountUseCase(
|
||||
authRepository: AuthRepository,
|
||||
configStorage: ConfigStorage,
|
||||
workspaceManager: WorkspaceManager
|
||||
workspaceManager: WorkspaceManager,
|
||||
metricsProvider: MetricsProvider
|
||||
): CreateAccount = CreateAccount(
|
||||
repository = authRepository,
|
||||
configStorage = configStorage,
|
||||
workspaceManager = workspaceManager
|
||||
workspaceManager = workspaceManager,
|
||||
metricsProvider = metricsProvider
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
@ -83,6 +86,7 @@ interface OnboardingAuthDependencies : ComponentDependencies {
|
|||
fun relationsSubscriptionManager(): RelationsSubscriptionManager
|
||||
fun objectTypesSubscriptionManager(): ObjectTypesSubscriptionManager
|
||||
fun pathProvider(): PathProvider
|
||||
fun metricsProvider(): MetricsProvider
|
||||
}
|
||||
|
||||
@Scope
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences
|
|||
import androidx.security.crypto.EncryptedSharedPreferences
|
||||
import androidx.security.crypto.MasterKeys
|
||||
import com.anytypeio.anytype.app.DefaultAppActionManager
|
||||
import com.anytypeio.anytype.app.DefaultMetricsProvider
|
||||
import com.anytypeio.anytype.data.auth.config.DefaultFeaturesConfigProvider
|
||||
import com.anytypeio.anytype.data.auth.repo.AuthCache
|
||||
import com.anytypeio.anytype.data.auth.repo.AuthCacheDataStore
|
||||
|
@ -25,7 +26,6 @@ import com.anytypeio.anytype.data.auth.types.DefaultObjectTypesProvider
|
|||
import com.anytypeio.anytype.device.BuildProvider
|
||||
import com.anytypeio.anytype.device.DefaultBuildProvider
|
||||
import com.anytypeio.anytype.device.DefaultPathProvider
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.config.FeaturesConfigProvider
|
||||
|
@ -33,8 +33,10 @@ import com.anytypeio.anytype.domain.config.InfrastructureRepository
|
|||
import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.`object`.ObjectTypesProvider
|
||||
import com.anytypeio.anytype.domain.objects.DefaultObjectStore
|
||||
import com.anytypeio.anytype.domain.objects.ObjectStore
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.unsplash.UnsplashRepository
|
||||
import com.anytypeio.anytype.middleware.EventProxy
|
||||
import com.anytypeio.anytype.middleware.UnsplashMiddleware
|
||||
|
@ -291,6 +293,11 @@ object DataModule {
|
|||
@Singleton
|
||||
fun provideBuildProvider(): BuildProvider = DefaultBuildProvider()
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideMetricsProvider(): MetricsProvider = DefaultMetricsProvider()
|
||||
|
||||
@Module
|
||||
interface Bindings {
|
||||
|
||||
|
|
|
@ -84,6 +84,10 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore {
|
|||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun setMetrics(platform: String, version: String) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
override suspend fun saveLastOpenedObject(id: Id) { cache.saveLastOpenedObject(id) }
|
||||
override suspend fun getLastOpenedObject(): Id? = cache.getLastOpenedObject()
|
||||
override suspend fun clearLastOpenedObject() { cache.clearLastOpenedObject() }
|
||||
|
|
|
@ -14,6 +14,13 @@ class AuthDataRepository(
|
|||
private val factory: AuthDataStoreFactory
|
||||
) : AuthRepository {
|
||||
|
||||
override suspend fun setMetrics(platform: String, version: String) {
|
||||
factory.remote.setMetrics(
|
||||
platform = platform,
|
||||
version = version
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun selectAccount(
|
||||
id: String, path: String
|
||||
): AccountSetup = factory.remote.selectAccount(
|
||||
|
|
|
@ -42,6 +42,7 @@ interface AuthDataStore {
|
|||
suspend fun setCurrentAccount(id: String)
|
||||
|
||||
suspend fun getVersion(): String
|
||||
suspend fun setMetrics(platform: String, version: String)
|
||||
|
||||
suspend fun saveLastOpenedObject(id: Id)
|
||||
suspend fun getLastOpenedObject() : Id?
|
||||
|
|
|
@ -24,4 +24,5 @@ interface AuthRemote {
|
|||
suspend fun convertWallet(entropy: String): String
|
||||
|
||||
suspend fun getVersion(): String
|
||||
suspend fun setMetrics(platform: String, version: String)
|
||||
}
|
|
@ -86,6 +86,13 @@ class AuthRemoteDataStore(
|
|||
|
||||
override suspend fun getVersion(): String = authRemote.getVersion()
|
||||
|
||||
override suspend fun setMetrics(platform: String, version: String) {
|
||||
authRemote.setMetrics(
|
||||
platform = platform,
|
||||
version = version
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun saveLastOpenedObject(id: Id) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.Account
|
|||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
||||
|
||||
/**
|
||||
|
@ -12,10 +13,15 @@ import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
|||
open class CreateAccount(
|
||||
private val repository: AuthRepository,
|
||||
private val configStorage: ConfigStorage,
|
||||
private val workspaceManager: WorkspaceManager
|
||||
private val workspaceManager: WorkspaceManager,
|
||||
private val metricsProvider: MetricsProvider
|
||||
) : BaseUseCase<Account, CreateAccount.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repository.setMetrics(
|
||||
version = metricsProvider.getVersion(),
|
||||
platform = metricsProvider.getPlatform()
|
||||
)
|
||||
val setup = repository.createAccount(
|
||||
name = params.name,
|
||||
avatarPath = params.avatarPath,
|
||||
|
@ -34,7 +40,6 @@ open class CreateAccount(
|
|||
* @property avatarPath optional avatar image file path
|
||||
* @property name username
|
||||
* @property iconGradientValue random icon gradient value for new account/space background
|
||||
* @property invitationCode optional invite code
|
||||
*/
|
||||
class Params(
|
||||
val name: String,
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.anytypeio.anytype.domain.base.Either
|
|||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.config.FeaturesConfigProvider
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -19,10 +20,15 @@ class LaunchAccount(
|
|||
private val context: CoroutineContext = Dispatchers.IO,
|
||||
private val configStorage: ConfigStorage,
|
||||
private val featuresConfigProvider: FeaturesConfigProvider,
|
||||
private val workspaceManager: WorkspaceManager
|
||||
private val workspaceManager: WorkspaceManager,
|
||||
private val metricsProvider: MetricsProvider
|
||||
) : BaseUseCase<String, BaseUseCase.None>(context) {
|
||||
|
||||
override suspend fun run(params: None) = try {
|
||||
repository.setMetrics(
|
||||
version = metricsProvider.getVersion(),
|
||||
platform = metricsProvider.getPlatform()
|
||||
)
|
||||
repository.selectAccount(
|
||||
id = repository.getCurrentAccountId(),
|
||||
path = pathProvider.providePath()
|
||||
|
|
|
@ -9,6 +9,8 @@ import kotlinx.coroutines.flow.Flow
|
|||
|
||||
interface AuthRepository {
|
||||
|
||||
suspend fun setMetrics(platform: String, version: String)
|
||||
|
||||
/**
|
||||
* Launches an account.
|
||||
* @param id user account id
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.anytypeio.anytype.domain.platform
|
||||
|
||||
interface MetricsProvider {
|
||||
fun getVersion(): String
|
||||
fun getPlatform(): String
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.StubAccountSetup
|
|||
import com.anytypeio.anytype.domain.auth.interactor.CreateAccount
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.platform.MetricsProvider
|
||||
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
|
@ -35,6 +36,9 @@ class CreateAccountTest {
|
|||
@Mock
|
||||
lateinit var workspaceManager: WorkspaceManager
|
||||
|
||||
@Mock
|
||||
lateinit var metricsProvider: MetricsProvider
|
||||
|
||||
private lateinit var createAccount: CreateAccount
|
||||
|
||||
@Before
|
||||
|
@ -43,7 +47,8 @@ class CreateAccountTest {
|
|||
createAccount = CreateAccount(
|
||||
repository = repo,
|
||||
configStorage = configStorage,
|
||||
workspaceManager = workspaceManager
|
||||
workspaceManager = workspaceManager,
|
||||
metricsProvider = metricsProvider
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -76,4 +76,11 @@ class AuthMiddleware(
|
|||
override suspend fun getVersion(): String {
|
||||
return middleware.versionGet().version
|
||||
}
|
||||
|
||||
override suspend fun setMetrics(platform: String, version: String) {
|
||||
middleware.metricsSetParameters(
|
||||
platform = platform,
|
||||
version = version
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1571,6 +1571,20 @@ class Middleware(
|
|||
return response
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun metricsSetParameters(
|
||||
platform: String,
|
||||
version: String
|
||||
) {
|
||||
val request = Rpc.Metrics.SetParameters.Request(
|
||||
platform = platform,
|
||||
version = version
|
||||
)
|
||||
if (BuildConfig.DEBUG) logRequest(request)
|
||||
val response = service.metricsSetParameters(request)
|
||||
if (BuildConfig.DEBUG) logResponse(response)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun walletConvert(entropy: String): String {
|
||||
val request = Rpc.Wallet.Convert.Request(entropy = entropy)
|
||||
|
|
|
@ -9,6 +9,9 @@ interface MiddlewareService {
|
|||
|
||||
//region APP commands
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun metricsSetParameters(request: Rpc.Metrics.SetParameters.Request): Rpc.Metrics.SetParameters.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun versionGet(request: Rpc.App.GetVersion.Request): Rpc.App.GetVersion.Response
|
||||
|
||||
|
|
|
@ -1151,6 +1151,17 @@ class MiddlewareServiceImplementation @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun metricsSetParameters(request: Rpc.Metrics.SetParameters.Request): Rpc.Metrics.SetParameters.Response {
|
||||
val encoded = Service.metricsSetParameters(Rpc.Metrics.SetParameters.Request.ADAPTER.encode(request))
|
||||
val response = Rpc.Metrics.SetParameters.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.Metrics.SetParameters.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun walletConvert(request: Rpc.Wallet.Convert.Request): Rpc.Wallet.Convert.Response {
|
||||
val encoded = Service.walletConvert(Rpc.Wallet.Convert.Request.ADAPTER.encode(request))
|
||||
val response = Rpc.Wallet.Convert.Response.ADAPTER.decode(encoded)
|
||||
|
|
|
@ -9,7 +9,7 @@ interface BuildProvider {
|
|||
fun isDebug(): Boolean
|
||||
}
|
||||
|
||||
class DefaultBuildProvider() : BuildProvider {
|
||||
class DefaultBuildProvider : BuildProvider {
|
||||
override fun getManufacturer(): String {
|
||||
return Build.MANUFACTURER
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue