Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate filemanager to new ble api #958

Merged
merged 10 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Attention: don't forget to add the flag for F-Droid before release
- [Refactor] Remove ktorfit
- [Refactor] Add `core:storage`
- [Refactor] Add `core:atomicfile`
- [Refactor] Migrate filemanager to new ble api
- [FIX] Distinct fap items by id in paging sources
- [FIX] Battery level charge
- [FIX] Button arrow tint
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ commonDependencies {
implementation(projects.components.bridge.connection.feature.serialspeed.api)
implementation(projects.components.bridge.connection.feature.protocolversion.api)
implementation(projects.components.bridge.connection.feature.rpcinfo.api)
implementation(projects.components.bridge.connection.feature.storage.api)
implementation(projects.components.bridge.connection.feature.storageinfo.api)
implementation(projects.components.bridge.connection.feature.getinfo.api)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi
import com.flipperdevices.bridge.connection.feature.rpcinfo.api.FRpcInfoFeatureApi
import com.flipperdevices.bridge.connection.feature.seriallagsdetector.api.FLagsDetectorFeature
import com.flipperdevices.bridge.connection.feature.serialspeed.api.FSpeedFeatureApi
import com.flipperdevices.bridge.connection.feature.storage.api.FStorageFeatureApi
import com.flipperdevices.bridge.connection.feature.storageinfo.api.FStorageInfoFeatureApi
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.toPersistentMap
Expand All @@ -28,6 +29,7 @@ object FZeroFeatureClassToEnumMapper {
FDeviceFeature.RPC_INFO -> FRpcInfoFeatureApi::class
FDeviceFeature.STORAGE_INFO -> FStorageInfoFeatureApi::class
FDeviceFeature.GET_INFO -> FGetInfoFeatureApi::class
FDeviceFeature.STORAGE -> FStorageFeatureApi::class
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum class FDeviceFeature {
SERIAL_SPEED,
VERSION,
RPC_INFO,
STORAGE,
STORAGE_INFO,
GET_INFO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ 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.protobuf.CommandStatus
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.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull

Expand All @@ -22,33 +20,21 @@ class FGetInfoFeatureApiImpl @AssistedInject constructor(
) : FGetInfoFeatureApi {
private val mapper = FGetInfoApiKeyMapper()

override suspend fun get(property: FGetInfoApiProperty) = runCatching {
val forkResponse = rpcFeatureApi.request(
flowOf(
Main(
property_get_request = GetRequest(key = property.path)
).wrapToRequest()
)
)
val forkValue = if (forkResponse.command_status == CommandStatus.OK) {
forkResponse.property_get_response?.value_
} else {
null
}

if (forkValue == null) {
error(forkResponse.command_status.toString())
}

return@runCatching forkValue
}
override suspend fun get(
property: FGetInfoApiProperty
) = rpcFeatureApi.requestOnce(
Main(
property_get_request = GetRequest(key = property.path)
).wrapToRequest()
).mapCatching { it.property_get_response!!.value_ }

override fun get(group: FGetInfoApiGroup): Flow<Pair<FGetInfoApiProperty, String>> {
return rpcFeatureApi.request(
Main(
property_get_request = GetRequest(key = group.key)
).wrapToRequest()
).mapNotNull { it.property_get_response }
).mapNotNull { it.getOrNull() }
.mapNotNull { it.property_get_response }
.map { mapper.map(group, it.key) to it.value_ }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,24 @@ interface FRpcFeatureApi : FDeviceFeatureApi {
fun notificationFlow(): Flow<Main>

/**
* Send request and wait answer from them
* Send request and wait answer from them.
*
* You can use the extension Flow<Result<T>>.toThrowableFlow(): Flow<T> for more convenient error catching
*/
fun request(command: FlipperRequest): Flow<Main>
fun request(command: FlipperRequest): Flow<Result<Main>>

/**
* Send request and wait single answer
*/
suspend fun requestOnce(command: FlipperRequest): Result<Main>

/**
* Send batch of request in flipper and wait single answer
*/
suspend fun request(
commandFlow: Flow<FlipperRequest>,
onCancel: suspend (Int) -> Unit = {}
): Main
): Result<Main>

/**
* Send batch request without waiting response
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcAppCantStartException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcAppCmdErrorException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcAppNotRunningException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcAppSystemLockedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcBusyException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcContinuousCommandInterruptedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcDecodeException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

abstract class FRpcException : Throwable() {
abstract val response: Main
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcGeneralException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcGpioModeIncorrectException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcGpioUnknownPinModeException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcInvalidParametersException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcNotImplementedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageAlreadyOpenException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageDeniedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageDirNotEmptyException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageExistException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageInternalException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageInvalidNameException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageInvalidParameterException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageNotExistException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageNotImplementedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcStorageNotReadyException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcVirtualDisplayAlreadyStartedException(
override val response: Main
) : FRpcException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.bridge.connection.feature.rpc.api.exception

import com.flipperdevices.protobuf.Main

data class FRpcVirtualDisplayNotStartedException(
override val response: Main
) : FRpcException()
Loading
Loading