-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract SecureArea-specific UI into an interface
- Loading branch information
1 parent
9b37ddc
commit a20eed1
Showing
37 changed files
with
1,152 additions
and
1,017 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
128 changes: 128 additions & 0 deletions
128
appholder/src/main/java/com/android/identity/wallet/composables/AndroidSetupContainer.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,128 @@ | ||
package com.android.identity.wallet.composables | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Checkbox | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Switch | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.android.identity.wallet.R | ||
import com.android.identity.wallet.composables.state.AuthTypeState | ||
import com.android.identity.wallet.selfsigned.OutlinedContainerVertical | ||
|
||
@Composable | ||
fun AndroidSetupContainer( | ||
modifier: Modifier = Modifier, | ||
isOn: Boolean, | ||
timeoutSeconds: Int, | ||
lskfAuthTypeState: AuthTypeState, | ||
biometricAuthTypeState: AuthTypeState, | ||
useStrongBox: AuthTypeState, | ||
onUserAuthenticationChanged: (isOn: Boolean) -> Unit, | ||
onAuthTimeoutChanged: (authTimeout: Int) -> Unit, | ||
onLskfAuthChanged: (isOn: Boolean) -> Unit, | ||
onBiometricAuthChanged: (isOn: Boolean) -> Unit, | ||
onStrongBoxChanged: (isOn: Boolean) -> Unit | ||
) { | ||
Column(modifier = modifier) { | ||
OutlinedContainerVertical(modifier = Modifier.fillMaxWidth()) { | ||
val labelOn = stringResource(id = R.string.user_authentication_on) | ||
val labelOff = stringResource(id = R.string.user_authentication_off) | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
ValueLabel( | ||
modifier = Modifier.weight(1f), | ||
label = if (isOn) labelOn else labelOff, | ||
) | ||
Switch( | ||
modifier = Modifier.padding(start = 8.dp), | ||
checked = isOn, | ||
onCheckedChange = onUserAuthenticationChanged | ||
) | ||
} | ||
AnimatedVisibility( | ||
modifier = Modifier.fillMaxWidth(), | ||
visible = isOn | ||
) { | ||
Column(modifier = Modifier.fillMaxWidth()) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
ValueLabel( | ||
modifier = Modifier.weight(1f), | ||
label = stringResource(id = R.string.keystore_android_user_auth_timeout) | ||
) | ||
NumberChanger( | ||
number = timeoutSeconds, | ||
onNumberChanged = onAuthTimeoutChanged, | ||
counterTextStyle = MaterialTheme.typography.titleLarge | ||
) | ||
} | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
val alpha = if (lskfAuthTypeState.canBeModified) 1f else .5f | ||
ValueLabel( | ||
modifier = Modifier | ||
.weight(1f) | ||
.alpha(alpha), | ||
label = stringResource(id = R.string.user_auth_type_allow_lskf) | ||
) | ||
Checkbox( | ||
checked = lskfAuthTypeState.isEnabled, | ||
onCheckedChange = onLskfAuthChanged, | ||
enabled = lskfAuthTypeState.canBeModified | ||
) | ||
} | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
val alpha = if (biometricAuthTypeState.canBeModified) 1f else .5f | ||
ValueLabel( | ||
modifier = Modifier | ||
.weight(1f) | ||
.alpha(alpha), | ||
label = stringResource(id = R.string.user_auth_type_allow_biometric) | ||
) | ||
Checkbox( | ||
checked = biometricAuthTypeState.isEnabled, | ||
onCheckedChange = onBiometricAuthChanged, | ||
enabled = biometricAuthTypeState.canBeModified | ||
) | ||
} | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
val alpha = if (useStrongBox.canBeModified) 1f else .5f | ||
ValueLabel( | ||
modifier = Modifier | ||
.weight(1f) | ||
.alpha(alpha), | ||
label = stringResource(id = R.string.user_auth_use_strong_box) | ||
) | ||
Checkbox( | ||
checked = useStrongBox.isEnabled, | ||
onCheckedChange = onStrongBoxChanged, | ||
enabled = useStrongBox.canBeModified | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
76 changes: 76 additions & 0 deletions
76
...er/src/main/java/com/android/identity/wallet/composables/AuthenticationKeyCurveAndroid.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,76 @@ | ||
package com.android.identity.wallet.composables | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.res.stringResource | ||
import com.android.identity.wallet.R | ||
import com.android.identity.wallet.composables.state.AndroidAuthKeyCurveOption | ||
import com.android.identity.wallet.composables.state.MdocAuthOption | ||
import com.android.identity.wallet.composables.state.MdocAuthStateOption | ||
import com.android.identity.wallet.composables.state.AndroidAuthKeyCurveState | ||
|
||
@Composable | ||
fun AuthenticationKeyCurveAndroid( | ||
modifier: Modifier = Modifier, | ||
state: AndroidAuthKeyCurveState, | ||
mDocAuthState: MdocAuthOption, | ||
onAndroidAuthKeyCurveChanged: (newValue: AndroidAuthKeyCurveOption) -> Unit | ||
) { | ||
LabeledUserInput( | ||
modifier = modifier, | ||
label = stringResource(id = R.string.authentication_key_curve_label) | ||
) { | ||
var keyCurveDropDownExpanded by remember { mutableStateOf(false) } | ||
val clickModifier = if (state.isEnabled) { | ||
Modifier.clickable { keyCurveDropDownExpanded = true } | ||
} else { | ||
Modifier | ||
} | ||
val alpha = if (state.isEnabled) 1f else .5f | ||
OutlinedContainerHorizontal( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.alpha(alpha) | ||
.then(clickModifier) | ||
) { | ||
ValueLabel( | ||
modifier = Modifier.weight(1f), | ||
label = curveLabelFor(state.authCurve.toEcCurve()) | ||
) | ||
DropDownIndicator() | ||
} | ||
DropdownMenu( | ||
expanded = keyCurveDropDownExpanded, | ||
onDismissRequest = { keyCurveDropDownExpanded = false } | ||
) { | ||
val ecCurveOption = | ||
if (mDocAuthState.mDocAuthentication == MdocAuthStateOption.ECDSA) { | ||
AndroidAuthKeyCurveOption.Ed25519 | ||
} else { | ||
AndroidAuthKeyCurveOption.X25519 | ||
} | ||
TextDropDownRow( | ||
label = curveLabelFor(curveOption = AndroidAuthKeyCurveOption.P_256.toEcCurve()), | ||
onSelected = { | ||
onAndroidAuthKeyCurveChanged(AndroidAuthKeyCurveOption.P_256) | ||
keyCurveDropDownExpanded = false | ||
} | ||
) | ||
TextDropDownRow( | ||
label = curveLabelFor(curveOption = ecCurveOption.toEcCurve()), | ||
onSelected = { | ||
onAndroidAuthKeyCurveChanged(ecCurveOption) | ||
keyCurveDropDownExpanded = false | ||
} | ||
) | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...c/main/java/com/android/identity/wallet/composables/AuthenticationKeyCurveBouncyCastle.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,74 @@ | ||
package com.android.identity.wallet.composables | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.alpha | ||
import androidx.compose.ui.res.stringResource | ||
import com.android.identity.wallet.R | ||
import com.android.identity.wallet.composables.state.BouncyCastleAuthKeyCurveOption | ||
import com.android.identity.wallet.composables.state.BouncyCastleAuthKeyCurveState | ||
import com.android.identity.wallet.composables.state.MdocAuthOption | ||
import com.android.identity.wallet.composables.state.MdocAuthStateOption | ||
|
||
@Composable | ||
fun AuthenticationKeyCurveBouncyCastle( | ||
modifier: Modifier = Modifier, | ||
state: BouncyCastleAuthKeyCurveState, | ||
mDocAuthState: MdocAuthOption, | ||
onBouncyCastleAuthKeyCurveChanged: (newValue: BouncyCastleAuthKeyCurveOption) -> Unit | ||
) { | ||
LabeledUserInput( | ||
modifier = modifier, | ||
label = stringResource(id = R.string.authentication_key_curve_label) | ||
) { | ||
var keyCurveDropDownExpanded by remember { mutableStateOf(false) } | ||
val clickModifier = if (state.isEnabled) { | ||
Modifier.clickable { keyCurveDropDownExpanded = true } | ||
} else { | ||
Modifier | ||
} | ||
val alpha = if (state.isEnabled) 1f else .5f | ||
OutlinedContainerHorizontal( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.alpha(alpha) | ||
.then(clickModifier) | ||
) { | ||
ValueLabel( | ||
modifier = Modifier.weight(1f), | ||
label = curveLabelFor(state.authCurve.toEcCurve()) | ||
) | ||
DropDownIndicator() | ||
} | ||
val entries = | ||
BouncyCastleAuthKeyCurveOption.values().toMutableList() | ||
if (mDocAuthState.mDocAuthentication == MdocAuthStateOption.ECDSA) { | ||
entries.remove(BouncyCastleAuthKeyCurveOption.X448) | ||
entries.remove(BouncyCastleAuthKeyCurveOption.X25519) | ||
} else { | ||
entries.remove(BouncyCastleAuthKeyCurveOption.Ed448) | ||
entries.remove(BouncyCastleAuthKeyCurveOption.Ed25519) | ||
} | ||
DropdownMenu( | ||
expanded = keyCurveDropDownExpanded, | ||
onDismissRequest = { keyCurveDropDownExpanded = false } | ||
) { | ||
for (entry in entries) { | ||
TextDropDownRow( | ||
label = curveLabelFor(curveOption = entry.toEcCurve()), | ||
onSelected = { | ||
onBouncyCastleAuthKeyCurveChanged(entry) | ||
keyCurveDropDownExpanded = false | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...lder/src/main/java/com/android/identity/wallet/composables/BouncyCastlePassphraseInput.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,46 @@ | ||
package com.android.identity.wallet.composables | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.android.identity.wallet.R | ||
|
||
@Composable | ||
fun BouncyCastlePassphraseInput( | ||
modifier: Modifier = Modifier, | ||
value: String, | ||
onValueChanged: (newValue: String) -> Unit | ||
) { | ||
OutlinedContainerHorizontal(modifier = modifier) { | ||
Box(contentAlignment = Alignment.CenterStart) { | ||
BasicTextField( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 10.dp), | ||
textStyle = MaterialTheme.typography.labelMedium.copy( | ||
color = MaterialTheme.colorScheme.onSurface, | ||
), | ||
value = value, | ||
onValueChange = onValueChanged, | ||
cursorBrush = SolidColor(MaterialTheme.colorScheme.onSurface) | ||
) | ||
if (value.isEmpty()) { | ||
Text( | ||
text = stringResource(id = R.string.keystore_bouncy_castle_passphrase_hint), | ||
style = MaterialTheme.typography.labelMedium.copy( | ||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = .5f) | ||
), | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.