Skip to content

Commit

Permalink
added runtime adb check while screen is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Borodin committed Jan 4, 2024
1 parent c983610 commit a24dd5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import io.parity.signer.domain.NetworkState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.time.Duration


class AirGapViewModel : ViewModel() {

private val appContext = ServiceLocator.appContext
private val networkExposedStateKeeper =
ServiceLocator.networkExposedStateKeeper

Expand Down Expand Up @@ -49,18 +52,29 @@ class AirGapViewModel : ViewModel() {
fun init() {
val scope = CoroutineScope(viewModelScope.coroutineContext + Job())
scope.launch {
networkExposedStateKeeper.airPlaneModeEnabled.collect {
_state.value = _state.value.copy(airplaneModeEnabled = (it != false))
networkExposedStateKeeper.airPlaneModeEnabled.collect { newState ->
_state.update {it.copy(airplaneModeEnabled = (newState != false)) }
}
}
scope.launch {
networkExposedStateKeeper.bluetoothDisabledState.collect {
_state.value = _state.value.copy(bluetoothDisabled = (it != false))
networkExposedStateKeeper.bluetoothDisabledState.collect { newState ->
_state.update { it.copy(bluetoothDisabled = (newState != false)) }
}
}
scope.launch {
networkExposedStateKeeper.wifiDisabledState.collect {
_state.value = _state.value.copy(wifiDisabled = (it != false))
networkExposedStateKeeper.wifiDisabledState.collect { newState ->
_state.update { it.copy(wifiDisabled = (newState != false)) }
}
}
scope.launch {
while (true) {
val adbEnabled = isAdbEnabled(appContext)
if (_state.value.isAdbDisabled == !adbEnabled) {
//skip it's the same
} else {
_state.update { it.copy(isAdbDisabled = (!adbEnabled)) }
}
delay(1000) //1s
}
}
this.scope = scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ private fun PreviewAirgapScreenObnoarding() {
)
AirgapScreen(state = state,
isInitialOnboarding = true,
onCablesConfirmCheckbox = {},
onCta = {})
}
}
Expand All @@ -265,7 +264,6 @@ private fun PreviewAirgapScreenBlocker() {
)
AirgapScreen(state = state,
isInitialOnboarding = false,
onCablesConfirmCheckbox = {},
onCta = {})
}
}
Expand Down Expand Up @@ -293,7 +291,6 @@ private fun PreviewAirgapScreenSmall() {
)
AirgapScreen(state = state,
isInitialOnboarding = true,
onCablesConfirmCheckbox = {},
onCta = {})
}
}
Expand Down

0 comments on commit a24dd5b

Please sign in to comment.