-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate screenstreaming to new api (#1004)
**Background** Migrate screenstreaming to new api **Changes** - Migrated screenstreaming module - Added screenstreaming feature module **Test plan** - Open screenstreaming in mobile app - Close it - See there's no evet subscription leaks - See it's working as intended
- Loading branch information
1 parent
2ca9625
commit e59392f
Showing
21 changed files
with
454 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
components/bridge/connection/feature/screenstreaming/api/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.screenstreaming.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(projects.components.bridge.connection.pbutils) | ||
|
||
implementation(libs.kotlin.immutable.collections) | ||
implementation(libs.kotlin.coroutines) | ||
} |
22 changes: 22 additions & 0 deletions
22
...lipperdevices/bridge/connection/feature/screenstreaming/api/FScreenStreamingFeatureApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi | ||
import com.flipperdevices.protobuf.Main | ||
import com.flipperdevices.protobuf.screen.InputKey | ||
import com.flipperdevices.protobuf.screen.InputType | ||
import com.flipperdevices.protobuf.screen.ScreenFrame | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface FScreenStreamingFeatureApi : FDeviceFeatureApi { | ||
suspend fun awaitInput(inputKey: InputKey, inputType: InputType): Flow<Result<Main>> | ||
|
||
suspend fun sendInputAndForget(inputKey: InputKey, inputType: InputType) | ||
|
||
suspend fun stop(): Result<Main> | ||
|
||
/** | ||
* Start collect [ScreenFrame]. | ||
* Need to call [stop] to cancel data sending from flipper | ||
*/ | ||
suspend fun guiScreenFrameFlow(): Flow<ScreenFrame> | ||
} |
8 changes: 8 additions & 0 deletions
8
...m/flipperdevices/bridge/connection/feature/screenstreaming/api/FScreenUnlockFeatureApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi | ||
import com.flipperdevices.protobuf.Main | ||
|
||
interface FScreenUnlockFeatureApi : FDeviceFeatureApi { | ||
suspend fun unlock(): Result<Main> | ||
} |
27 changes: 27 additions & 0 deletions
27
components/bridge/connection/feature/screenstreaming/impl/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
id("flipper.anvil-multiplatform") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.screenstreaming.impl" | ||
|
||
commonDependencies { | ||
implementation(projects.components.bridge.connection.feature.screenstreaming.api) | ||
|
||
implementation(projects.components.core.di) | ||
implementation(projects.components.core.log) | ||
implementation(projects.components.core.ktx) | ||
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) | ||
|
||
implementation(libs.kotlin.coroutines) | ||
} |
29 changes: 29 additions & 0 deletions
29
...devices/bridge/connection/feature/screenstreaming/impl/api/FScreenStreamingFactoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.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.SCREEN_STREAMING) | ||
@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) | ||
class FScreenStreamingFactoryImpl @Inject constructor( | ||
private val factory: FScreenStreamingFeatureApiImpl.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, | ||
) | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ices/bridge/connection/feature/screenstreaming/impl/api/FScreenStreamingFeatureApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.impl.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest | ||
import com.flipperdevices.bridge.connection.feature.screenstreaming.api.FScreenStreamingFeatureApi | ||
import com.flipperdevices.core.log.LogTagProvider | ||
import com.flipperdevices.protobuf.Main | ||
import com.flipperdevices.protobuf.screen.InputKey | ||
import com.flipperdevices.protobuf.screen.InputType | ||
import com.flipperdevices.protobuf.screen.ScreenFrame | ||
import com.flipperdevices.protobuf.screen.SendInputEventRequest | ||
import com.flipperdevices.protobuf.screen.StartScreenStreamRequest | ||
import com.flipperdevices.protobuf.screen.StopScreenStreamRequest | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.mapNotNull | ||
|
||
class FScreenStreamingFeatureApiImpl @AssistedInject constructor( | ||
@Assisted private val rpcFeatureApi: FRpcFeatureApi, | ||
) : FScreenStreamingFeatureApi, | ||
LogTagProvider { | ||
override val TAG = "FScreenStreamingFeatureApi" | ||
|
||
override suspend fun sendInputAndForget(inputKey: InputKey, inputType: InputType) { | ||
return rpcFeatureApi.requestWithoutAnswer( | ||
Main( | ||
gui_send_input_event_request = SendInputEventRequest( | ||
key = inputKey, | ||
type = inputType | ||
) | ||
).wrapToRequest() | ||
) | ||
} | ||
|
||
override suspend fun awaitInput(inputKey: InputKey, inputType: InputType): Flow<Result<Main>> { | ||
return rpcFeatureApi.request( | ||
Main( | ||
gui_send_input_event_request = SendInputEventRequest( | ||
key = inputKey, | ||
type = inputType | ||
) | ||
).wrapToRequest() | ||
) | ||
} | ||
|
||
override suspend fun stop(): Result<Main> { | ||
return rpcFeatureApi.requestOnce( | ||
Main( | ||
gui_stop_screen_stream_request = StopScreenStreamRequest() | ||
).wrapToRequest() | ||
) | ||
} | ||
|
||
override suspend fun guiScreenFrameFlow(): Flow<ScreenFrame> { | ||
return rpcFeatureApi.request( | ||
Main( | ||
gui_start_screen_stream_request = StartScreenStreamRequest() | ||
).wrapToRequest() | ||
).mapNotNull { result -> result.getOrNull()?.gui_screen_frame } | ||
} | ||
|
||
@AssistedFactory | ||
fun interface InternalFactory { | ||
operator fun invoke( | ||
rpcFeatureApi: FRpcFeatureApi, | ||
): FScreenStreamingFeatureApiImpl | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...perdevices/bridge/connection/feature/screenstreaming/impl/api/FScreenUnlockFactoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.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.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_UNLOCK = SemVer( | ||
majorVersion = 0, | ||
minorVersion = 16 | ||
) | ||
|
||
@FDeviceFeatureQualifier(FDeviceFeature.SCREEN_UNLOCK) | ||
@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) | ||
class FScreenUnlockFactoryImpl @Inject constructor( | ||
private val factory: FScreenUnlockFeatureApiImpl.InternalFactory | ||
) : FDeviceFeatureApi.Factory, LogTagProvider { | ||
override val TAG: String = "FScreenUnlockFactoryImpl" | ||
|
||
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_UNLOCK" } | ||
val isSupported = versionApi.isSupported(API_SUPPORTED_UNLOCK) | ||
if (!isSupported) { | ||
error { "Failed init FScreenUnlockFeatureApi, because isSupported=false" } | ||
return null | ||
} | ||
info { "Version $API_SUPPORTED_UNLOCK supported, so continue building FScreenUnlockFeatureApi" } | ||
|
||
val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null | ||
return factory( | ||
rpcFeatureApi = rpcApi, | ||
) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...devices/bridge/connection/feature/screenstreaming/impl/api/FScreenUnlockFeatureApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.flipperdevices.bridge.connection.feature.screenstreaming.impl.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.rpc.model.FlipperRequestPriority | ||
import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest | ||
import com.flipperdevices.bridge.connection.feature.screenstreaming.api.FScreenUnlockFeatureApi | ||
import com.flipperdevices.core.log.LogTagProvider | ||
import com.flipperdevices.protobuf.Main | ||
import com.flipperdevices.protobuf.desktop.UnlockRequest | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
class FScreenUnlockFeatureApiImpl @AssistedInject constructor( | ||
@Assisted private val rpcFeatureApi: FRpcFeatureApi, | ||
) : FScreenUnlockFeatureApi, | ||
LogTagProvider { | ||
override val TAG = "FScreenUnlockFeatureApi" | ||
|
||
override suspend fun unlock(): Result<Main> { | ||
return rpcFeatureApi.requestOnce( | ||
Main( | ||
desktop_unlock_request = UnlockRequest() | ||
).wrapToRequest(FlipperRequestPriority.FOREGROUND) | ||
) | ||
} | ||
|
||
@AssistedFactory | ||
fun interface InternalFactory { | ||
operator fun invoke( | ||
rpcFeatureApi: FRpcFeatureApi, | ||
): FScreenUnlockFeatureApiImpl | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.