Skip to content

Commit 4a3b117

Browse files
committed
fix: do not momentarily show pair adb steps after connecting to a wifi network
1 parent 4c61530 commit 4a3b117

1 file changed

Lines changed: 33 additions & 13 deletions

File tree

base/src/main/java/io/github/sds100/keymapper/base/expertmode/SystemBridgeSetupUseCase.kt

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import io.github.sds100.keymapper.system.permissions.PermissionAdapter
2323
import io.github.sds100.keymapper.system.root.SuAdapter
2424
import io.github.sds100.keymapper.system.shizuku.ShizukuAdapter
2525
import javax.inject.Inject
26-
import kotlinx.coroutines.Dispatchers
2726
import kotlinx.coroutines.ExperimentalCoroutinesApi
2827
import kotlinx.coroutines.flow.Flow
2928
import kotlinx.coroutines.flow.combine
29+
import kotlinx.coroutines.flow.emptyFlow
3030
import kotlinx.coroutines.flow.flatMapLatest
31+
import kotlinx.coroutines.flow.flow
3132
import kotlinx.coroutines.flow.flowOf
32-
import kotlinx.coroutines.flow.flowOn
3333
import kotlinx.coroutines.flow.map
3434

3535
@OptIn(ExperimentalCoroutinesApi::class)
@@ -58,18 +58,29 @@ class SystemBridgeSetupUseCaseImpl @Inject constructor(
5858
override val isWarningUnderstood: Flow<Boolean> =
5959
preferences.get(Keys.isExpertModeWarningUnderstood).map { it ?: false }
6060

61-
private val isAdbAutoStartAllowed: Flow<Boolean> =
61+
private val adbAutoStartEligibility: Flow<AdbAutoStartEligibility> =
6262
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
6363
combine(
6464
permissionAdapter.isGrantedFlow(Permission.WRITE_SECURE_SETTINGS),
6565
networkAdapter.isWifiConnected,
6666
) { isWriteSecureSettingsGranted, isWifiConnected ->
67-
isWriteSecureSettingsGranted &&
68-
isWifiConnected &&
69-
systemBridgeSetupController.isAdbPaired()
70-
}.flowOn(Dispatchers.IO)
67+
isWriteSecureSettingsGranted && isWifiConnected
68+
}.flatMapLatest { canCheck ->
69+
if (canCheck) {
70+
flow {
71+
emit(AdbAutoStartEligibility.CHECKING)
72+
if (systemBridgeSetupController.isAdbPaired()) {
73+
emit(AdbAutoStartEligibility.ELIGIBLE)
74+
} else {
75+
emit(AdbAutoStartEligibility.NOT_ELIGIBLE)
76+
}
77+
}
78+
} else {
79+
flowOf(AdbAutoStartEligibility.NOT_ELIGIBLE)
80+
}
81+
}
7182
} else {
72-
flowOf(false)
83+
flowOf(AdbAutoStartEligibility.NOT_ELIGIBLE)
7384
}
7485

7586
override fun onUnderstoodWarning() {
@@ -108,11 +119,14 @@ class SystemBridgeSetupUseCaseImpl @Inject constructor(
108119
if (isConnected) {
109120
flowOf(SystemBridgeSetupStep.STARTED)
110121
} else {
111-
isAdbAutoStartAllowed.flatMapLatest { isAdbAutoStartAllowed ->
112-
if (isAdbAutoStartAllowed) {
113-
flowOf(SystemBridgeSetupStep.START_SERVICE)
114-
} else {
115-
combine(
122+
adbAutoStartEligibility.flatMapLatest { adbAutoStartEligibility ->
123+
when (adbAutoStartEligibility) {
124+
AdbAutoStartEligibility.ELIGIBLE ->
125+
flowOf(SystemBridgeSetupStep.START_SERVICE)
126+
127+
AdbAutoStartEligibility.CHECKING -> emptyFlow()
128+
129+
AdbAutoStartEligibility.NOT_ELIGIBLE -> combine(
116130
accessibilityServiceAdapter.state,
117131
isNotificationPermissionGranted,
118132
systemBridgeSetupController.isDeveloperOptionsEnabled,
@@ -347,3 +361,9 @@ interface SystemBridgeSetupUseCase {
347361

348362
suspend fun getShellStartCommand(): KMResult<String>
349363
}
364+
365+
enum class AdbAutoStartEligibility {
366+
ELIGIBLE,
367+
CHECKING,
368+
NOT_ELIGIBLE,
369+
}

0 commit comments

Comments
 (0)