From 9a4b9d769948b213607da48ae26ff6da25082460 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 14:46:47 +0300 Subject: [PATCH 01/18] add connection service --- components/bridge/connection/service/impl/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/bridge/connection/service/impl/build.gradle.kts b/components/bridge/connection/service/impl/build.gradle.kts index 139257ef32..319af6e5ad 100644 --- a/components/bridge/connection/service/impl/build.gradle.kts +++ b/components/bridge/connection/service/impl/build.gradle.kts @@ -10,10 +10,12 @@ commonDependencies { implementation(projects.components.core.ktx) implementation(projects.components.core.log) implementation(projects.components.core.di) + implementation(projects.components.core.ui.lifecycle) implementation(projects.components.bridge.connection.service.api) implementation(projects.components.bridge.connection.orchestrator.api) implementation(projects.components.bridge.connection.config.api) + implementation(libs.decompose) implementation(libs.kotlin.coroutines) } From 8c66441d5a97bff57b9eacbde737bbc8c84860f0 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 14:51:20 +0300 Subject: [PATCH 02/18] remove unused deps --- components/bridge/connection/service/impl/build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/bridge/connection/service/impl/build.gradle.kts b/components/bridge/connection/service/impl/build.gradle.kts index 319af6e5ad..139257ef32 100644 --- a/components/bridge/connection/service/impl/build.gradle.kts +++ b/components/bridge/connection/service/impl/build.gradle.kts @@ -10,12 +10,10 @@ commonDependencies { implementation(projects.components.core.ktx) implementation(projects.components.core.log) implementation(projects.components.core.di) - implementation(projects.components.core.ui.lifecycle) implementation(projects.components.bridge.connection.service.api) implementation(projects.components.bridge.connection.orchestrator.api) implementation(projects.components.bridge.connection.config.api) - implementation(libs.decompose) implementation(libs.kotlin.coroutines) } From 5b7de017162101f4ccbc4a2f18263c22f26c9953 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 17:21:58 +0300 Subject: [PATCH 03/18] add color, alarm features --- .../device/fzero/impl/build.gradle.kts | 2 + .../utils/FZeroFeatureClassToEnumMapper.kt | 4 ++ .../feature/alarm/api/build.gradle.kts | 18 +++++ .../feature/alarm/api/FAlarmFeatureApi.kt | 7 ++ .../feature/alarm/impl/build.gradle.kts | 25 +++++++ .../alarm/impl/api/FAlarmFeatureApiImpl.kt | 49 ++++++++++++++ .../impl/api/FAlarmFeatureFactoryImpl.kt | 30 +++++++++ .../feature/common/api/FDeviceFeature.kt | 4 +- .../feature/device-color/api/build.gradle.kts | 19 ++++++ .../devicecolor/api/FDeviceColorFeatureApi.kt | 13 ++++ .../device-color/impl/build.gradle.kts | 26 ++++++++ .../impl/api/FDeviceColorFeatureApiImpl.kt | 52 +++++++++++++++ .../api/FDeviceColorFeatureFactoryImpl.kt | 29 +++++++++ .../service/api/FConnectionService.kt | 5 ++ .../service/impl/FConnectionServiceImpl.kt | 16 +++-- components/info/impl/build.gradle.kts | 13 +++- .../api/UpdateScreenDecomposeComponent.kt | 1 + .../ComposableConnectedDeviceActionCard.kt | 3 +- .../screens/ComposableDeviceInfoScreen.kt | 4 +- .../info/impl/viewmodel/AlarmViewModel.kt | 33 +++++----- .../info/impl/viewmodel/ConnectViewModel.kt | 28 ++++---- .../impl/viewmodel/FlipperColorViewModel.kt | 65 ++++++------------- instances/android/app/build.gradle.kts | 4 ++ settings.gradle.kts | 4 ++ 24 files changed, 368 insertions(+), 86 deletions(-) create mode 100644 components/bridge/connection/feature/alarm/api/build.gradle.kts create mode 100644 components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt create mode 100644 components/bridge/connection/feature/alarm/impl/build.gradle.kts create mode 100644 components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt create mode 100644 components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt create mode 100644 components/bridge/connection/feature/device-color/api/build.gradle.kts create mode 100644 components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt create mode 100644 components/bridge/connection/feature/device-color/impl/build.gradle.kts create mode 100644 components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt create mode 100644 components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt diff --git a/components/bridge/connection/device/fzero/impl/build.gradle.kts b/components/bridge/connection/device/fzero/impl/build.gradle.kts index ffb56865bb..662db55269 100644 --- a/components/bridge/connection/device/fzero/impl/build.gradle.kts +++ b/components/bridge/connection/device/fzero/impl/build.gradle.kts @@ -26,6 +26,8 @@ commonDependencies { implementation(projects.components.bridge.connection.feature.storage.api) implementation(projects.components.bridge.connection.feature.storageinfo.api) implementation(projects.components.bridge.connection.feature.getinfo.api) + implementation(projects.components.bridge.connection.feature.alarm.api) + implementation(projects.components.bridge.connection.feature.deviceColor.api) implementation(libs.kotlin.coroutines) implementation(libs.kotlin.immutable.collections) diff --git a/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt b/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt index b2ae40edb8..8df0a2cbdc 100644 --- a/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt +++ b/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt @@ -1,7 +1,9 @@ package com.flipperdevices.bridge.connection.device.fzero.impl.utils +import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.feature.restartrpc.api.FRestartRpcFeatureApi @@ -30,6 +32,8 @@ object FZeroFeatureClassToEnumMapper { FDeviceFeature.STORAGE_INFO -> FStorageInfoFeatureApi::class FDeviceFeature.GET_INFO -> FGetInfoFeatureApi::class FDeviceFeature.STORAGE -> FStorageFeatureApi::class + FDeviceFeature.ALARM -> FAlarmFeatureApi::class + FDeviceFeature.DEVICE_COLOR -> FDeviceColorFeatureApi::class } } diff --git a/components/bridge/connection/feature/alarm/api/build.gradle.kts b/components/bridge/connection/feature/alarm/api/build.gradle.kts new file mode 100644 index 0000000000..46e51ce0ed --- /dev/null +++ b/components/bridge/connection/feature/alarm/api/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + id("flipper.multiplatform") + id("flipper.multiplatform-dependencies") +} + +android.namespace = "com.flipperdevices.bridge.connection.feature.alarm.api" + +commonDependencies { + implementation(projects.components.core.data) + implementation(projects.components.core.ktx) + + implementation(projects.components.bridge.connection.feature.common.api) + implementation(projects.components.bridge.connection.transport.common.api) + implementation(projects.components.bridge.connection.feature.rpcinfo.api) + + implementation(libs.kotlin.immutable.collections) + implementation(libs.kotlin.coroutines) +} diff --git a/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt b/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt new file mode 100644 index 0000000000..051c1a61b2 --- /dev/null +++ b/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt @@ -0,0 +1,7 @@ +package com.flipperdevices.bridge.connection.feature.alarm.api + +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi + +interface FAlarmFeatureApi: FDeviceFeatureApi { + suspend fun makeSound() +} \ No newline at end of file diff --git a/components/bridge/connection/feature/alarm/impl/build.gradle.kts b/components/bridge/connection/feature/alarm/impl/build.gradle.kts new file mode 100644 index 0000000000..c9b95cdd67 --- /dev/null +++ b/components/bridge/connection/feature/alarm/impl/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + id("flipper.multiplatform") + id("flipper.multiplatform-dependencies") + id("flipper.anvil-multiplatform") +} + +android.namespace = "com.flipperdevices.bridge.connection.feature.alarm.impl" + +commonDependencies { + implementation(projects.components.bridge.connection.feature.alarm.api) + + implementation(projects.components.core.di) + implementation(projects.components.core.log) + implementation(projects.components.core.ktx) + + implementation(projects.components.bridge.connection.feature.common.api) + implementation(projects.components.bridge.connection.transport.common.api) + implementation(projects.components.bridge.connection.feature.rpc.api) + implementation(projects.components.bridge.connection.feature.rpc.model) + implementation(projects.components.bridge.connection.feature.rpcinfo.api) + + implementation(projects.components.bridge.connection.pbutils) + + implementation(libs.kotlin.coroutines) +} diff --git a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt new file mode 100644 index 0000000000..850b46ae85 --- /dev/null +++ b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt @@ -0,0 +1,49 @@ +package com.flipperdevices.bridge.connection.feature.alarm.impl.api + +import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus +import com.flipperdevices.core.ktx.jre.toThrowableFlow +import com.flipperdevices.core.ktx.jre.withLock +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.info +import com.flipperdevices.protobuf.Main +import com.flipperdevices.protobuf.storage.InfoRequest +import com.flipperdevices.protobuf.system.PlayAudiovisualAlertRequest +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancelAndJoin +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock + +class FAlarmFeatureApiImpl @AssistedInject constructor( + @Assisted private val rpcFeatureApi: FRpcFeatureApi, +) : FAlarmFeatureApi, + LogTagProvider { + override val TAG = "FAlarmFeatureApi" + + + override suspend fun makeSound() { + rpcFeatureApi.requestWithoutAnswer( + Main( + system_play_audiovisual_alert_request = PlayAudiovisualAlertRequest() + ).wrapToRequest() + ) + } + + @AssistedFactory + fun interface InternalFactory { + operator fun invoke( + rpcFeatureApi: FRpcFeatureApi, + ): FAlarmFeatureApiImpl + } +} \ No newline at end of file diff --git a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt new file mode 100644 index 0000000000..0e1198c64d --- /dev/null +++ b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt @@ -0,0 +1,30 @@ +package com.flipperdevices.bridge.connection.feature.alarm.impl.api + +import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier +import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi +import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi +import com.flipperdevices.core.di.AppGraph +import com.squareup.anvil.annotations.ContributesMultibinding +import kotlinx.coroutines.CoroutineScope +import javax.inject.Inject + +@FDeviceFeatureQualifier(FDeviceFeature.ALARM) +@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) +class FAlarmFeatureFactoryImpl @Inject constructor( + private val factory: FAlarmFeatureApiImpl.InternalFactory +) : FDeviceFeatureApi.Factory { + override suspend fun invoke( + unsafeFeatureDeviceApi: FUnsafeDeviceFeatureApi, + scope: CoroutineScope, + connectedDevice: FConnectedDeviceApi + ): FDeviceFeatureApi? { + val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null + return factory( + rpcFeatureApi = rpcApi, + ) + } +} diff --git a/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt b/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt index a300622913..ecb2c3381a 100644 --- a/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt +++ b/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt @@ -11,7 +11,9 @@ enum class FDeviceFeature { RPC_INFO, STORAGE, STORAGE_INFO, - GET_INFO + GET_INFO, + ALARM, + DEVICE_COLOR } @Retention(AnnotationRetention.RUNTIME) diff --git a/components/bridge/connection/feature/device-color/api/build.gradle.kts b/components/bridge/connection/feature/device-color/api/build.gradle.kts new file mode 100644 index 0000000000..96a6834200 --- /dev/null +++ b/components/bridge/connection/feature/device-color/api/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("flipper.multiplatform") + id("flipper.multiplatform-dependencies") +} + +android.namespace = "com.flipperdevices.bridge.connection.feature.devicecolor.api" + +commonDependencies { + implementation(projects.components.core.data) + implementation(projects.components.core.ktx) + implementation(projects.components.core.preference) + + implementation(projects.components.bridge.connection.feature.common.api) + implementation(projects.components.bridge.connection.transport.common.api) + implementation(projects.components.bridge.connection.feature.rpcinfo.api) + + implementation(libs.kotlin.immutable.collections) + implementation(libs.kotlin.coroutines) +} diff --git a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt new file mode 100644 index 0000000000..41e7484bed --- /dev/null +++ b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt @@ -0,0 +1,13 @@ +package com.flipperdevices.bridge.connection.feature.devicecolor.api + +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.core.preference.pb.HardwareColor +import kotlinx.coroutines.flow.Flow + +interface FDeviceColorFeatureApi : FDeviceFeatureApi { + /** + * Returns flipper case color + * @param default default value on response failure + */ + fun getColor(default: HardwareColor = HardwareColor.WHITE): Flow +} \ No newline at end of file diff --git a/components/bridge/connection/feature/device-color/impl/build.gradle.kts b/components/bridge/connection/feature/device-color/impl/build.gradle.kts new file mode 100644 index 0000000000..3d54d6f649 --- /dev/null +++ b/components/bridge/connection/feature/device-color/impl/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("flipper.multiplatform") + id("flipper.multiplatform-dependencies") + id("flipper.anvil-multiplatform") +} + +android.namespace = "com.flipperdevices.bridge.connection.feature.devicecolor.impl" + +commonDependencies { + implementation(projects.components.bridge.connection.feature.deviceColor.api) + + implementation(projects.components.core.di) + implementation(projects.components.core.log) + implementation(projects.components.core.ktx) + implementation(projects.components.core.preference) + + implementation(projects.components.bridge.connection.feature.common.api) + implementation(projects.components.bridge.connection.transport.common.api) + implementation(projects.components.bridge.connection.feature.rpc.api) + implementation(projects.components.bridge.connection.feature.rpc.model) + implementation(projects.components.bridge.connection.feature.rpcinfo.api) + + implementation(projects.components.bridge.connection.pbutils) + + implementation(libs.kotlin.coroutines) +} diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt new file mode 100644 index 0000000000..f090abb748 --- /dev/null +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -0,0 +1,52 @@ +package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api + +import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.preference.pb.HardwareColor +import com.flipperdevices.protobuf.Main +import com.flipperdevices.protobuf.property.GetRequest +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +class FDeviceColorFeatureApiImpl @AssistedInject constructor( + @Assisted private val rpcFeatureApi: FRpcFeatureApi, +) : FDeviceColorFeatureApi, + LogTagProvider { + override val TAG = "FDeviceColorFeatureApi" + + override fun getColor(default: HardwareColor): Flow { + return rpcFeatureApi.request( + Main( + property_get_request = GetRequest( + key = RPC_KEY_HARDWARE_COLOR + ) + ).wrapToRequest() + ).map { result -> + val intValue = result.getOrNull() + ?.property_get_response + ?.value_ + ?.toIntOrNull() + when (intValue) { + HardwareColor.WHITE.value -> HardwareColor.WHITE + HardwareColor.BLACK.value -> HardwareColor.BLACK + else -> default + } + } + } + + @AssistedFactory + fun interface InternalFactory { + operator fun invoke( + rpcFeatureApi: FRpcFeatureApi, + ): FDeviceColorFeatureApiImpl + } + + companion object { + private const val RPC_KEY_HARDWARE_COLOR = "hardware.color" + } +} \ No newline at end of file diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt new file mode 100644 index 0000000000..040ba59ae5 --- /dev/null +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt @@ -0,0 +1,29 @@ +package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api + +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier +import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi +import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi +import com.flipperdevices.core.di.AppGraph +import com.squareup.anvil.annotations.ContributesMultibinding +import kotlinx.coroutines.CoroutineScope +import javax.inject.Inject + +@FDeviceFeatureQualifier(FDeviceFeature.DEVICE_COLOR) +@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) +class FDeviceColorFeatureFactoryImpl @Inject constructor( + private val factory: FDeviceColorFeatureApiImpl.InternalFactory +) : FDeviceFeatureApi.Factory { + override suspend fun invoke( + unsafeFeatureDeviceApi: FUnsafeDeviceFeatureApi, + scope: CoroutineScope, + connectedDevice: FConnectedDeviceApi + ): FDeviceFeatureApi? { + val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null + return factory( + rpcFeatureApi = rpcApi, + ) + } +} diff --git a/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt b/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt index 45ef23b5c7..c8dde0148e 100644 --- a/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt +++ b/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt @@ -19,4 +19,9 @@ interface FConnectionService { * @param force if true, will not reconnect until [forceReconnect] */ fun disconnect(force: Boolean = false) + + /** + * Forget current device and disconnect from it as side effect + */ + fun forgetCurrentDevice() } \ No newline at end of file diff --git a/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt b/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt index 99bea6d2cc..57f97176ae 100644 --- a/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt +++ b/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt @@ -7,17 +7,13 @@ import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.ktx.jre.FlipperDispatchers import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.log.warn -import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.squareup.anvil.annotations.ContributesBinding import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -70,4 +66,14 @@ class FConnectionServiceImpl @Inject constructor( orchestrator.disconnectCurrent() } } + + override fun forgetCurrentDevice() { + scope.launch { + fDevicePersistedStorage.getCurrentDevice() + .first() + ?.let { currentDevice -> + fDevicePersistedStorage.removeDevice(currentDevice.uniqueId) + } + } + } } \ No newline at end of file diff --git a/components/info/impl/build.gradle.kts b/components/info/impl/build.gradle.kts index d01a68f01b..a0f880d4b0 100644 --- a/components/info/impl/build.gradle.kts +++ b/components/info/impl/build.gradle.kts @@ -36,8 +36,19 @@ dependencies { implementation(projects.components.rootscreen.api) implementation(projects.components.analytics.metric.api) - implementation(projects.components.bridge.api) implementation(projects.components.bridge.synchronization.api) + implementation(projects.components.bridge.connection.service.api) + implementation(projects.components.bridge.connection.orchestrator.api) + implementation(projects.components.bridge.connection.config.api) + implementation(projects.components.bridge.connection.service.api) + implementation(projects.components.bridge.connection.feature.common.api) + implementation(projects.components.bridge.connection.feature.provider.api) + implementation(projects.components.bridge.connection.feature.getinfo.api) + implementation(projects.components.bridge.connection.feature.storageinfo.api) + implementation(projects.components.bridge.connection.feature.alarm.api) + implementation(projects.components.bridge.connection.feature.deviceColor.api) + + implementation(projects.components.bridge.api) implementation(projects.components.bridge.service.api) implementation(projects.components.bridge.pbutils) implementation(projects.components.bridge.rpcinfo.api) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt index 443e985fe8..6bee24fdf9 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt @@ -102,6 +102,7 @@ class UpdateScreenDecomposeComponent @AssistedInject constructor( hardwareColor = flipperColor, supportedState = supportState, updateState = updateState, + hasAlarm = alarmViewModel.hasAlarm.collectAsState().value, alarmOnFlipper = alarmViewModel::alarmOnFlipper, deviceInfo = basicInfo, scrollState = scrollState, diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt index b17b6ce410..167f96891f 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt @@ -18,6 +18,7 @@ fun ComposableConnectedDeviceActionCard( supportedState: FlipperSupportedState, requestSynchronize: () -> Unit, alarmOnFlipper: () -> Unit, + hasAlarm: Boolean, modifier: Modifier = Modifier, ) { if (deviceStatus is DeviceStatus.NoDevice) { @@ -34,7 +35,7 @@ fun ComposableConnectedDeviceActionCard( ) ComposableInfoDivider() ComposableAlarmElement( - enabled = enabled, + enabled = hasAlarm && enabled, alarmOnFlipper = alarmOnFlipper ) } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt index b99ac18c97..da87098177 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt @@ -49,6 +49,7 @@ fun ComposableDeviceInfoScreen( deviceInfo: FlipperBasicInfo, onOpenFullDeviceInfo: () -> Unit, onOpenOptions: () -> Unit, + hasAlarm: Boolean, alarmOnFlipper: () -> Unit, onOpenRemoteControl: () -> Unit, onStartUpdateRequest: (UpdateRequest) -> Unit, @@ -107,7 +108,8 @@ fun ComposableDeviceInfoScreen( deviceStatus = deviceStatus, supportedState = supportedState, requestSynchronize = connectViewModel::requestSynchronize, - alarmOnFlipper = alarmOnFlipper + alarmOnFlipper = alarmOnFlipper, + hasAlarm = hasAlarm ) ComposablePairDeviceActionCard( modifier = Modifier.padding(top = 14.dp, bottom = 14.dp), diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/AlarmViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/AlarmViewModel.kt index 8cb747f6b2..abd22587af 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/AlarmViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/AlarmViewModel.kt @@ -1,30 +1,27 @@ package com.flipperdevices.info.impl.viewmodel -import com.flipperdevices.bridge.api.model.wrapToRequest -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider +import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get +import com.flipperdevices.bridge.connection.feature.provider.api.getSync import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel -import com.flipperdevices.protobuf.main -import com.flipperdevices.protobuf.system.playAudiovisualAlertRequest +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import javax.inject.Inject class AlarmViewModel @Inject constructor( - private val serviceProvider: FlipperServiceProvider + private val featureProvider: FFeatureProvider ) : DecomposeViewModel() { + val hasAlarm = featureProvider.get() + .map { status -> status is FFeatureStatus.Supported } + .stateIn(viewModelScope, SharingStarted.Eagerly, false) + fun alarmOnFlipper() { - serviceProvider.provideServiceApi(this) { serviceApi -> - viewModelScope.launch { - alarmOnFlipperInternal(serviceApi) - } + viewModelScope.launch { + featureProvider.getSync()?.makeSound() } } - - private suspend fun alarmOnFlipperInternal(serviceApi: FlipperServiceApi) { - serviceApi.requestApi.requestWithoutAnswer( - main { - systemPlayAudiovisualAlertRequest = playAudiovisualAlertRequest { } - }.wrapToRequest() - ) - } } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt index 1fbd6dd701..e53e3b49b2 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt @@ -1,21 +1,24 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider +import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage +import com.flipperdevices.bridge.connection.orchestrator.api.FDeviceOrchestrator +import com.flipperdevices.bridge.connection.service.api.FConnectionService import com.flipperdevices.bridge.synchronization.api.SynchronizationApi import com.flipperdevices.core.preference.pb.PairSettings import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.info.impl.model.ConnectRequestState import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject class ConnectViewModel @Inject constructor( - private val serviceProvider: FlipperServiceProvider, private val synchronizationApi: SynchronizationApi, - private val dataStoreFirstPair: DataStore + private val dataStoreFirstPair: DataStore, + private val fConnectionService: FConnectionService ) : DecomposeViewModel() { private val connectRequestState = MutableStateFlow( ConnectRequestState.NOT_REQUESTED @@ -27,21 +30,17 @@ class ConnectViewModel @Inject constructor( return } connectRequestState.update { ConnectRequestState.CONNECTING_AND_SYNCHRONIZING } - serviceProvider.provideServiceApi(this) { - viewModelScope.launch { - it.reconnect() - synchronizationApi.startSynchronization(force = true) - connectRequestState.update { ConnectRequestState.NOT_REQUESTED } - alreadyRequestConnect.compareAndSet(true, false) - } + viewModelScope.launch { + fConnectionService.forceReconnect() + synchronizationApi.startSynchronization(force = true) + connectRequestState.update { ConnectRequestState.NOT_REQUESTED } + alreadyRequestConnect.compareAndSet(true, false) } } fun onDisconnect() { - serviceProvider.provideServiceApi(this) { - viewModelScope.launch { - it.disconnect() - } + viewModelScope.launch { + fConnectionService.disconnect(true) } } @@ -51,6 +50,7 @@ class ConnectViewModel @Inject constructor( fun forgetFlipper() { viewModelScope.launch { + fConnectionService.forgetCurrentDevice() dataStoreFirstPair.updateData { it.copy( device_name = "", diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt index 450cd6162a..b891a6668e 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt @@ -1,66 +1,41 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.api.model.FlipperRequestPriority -import com.flipperdevices.bridge.api.model.wrapToRequest -import com.flipperdevices.bridge.api.utils.Constants -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer +import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get import com.flipperdevices.core.preference.pb.HardwareColor import com.flipperdevices.core.preference.pb.PairSettings import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel -import com.flipperdevices.protobuf.main -import com.flipperdevices.protobuf.property.getRequest import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.launch import javax.inject.Inject -private const val RPC_KEY_HARDWARE_COLOR = "hardware.color" - class FlipperColorViewModel @Inject constructor( - private val settings: DataStore -) : DecomposeViewModel(), FlipperBleServiceConsumer { - private val colorFlipperState = MutableStateFlow(HardwareColor.fromValue(-1)) + private val settings: DataStore, + fFeatureProvider: FFeatureProvider +) : DecomposeViewModel() { + private val colorFlipperState = MutableStateFlow(HardwareColor.fromValue(-1)) + + fun getFlipperColor(): StateFlow = colorFlipperState init { settings.data.onEach { colorFlipperState.emit(it.hardware_color) }.launchIn(viewModelScope) - } - - fun getFlipperColor(): StateFlow = colorFlipperState - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - viewModelScope.launch { - if (!serviceApi.flipperVersionApi.isSupported(Constants.API_SUPPORTED_GET_REQUEST)) { - return@launch - } - val response = serviceApi.requestApi.request( - flowOf( - main { - propertyGetRequest = getRequest { - key = RPC_KEY_HARDWARE_COLOR - } - }.wrapToRequest(FlipperRequestPriority.BACKGROUND) - ) - ) - if (response.hasPropertyGetResponse().not()) { - return@launch - } - val hardwareColor = when (response.propertyGetResponse.value.toIntOrNull()) { - HardwareColor.WHITE.value -> HardwareColor.WHITE - HardwareColor.BLACK.value -> HardwareColor.BLACK - else -> HardwareColor.WHITE - } - settings.updateData { - it.copy( - hardware_color = hardwareColor - ) - } - } + fFeatureProvider.get() + .filterIsInstance>() + .flatMapLatest { status -> status.featureApi.getColor() } + .onEach { hardwareColor -> + settings.updateData { data -> + data.copy(hardware_color = hardwareColor) + } + }.launchIn(viewModelScope) } } diff --git a/instances/android/app/build.gradle.kts b/instances/android/app/build.gradle.kts index f2a3fdf428..82f582ccbd 100644 --- a/instances/android/app/build.gradle.kts +++ b/instances/android/app/build.gradle.kts @@ -184,6 +184,10 @@ dependencies { implementation(projects.components.bridge.connection.feature.storage.impl) implementation(projects.components.bridge.connection.feature.storageinfo.api) implementation(projects.components.bridge.connection.feature.storageinfo.impl) + implementation(projects.components.bridge.connection.feature.alarm.api) + implementation(projects.components.bridge.connection.feature.alarm.impl) + implementation(projects.components.bridge.connection.feature.deviceColor.api) + implementation(projects.components.bridge.connection.feature.deviceColor.impl) implementation(projects.components.analytics.shake2report.api) if (IS_SENTRY_ENABLED) { diff --git a/settings.gradle.kts b/settings.gradle.kts index 94626a3631..9239ebf125 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -87,6 +87,10 @@ include( ":components:bridge:connection:feature:actionnotifier:api", ":components:bridge:connection:feature:serialspeed:api", ":components:bridge:connection:feature:serialspeed:impl", + ":components:bridge:connection:feature:alarm:api", + ":components:bridge:connection:feature:alarm:impl", + ":components:bridge:connection:feature:device-color:api", + ":components:bridge:connection:feature:device-color:impl", ":components:filemngr:util", ":components:filemanager:api", From d17f514f188d624fbd8fe3e22618f076ee557bf8 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 17:28:29 +0300 Subject: [PATCH 04/18] firmware update --- components/info/impl/build.gradle.kts | 9 ++-- .../impl/viewmodel/FirmwareUpdateViewModel.kt | 52 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/components/info/impl/build.gradle.kts b/components/info/impl/build.gradle.kts index a0f880d4b0..e3776869f1 100644 --- a/components/info/impl/build.gradle.kts +++ b/components/info/impl/build.gradle.kts @@ -47,11 +47,12 @@ dependencies { implementation(projects.components.bridge.connection.feature.storageinfo.api) implementation(projects.components.bridge.connection.feature.alarm.api) implementation(projects.components.bridge.connection.feature.deviceColor.api) + implementation(projects.components.bridge.connection.feature.protocolversion.api) - implementation(projects.components.bridge.api) - implementation(projects.components.bridge.service.api) - implementation(projects.components.bridge.pbutils) - implementation(projects.components.bridge.rpcinfo.api) +// implementation(projects.components.bridge.api) +// implementation(projects.components.bridge.service.api) +// implementation(projects.components.bridge.pbutils) +// implementation(projects.components.bridge.rpcinfo.api) // Core deps implementation(libs.ktx) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt index 91e762c0cc..9e1036178e 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt @@ -1,40 +1,38 @@ package com.flipperdevices.info.impl.viewmodel -import com.flipperdevices.bridge.api.manager.ktx.state.ConnectionState -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider +import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi +import com.flipperdevices.bridge.connection.feature.protocolversion.model.FlipperSupportedState +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get import com.flipperdevices.core.log.LogTagProvider -import com.flipperdevices.core.log.info import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel -import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import javax.inject.Inject class FirmwareUpdateViewModel @Inject constructor( - serviceProvider: FlipperServiceProvider -) : DecomposeViewModel(), FlipperBleServiceConsumer, LogTagProvider { + private val fFeatureProvider: FFeatureProvider +) : DecomposeViewModel(), LogTagProvider { override val TAG = "FirmwareUpdateViewModel" - private val connectionState = MutableStateFlow( - FlipperSupportedState.READY - ) - - init { - serviceProvider.provideServiceApi(consumer = this, lifecycleOwner = this) - } - - fun getState(): StateFlow = connectionState - - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - serviceApi.connectionInformationApi.getConnectionStateFlow().onEach { - info { "Receive connection state: $it" } - if (it is ConnectionState.Ready) { - connectionState.emit(it.supportedState) + fun getState(): StateFlow { + return fFeatureProvider.get().flatMapLatest { status -> + when (status) { + FFeatureStatus.NotFound -> flowOf(FlipperSupportedState.DEPRECATED_FLIPPER) + FFeatureStatus.Unsupported -> flowOf(FlipperSupportedState.DEPRECATED_FLIPPER) + FFeatureStatus.Retrieving -> flowOf(FlipperSupportedState.READY) + is FFeatureStatus.Supported -> { + status.featureApi + .getSupportedStateFlow() + .map { state -> state ?: FlipperSupportedState.DEPRECATED_FLIPPER } + } } - }.launchIn(viewModelScope) + }.stateIn(viewModelScope, SharingStarted.Eagerly, FlipperSupportedState.READY) } + } From c744b04a0cdec16f9972af2e5e20a242007cdd37 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 19:23:57 +0300 Subject: [PATCH 05/18] fix characteristic collect --- .../ble/impl/meta/FTransportMetaInfoApiImpl.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt b/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt index 11730426bc..7f0d7dfc32 100644 --- a/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt +++ b/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt @@ -10,9 +10,13 @@ import com.flipperdevices.core.log.warn import kotlinx.collections.immutable.ImmutableMap import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.merge +import kotlinx.coroutines.flow.onEach import no.nordicsemi.android.kotlin.ble.client.main.callback.ClientBleGatt import no.nordicsemi.android.kotlin.ble.client.main.service.ClientBleGattServices import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty @@ -57,6 +61,10 @@ class FTransportMetaInfoApiImpl( return flowOf(characteristic.read().value) } info { "Subscribe on $address characteristic" } - return characteristic.getNotifications().map { it.value } + // Don't block one flow by another + return listOf( + flow { emit(characteristic.read().value) }, + characteristic.getNotifications().map { it.value } + ).merge() } } From 526f49a926de629f9b00b2e7035d8d6aebceae5b Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 19:24:54 +0300 Subject: [PATCH 06/18] add fgattinformation to new api --- .../feature/getinfo/api/FGetInfoFeatureApi.kt | 4 + .../feature/getinfo/model/FGattInformation.kt | 8 ++ .../impl/api/FGetInfoFeatureApiImpl.kt | 91 ++++++++++++++++- .../impl/api/FGetInfoFeatureFactoryImpl.kt | 6 +- components/info/impl/build.gradle.kts | 8 +- .../ComposableConnectedDeviceActionCard.kt | 2 +- .../elements/ComposableFirmwareUnsupported.kt | 2 +- .../impl/compose/info/ComposableInfoCard.kt | 2 +- .../screens/ComposableDeviceInfoScreen.kt | 2 +- .../impl/viewmodel/DeviceStatusViewModel.kt | 98 ++++++++++--------- 10 files changed, 167 insertions(+), 56 deletions(-) create mode 100644 components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt index 7a39f7a3de..62325eccea 100644 --- a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt @@ -1,12 +1,16 @@ package com.flipperdevices.bridge.connection.feature.getinfo.api import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiGroup import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow interface FGetInfoFeatureApi : FDeviceFeatureApi { suspend fun get(property: FGetInfoApiProperty): Result fun get(group: FGetInfoApiGroup): Flow> + + fun getGattInfoFlow(): MutableStateFlow } diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt new file mode 100644 index 0000000000..316fb850ef --- /dev/null +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt @@ -0,0 +1,8 @@ +package com.flipperdevices.bridge.connection.feature.getinfo.model + +data class FGattInformation( + val deviceName: String? = null, + val manufacturerName: String? = null, + val batteryLevel: Float? = null, + val isCharging: Boolean = false +) \ No newline at end of file diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt index 6d4412f4fa..ea61e649d8 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt @@ -2,22 +2,42 @@ package com.flipperdevices.bridge.connection.feature.getinfo.impl.api import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.impl.mapper.FGetInfoApiKeyMapper +import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiGroup import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest +import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi +import com.flipperdevices.bridge.connection.transport.common.api.meta.TransportMetaInfoKey +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.error +import com.flipperdevices.core.log.info import com.flipperdevices.protobuf.Main import com.flipperdevices.protobuf.property.GetRequest import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update +import kotlin.experimental.and class FGetInfoFeatureApiImpl @AssistedInject constructor( - @Assisted private val rpcFeatureApi: FRpcFeatureApi -) : FGetInfoFeatureApi { + @Assisted private val rpcFeatureApi: FRpcFeatureApi, + @Assisted private val metaInfoApi: FTransportMetaInfoApi, + @Assisted private val scope: CoroutineScope, +) : FGetInfoFeatureApi, LogTagProvider { + override val TAG: String = "FGetInfoFeatureApi" private val mapper = FGetInfoApiKeyMapper() override suspend fun get( @@ -38,10 +58,75 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor( .map { mapper.map(group, it.key) to it.value_ } } + private val gattInfo = MutableStateFlow(FGattInformation()) + + override fun getGattInfoFlow(): MutableStateFlow = gattInfo + + private fun collectGattInfo() { + listOf( + TransportMetaInfoKey.DEVICE_NAME, + TransportMetaInfoKey.MANUFACTURER, + TransportMetaInfoKey.BATTERY_LEVEL, + TransportMetaInfoKey.BATTERY_POWER_STATE + ).forEach { key -> + val flow = metaInfoApi.get(key) + .onFailure { error(it) { "#collectGattInfo could not find flow for key $key" } } + .getOrNull() + (flow ?: emptyFlow()) + .filterNotNull() + .onEach { byteArray -> + info { "#collectGattInfo array for $key ${byteArray.toList()}" } + gattInfo.update { state -> + when (key) { + TransportMetaInfoKey.DEVICE_NAME -> { + state.copy(deviceName = String(byteArray)) + } + + TransportMetaInfoKey.MANUFACTURER -> { + state.copy(manufacturerName = String(byteArray)) + } + + TransportMetaInfoKey.BATTERY_LEVEL -> { + state.copy( + batteryLevel = byteArray.firstOrNull() + ?.toFloat() + ?.div(MAX_BATTERY_LEVEL) + ?.coerceIn(0f, 1f) + ) + } + + TransportMetaInfoKey.BATTERY_POWER_STATE -> { + state.copy( + isCharging = byteArray.firstOrNull() + ?.and(BATTERY_POWER_STATE_MASK) + ?.equals(BATTERY_POWER_STATE_MASK) + ?: false + ) + } + + else -> state + } + + } + }.launchIn(scope) + } + } + + init { + collectGattInfo() + } + @AssistedFactory fun interface InternalFactory { operator fun invoke( - rpcFeatureApi: FRpcFeatureApi + rpcFeatureApi: FRpcFeatureApi, + metaInfoApi: FTransportMetaInfoApi, + scope: CoroutineScope, ): FGetInfoFeatureApiImpl } + + companion object { + private const val MAX_BATTERY_LEVEL = 100 + const val BATTERY_POWER_STATE_MASK: Byte = 0b0011_0000 + } } diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt index 814d2f085f..cdcb681807 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt @@ -7,6 +7,7 @@ import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeat import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi +import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi import com.flipperdevices.core.data.SemVer import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.log.LogTagProvider @@ -43,9 +44,12 @@ class FGetInfoFeatureFactoryImpl @Inject constructor( info { "Version $API_SUPPORTED_GET_REQUEST supported, so continue building FGetInfoFeatureApi" } val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null + val metaInfoApi = connectedDevice as? FTransportMetaInfoApi ?: return null return factory( - rpcApi + rpcFeatureApi = rpcApi, + metaInfoApi = metaInfoApi, + scope = scope ) } } diff --git a/components/info/impl/build.gradle.kts b/components/info/impl/build.gradle.kts index e3776869f1..4f01580dd3 100644 --- a/components/info/impl/build.gradle.kts +++ b/components/info/impl/build.gradle.kts @@ -49,10 +49,10 @@ dependencies { implementation(projects.components.bridge.connection.feature.deviceColor.api) implementation(projects.components.bridge.connection.feature.protocolversion.api) -// implementation(projects.components.bridge.api) -// implementation(projects.components.bridge.service.api) -// implementation(projects.components.bridge.pbutils) -// implementation(projects.components.bridge.rpcinfo.api) + implementation(projects.components.bridge.api) + implementation(projects.components.bridge.service.api) + implementation(projects.components.bridge.pbutils) + implementation(projects.components.bridge.rpcinfo.api) // Core deps implementation(libs.ktx) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt index 167f96891f..8c32931882 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableConnectedDeviceActionCard.kt @@ -3,7 +3,7 @@ package com.flipperdevices.info.impl.compose.elements import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState +import com.flipperdevices.bridge.connection.feature.protocolversion.model.FlipperSupportedState import com.flipperdevices.core.ui.theme.LocalPallet import com.flipperdevices.info.impl.R import com.flipperdevices.info.impl.model.DeviceStatus diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableFirmwareUnsupported.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableFirmwareUnsupported.kt index 3c1326d779..d0f389ed23 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableFirmwareUnsupported.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableFirmwareUnsupported.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState +import com.flipperdevices.bridge.connection.feature.protocolversion.model.FlipperSupportedState import com.flipperdevices.core.markdown.ClickableUrlText import com.flipperdevices.core.ui.theme.LocalPallet import com.flipperdevices.core.ui.theme.LocalTypography diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/info/ComposableInfoCard.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/info/ComposableInfoCard.kt index ecf10265bb..022ffe686a 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/info/ComposableInfoCard.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/info/ComposableInfoCard.kt @@ -17,7 +17,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState +import com.flipperdevices.bridge.connection.feature.protocolversion.model.FlipperSupportedState import com.flipperdevices.core.ui.ktx.clickableRipple import com.flipperdevices.core.ui.ktx.elements.animatedDots import com.flipperdevices.core.ui.theme.LocalPallet diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt index da87098177..5b07f99577 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableDeviceInfoScreen.kt @@ -15,7 +15,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.arkivanov.decompose.ComponentContext -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState +import com.flipperdevices.bridge.connection.feature.protocolversion.model.FlipperSupportedState import com.flipperdevices.core.preference.pb.HardwareColor import com.flipperdevices.core.ui.ktx.elements.SwipeRefresh import com.flipperdevices.core.ui.theme.LocalPallet diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt index 7e9fd55a86..952204bfb6 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt @@ -2,6 +2,12 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore import com.flipperdevices.bridge.api.manager.ktx.state.ConnectionState +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get +import com.flipperdevices.bridge.connection.orchestrator.api.FDeviceOrchestrator +import com.flipperdevices.bridge.connection.orchestrator.api.model.FDeviceConnectStatus import com.flipperdevices.bridge.service.api.FlipperServiceApi import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider @@ -11,41 +17,39 @@ import com.flipperdevices.info.impl.model.DeviceStatus import com.flipperdevices.updater.api.UpdateStateApi import com.flipperdevices.updater.model.FlipperUpdateState import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.stateIn import javax.inject.Inject class DeviceStatusViewModel @Inject constructor( serviceProvider: FlipperServiceProvider, private val dataStorePair: DataStore, - private val updateStateApi: UpdateStateApi + private val updateStateApi: UpdateStateApi, + private val fFeatureProvider: FFeatureProvider, + private val fDeviceOrchestrator: FDeviceOrchestrator ) : DecomposeViewModel(), FlipperBleServiceConsumer { - private val deviceStatus = MutableStateFlow(DeviceStatus.NoDevice) private val updateStatus = MutableStateFlow(FlipperUpdateState.NotConnected) init { serviceProvider.provideServiceApi(consumer = this, lifecycleOwner = this) } - - fun getState(): StateFlow = deviceStatus - fun getUpdateState(): StateFlow = updateStatus - - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - updateStateApi.getFlipperUpdateState(serviceApi, viewModelScope).onEach { - updateStatus.emit(it) - }.launchIn(viewModelScope) - - combine( - serviceApi.connectionInformationApi.getConnectionStateFlow(), - serviceApi.flipperInformationApi.getInformationFlow(), - dataStorePair.data - ) { connectionState, flipperInformation, pairSettings -> - return@combine when (connectionState) { - is ConnectionState.Disconnected -> if (pairSettings.device_name.isBlank() || - pairSettings.device_id.isBlank() - ) { + fun getState(): StateFlow = combine( + flow = fDeviceOrchestrator.getState(), + flow2 = fFeatureProvider.get() + .map { status -> status as? FFeatureStatus.Supported } + .flatMapLatest { status -> status?.featureApi?.getGattInfoFlow() ?: emptyFlow() }, + flow3 = dataStorePair.data + ) { connectionState, flipperInformation, pairSettings -> + when (connectionState) { + is FDeviceConnectStatus.Disconnected -> { + if (pairSettings.device_name.isBlank() || pairSettings.device_id.isBlank()) { DeviceStatus.NoDevice } else { DeviceStatus.NoDeviceInformation( @@ -53,32 +57,38 @@ class DeviceStatusViewModel @Inject constructor( connectInProgress = false ) } - ConnectionState.Connecting, - ConnectionState.Disconnecting, - ConnectionState.Initializing, - is ConnectionState.Ready, - ConnectionState.RetrievingInformation -> { - var deviceName = pairSettings.device_name - if (deviceName.isBlank()) { - deviceName = "Unknown" - } - val batteryLevel = flipperInformation.batteryLevel - if (batteryLevel == null) { - DeviceStatus.NoDeviceInformation( - deviceName, - connectInProgress = true - ) - } else { - DeviceStatus.Connected( - deviceName, - batteryLevel, - flipperInformation.isCharging - ) - } + } + + is FDeviceConnectStatus.Connecting, + is FDeviceConnectStatus.Disconnecting, + is FDeviceConnectStatus.Connected -> { + var deviceName = pairSettings.device_name + if (deviceName.isBlank()) { + deviceName = "Unknown" + } + val batteryLevel = flipperInformation.batteryLevel + if (batteryLevel == null) { + DeviceStatus.NoDeviceInformation( + deviceName, + connectInProgress = true + ) + } else { + DeviceStatus.Connected( + deviceName, + batteryLevel, + flipperInformation.isCharging + ) } } - }.onEach { - deviceStatus.emit(it) + } + }.stateIn(viewModelScope, SharingStarted.Eagerly, DeviceStatus.NoDevice) + + fun getUpdateState(): StateFlow = updateStatus + + override fun onServiceApiReady(serviceApi: FlipperServiceApi) { + // todo + updateStateApi.getFlipperUpdateState(serviceApi, viewModelScope).onEach { + updateStatus.emit(it) }.launchIn(viewModelScope) } } From 0eddf4137cf27478ddaf3a7c8e2f40809cb25c1f Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 11 Dec 2024 14:47:49 +0300 Subject: [PATCH 07/18] migrate info to new api --- .../feature/alarm/api/FAlarmFeatureApi.kt | 4 +- .../alarm/impl/api/FAlarmFeatureApiImpl.kt | 18 +-- .../impl/api/FAlarmFeatureFactoryImpl.kt | 1 - .../devicecolor/api/FDeviceColorFeatureApi.kt | 2 +- .../impl/api/FDeviceColorFeatureApiImpl.kt | 2 +- .../feature/getinfo/model/FGattInformation.kt | 4 +- .../impl/api/FGetInfoFeatureApiImpl.kt | 19 ++- .../storageinfo/api/FStorageInfoFeatureApi.kt | 9 ++ .../service/api/FConnectionService.kt | 2 +- .../service/impl/FConnectionServiceImpl.kt | 2 +- .../impl/meta/FTransportMetaInfoApiImpl.kt | 2 - components/info/impl/build.gradle.kts | 7 +- .../elements/ComposableInfoCardContent.kt | 16 +-- .../screens/ComposableFullDeviceInfoScreen.kt | 14 +-- .../fullinfo/ComposableFirmwareInfo.kt | 2 +- .../fullinfo/ComposableFlipperDevicesInfo.kt | 2 +- .../fullinfo/ComposableFullInfoDevice.kt | 2 +- .../fullinfo/ComposableRadioStackInfo.kt | 4 +- .../info/impl/model/FlipperBasicInfo.kt | 4 +- .../info/impl/viewmodel/ConnectViewModel.kt | 3 - .../impl/viewmodel/DeviceStatusViewModel.kt | 83 +++++++++----- .../impl/viewmodel/FirmwareUpdateViewModel.kt | 1 - .../deviceinfo/BasicInfoViewModel.kt | 108 +++++++++--------- .../viewmodel/deviceinfo/FullInfoViewModel.kt | 96 ++++++---------- .../deviceinfo/ShareFullInfoFileViewModel.kt | 8 +- 25 files changed, 210 insertions(+), 205 deletions(-) diff --git a/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt b/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt index 051c1a61b2..3105e99abb 100644 --- a/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt +++ b/components/bridge/connection/feature/alarm/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt @@ -2,6 +2,6 @@ package com.flipperdevices.bridge.connection.feature.alarm.api import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi -interface FAlarmFeatureApi: FDeviceFeatureApi { +interface FAlarmFeatureApi : FDeviceFeatureApi { suspend fun makeSound() -} \ No newline at end of file +} diff --git a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt index 850b46ae85..c9d8b1b651 100644 --- a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt +++ b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt @@ -3,27 +3,12 @@ package com.flipperdevices.bridge.connection.feature.alarm.impl.api import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest -import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.core.ktx.jre.toThrowableFlow -import com.flipperdevices.core.ktx.jre.withLock import com.flipperdevices.core.log.LogTagProvider -import com.flipperdevices.core.log.info import com.flipperdevices.protobuf.Main -import com.flipperdevices.protobuf.storage.InfoRequest import com.flipperdevices.protobuf.system.PlayAudiovisualAlertRequest import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.cancelAndJoin -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import kotlinx.coroutines.sync.Mutex -import kotlinx.coroutines.sync.withLock class FAlarmFeatureApiImpl @AssistedInject constructor( @Assisted private val rpcFeatureApi: FRpcFeatureApi, @@ -31,7 +16,6 @@ class FAlarmFeatureApiImpl @AssistedInject constructor( LogTagProvider { override val TAG = "FAlarmFeatureApi" - override suspend fun makeSound() { rpcFeatureApi.requestWithoutAnswer( Main( @@ -46,4 +30,4 @@ class FAlarmFeatureApiImpl @AssistedInject constructor( rpcFeatureApi: FRpcFeatureApi, ): FAlarmFeatureApiImpl } -} \ No newline at end of file +} diff --git a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt index 0e1198c64d..411e399a7d 100644 --- a/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/alarm/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt @@ -1,6 +1,5 @@ package com.flipperdevices.bridge.connection.feature.alarm.impl.api -import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier diff --git a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt index 41e7484bed..6b3e68eb7f 100644 --- a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt +++ b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt @@ -10,4 +10,4 @@ interface FDeviceColorFeatureApi : FDeviceFeatureApi { * @param default default value on response failure */ fun getColor(default: HardwareColor = HardwareColor.WHITE): Flow -} \ No newline at end of file +} diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index f090abb748..509bd3ac75 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -49,4 +49,4 @@ class FDeviceColorFeatureApiImpl @AssistedInject constructor( companion object { private const val RPC_KEY_HARDWARE_COLOR = "hardware.color" } -} \ No newline at end of file +} diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt index 316fb850ef..58cf914488 100644 --- a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGattInformation.kt @@ -3,6 +3,8 @@ package com.flipperdevices.bridge.connection.feature.getinfo.model data class FGattInformation( val deviceName: String? = null, val manufacturerName: String? = null, + val hardwareRevision: String? = null, + val softwareVersion: String? = null, val batteryLevel: Float? = null, val isCharging: Boolean = false -) \ No newline at end of file +) diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt index ea61e649d8..3fa6de836b 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt @@ -20,11 +20,9 @@ import dagger.assisted.AssistedInject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull @@ -67,7 +65,9 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor( TransportMetaInfoKey.DEVICE_NAME, TransportMetaInfoKey.MANUFACTURER, TransportMetaInfoKey.BATTERY_LEVEL, - TransportMetaInfoKey.BATTERY_POWER_STATE + TransportMetaInfoKey.BATTERY_POWER_STATE, + TransportMetaInfoKey.SOFTWARE_VERSION, + TransportMetaInfoKey.HARDWARE_VERSION ).forEach { key -> val flow = metaInfoApi.get(key) .onFailure { error(it) { "#collectGattInfo could not find flow for key $key" } } @@ -104,9 +104,20 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor( ) } + TransportMetaInfoKey.SOFTWARE_VERSION -> { + state.copy( + softwareVersion = String(byteArray) + ) + } + + TransportMetaInfoKey.HARDWARE_VERSION -> { + state.copy( + hardwareRevision = String(byteArray) + ) + } + else -> state } - } }.launchIn(scope) } diff --git a/components/bridge/connection/feature/storageinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/storageinfo/api/FStorageInfoFeatureApi.kt b/components/bridge/connection/feature/storageinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/storageinfo/api/FStorageInfoFeatureApi.kt index 78ba6da5db..1fe20a6d12 100644 --- a/components/bridge/connection/feature/storageinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/storageinfo/api/FStorageInfoFeatureApi.kt +++ b/components/bridge/connection/feature/storageinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/storageinfo/api/FStorageInfoFeatureApi.kt @@ -8,10 +8,19 @@ import kotlinx.coroutines.flow.StateFlow interface FStorageInfoFeatureApi : FDeviceFeatureApi { fun getStorageInformationFlow(): StateFlow + /** + * Update current [getStorageInformationFlow] + * @param scope parent scope to be launched in + * @param force if true, will cancel last invalidation and start new. + * If true and invalidation in progress, will be skipped + */ suspend fun invalidate( scope: CoroutineScope, force: Boolean = false ) + /** + * Cancels current [invalidate] and reset [getStorageInformationFlow] + */ suspend fun reset() } diff --git a/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt b/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt index c8dde0148e..b2a7fdbe36 100644 --- a/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt +++ b/components/bridge/connection/service/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/api/FConnectionService.kt @@ -24,4 +24,4 @@ interface FConnectionService { * Forget current device and disconnect from it as side effect */ fun forgetCurrentDevice() -} \ No newline at end of file +} diff --git a/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt b/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt index 57f97176ae..b6b02bf152 100644 --- a/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt +++ b/components/bridge/connection/service/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/service/impl/FConnectionServiceImpl.kt @@ -76,4 +76,4 @@ class FConnectionServiceImpl @Inject constructor( } } } -} \ No newline at end of file +} diff --git a/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt b/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt index 7f0d7dfc32..85561bc99b 100644 --- a/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt +++ b/components/bridge/connection/transport/ble/impl/src/androidMain/kotlin/com/flipperdevices/bridge/connection/transport/ble/impl/meta/FTransportMetaInfoApiImpl.kt @@ -10,13 +10,11 @@ import com.flipperdevices.core.log.warn import kotlinx.collections.immutable.ImmutableMap import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge -import kotlinx.coroutines.flow.onEach import no.nordicsemi.android.kotlin.ble.client.main.callback.ClientBleGatt import no.nordicsemi.android.kotlin.ble.client.main.service.ClientBleGattServices import no.nordicsemi.android.kotlin.ble.core.data.BleGattProperty diff --git a/components/info/impl/build.gradle.kts b/components/info/impl/build.gradle.kts index 4f01580dd3..758cd3f913 100644 --- a/components/info/impl/build.gradle.kts +++ b/components/info/impl/build.gradle.kts @@ -48,11 +48,8 @@ dependencies { implementation(projects.components.bridge.connection.feature.alarm.api) implementation(projects.components.bridge.connection.feature.deviceColor.api) implementation(projects.components.bridge.connection.feature.protocolversion.api) - - implementation(projects.components.bridge.api) - implementation(projects.components.bridge.service.api) - implementation(projects.components.bridge.pbutils) - implementation(projects.components.bridge.rpcinfo.api) + implementation(projects.components.bridge.connection.feature.rpcinfo.api) + implementation(projects.components.bridge.connection.feature.rpcstats.api) // Core deps implementation(libs.ktx) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableInfoCardContent.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableInfoCardContent.kt index 0582f57636..87ef0ce257 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableInfoCardContent.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/elements/ComposableInfoCardContent.kt @@ -5,14 +5,14 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview -import com.flipperdevices.bridge.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.bridge.rpcinfo.model.FlipperStorageInformation -import com.flipperdevices.bridge.rpcinfo.model.StorageStats -import com.flipperdevices.bridge.rpcinfo.model.dataOrNull -import com.flipperdevices.bridge.rpcinfo.model.externalStorageRequestInProgress -import com.flipperdevices.bridge.rpcinfo.model.flashSdStats -import com.flipperdevices.bridge.rpcinfo.model.isExtStorageEnding -import com.flipperdevices.bridge.rpcinfo.model.toString +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus +import com.flipperdevices.bridge.connection.feature.storageinfo.model.FlipperStorageInformation +import com.flipperdevices.bridge.connection.feature.storageinfo.model.StorageStats +import com.flipperdevices.bridge.connection.feature.storageinfo.model.dataOrNull +import com.flipperdevices.bridge.connection.feature.storageinfo.model.externalStorageRequestInProgress +import com.flipperdevices.bridge.connection.feature.storageinfo.model.flashSdStats +import com.flipperdevices.bridge.connection.feature.storageinfo.model.isExtStorageEnding +import com.flipperdevices.bridge.connection.feature.storageinfo.model.toString import com.flipperdevices.core.ui.theme.FlipperThemeInternal import com.flipperdevices.core.ui.theme.LocalPallet import com.flipperdevices.info.impl.R diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableFullDeviceInfoScreen.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableFullDeviceInfoScreen.kt index 872a27ca66..8ad9cebba5 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableFullDeviceInfoScreen.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/ComposableFullDeviceInfoScreen.kt @@ -10,9 +10,9 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import com.flipperdevices.bridge.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.bridge.rpcinfo.model.FlipperRpcInformation -import com.flipperdevices.bridge.rpcinfo.model.dataOrNull +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperRpcInformation +import com.flipperdevices.bridge.connection.feature.storageinfo.model.dataOrNull import com.flipperdevices.core.ui.ktx.OrangeAppBar import com.flipperdevices.core.ui.ktx.clickableRipple import com.flipperdevices.core.ui.theme.LocalPallet @@ -42,10 +42,10 @@ fun ComposableFullDeviceInfoScreen( val inProgress = when (localDeviceStatus) { is DeviceStatus.NoDeviceInformation -> localDeviceStatus.connectInProgress is DeviceStatus.Connected -> - flipperRpcInformation !is FlipperInformationStatus.Ready || - basicInfo.storageInfo.externalStorageStatus !is FlipperInformationStatus.Ready || - basicInfo.storageInfo.internalStorageStatus !is FlipperInformationStatus.Ready || - basicInfo.firmwareVersion !is FlipperInformationStatus.Ready + flipperRpcInformation !is FlipperInformationStatus.Ready<*> || + basicInfo.storageInfo.externalStorageStatus !is FlipperInformationStatus.Ready<*> || + basicInfo.storageInfo.internalStorageStatus !is FlipperInformationStatus.Ready<*> || + basicInfo.firmwareVersion !is FlipperInformationStatus.Ready<*> else -> false } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFirmwareInfo.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFirmwareInfo.kt index 742756150f..674e8da4e4 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFirmwareInfo.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFirmwareInfo.kt @@ -2,7 +2,7 @@ package com.flipperdevices.info.impl.compose.screens.fullinfo import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color -import com.flipperdevices.bridge.rpcinfo.model.FirmwareInfo +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FirmwareInfo import com.flipperdevices.info.impl.R import com.flipperdevices.info.shared.ComposableDeviceInfoRow import com.flipperdevices.info.shared.ComposableDeviceInfoRowWithText diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFlipperDevicesInfo.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFlipperDevicesInfo.kt index 7e9d0656cd..3f0875947b 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFlipperDevicesInfo.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFlipperDevicesInfo.kt @@ -3,7 +3,7 @@ package com.flipperdevices.info.impl.compose.screens.fullinfo import androidx.compose.foundation.layout.Row import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment -import com.flipperdevices.bridge.rpcinfo.model.FlipperDeviceInfo +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperDeviceInfo import com.flipperdevices.info.impl.R import com.flipperdevices.info.shared.ComposableDeviceInfoRow import com.flipperdevices.info.shared.ComposableDeviceInfoRowText diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFullInfoDevice.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFullInfoDevice.kt index 72451671eb..020db28e92 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFullInfoDevice.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableFullInfoDevice.kt @@ -8,7 +8,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.flipperdevices.bridge.rpcinfo.model.FlipperRpcInformation +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperRpcInformation import com.flipperdevices.core.ktx.jre.titlecaseFirstCharIfItIsLowercase import com.flipperdevices.core.ui.ktx.elements.SwipeRefresh import com.flipperdevices.info.impl.R diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableRadioStackInfo.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableRadioStackInfo.kt index def4a428e4..facb764f1d 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableRadioStackInfo.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/compose/screens/fullinfo/ComposableRadioStackInfo.kt @@ -2,8 +2,8 @@ package com.flipperdevices.info.impl.compose.screens.fullinfo import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource -import com.flipperdevices.bridge.rpcinfo.model.RadioStackInfo -import com.flipperdevices.bridge.rpcinfo.model.RadioStackType +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.RadioStackInfo +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.RadioStackType import com.flipperdevices.core.ktx.jre.isNotNull import com.flipperdevices.info.impl.R import com.flipperdevices.info.shared.ComposableDeviceInfoRowWithText diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/model/FlipperBasicInfo.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/model/FlipperBasicInfo.kt index 2e2ffbab10..6606dbd1fa 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/model/FlipperBasicInfo.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/model/FlipperBasicInfo.kt @@ -1,8 +1,8 @@ package com.flipperdevices.info.impl.model import androidx.compose.runtime.Stable -import com.flipperdevices.bridge.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.bridge.rpcinfo.model.FlipperStorageInformation +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus +import com.flipperdevices.bridge.connection.feature.storageinfo.model.FlipperStorageInformation import com.flipperdevices.updater.model.FirmwareVersion @Stable diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt index e53e3b49b2..a624227d28 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/ConnectViewModel.kt @@ -1,15 +1,12 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage -import com.flipperdevices.bridge.connection.orchestrator.api.FDeviceOrchestrator import com.flipperdevices.bridge.connection.service.api.FConnectionService import com.flipperdevices.bridge.synchronization.api.SynchronizationApi import com.flipperdevices.core.preference.pb.PairSettings import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.info.impl.model.ConnectRequestState import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import java.util.concurrent.atomic.AtomicBoolean diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt index 952204bfb6..3d2c8496fd 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt @@ -1,46 +1,38 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.api.manager.ktx.state.ConnectionState import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus import com.flipperdevices.bridge.connection.feature.provider.api.get import com.flipperdevices.bridge.connection.orchestrator.api.FDeviceOrchestrator import com.flipperdevices.bridge.connection.orchestrator.api.model.FDeviceConnectStatus -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider import com.flipperdevices.core.preference.pb.PairSettings import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.info.impl.model.DeviceStatus -import com.flipperdevices.updater.api.UpdateStateApi +import com.flipperdevices.updater.api.FirmwareVersionBuilderApi +import com.flipperdevices.updater.api.UpdaterApi import com.flipperdevices.updater.model.FlipperUpdateState -import kotlinx.coroutines.flow.MutableStateFlow +import com.flipperdevices.updater.model.UpdatingState import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.emptyFlow import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.stateIn import javax.inject.Inject class DeviceStatusViewModel @Inject constructor( - serviceProvider: FlipperServiceProvider, - private val dataStorePair: DataStore, - private val updateStateApi: UpdateStateApi, - private val fFeatureProvider: FFeatureProvider, - private val fDeviceOrchestrator: FDeviceOrchestrator -) : DecomposeViewModel(), FlipperBleServiceConsumer { - private val updateStatus = MutableStateFlow(FlipperUpdateState.NotConnected) + dataStorePair: DataStore, + fFeatureProvider: FFeatureProvider, + fDeviceOrchestrator: FDeviceOrchestrator, + private val updaterApi: UpdaterApi, + private val firmwareVersionBuilderApi: FirmwareVersionBuilderApi +) : DecomposeViewModel() { - init { - serviceProvider.provideServiceApi(consumer = this, lifecycleOwner = this) - } - fun getState(): StateFlow = combine( + private val deviceState = combine( flow = fDeviceOrchestrator.getState(), flow2 = fFeatureProvider.get() .map { status -> status as? FFeatureStatus.Supported } @@ -83,12 +75,51 @@ class DeviceStatusViewModel @Inject constructor( } }.stateIn(viewModelScope, SharingStarted.Eagerly, DeviceStatus.NoDevice) - fun getUpdateState(): StateFlow = updateStatus + fun getState(): StateFlow = deviceState + + private val updateStatus = combine( + flow = updaterApi.getState(), + flow2 = fFeatureProvider.get() + .map { it as? FFeatureStatus.Supported } + .flatMapLatest { it?.featureApi?.getGattInfoFlow() ?: flowOf(null) } + .map { gattInfo -> gattInfo?.softwareVersion } + .map { firmwareVersion -> + firmwareVersion?.let(firmwareVersionBuilderApi::buildFirmwareVersionFromString) + }, + flow3 = fDeviceOrchestrator.getState(), + transform = { updaterState, firmwareVersion, orchestratorState -> + when (orchestratorState) { + is FDeviceConnectStatus.Connected -> { + if (firmwareVersion != null) { + when (updaterState.state) { + is UpdatingState.Rebooting -> { + updaterApi.onDeviceConnected(firmwareVersion) + FlipperUpdateState.Ready + } - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - // todo - updateStateApi.getFlipperUpdateState(serviceApi, viewModelScope).onEach { - updateStatus.emit(it) - }.launchIn(viewModelScope) - } + is UpdatingState.Complete -> { + FlipperUpdateState.Complete(updaterState.request?.updateTo) + } + + is UpdatingState.Failed -> { + FlipperUpdateState.Failed(updaterState.request?.updateTo) + } + + else -> FlipperUpdateState.Ready + } + } else if (updaterState.state is UpdatingState.Rebooting) { + FlipperUpdateState.Updating + } else { + FlipperUpdateState.ConnectingInProgress + } + } + + is FDeviceConnectStatus.Connecting -> FlipperUpdateState.ConnectingInProgress + is FDeviceConnectStatus.Disconnecting -> FlipperUpdateState.ConnectingInProgress + is FDeviceConnectStatus.Disconnected -> FlipperUpdateState.NotConnected + } + } + ).stateIn(viewModelScope, SharingStarted.Eagerly, FlipperUpdateState.NotConnected) + + fun getUpdateState(): StateFlow = updateStatus } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt index 9e1036178e..60cdd87575 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FirmwareUpdateViewModel.kt @@ -34,5 +34,4 @@ class FirmwareUpdateViewModel @Inject constructor( } }.stateIn(viewModelScope, SharingStarted.Eagerly, FlipperSupportedState.READY) } - } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt index e64125b0fc..52ef2ca780 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt @@ -1,77 +1,81 @@ package com.flipperdevices.info.impl.viewmodel.deviceinfo -import com.flipperdevices.bridge.api.manager.ktx.state.ConnectionState -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState -import com.flipperdevices.bridge.rpcinfo.api.FlipperStorageInformationApi -import com.flipperdevices.bridge.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider -import com.flipperdevices.core.ktx.jre.cancelAndClear +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus +import com.flipperdevices.bridge.connection.feature.storageinfo.api.FStorageInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.storageinfo.model.FlipperStorageInformation import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.info.impl.model.FlipperBasicInfo -import com.flipperdevices.updater.api.FlipperVersionProviderApi -import kotlinx.coroutines.Job +import com.flipperdevices.updater.api.FirmwareVersionBuilderApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import kotlinx.coroutines.plus import javax.inject.Inject class BasicInfoViewModel @Inject constructor( - serviceProvider: FlipperServiceProvider, - private val flipperVersionProviderApi: FlipperVersionProviderApi, - private val flipperStorageInformationApi: FlipperStorageInformationApi -) : DecomposeViewModel(), FlipperBleServiceConsumer, LogTagProvider { + private val fFeatureProvider: FFeatureProvider, + private val firmwareVersionBuilderApi: FirmwareVersionBuilderApi +) : DecomposeViewModel(), LogTagProvider { override val TAG = "DeviceInfoViewModel" private val flipperBasicInfoState = MutableStateFlow(FlipperBasicInfo()) - private val jobs = mutableListOf() + fun getDeviceInfo() = flipperBasicInfoState.asStateFlow() - init { - serviceProvider.provideServiceApi(this, this) + private fun collectStorageInfo() { + fFeatureProvider.get() + .map { it as? FFeatureStatus.Supported } + .flatMapLatest { + it?.featureApi + ?.getStorageInformationFlow() + ?: flowOf(FlipperStorageInformation()) + }.onEach { storageInfo -> + flipperBasicInfoState.update { basicInfo -> basicInfo.copy(storageInfo = storageInfo) } + }.launchIn(viewModelScope) } - fun getDeviceInfo() = flipperBasicInfoState.asStateFlow() + private fun invalidateStorageInfo() { + fFeatureProvider.get() + .filterIsInstance>() + .onEach { status -> status.featureApi.invalidate(viewModelScope, true) } + .launchIn(viewModelScope) + } - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - jobs.cancelAndClear() - jobs += flipperVersionProviderApi.getCurrentFlipperVersion(viewModelScope, serviceApi) - .onEach { firmwareVersion -> - flipperBasicInfoState.update { - it.copy( - firmwareVersion = FlipperInformationStatus.Ready( - firmwareVersion + private fun collectFirmwareInformation() { + fFeatureProvider.get() + .map { it as? FFeatureStatus.Supported } + .flatMapLatest { it?.featureApi?.getGattInfoFlow() ?: flowOf(null) } + .map { it?.softwareVersion } + .onEach { softwareVersion -> + if (softwareVersion == null) { + flipperBasicInfoState.update { basicInfo -> + basicInfo.copy(firmwareVersion = FlipperInformationStatus.NotStarted()) + } + } else { + flipperBasicInfoState.update { basicInfo -> + basicInfo.copy( + firmwareVersion = FlipperInformationStatus.Ready( + data = firmwareVersionBuilderApi.buildFirmwareVersionFromString( + firmwareVersion = softwareVersion + ) + ) ) - ) + } } }.launchIn(viewModelScope) + } - jobs += serviceApi.connectionInformationApi.getConnectionStateFlow().onEach { - when (it) { - is ConnectionState.Ready -> if (it.supportedState == FlipperSupportedState.READY) { - flipperStorageInformationApi.invalidate( - viewModelScope, - serviceApi, - force = false - ) - } - else -> flipperStorageInformationApi.reset() - } - }.launchIn(viewModelScope) - - jobs += flipperStorageInformationApi.getStorageInformationFlow().onEach { storageInfo -> - flipperBasicInfoState.update { it.copy(storageInfo = storageInfo) } - }.launchIn(viewModelScope) - - jobs += viewModelScope.launch { - flipperStorageInformationApi.invalidate( - viewModelScope, - serviceApi - ) - } + init { + collectStorageInfo() + invalidateStorageInfo() + collectFirmwareInformation() } } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/FullInfoViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/FullInfoViewModel.kt index 12c3f3cc54..23cd1c7f38 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/FullInfoViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/FullInfoViewModel.kt @@ -1,82 +1,45 @@ package com.flipperdevices.info.impl.viewmodel.deviceinfo -import com.flipperdevices.bridge.api.manager.ktx.state.ConnectionState -import com.flipperdevices.bridge.api.manager.ktx.state.FlipperSupportedState -import com.flipperdevices.bridge.rpcinfo.api.FlipperRpcInformationApi -import com.flipperdevices.bridge.rpcinfo.model.FlipperInformationStatus -import com.flipperdevices.bridge.rpcinfo.model.FlipperRpcInformation -import com.flipperdevices.bridge.service.api.FlipperServiceApi -import com.flipperdevices.bridge.service.api.provider.FlipperBleServiceConsumer -import com.flipperdevices.bridge.service.api.provider.FlipperServiceProvider -import com.flipperdevices.core.ktx.jre.cancelAndClear +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider +import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus +import com.flipperdevices.bridge.connection.feature.provider.api.get +import com.flipperdevices.bridge.connection.feature.provider.api.getSync +import com.flipperdevices.bridge.connection.feature.rpcinfo.api.FRpcInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperInformationStatus import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import com.flipperdevices.updater.api.FirmwareVersionBuilderApi import com.flipperdevices.updater.model.FirmwareChannel -import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import kotlinx.coroutines.plus import javax.inject.Inject class FullInfoViewModel @Inject constructor( - private val serviceProvider: FlipperServiceProvider, - private val flipperRpcInformationApi: FlipperRpcInformationApi, - private val firmwareVersionBuilderApi: FirmwareVersionBuilderApi + private val firmwareVersionBuilderApi: FirmwareVersionBuilderApi, + private val fFeatureProvider: FFeatureProvider ) : DecomposeViewModel(), - FlipperBleServiceConsumer, LogTagProvider { override val TAG = "FullInfoViewModel" - private val jobs = mutableListOf() - private val flipperRpcInformationState = - MutableStateFlow>( - FlipperInformationStatus.NotStarted() - ) - init { - serviceProvider.provideServiceApi(this, this) - } - - fun getFlipperRpcInformation() = flipperRpcInformationState.asStateFlow() - - fun refresh() { - viewModelScope.launch { - flipperRpcInformationApi.invalidate( - viewModelScope, - serviceProvider.getServiceApi(), - force = true - ) - } - } - - override fun onServiceApiReady(serviceApi: FlipperServiceApi) { - jobs.cancelAndClear() - jobs += serviceApi.connectionInformationApi.getConnectionStateFlow().onEach { - when (it) { - is ConnectionState.Ready -> if (it.supportedState == FlipperSupportedState.READY) { - flipperRpcInformationApi.invalidate( - viewModelScope, - serviceApi, - force = true - ) - } - else -> flipperRpcInformationApi.reset() - } - }.launchIn(viewModelScope) + private val flipperRpcInformation = fFeatureProvider.get() + .map { status -> status as? FFeatureStatus.Supported } + .flatMapLatest { status -> status?.featureApi?.getRpcInformationFlow() ?: flowOf(null) } + .map { informationStatus -> informationStatus ?: FlipperInformationStatus.NotStarted() } + .stateIn(viewModelScope, SharingStarted.Eagerly, FlipperInformationStatus.NotStarted()) - jobs += flipperRpcInformationApi.getRpcInformationFlow().onEach { rpcInformation -> - flipperRpcInformationState.emit(rpcInformation) - }.launchIn(viewModelScope) + fun getFlipperRpcInformation() = flipperRpcInformation - jobs += viewModelScope.launch { - flipperRpcInformationApi.invalidate( - viewModelScope, - serviceApi - ) - } + private fun invalidateRpcInfo() { + fFeatureProvider.get() + .map { status -> status as? FFeatureStatus.Supported } + .onEach { status -> status?.featureApi?.invalidate(viewModelScope, force = true) } + .launchIn(viewModelScope) } fun getFirmwareChannel(commit: String?): FirmwareChannel? { @@ -86,4 +49,15 @@ class FullInfoViewModel @Inject constructor( val branch = preparedCommit.first() return firmwareVersionBuilderApi.getFirmwareChannel(branch) } + + fun refresh() { + viewModelScope.launch { + fFeatureProvider.getSync() + ?.invalidate(viewModelScope, force = true) + } + } + + init { + invalidateRpcInfo() + } } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/ShareFullInfoFileViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/ShareFullInfoFileViewModel.kt index 2ed75d9075..2565f9dfeb 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/ShareFullInfoFileViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/ShareFullInfoFileViewModel.kt @@ -1,10 +1,10 @@ package com.flipperdevices.info.impl.viewmodel.deviceinfo import android.app.Application -import com.flipperdevices.bridge.rpcinfo.model.FlipperRpcInformation -import com.flipperdevices.bridge.rpcinfo.model.StorageStats -import com.flipperdevices.bridge.rpcinfo.model.flashIntStats -import com.flipperdevices.bridge.rpcinfo.model.flashSdStats +import com.flipperdevices.bridge.connection.feature.rpcinfo.model.FlipperRpcInformation +import com.flipperdevices.bridge.connection.feature.storageinfo.model.StorageStats +import com.flipperdevices.bridge.connection.feature.storageinfo.model.flashIntStats +import com.flipperdevices.bridge.connection.feature.storageinfo.model.flashSdStats import com.flipperdevices.core.ktx.jre.createClearNewFileWithMkDirs import com.flipperdevices.core.log.error import com.flipperdevices.core.share.SharableFile From 8917829bea1b70b4ef1de5ab2fececad096ec8b5 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Tue, 10 Dec 2024 17:21:58 +0300 Subject: [PATCH 08/18] add flipper version check for device color get request --- .../device-color/impl/build.gradle.kts | 2 ++ .../api/FDeviceColorFeatureFactoryImpl.kt | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/components/bridge/connection/feature/device-color/impl/build.gradle.kts b/components/bridge/connection/feature/device-color/impl/build.gradle.kts index 3d54d6f649..a79ef7b724 100644 --- a/components/bridge/connection/feature/device-color/impl/build.gradle.kts +++ b/components/bridge/connection/feature/device-color/impl/build.gradle.kts @@ -13,12 +13,14 @@ commonDependencies { implementation(projects.components.core.log) implementation(projects.components.core.ktx) implementation(projects.components.core.preference) + implementation(projects.components.core.data) implementation(projects.components.bridge.connection.feature.common.api) implementation(projects.components.bridge.connection.transport.common.api) implementation(projects.components.bridge.connection.feature.rpc.api) implementation(projects.components.bridge.connection.feature.rpc.model) implementation(projects.components.bridge.connection.feature.rpcinfo.api) + implementation(projects.components.bridge.connection.feature.protocolversion.api) implementation(projects.components.bridge.connection.pbutils) diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt index 040ba59ae5..e66c1cea26 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt @@ -4,23 +4,43 @@ import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi +import com.flipperdevices.core.data.SemVer import com.flipperdevices.core.di.AppGraph +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.error +import com.flipperdevices.core.log.info import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject + +private val API_SUPPORTED_GET_REQUEST = SemVer( + majorVersion = 0, + minorVersion = 14 +) + @FDeviceFeatureQualifier(FDeviceFeature.DEVICE_COLOR) @ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) class FDeviceColorFeatureFactoryImpl @Inject constructor( private val factory: FDeviceColorFeatureApiImpl.InternalFactory -) : FDeviceFeatureApi.Factory { +) : FDeviceFeatureApi.Factory, LogTagProvider { + override val TAG = "FDeviceColorFeatureFactory" + override suspend fun invoke( unsafeFeatureDeviceApi: FUnsafeDeviceFeatureApi, scope: CoroutineScope, connectedDevice: FConnectedDeviceApi ): FDeviceFeatureApi? { + val versionApi = unsafeFeatureDeviceApi.getUnsafe(FVersionFeatureApi::class) ?: return null + info { "Start request supported state for api level $API_SUPPORTED_GET_REQUEST" } + val isSupported = versionApi.isSupported(API_SUPPORTED_GET_REQUEST) + if (!isSupported) { + error { "Failed init FDeviceColorFeatureApi, because isSupported=false" } + return null + } val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null return factory( rpcFeatureApi = rpcApi, From 0b12f2b584ea86e52e16460766f32a8218f9dd9f Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Mon, 16 Dec 2024 00:42:21 +0300 Subject: [PATCH 09/18] split FGattInfoFeatureApi --- .../utils/FZeroFeatureClassToEnumMapper.kt | 2 + .../feature/common/api/FDeviceFeature.kt | 3 +- .../api/FDeviceColorFeatureFactoryImpl.kt | 2 +- .../getinfo/api/FGattInfoFeatureApi.kt | 9 ++ .../feature/getinfo/api/FGetInfoFeatureApi.kt | 4 - .../impl/api/FGattInfoFeatureApiImpl.kt | 111 ++++++++++++++++++ .../impl/api/FGattInfoFeatureFactoryImpl.kt | 52 ++++++++ .../impl/api/FGetInfoFeatureApiImpl.kt | 94 --------------- .../impl/api/FGetInfoFeatureFactoryImpl.kt | 5 +- .../impl/viewmodel/DeviceStatusViewModel.kt | 10 +- .../deviceinfo/BasicInfoViewModel.kt | 6 +- 11 files changed, 186 insertions(+), 112 deletions(-) create mode 100644 components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGattInfoFeatureApi.kt create mode 100644 components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureApiImpl.kt create mode 100644 components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt diff --git a/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt b/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt index 8df0a2cbdc..e6afff3bc2 100644 --- a/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt +++ b/components/bridge/connection/device/fzero/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/device/fzero/impl/utils/FZeroFeatureClassToEnumMapper.kt @@ -4,6 +4,7 @@ import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGattInfoFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.feature.restartrpc.api.FRestartRpcFeatureApi @@ -34,6 +35,7 @@ object FZeroFeatureClassToEnumMapper { FDeviceFeature.STORAGE -> FStorageFeatureApi::class FDeviceFeature.ALARM -> FAlarmFeatureApi::class FDeviceFeature.DEVICE_COLOR -> FDeviceColorFeatureApi::class + FDeviceFeature.GATT_INFO -> FGattInfoFeatureApi::class } } diff --git a/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt b/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt index ecb2c3381a..c1a7344462 100644 --- a/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt +++ b/components/bridge/connection/feature/common/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/common/api/FDeviceFeature.kt @@ -13,7 +13,8 @@ enum class FDeviceFeature { STORAGE_INFO, GET_INFO, ALARM, - DEVICE_COLOR + DEVICE_COLOR, + GATT_INFO, } @Retention(AnnotationRetention.RUNTIME) diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt index e66c1cea26..d4d3227bbd 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt @@ -16,7 +16,7 @@ import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject - +// todo move to shared const private val API_SUPPORTED_GET_REQUEST = SemVer( majorVersion = 0, minorVersion = 14 diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGattInfoFeatureApi.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGattInfoFeatureApi.kt new file mode 100644 index 0000000000..4607f0ac43 --- /dev/null +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGattInfoFeatureApi.kt @@ -0,0 +1,9 @@ +package com.flipperdevices.bridge.connection.feature.getinfo.api + +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation +import kotlinx.coroutines.flow.StateFlow + +interface FGattInfoFeatureApi : FDeviceFeatureApi { + fun getGattInfoFlow(): StateFlow +} diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt index 62325eccea..7a39f7a3de 100644 --- a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/api/FGetInfoFeatureApi.kt @@ -1,16 +1,12 @@ package com.flipperdevices.bridge.connection.feature.getinfo.api import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi -import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiGroup import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow interface FGetInfoFeatureApi : FDeviceFeatureApi { suspend fun get(property: FGetInfoApiProperty): Result fun get(group: FGetInfoApiGroup): Flow> - - fun getGattInfoFlow(): MutableStateFlow } diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureApiImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureApiImpl.kt new file mode 100644 index 0000000000..0969ae82c1 --- /dev/null +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureApiImpl.kt @@ -0,0 +1,111 @@ +package com.flipperdevices.bridge.connection.feature.getinfo.impl.api + +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGattInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation +import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi +import com.flipperdevices.bridge.connection.transport.common.api.meta.TransportMetaInfoKey +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.error +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update +import kotlin.experimental.and + +class FGattInfoFeatureApiImpl @AssistedInject constructor( + @Assisted private val metaInfoApi: FTransportMetaInfoApi, + @Assisted private val scope: CoroutineScope, +) : FGattInfoFeatureApi, LogTagProvider { + override val TAG: String = "FGetInfoFeatureApi" + + private val gattInfo = MutableStateFlow(FGattInformation()) + + override fun getGattInfoFlow() = gattInfo.asStateFlow() + + private fun collectGattInfo() { + listOf( + TransportMetaInfoKey.DEVICE_NAME, + TransportMetaInfoKey.MANUFACTURER, + TransportMetaInfoKey.BATTERY_LEVEL, + TransportMetaInfoKey.BATTERY_POWER_STATE, + TransportMetaInfoKey.SOFTWARE_VERSION, + TransportMetaInfoKey.HARDWARE_VERSION + ).forEach { key -> + val flow = metaInfoApi.get(key) + .onFailure { error(it) { "#collectGattInfo could not find flow for key $key" } } + .getOrNull() + (flow ?: emptyFlow()) + .filterNotNull() + .onEach { byteArray -> + gattInfo.update { state -> + when (key) { + TransportMetaInfoKey.DEVICE_NAME -> { + state.copy(deviceName = String(byteArray)) + } + + TransportMetaInfoKey.MANUFACTURER -> { + state.copy(manufacturerName = String(byteArray)) + } + + TransportMetaInfoKey.BATTERY_LEVEL -> { + state.copy( + batteryLevel = byteArray.firstOrNull() + ?.toFloat() + ?.div(MAX_BATTERY_LEVEL) + ?.coerceIn(0f, 1f) + ) + } + + TransportMetaInfoKey.BATTERY_POWER_STATE -> { + state.copy( + isCharging = byteArray.firstOrNull() + ?.and(BATTERY_POWER_STATE_MASK) + ?.equals(BATTERY_POWER_STATE_MASK) + ?: false + ) + } + + TransportMetaInfoKey.SOFTWARE_VERSION -> { + state.copy( + softwareVersion = String(byteArray) + ) + } + + TransportMetaInfoKey.HARDWARE_VERSION -> { + state.copy( + hardwareRevision = String(byteArray) + ) + } + + else -> state + } + } + }.launchIn(scope) + } + } + + init { + collectGattInfo() + } + + @AssistedFactory + fun interface InternalFactory { + operator fun invoke( + metaInfoApi: FTransportMetaInfoApi, + scope: CoroutineScope, + ): FGattInfoFeatureApiImpl + } + + companion object { + private const val MAX_BATTERY_LEVEL = 100 + const val BATTERY_POWER_STATE_MASK: Byte = 0b0011_0000 + } +} diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt new file mode 100644 index 0000000000..356850183b --- /dev/null +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt @@ -0,0 +1,52 @@ +package com.flipperdevices.bridge.connection.feature.getinfo.impl.api + +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier +import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi +import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi +import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi +import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi +import com.flipperdevices.core.data.SemVer +import com.flipperdevices.core.di.AppGraph +import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.error +import com.flipperdevices.core.log.info +import com.squareup.anvil.annotations.ContributesMultibinding +import kotlinx.coroutines.CoroutineScope +import javax.inject.Inject + +// todo move to shared const +private val API_SUPPORTED_GET_REQUEST = SemVer( + majorVersion = 0, + minorVersion = 14 +) + +@FDeviceFeatureQualifier(FDeviceFeature.GATT_INFO) +@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) +class FGattInfoFeatureFactoryImpl @Inject constructor( + private val factory: FGattInfoFeatureApiImpl.InternalFactory +) : FDeviceFeatureApi.Factory, LogTagProvider { + override val TAG = "FGattInfoFeatureFactory" + + override suspend fun invoke( + unsafeFeatureDeviceApi: FUnsafeDeviceFeatureApi, + scope: CoroutineScope, + connectedDevice: FConnectedDeviceApi + ): FDeviceFeatureApi? { + val versionApi = unsafeFeatureDeviceApi.getUnsafe(FVersionFeatureApi::class) ?: return null + info { "Start request supported state for api level $API_SUPPORTED_GET_REQUEST" } + val isSupported = versionApi.isSupported(API_SUPPORTED_GET_REQUEST) + if (!isSupported) { + error { "Failed init FGattInfoFeatureApi, because isSupported=false" } + return null + } + + val metaInfoApi = connectedDevice as? FTransportMetaInfoApi ?: return null + + return factory( + metaInfoApi = metaInfoApi, + scope = scope + ) + } +} diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt index 3fa6de836b..188d03fd09 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt @@ -2,38 +2,22 @@ package com.flipperdevices.bridge.connection.feature.getinfo.impl.api import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.impl.mapper.FGetInfoApiKeyMapper -import com.flipperdevices.bridge.connection.feature.getinfo.model.FGattInformation import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiGroup import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest -import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi -import com.flipperdevices.bridge.connection.transport.common.api.meta.TransportMetaInfoKey import com.flipperdevices.core.log.LogTagProvider -import com.flipperdevices.core.log.error -import com.flipperdevices.core.log.info import com.flipperdevices.protobuf.Main import com.flipperdevices.protobuf.property.GetRequest import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.emptyFlow -import kotlinx.coroutines.flow.filterNotNull -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapNotNull -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.update -import kotlin.experimental.and class FGetInfoFeatureApiImpl @AssistedInject constructor( @Assisted private val rpcFeatureApi: FRpcFeatureApi, - @Assisted private val metaInfoApi: FTransportMetaInfoApi, - @Assisted private val scope: CoroutineScope, ) : FGetInfoFeatureApi, LogTagProvider { override val TAG: String = "FGetInfoFeatureApi" private val mapper = FGetInfoApiKeyMapper() @@ -56,88 +40,10 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor( .map { mapper.map(group, it.key) to it.value_ } } - private val gattInfo = MutableStateFlow(FGattInformation()) - - override fun getGattInfoFlow(): MutableStateFlow = gattInfo - - private fun collectGattInfo() { - listOf( - TransportMetaInfoKey.DEVICE_NAME, - TransportMetaInfoKey.MANUFACTURER, - TransportMetaInfoKey.BATTERY_LEVEL, - TransportMetaInfoKey.BATTERY_POWER_STATE, - TransportMetaInfoKey.SOFTWARE_VERSION, - TransportMetaInfoKey.HARDWARE_VERSION - ).forEach { key -> - val flow = metaInfoApi.get(key) - .onFailure { error(it) { "#collectGattInfo could not find flow for key $key" } } - .getOrNull() - (flow ?: emptyFlow()) - .filterNotNull() - .onEach { byteArray -> - info { "#collectGattInfo array for $key ${byteArray.toList()}" } - gattInfo.update { state -> - when (key) { - TransportMetaInfoKey.DEVICE_NAME -> { - state.copy(deviceName = String(byteArray)) - } - - TransportMetaInfoKey.MANUFACTURER -> { - state.copy(manufacturerName = String(byteArray)) - } - - TransportMetaInfoKey.BATTERY_LEVEL -> { - state.copy( - batteryLevel = byteArray.firstOrNull() - ?.toFloat() - ?.div(MAX_BATTERY_LEVEL) - ?.coerceIn(0f, 1f) - ) - } - - TransportMetaInfoKey.BATTERY_POWER_STATE -> { - state.copy( - isCharging = byteArray.firstOrNull() - ?.and(BATTERY_POWER_STATE_MASK) - ?.equals(BATTERY_POWER_STATE_MASK) - ?: false - ) - } - - TransportMetaInfoKey.SOFTWARE_VERSION -> { - state.copy( - softwareVersion = String(byteArray) - ) - } - - TransportMetaInfoKey.HARDWARE_VERSION -> { - state.copy( - hardwareRevision = String(byteArray) - ) - } - - else -> state - } - } - }.launchIn(scope) - } - } - - init { - collectGattInfo() - } - @AssistedFactory fun interface InternalFactory { operator fun invoke( rpcFeatureApi: FRpcFeatureApi, - metaInfoApi: FTransportMetaInfoApi, - scope: CoroutineScope, ): FGetInfoFeatureApiImpl } - - companion object { - private const val MAX_BATTERY_LEVEL = 100 - const val BATTERY_POWER_STATE_MASK: Byte = 0b0011_0000 - } } diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt index cdcb681807..7b9ae87c21 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureFactoryImpl.kt @@ -7,7 +7,6 @@ import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeat import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi -import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi import com.flipperdevices.core.data.SemVer import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.log.LogTagProvider @@ -17,6 +16,7 @@ import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject +// todo move to shared const private val API_SUPPORTED_GET_REQUEST = SemVer( majorVersion = 0, minorVersion = 14 @@ -44,12 +44,9 @@ class FGetInfoFeatureFactoryImpl @Inject constructor( info { "Version $API_SUPPORTED_GET_REQUEST supported, so continue building FGetInfoFeatureApi" } val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null - val metaInfoApi = connectedDevice as? FTransportMetaInfoApi ?: return null return factory( rpcFeatureApi = rpcApi, - metaInfoApi = metaInfoApi, - scope = scope ) } } diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt index 3d2c8496fd..b1c2d5d5fb 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/DeviceStatusViewModel.kt @@ -1,7 +1,7 @@ package com.flipperdevices.info.impl.viewmodel import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGattInfoFeatureApi import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus import com.flipperdevices.bridge.connection.feature.provider.api.get @@ -34,8 +34,8 @@ class DeviceStatusViewModel @Inject constructor( private val deviceState = combine( flow = fDeviceOrchestrator.getState(), - flow2 = fFeatureProvider.get() - .map { status -> status as? FFeatureStatus.Supported } + flow2 = fFeatureProvider.get() + .map { status -> status as? FFeatureStatus.Supported } .flatMapLatest { status -> status?.featureApi?.getGattInfoFlow() ?: emptyFlow() }, flow3 = dataStorePair.data ) { connectionState, flipperInformation, pairSettings -> @@ -79,8 +79,8 @@ class DeviceStatusViewModel @Inject constructor( private val updateStatus = combine( flow = updaterApi.getState(), - flow2 = fFeatureProvider.get() - .map { it as? FFeatureStatus.Supported } + flow2 = fFeatureProvider.get() + .map { it as? FFeatureStatus.Supported } .flatMapLatest { it?.featureApi?.getGattInfoFlow() ?: flowOf(null) } .map { gattInfo -> gattInfo?.softwareVersion } .map { firmwareVersion -> diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt index 52ef2ca780..ffa9e24608 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/deviceinfo/BasicInfoViewModel.kt @@ -1,6 +1,6 @@ package com.flipperdevices.info.impl.viewmodel.deviceinfo -import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGattInfoFeatureApi import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus import com.flipperdevices.bridge.connection.feature.provider.api.get @@ -50,8 +50,8 @@ class BasicInfoViewModel @Inject constructor( } private fun collectFirmwareInformation() { - fFeatureProvider.get() - .map { it as? FFeatureStatus.Supported } + fFeatureProvider.get() + .map { it as? FFeatureStatus.Supported } .flatMapLatest { it?.featureApi?.getGattInfoFlow() ?: flowOf(null) } .map { it?.softwareVersion } .onEach { softwareVersion -> From f8019260fe0adab87c1d6f60a637a6cc242dbb5a Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Mon, 16 Dec 2024 00:57:26 +0300 Subject: [PATCH 10/18] save color into settings --- .../devicecolor/api/FDeviceColorFeatureApi.kt | 4 ++-- .../impl/api/FDeviceColorFeatureApiImpl.kt | 19 +++++++++++++------ .../impl/viewmodel/FlipperColorViewModel.kt | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt index 6b3e68eb7f..7d0446ab87 100644 --- a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt +++ b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt @@ -6,8 +6,8 @@ import kotlinx.coroutines.flow.Flow interface FDeviceColorFeatureApi : FDeviceFeatureApi { /** - * Returns flipper case color + * Receive color from flipper and save it into settings * @param default default value on response failure */ - fun getColor(default: HardwareColor = HardwareColor.WHITE): Flow + fun updateAndGetColorFlow(default: HardwareColor = HardwareColor.WHITE): Flow } diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index 509bd3ac75..c8408837b4 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -1,42 +1,49 @@ package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api +import androidx.datastore.core.DataStore import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.preference.pb.HardwareColor +import com.flipperdevices.core.preference.pb.PairSettings import com.flipperdevices.protobuf.Main import com.flipperdevices.protobuf.property.GetRequest import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.onEach class FDeviceColorFeatureApiImpl @AssistedInject constructor( @Assisted private val rpcFeatureApi: FRpcFeatureApi, + private val settings: DataStore ) : FDeviceColorFeatureApi, LogTagProvider { override val TAG = "FDeviceColorFeatureApi" - override fun getColor(default: HardwareColor): Flow { - return rpcFeatureApi.request( + override fun updateAndGetColorFlow(default: HardwareColor): Flow = flow { + rpcFeatureApi.request( Main( property_get_request = GetRequest( key = RPC_KEY_HARDWARE_COLOR ) ).wrapToRequest() - ).map { result -> + ).onEach { result -> val intValue = result.getOrNull() ?.property_get_response ?.value_ ?.toIntOrNull() - when (intValue) { + val hardwareColor = when (intValue) { HardwareColor.WHITE.value -> HardwareColor.WHITE HardwareColor.BLACK.value -> HardwareColor.BLACK else -> default } - } + settings.updateData { pairSettings -> pairSettings.copy(hardware_color = hardwareColor) } + emit(hardwareColor) + }.collect() } @AssistedFactory diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt index b891a6668e..e74f786526 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt @@ -31,7 +31,7 @@ class FlipperColorViewModel @Inject constructor( fFeatureProvider.get() .filterIsInstance>() - .flatMapLatest { status -> status.featureApi.getColor() } + .flatMapLatest { status -> status.featureApi.updateAndGetColorFlow() } .onEach { hardwareColor -> settings.updateData { data -> data.copy(hardware_color = hardwareColor) From 202b8e3632c0f3b13d40a2057e5d0339d5f5df8a Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Mon, 16 Dec 2024 01:00:20 +0300 Subject: [PATCH 11/18] emit initial value --- .../devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index c8408837b4..63efeb5f42 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -14,7 +14,9 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach class FDeviceColorFeatureApiImpl @AssistedInject constructor( @@ -25,6 +27,9 @@ class FDeviceColorFeatureApiImpl @AssistedInject constructor( override val TAG = "FDeviceColorFeatureApi" override fun updateAndGetColorFlow(default: HardwareColor): Flow = flow { + settings.data.map { it.hardware_color } + .firstOrNull() + ?.let { initialColor -> emit(initialColor) } rpcFeatureApi.request( Main( property_get_request = GetRequest( From 75bbe1707bcc9e29dbbb92bd2a9ef9e87056fa3c Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 11:08:50 +0300 Subject: [PATCH 12/18] remove version check for FGattInfo --- .../impl/api/FGattInfoFeatureFactoryImpl.kt | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt index 356850183b..6db0a980be 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGattInfoFeatureFactoryImpl.kt @@ -4,24 +4,14 @@ import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi -import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi import com.flipperdevices.bridge.connection.transport.common.api.meta.FTransportMetaInfoApi -import com.flipperdevices.core.data.SemVer import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.log.LogTagProvider -import com.flipperdevices.core.log.error -import com.flipperdevices.core.log.info import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject -// todo move to shared const -private val API_SUPPORTED_GET_REQUEST = SemVer( - majorVersion = 0, - minorVersion = 14 -) - @FDeviceFeatureQualifier(FDeviceFeature.GATT_INFO) @ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) class FGattInfoFeatureFactoryImpl @Inject constructor( @@ -34,14 +24,6 @@ class FGattInfoFeatureFactoryImpl @Inject constructor( scope: CoroutineScope, connectedDevice: FConnectedDeviceApi ): FDeviceFeatureApi? { - val versionApi = unsafeFeatureDeviceApi.getUnsafe(FVersionFeatureApi::class) ?: return null - info { "Start request supported state for api level $API_SUPPORTED_GET_REQUEST" } - val isSupported = versionApi.isSupported(API_SUPPORTED_GET_REQUEST) - if (!isSupported) { - error { "Failed init FGattInfoFeatureApi, because isSupported=false" } - return null - } - val metaInfoApi = connectedDevice as? FTransportMetaInfoApi ?: return null return factory( From 77ec9e03960e9905989a0a98ce3e2c3b95da87bd Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 11:25:23 +0300 Subject: [PATCH 13/18] replace rpcapi with getInfoFeatureApi --- .../device-color/impl/build.gradle.kts | 10 ++-- .../impl/api/FDeviceColorFeatureApiImpl.kt | 52 +++++++------------ .../api/FDeviceColorFeatureFactoryImpl.kt | 24 ++------- .../getinfo/model/FGetInfoApiProperty.kt | 3 +- 4 files changed, 32 insertions(+), 57 deletions(-) diff --git a/components/bridge/connection/feature/device-color/impl/build.gradle.kts b/components/bridge/connection/feature/device-color/impl/build.gradle.kts index a79ef7b724..1b955a78f2 100644 --- a/components/bridge/connection/feature/device-color/impl/build.gradle.kts +++ b/components/bridge/connection/feature/device-color/impl/build.gradle.kts @@ -17,10 +17,12 @@ commonDependencies { implementation(projects.components.bridge.connection.feature.common.api) implementation(projects.components.bridge.connection.transport.common.api) - implementation(projects.components.bridge.connection.feature.rpc.api) - implementation(projects.components.bridge.connection.feature.rpc.model) - implementation(projects.components.bridge.connection.feature.rpcinfo.api) - implementation(projects.components.bridge.connection.feature.protocolversion.api) +// implementation(projects.components.bridge.connection.feature.rpc.api) +// implementation(projects.components.bridge.connection.feature.rpc.model) +// implementation(projects.components.bridge.connection.feature.rpcinfo.api) +// implementation(projects.components.bridge.connection.feature.protocolversion.api) + implementation(projects.components.bridge.connection.feature.getinfo.api) + implementation(projects.components.bridge.connection.config.api) implementation(projects.components.bridge.connection.pbutils) diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index 63efeb5f42..eab4c1f170 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -2,63 +2,49 @@ package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api import androidx.datastore.core.DataStore import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi -import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi -import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.log.error import com.flipperdevices.core.preference.pb.HardwareColor import com.flipperdevices.core.preference.pb.PairSettings -import com.flipperdevices.protobuf.Main -import com.flipperdevices.protobuf.property.GetRequest import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onEach class FDeviceColorFeatureApiImpl @AssistedInject constructor( - @Assisted private val rpcFeatureApi: FRpcFeatureApi, + @Assisted private val fGetInfoFeatureApi: FGetInfoFeatureApi, private val settings: DataStore ) : FDeviceColorFeatureApi, LogTagProvider { override val TAG = "FDeviceColorFeatureApi" override fun updateAndGetColorFlow(default: HardwareColor): Flow = flow { - settings.data.map { it.hardware_color } + val savedHardwareColor = settings.data.map { it.hardware_color } .firstOrNull() - ?.let { initialColor -> emit(initialColor) } - rpcFeatureApi.request( - Main( - property_get_request = GetRequest( - key = RPC_KEY_HARDWARE_COLOR - ) - ).wrapToRequest() - ).onEach { result -> - val intValue = result.getOrNull() - ?.property_get_response - ?.value_ - ?.toIntOrNull() - val hardwareColor = when (intValue) { - HardwareColor.WHITE.value -> HardwareColor.WHITE - HardwareColor.BLACK.value -> HardwareColor.BLACK - else -> default - } - settings.updateData { pairSettings -> pairSettings.copy(hardware_color = hardwareColor) } - emit(hardwareColor) - }.collect() + ?.also { initialColor -> emit(initialColor) } + val intHardwareColor = fGetInfoFeatureApi.get(FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR) + .onFailure { error(it) { "#updateAndGetColorFlow could not fetch ${FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR}" } } + .map { it.toIntOrNull() } + .getOrDefault(savedHardwareColor?.value) + + val hardwareColor = when (intHardwareColor) { + HardwareColor.WHITE.value -> HardwareColor.WHITE + HardwareColor.BLACK.value -> HardwareColor.BLACK + else -> default + } + settings.updateData { pairSettings -> pairSettings.copy(hardware_color = hardwareColor) } + emit(hardwareColor) } @AssistedFactory fun interface InternalFactory { operator fun invoke( - rpcFeatureApi: FRpcFeatureApi, + fGetInfoFeatureApi: FGetInfoFeatureApi, ): FDeviceColorFeatureApiImpl } - - companion object { - private const val RPC_KEY_HARDWARE_COLOR = "hardware.color" - } } diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt index d4d3227bbd..334d5a5d85 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt @@ -4,23 +4,14 @@ import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi -import com.flipperdevices.bridge.connection.feature.protocolversion.api.FVersionFeatureApi -import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi +import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi -import com.flipperdevices.core.data.SemVer import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.log.LogTagProvider -import com.flipperdevices.core.log.error -import com.flipperdevices.core.log.info import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject -// todo move to shared const -private val API_SUPPORTED_GET_REQUEST = SemVer( - majorVersion = 0, - minorVersion = 14 -) @FDeviceFeatureQualifier(FDeviceFeature.DEVICE_COLOR) @ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) @@ -34,16 +25,11 @@ class FDeviceColorFeatureFactoryImpl @Inject constructor( scope: CoroutineScope, connectedDevice: FConnectedDeviceApi ): FDeviceFeatureApi? { - val versionApi = unsafeFeatureDeviceApi.getUnsafe(FVersionFeatureApi::class) ?: return null - info { "Start request supported state for api level $API_SUPPORTED_GET_REQUEST" } - val isSupported = versionApi.isSupported(API_SUPPORTED_GET_REQUEST) - if (!isSupported) { - error { "Failed init FDeviceColorFeatureApi, because isSupported=false" } - return null - } - val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null + val fGetInfoFeatureApi = unsafeFeatureDeviceApi + .getUnsafe(FGetInfoFeatureApi::class) + ?: return null return factory( - rpcFeatureApi = rpcApi, + fGetInfoFeatureApi = fGetInfoFeatureApi, ) } } diff --git a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGetInfoApiProperty.kt b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGetInfoApiProperty.kt index 5b119f2c73..fc37cf9155 100644 --- a/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGetInfoApiProperty.kt +++ b/components/bridge/connection/feature/getinfo/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/model/FGetInfoApiProperty.kt @@ -25,7 +25,8 @@ sealed interface FGetInfoApiProperty { RADIO_STACK_TYPE("radio.stack.type"), RADIO_STACK_SUB("radio.stack.sub"), FIRMWARE_FORK("firmware.origin.fork"), - FIRMWARE_ORIGIN("firmware.origin.git"); + FIRMWARE_ORIGIN("firmware.origin.git"), + HARDWARE_COLOR("hardware.color"); override val group = FGetInfoApiGroup.DEVICE_INFO } From 1e06a7b30e16e22e6a3143541eab647f5150c22b Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 12:07:28 +0300 Subject: [PATCH 14/18] add flipper device color into settings --- .../connection/config/api/build.gradle.kts | 2 + .../config/api/FDevicePersistedStorage.kt | 2 + .../api/model/FDeviceFlipperZeroBleModel.kt | 8 +++- .../impl/FDevicePersistedStorageImpl.kt | 19 ++++++++- .../devicecolor/api/FDeviceColorFeatureApi.kt | 2 +- .../impl/api/FDeviceColorFeatureApiImpl.kt | 30 +++++++------ .../api/FDeviceColorFeatureFactoryImpl.kt | 1 - .../src/commonMain/proto/new_pair.proto | 10 ++++- .../impl/storage/FirstPairStorageImpl.kt | 3 +- .../api/UpdateScreenDecomposeComponent.kt | 3 +- .../impl/viewmodel/FlipperColorViewModel.kt | 42 ++++++------------- 11 files changed, 73 insertions(+), 49 deletions(-) diff --git a/components/bridge/connection/config/api/build.gradle.kts b/components/bridge/connection/config/api/build.gradle.kts index 26993b9f4c..c967afbac2 100644 --- a/components/bridge/connection/config/api/build.gradle.kts +++ b/components/bridge/connection/config/api/build.gradle.kts @@ -7,6 +7,8 @@ plugins { android.namespace = "com.flipperdevices.bridge.connection.config.api" commonDependencies { + implementation(projects.components.core.preference) + implementation(libs.kotlin.coroutines) implementation(libs.kotlin.serialization.json) } diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt index ef37eca0fc..665a65fd03 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt @@ -1,6 +1,7 @@ package com.flipperdevices.bridge.connection.config.api import com.flipperdevices.bridge.connection.config.api.model.FDeviceBaseModel +import com.flipperdevices.core.preference.pb.SavedDevice import kotlinx.coroutines.flow.Flow interface FDevicePersistedStorage { @@ -9,4 +10,5 @@ interface FDevicePersistedStorage { suspend fun addDevice(device: FDeviceBaseModel) suspend fun removeDevice(id: String) fun getAllDevices(): Flow> + suspend fun setCurrentDeviceColor(hardwareColor: SavedDevice.HardwareColor) } diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt index 4e19118528..375b95e3e7 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt @@ -1,7 +1,9 @@ package com.flipperdevices.bridge.connection.config.api.model import com.flipperdevices.bridge.connection.config.api.FDeviceType +import com.flipperdevices.core.preference.pb.SavedDevice import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient import java.util.UUID @Serializable @@ -9,7 +11,11 @@ data class FDeviceFlipperZeroBleModel( val name: String, val address: String, override val uniqueId: String = UUID.randomUUID().toString(), - override val humanReadableName: String = "Flipper $name" + override val humanReadableName: String = "Flipper $name", + private val intHardwareColor: Int ) : FDeviceBaseModel { override val type = FDeviceType.FLIPPER_ZERO_BLE + + @Transient + val hardwareColor = SavedDevice.HardwareColor.fromValue(intHardwareColor) } diff --git a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt index 4dc67be59e..74230d294b 100644 --- a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt +++ b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt @@ -85,7 +85,8 @@ class FDevicePersistedStorageImpl @Inject constructor( return FDeviceFlipperZeroBleModel( name = device.name, uniqueId = device.id, - address = flipperZeroBle.address + address = flipperZeroBle.address, + intHardwareColor = device.hardware_color.value ) } return null @@ -104,4 +105,20 @@ class FDevicePersistedStorageImpl @Inject constructor( else -> error("Can't find parser for $device") } } + + override suspend fun setCurrentDeviceColor(hardwareColor: SavedDevice.HardwareColor) { + newPairSettings.updateData { newPairSettings -> + newPairSettings.copy( + devices = newPairSettings.devices.toMutableList().apply { + replaceAll { device -> + if (device.id == newPairSettings.current_selected_device_id) { + device.copy(hardware_color = hardwareColor) + } else { + device + } + } + }.toList() + ) + } + } } diff --git a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt index 7d0446ab87..2f803f3a4c 100644 --- a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt +++ b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt @@ -1,7 +1,7 @@ package com.flipperdevices.bridge.connection.feature.devicecolor.api import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi -import com.flipperdevices.core.preference.pb.HardwareColor +import com.flipperdevices.core.preference.pb.SavedDevice.HardwareColor import kotlinx.coroutines.flow.Flow interface FDeviceColorFeatureApi : FDeviceFeatureApi { diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index eab4c1f170..b55fa7eb20 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -1,43 +1,49 @@ package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api -import androidx.datastore.core.DataStore +import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage +import com.flipperdevices.bridge.connection.config.api.model.FDeviceFlipperZeroBleModel import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.log.error -import com.flipperdevices.core.preference.pb.HardwareColor -import com.flipperdevices.core.preference.pb.PairSettings +import com.flipperdevices.core.preference.pb.SavedDevice.HardwareColor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.map class FDeviceColorFeatureApiImpl @AssistedInject constructor( @Assisted private val fGetInfoFeatureApi: FGetInfoFeatureApi, - private val settings: DataStore + private val fDevicePersistedStorage: FDevicePersistedStorage ) : FDeviceColorFeatureApi, LogTagProvider { override val TAG = "FDeviceColorFeatureApi" override fun updateAndGetColorFlow(default: HardwareColor): Flow = flow { - val savedHardwareColor = settings.data.map { it.hardware_color } - .firstOrNull() - ?.also { initialColor -> emit(initialColor) } + val currentColoredDevice = fDevicePersistedStorage + .getCurrentDevice() + .first() as? FDeviceFlipperZeroBleModel + if (currentColoredDevice != null) { + emit(currentColoredDevice.hardwareColor) + } + val intHardwareColor = fGetInfoFeatureApi.get(FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR) - .onFailure { error(it) { "#updateAndGetColorFlow could not fetch ${FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR}" } } + .onFailure { error( + it + ) { "#updateAndGetColorFlow could not fetch ${FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR}" } } .map { it.toIntOrNull() } - .getOrDefault(savedHardwareColor?.value) + .getOrNull() val hardwareColor = when (intHardwareColor) { HardwareColor.WHITE.value -> HardwareColor.WHITE HardwareColor.BLACK.value -> HardwareColor.BLACK + HardwareColor.TRANSPARENT.value -> HardwareColor.TRANSPARENT else -> default } - settings.updateData { pairSettings -> pairSettings.copy(hardware_color = hardwareColor) } + fDevicePersistedStorage.setCurrentDeviceColor(hardwareColor) emit(hardwareColor) } diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt index 334d5a5d85..2649352a97 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureFactoryImpl.kt @@ -12,7 +12,6 @@ import com.squareup.anvil.annotations.ContributesMultibinding import kotlinx.coroutines.CoroutineScope import javax.inject.Inject - @FDeviceFeatureQualifier(FDeviceFeature.DEVICE_COLOR) @ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) class FDeviceColorFeatureFactoryImpl @Inject constructor( diff --git a/components/core/preference/src/commonMain/proto/new_pair.proto b/components/core/preference/src/commonMain/proto/new_pair.proto index ba5921ae52..29aa2665b5 100644 --- a/components/core/preference/src/commonMain/proto/new_pair.proto +++ b/components/core/preference/src/commonMain/proto/new_pair.proto @@ -19,8 +19,16 @@ message SavedDevice { oneof data { FlipperZeroBle flipper_zero_ble = 10; } + + enum HardwareColor { + WHITE = 0; + BLACK = 1; + TRANSPARENT = 2; + } + + HardwareColor hardware_color = 11; } message FlipperZeroBle { string address = 1; -} \ No newline at end of file +} diff --git a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt index 962d807053..ebb3fd00f0 100644 --- a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt +++ b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt @@ -58,7 +58,8 @@ class FirstPairStorageImpl @Inject constructor( val device = FDeviceFlipperZeroBleModel( name = deviceNameFormatted, address = address.orEmpty(), - uniqueId = deviceId ?: UUID.randomUUID().toString() + uniqueId = deviceId ?: UUID.randomUUID().toString(), + intHardwareColor = pairSetting.hardware_color.value ) persistedStorage.addDevice(device) persistedStorage.setCurrentDevice(deviceId) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt index 6bee24fdf9..d17fca2675 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/api/UpdateScreenDecomposeComponent.kt @@ -9,6 +9,7 @@ import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.router.stack.StackNavigator import com.arkivanov.decompose.router.stack.pushToFront import com.flipperdevices.bottombar.handlers.ResetTabDecomposeHandler +import com.flipperdevices.core.preference.pb.HardwareColor import com.flipperdevices.core.ui.lifecycle.viewModelWithFactory import com.flipperdevices.deeplink.model.Deeplink import com.flipperdevices.info.impl.compose.screens.ComposableDeviceInfoScreen @@ -99,7 +100,7 @@ class UpdateScreenDecomposeComponent @AssistedInject constructor( deeplink = deeplink, deviceStatus = deviceStatus, connectViewModel = connectViewModel, - hardwareColor = flipperColor, + hardwareColor = HardwareColor.fromValue(flipperColor.value), // TODO change after full migration supportedState = supportState, updateState = updateState, hasAlarm = alarmViewModel.hasAlarm.collectAsState().value, diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt index e74f786526..3ad40f4cf1 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt @@ -1,41 +1,23 @@ package com.flipperdevices.info.impl.viewmodel -import androidx.datastore.core.DataStore -import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi -import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureProvider -import com.flipperdevices.bridge.connection.feature.provider.api.FFeatureStatus -import com.flipperdevices.bridge.connection.feature.provider.api.get -import com.flipperdevices.core.preference.pb.HardwareColor -import com.flipperdevices.core.preference.pb.PairSettings +import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage +import com.flipperdevices.bridge.connection.config.api.model.FDeviceFlipperZeroBleModel +import com.flipperdevices.core.preference.pb.SavedDevice import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel -import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filterIsInstance -import kotlinx.coroutines.flow.flatMapLatest -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import javax.inject.Inject class FlipperColorViewModel @Inject constructor( - private val settings: DataStore, - fFeatureProvider: FFeatureProvider + fDevicePersistedStorage: FDevicePersistedStorage, ) : DecomposeViewModel() { - private val colorFlipperState = MutableStateFlow(HardwareColor.fromValue(-1)) + private val colorFlipperState = fDevicePersistedStorage.getCurrentDevice() + .filterIsInstance() + .map { coloredDevice -> coloredDevice.hardwareColor } + .stateIn(viewModelScope, SharingStarted.Eagerly, SavedDevice.HardwareColor.fromValue(-1)) - fun getFlipperColor(): StateFlow = colorFlipperState - - init { - settings.data.onEach { - colorFlipperState.emit(it.hardware_color) - }.launchIn(viewModelScope) - - fFeatureProvider.get() - .filterIsInstance>() - .flatMapLatest { status -> status.featureApi.updateAndGetColorFlow() } - .onEach { hardwareColor -> - settings.updateData { data -> - data.copy(hardware_color = hardwareColor) - } - }.launchIn(viewModelScope) - } + fun getFlipperColor(): StateFlow = colorFlipperState } From edfc99d5824c62841c006b96570d423a07e02b78 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 12:11:32 +0300 Subject: [PATCH 15/18] fix serializer for hardware color --- .../api/model/FDeviceFlipperZeroBleModel.kt | 8 +++--- .../serialization/HardwareColorSerializer.kt | 25 +++++++++++++++++++ .../impl/FDevicePersistedStorageImpl.kt | 2 +- .../impl/storage/FirstPairStorageImpl.kt | 3 ++- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt index 375b95e3e7..c185064c89 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt @@ -1,9 +1,9 @@ package com.flipperdevices.bridge.connection.config.api.model import com.flipperdevices.bridge.connection.config.api.FDeviceType +import com.flipperdevices.bridge.connection.config.api.serialization.HardwareColorSerializer import com.flipperdevices.core.preference.pb.SavedDevice import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient import java.util.UUID @Serializable @@ -12,10 +12,8 @@ data class FDeviceFlipperZeroBleModel( val address: String, override val uniqueId: String = UUID.randomUUID().toString(), override val humanReadableName: String = "Flipper $name", - private val intHardwareColor: Int + @Serializable(HardwareColorSerializer::class) + private val hardwareColor: SavedDevice.HardwareColor ) : FDeviceBaseModel { override val type = FDeviceType.FLIPPER_ZERO_BLE - - @Transient - val hardwareColor = SavedDevice.HardwareColor.fromValue(intHardwareColor) } diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt new file mode 100644 index 0000000000..c50e2e4ae7 --- /dev/null +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt @@ -0,0 +1,25 @@ +package com.flipperdevices.bridge.connection.config.api.serialization + +import com.flipperdevices.core.preference.pb.SavedDevice +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +internal object HardwareColorSerializer : KSerializer { + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( + serialName = "com.flipperdevices.SavedDevice.HardwareColor", + kind = PrimitiveKind.INT + ) + + override fun deserialize(decoder: Decoder): SavedDevice.HardwareColor { + val intValue = decoder.decodeInt() + return SavedDevice.HardwareColor.fromValue(intValue) + } + + override fun serialize(encoder: Encoder, value: SavedDevice.HardwareColor) { + encoder.encodeInt(value.value) + } +} \ No newline at end of file diff --git a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt index 74230d294b..f7602b3051 100644 --- a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt +++ b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt @@ -86,7 +86,7 @@ class FDevicePersistedStorageImpl @Inject constructor( name = device.name, uniqueId = device.id, address = flipperZeroBle.address, - intHardwareColor = device.hardware_color.value + hardwareColor = device.hardware_color ) } return null diff --git a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt index ebb3fd00f0..60a9392796 100644 --- a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt +++ b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt @@ -8,6 +8,7 @@ import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.ktx.jre.runBlockingWithLog import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.preference.pb.PairSettings +import com.flipperdevices.core.preference.pb.SavedDevice import com.squareup.anvil.annotations.ContributesBinding import kotlinx.coroutines.flow.first import java.util.UUID @@ -59,7 +60,7 @@ class FirstPairStorageImpl @Inject constructor( name = deviceNameFormatted, address = address.orEmpty(), uniqueId = deviceId ?: UUID.randomUUID().toString(), - intHardwareColor = pairSetting.hardware_color.value + hardwareColor = SavedDevice.HardwareColor.fromValue(pairSetting.hardware_color.value) ) persistedStorage.addDevice(device) persistedStorage.setCurrentDevice(deviceId) From 51515f0eaabb776ab40079244dd1fef4ca5eeaa7 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 12:14:15 +0300 Subject: [PATCH 16/18] fix serializer for hardware color --- .../connection/config/api/model/FDeviceFlipperZeroBleModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt index c185064c89..b88c57e295 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt @@ -13,7 +13,7 @@ data class FDeviceFlipperZeroBleModel( override val uniqueId: String = UUID.randomUUID().toString(), override val humanReadableName: String = "Flipper $name", @Serializable(HardwareColorSerializer::class) - private val hardwareColor: SavedDevice.HardwareColor + val hardwareColor: SavedDevice.HardwareColor ) : FDeviceBaseModel { override val type = FDeviceType.FLIPPER_ZERO_BLE } From dad9fcfc7212eeb70224582dfdecaf30b2b9f6a7 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 12:21:25 +0300 Subject: [PATCH 17/18] fix hardware color location --- .../connection/config/api/FDevicePersistedStorage.kt | 4 ++-- .../config/api/model/FDeviceFlipperZeroBleModel.kt | 4 ++-- .../api/serialization/HardwareColorSerializer.kt | 10 +++++----- .../config/impl/FDevicePersistedStorageImpl.kt | 11 ++++++++--- .../feature/devicecolor/api/FDeviceColorFeatureApi.kt | 2 +- .../feature/device-color/impl/build.gradle.kts | 4 ---- .../impl/api/FDeviceColorFeatureApiImpl.kt | 2 +- .../preference/src/commonMain/proto/new_pair.proto | 10 +++++----- components/firstpair/impl/build.gradle.kts | 5 ----- .../firstpair/impl/storage/FirstPairStorageImpl.kt | 4 ++-- .../info/impl/viewmodel/FlipperColorViewModel.kt | 6 ++++-- 11 files changed, 30 insertions(+), 32 deletions(-) diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt index 665a65fd03..21f5807183 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/FDevicePersistedStorage.kt @@ -1,7 +1,7 @@ package com.flipperdevices.bridge.connection.config.api import com.flipperdevices.bridge.connection.config.api.model.FDeviceBaseModel -import com.flipperdevices.core.preference.pb.SavedDevice +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import kotlinx.coroutines.flow.Flow interface FDevicePersistedStorage { @@ -10,5 +10,5 @@ interface FDevicePersistedStorage { suspend fun addDevice(device: FDeviceBaseModel) suspend fun removeDevice(id: String) fun getAllDevices(): Flow> - suspend fun setCurrentDeviceColor(hardwareColor: SavedDevice.HardwareColor) + suspend fun setCurrentDeviceColor(hardwareColor: HardwareColor) } diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt index b88c57e295..17f431f10b 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/model/FDeviceFlipperZeroBleModel.kt @@ -2,7 +2,7 @@ package com.flipperdevices.bridge.connection.config.api.model import com.flipperdevices.bridge.connection.config.api.FDeviceType import com.flipperdevices.bridge.connection.config.api.serialization.HardwareColorSerializer -import com.flipperdevices.core.preference.pb.SavedDevice +import com.flipperdevices.core.preference.pb.FlipperZeroBle import kotlinx.serialization.Serializable import java.util.UUID @@ -13,7 +13,7 @@ data class FDeviceFlipperZeroBleModel( override val uniqueId: String = UUID.randomUUID().toString(), override val humanReadableName: String = "Flipper $name", @Serializable(HardwareColorSerializer::class) - val hardwareColor: SavedDevice.HardwareColor + val hardwareColor: FlipperZeroBle.HardwareColor ) : FDeviceBaseModel { override val type = FDeviceType.FLIPPER_ZERO_BLE } diff --git a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt index c50e2e4ae7..2820aff094 100644 --- a/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt +++ b/components/bridge/connection/config/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt @@ -1,6 +1,6 @@ package com.flipperdevices.bridge.connection.config.api.serialization -import com.flipperdevices.core.preference.pb.SavedDevice +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import kotlinx.serialization.KSerializer import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor @@ -8,18 +8,18 @@ import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -internal object HardwareColorSerializer : KSerializer { +internal object HardwareColorSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( serialName = "com.flipperdevices.SavedDevice.HardwareColor", kind = PrimitiveKind.INT ) - override fun deserialize(decoder: Decoder): SavedDevice.HardwareColor { + override fun deserialize(decoder: Decoder): HardwareColor { val intValue = decoder.decodeInt() - return SavedDevice.HardwareColor.fromValue(intValue) + return HardwareColor.fromValue(intValue) } - override fun serialize(encoder: Encoder, value: SavedDevice.HardwareColor) { + override fun serialize(encoder: Encoder, value: HardwareColor) { encoder.encodeInt(value.value) } } \ No newline at end of file diff --git a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt index f7602b3051..8be4511173 100644 --- a/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt +++ b/components/bridge/connection/config/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/config/impl/FDevicePersistedStorageImpl.kt @@ -9,6 +9,7 @@ import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.log.info import com.flipperdevices.core.log.warn import com.flipperdevices.core.preference.pb.FlipperZeroBle +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import com.flipperdevices.core.preference.pb.NewPairSettings import com.flipperdevices.core.preference.pb.SavedDevice import com.squareup.anvil.annotations.ContributesBinding @@ -86,7 +87,7 @@ class FDevicePersistedStorageImpl @Inject constructor( name = device.name, uniqueId = device.id, address = flipperZeroBle.address, - hardwareColor = device.hardware_color + hardwareColor = flipperZeroBle.hardware_color ) } return null @@ -106,13 +107,17 @@ class FDevicePersistedStorageImpl @Inject constructor( } } - override suspend fun setCurrentDeviceColor(hardwareColor: SavedDevice.HardwareColor) { + override suspend fun setCurrentDeviceColor(hardwareColor: HardwareColor) { newPairSettings.updateData { newPairSettings -> newPairSettings.copy( devices = newPairSettings.devices.toMutableList().apply { replaceAll { device -> if (device.id == newPairSettings.current_selected_device_id) { - device.copy(hardware_color = hardwareColor) + device.copy( + flipper_zero_ble = device + .flipper_zero_ble + ?.copy(hardware_color = hardwareColor) + ) } else { device } diff --git a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt index 2f803f3a4c..a796c92b52 100644 --- a/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt +++ b/components/bridge/connection/feature/device-color/api/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt @@ -1,7 +1,7 @@ package com.flipperdevices.bridge.connection.feature.devicecolor.api import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi -import com.flipperdevices.core.preference.pb.SavedDevice.HardwareColor +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import kotlinx.coroutines.flow.Flow interface FDeviceColorFeatureApi : FDeviceFeatureApi { diff --git a/components/bridge/connection/feature/device-color/impl/build.gradle.kts b/components/bridge/connection/feature/device-color/impl/build.gradle.kts index 1b955a78f2..6ed556331a 100644 --- a/components/bridge/connection/feature/device-color/impl/build.gradle.kts +++ b/components/bridge/connection/feature/device-color/impl/build.gradle.kts @@ -17,10 +17,6 @@ commonDependencies { implementation(projects.components.bridge.connection.feature.common.api) implementation(projects.components.bridge.connection.transport.common.api) -// implementation(projects.components.bridge.connection.feature.rpc.api) -// implementation(projects.components.bridge.connection.feature.rpc.model) -// implementation(projects.components.bridge.connection.feature.rpcinfo.api) -// implementation(projects.components.bridge.connection.feature.protocolversion.api) implementation(projects.components.bridge.connection.feature.getinfo.api) implementation(projects.components.bridge.connection.config.api) diff --git a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt index b55fa7eb20..6dff7c77b4 100644 --- a/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt +++ b/components/bridge/connection/feature/device-color/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt @@ -7,7 +7,7 @@ import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureA import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.core.log.error -import com.flipperdevices.core.preference.pb.SavedDevice.HardwareColor +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject diff --git a/components/core/preference/src/commonMain/proto/new_pair.proto b/components/core/preference/src/commonMain/proto/new_pair.proto index 29aa2665b5..98dc771373 100644 --- a/components/core/preference/src/commonMain/proto/new_pair.proto +++ b/components/core/preference/src/commonMain/proto/new_pair.proto @@ -19,6 +19,10 @@ message SavedDevice { oneof data { FlipperZeroBle flipper_zero_ble = 10; } +} + +message FlipperZeroBle { + string address = 1; enum HardwareColor { WHITE = 0; @@ -26,9 +30,5 @@ message SavedDevice { TRANSPARENT = 2; } - HardwareColor hardware_color = 11; -} - -message FlipperZeroBle { - string address = 1; + HardwareColor hardware_color = 2; } diff --git a/components/firstpair/impl/build.gradle.kts b/components/firstpair/impl/build.gradle.kts index 02a53dce72..6a5e0d12e5 100644 --- a/components/firstpair/impl/build.gradle.kts +++ b/components/firstpair/impl/build.gradle.kts @@ -29,11 +29,6 @@ dependencies { implementation(libs.ble.common) implementation(libs.ble.scan) - // BLE-new -// implementation(projects.components.bridge.connection.transport.ble.api) -// implementation(projects.components.bridge.connection.transport.common.api) -// implementation(projects.components.bridge.connection.orchestrator.api) -// implementation(projects.components.bridge.connection.device.common.api) implementation(projects.components.bridge.connection.config.api) implementation(libs.appcompat) diff --git a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt index 60a9392796..6ca788b46a 100644 --- a/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt +++ b/components/firstpair/impl/src/main/java/com/flipperdevices/firstpair/impl/storage/FirstPairStorageImpl.kt @@ -7,8 +7,8 @@ import com.flipperdevices.bridge.connection.config.api.model.FDeviceFlipperZeroB import com.flipperdevices.core.di.AppGraph import com.flipperdevices.core.ktx.jre.runBlockingWithLog import com.flipperdevices.core.log.LogTagProvider +import com.flipperdevices.core.preference.pb.FlipperZeroBle import com.flipperdevices.core.preference.pb.PairSettings -import com.flipperdevices.core.preference.pb.SavedDevice import com.squareup.anvil.annotations.ContributesBinding import kotlinx.coroutines.flow.first import java.util.UUID @@ -60,7 +60,7 @@ class FirstPairStorageImpl @Inject constructor( name = deviceNameFormatted, address = address.orEmpty(), uniqueId = deviceId ?: UUID.randomUUID().toString(), - hardwareColor = SavedDevice.HardwareColor.fromValue(pairSetting.hardware_color.value) + hardwareColor = FlipperZeroBle.HardwareColor.fromValue(pairSetting.hardware_color.value) ) persistedStorage.addDevice(device) persistedStorage.setCurrentDevice(deviceId) diff --git a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt index 3ad40f4cf1..82140a5a0e 100644 --- a/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt +++ b/components/info/impl/src/main/java/com/flipperdevices/info/impl/viewmodel/FlipperColorViewModel.kt @@ -2,6 +2,8 @@ package com.flipperdevices.info.impl.viewmodel import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage import com.flipperdevices.bridge.connection.config.api.model.FDeviceFlipperZeroBleModel +import com.flipperdevices.core.preference.pb.FlipperZeroBle +import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor import com.flipperdevices.core.preference.pb.SavedDevice import com.flipperdevices.core.ui.lifecycle.DecomposeViewModel import kotlinx.coroutines.flow.SharingStarted @@ -17,7 +19,7 @@ class FlipperColorViewModel @Inject constructor( private val colorFlipperState = fDevicePersistedStorage.getCurrentDevice() .filterIsInstance() .map { coloredDevice -> coloredDevice.hardwareColor } - .stateIn(viewModelScope, SharingStarted.Eagerly, SavedDevice.HardwareColor.fromValue(-1)) + .stateIn(viewModelScope, SharingStarted.Eagerly, HardwareColor.fromValue(-1)) - fun getFlipperColor(): StateFlow = colorFlipperState + fun getFlipperColor(): StateFlow = colorFlipperState } From b5bd89728a9948bd1e74074d3d8421c07f6c3c83 Mon Sep 17 00:00:00 2001 From: Roman Makeev Date: Wed, 18 Dec 2024 12:25:05 +0300 Subject: [PATCH 18/18] fix commit for FGetInfoFeatureApiImpl --- .../feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt index 188d03fd09..b81e556bce 100644 --- a/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt +++ b/components/bridge/connection/feature/getinfo/impl/src/commonMain/kotlin/com/flipperdevices/bridge/connection/feature/getinfo/impl/api/FGetInfoFeatureApiImpl.kt @@ -6,7 +6,6 @@ import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiGro import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest -import com.flipperdevices.core.log.LogTagProvider import com.flipperdevices.protobuf.Main import com.flipperdevices.protobuf.property.GetRequest import dagger.assisted.Assisted @@ -18,8 +17,7 @@ import kotlinx.coroutines.flow.mapNotNull class FGetInfoFeatureApiImpl @AssistedInject constructor( @Assisted private val rpcFeatureApi: FRpcFeatureApi, -) : FGetInfoFeatureApi, LogTagProvider { - override val TAG: String = "FGetInfoFeatureApi" +) : FGetInfoFeatureApi { private val mapper = FGetInfoApiKeyMapper() override suspend fun get( @@ -43,7 +41,7 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor( @AssistedFactory fun interface InternalFactory { operator fun invoke( - rpcFeatureApi: FRpcFeatureApi, + rpcFeatureApi: FRpcFeatureApi ): FGetInfoFeatureApiImpl } }