Skip to content

Commit

Permalink
adding logic to check usb and adb connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Borodin committed Jan 3, 2024
1 parent 3d84559 commit 7125e34
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 47 deletions.
2 changes: 2 additions & 0 deletions android/src/main/java/io/parity/signer/domain/FeatureFlags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object FeatureFlags {
FeatureOption.SKIP_ROOTED_CHECK_EMULATOR -> false
FeatureOption.EXPORT_SECRET_KEY -> false //unused
FeatureOption.FAIL_DB_VERSION_CHECK -> false
FeatureOption.SKIP_USB_CHECK -> true

}
}
Expand All @@ -24,6 +25,7 @@ enum class FeatureOption {
FAIL_DB_VERSION_CHECK,
SKIP_UNLOCK_FOR_DEVELOPMENT,
SKIP_ROOTED_CHECK_EMULATOR,
SKIP_USB_CHECK,
EXPORT_SECRET_KEY; //unused as sample

fun isEnabled() = FeatureFlags.isEnabled(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.parity.signer.screens.initial.eachstartchecks.airgap

import android.content.Context
import android.provider.Settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.parity.signer.dependencygraph.ServiceLocator
import io.parity.signer.domain.FeatureFlags
import io.parity.signer.domain.FeatureOption
import io.parity.signer.domain.NetworkState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -34,6 +38,15 @@ class AirGapViewModel : ViewModel() {
_state.update { it.copy(cablesDisconnected = !_state.value.cablesDisconnected) }
}

fun isAdbEnabled(context: Context): Boolean {
//todo dmitry check usb checks
if (FeatureFlags.isEnabled(FeatureOption.SKIP_USB_CHECK)) return false

return Settings.Global.getInt(context.contentResolver,
Settings.Global.ADB_ENABLED, 0
) == 1;
}

fun init() {
val scope = CoroutineScope(viewModelScope.coroutineContext + Job())
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Adb
import androidx.compose.material.icons.filled.AirplanemodeActive
import androidx.compose.material.icons.filled.Bluetooth
import androidx.compose.material.icons.filled.Cable
Expand Down Expand Up @@ -113,47 +114,10 @@ private fun AirgapScreen(
AirgapItem(AirgapItemType.WIFI, state.wifiDisabled)
SignerDivider(modifier = Modifier.padding(start = 40.dp))
AirgapItem(AirgapItemType.BLUETOOTH, state.bluetoothDisabled)
}
}

Surface(
shape = RoundedCornerShape(dimensionResource(id = R.dimen.innerFramesCornerRadius)),
border = BorderStroke(1.dp, color = MaterialTheme.colors.fill12),
color = MaterialTheme.colors.fill6,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(16.dp),
) {
Image(
imageVector = Icons.Filled.Cable,
contentDescription = null,
colorFilter = ColorFilter.tint(MaterialTheme.colors.textTertiary),
modifier = Modifier
.padding(8.dp)
.size(24.dp)
)
Text(
text = stringResource(R.string.airgap_onboarding_disconnect_cable_header),
color = MaterialTheme.colors.textTertiary,
style = SignerTypeface.TitleS,
modifier = Modifier
.padding(horizontal = 16.dp, vertical = 14.dp)
.weight(1f)
)
}
SignerDivider()
CheckboxWithTextWithGap(
checked = state.cablesDisconnected,
text = stringResource(R.string.airgap_onboarding_disconnect_cable_checkbox_description),
modifier = Modifier.padding(16.dp),
) { newIsChecked ->
onCablesConfirmCheckbox()
}
SignerDivider(modifier = Modifier.padding(start = 40.dp))
AirgapItem(AirgapItemType.ADB_ENABLED, false, )//todo dmitry
SignerDivider(modifier = Modifier.padding(start = 40.dp))
AirgapItem(AirgapItemType.USB, false)//todo dmitry
}
}
}
Expand Down Expand Up @@ -221,13 +185,17 @@ private fun AirgapItem(type: AirgapItemType, isPassed: Boolean) {
AirgapItemType.WIFI -> Icons.Filled.Wifi
AirgapItemType.AIRPLANE_MODE -> Icons.Filled.AirplanemodeActive
AirgapItemType.BLUETOOTH -> Icons.Filled.Bluetooth
AirgapItemType.USB -> Icons.Filled.Cable
AirgapItemType.ADB_ENABLED -> Icons.Filled.Adb
}
IconWithCheckmark(color, icon, backgroundColor, isPassed)

val text = when (type) {
AirgapItemType.WIFI -> stringResource(R.string.airgap_onboarding_wifi_header)
AirgapItemType.AIRPLANE_MODE -> stringResource(R.string.airgap_onboarding_airplane_mode_header)
AirgapItemType.BLUETOOTH -> stringResource(R.string.airgap_onboarding_bluetooth_header)
AirgapItemType.USB -> stringResource(R.string.airgap_onboarding_disconnect_cable_checkbox_description)
AirgapItemType.ADB_ENABLED -> stringResource(R.string.airgap_onboarding_adb_disable)
}
Text(
text = text,
Expand Down Expand Up @@ -277,8 +245,7 @@ private fun IconWithCheckmark(
}
}


private enum class AirgapItemType { WIFI, AIRPLANE_MODE, BLUETOOTH }
private enum class AirgapItemType { WIFI, AIRPLANE_MODE, BLUETOOTH, USB, ADB_ENABLED, }


@Preview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package io.parity.signer.screens.scan.camera
import android.annotation.SuppressLint
import android.os.Trace
import android.util.Log
import android.widget.Toast
import androidx.camera.core.ImageProxy
import androidx.lifecycle.ViewModel
import com.google.mlkit.vision.barcode.BarcodeScanner
import com.google.mlkit.vision.common.InputImage
import io.parity.signer.dependencygraph.ServiceLocator
import io.parity.signer.domain.FeatureFlags
import io.parity.signer.domain.FeatureOption
import io.parity.signer.domain.encodeHex
import io.parity.signer.domain.submitErrorState
import io.parity.signer.uniffi.*
Expand Down
1 change: 1 addition & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
<string name="add_derived_keys_screen_cta">Confirm and Add Keys</string>
<string name="add_derived_keys_screen_alert_title">Confirm by entering the PIN code</string>
<string name="add_derived_keys_screen_alert_content">To finalize the addition of keys to the key set, please confirm that you have scanned the QR code back into the app by entering the PIN code.</string>
<string name="airgap_onboarding_adb_disable">Disable ADB on the device</string>

</resources>

Expand Down

0 comments on commit 7125e34

Please sign in to comment.