Skip to content

Commit

Permalink
password: add RequiredStrongAuthTimeout
Browse files Browse the repository at this point in the history
optimize ScreenTimeout, MaxFailedPasswordForWipe, PasswordExpiration and PasswordHistoryLength
  • Loading branch information
BinTianqi committed Jun 2, 2024
1 parent 7058495 commit 5f4df48
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 36 deletions.
103 changes: 67 additions & 36 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fun Password(navCtrl: NavHostController) {
composable(route = "MaxTimeToLock") { ScreenTimeout() }
composable(route = "PasswordTimeout") { PasswordExpiration() }
composable(route = "MaxPasswordFail") { MaxFailedPasswordForWipe() }
composable(route = "RequiredStrongAuthTimeout") { RequiredStrongAuthTimeout() }
composable(route = "PasswordHistoryLength") { PasswordHistoryLength() }
composable(route = "RequirePasswordQuality") { PasswordQuality() }
}
Expand All @@ -79,6 +80,8 @@ fun Password(navCtrl: NavHostController) {

@Composable
private fun Home(navCtrl:NavHostController,scrollState: ScrollState) {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState)) {
Text(
text = stringResource(R.string.password_and_keyguard),
Expand All @@ -94,10 +97,15 @@ private fun Home(navCtrl:NavHostController,scrollState: ScrollState) {
SubPageItem(R.string.required_password_complexity, "", R.drawable.password_fill0) { navCtrl.navigate("RequirePasswordComplexity") }
}
SubPageItem(R.string.keyguard_disabled_features, "", R.drawable.screen_lock_portrait_fill0) { navCtrl.navigate("KeyguardDisabledFeatures") }
SubPageItem(R.string.max_time_to_lock, "", R.drawable.schedule_fill0) { navCtrl.navigate("MaxTimeToLock") }
SubPageItem(R.string.pwd_timeout, "", R.drawable.lock_clock_fill0) { navCtrl.navigate("PasswordTimeout") }
SubPageItem(R.string.max_pwd_fail, "", R.drawable.no_encryption_fill0) { navCtrl.navigate("MaxPasswordFail") }
SubPageItem(R.string.pwd_history, "", R.drawable.history_fill0) { navCtrl.navigate("PasswordHistoryLength") }
if(isDeviceOwner(dpm)) {
SubPageItem(R.string.max_time_to_lock, "", R.drawable.schedule_fill0) { navCtrl.navigate("MaxTimeToLock") }
SubPageItem(R.string.pwd_timeout, "", R.drawable.lock_clock_fill0) { navCtrl.navigate("PasswordTimeout") }
SubPageItem(R.string.max_pwd_fail, "", R.drawable.no_encryption_fill0) { navCtrl.navigate("MaxPasswordFail") }
SubPageItem(R.string.pwd_history, "", R.drawable.history_fill0) { navCtrl.navigate("PasswordHistoryLength") }
}
if(VERSION.SDK_INT >= 26 && (isDeviceOwner(dpm) || isProfileOwner(dpm))) {
SubPageItem(R.string.required_strong_auth_timeout, "", R.drawable.fingerprint_off_fill0) { navCtrl.navigate("RequiredStrongAuthTimeout") }
}
SubPageItem(R.string.required_password_quality, "", R.drawable.password_fill0) { navCtrl.navigate("RequirePasswordQuality") }
Spacer(Modifier.padding(vertical = 30.dp))
}
Expand Down Expand Up @@ -349,8 +357,8 @@ private fun ScreenTimeout() {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val focusMgr = LocalFocusManager.current
var inputContent by remember { mutableStateOf(if(isDeviceOwner(dpm)) dpm.getMaximumTimeToLock(receiver).toString() else "") }
var ableToApply by remember { mutableStateOf(inputContent!="") }
var inputContent by remember { mutableStateOf("") }
LaunchedEffect(Unit) { inputContent = dpm.getMaximumTimeToLock(receiver).toString() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.max_time_to_lock), style = typography.headlineLarge)
Expand All @@ -360,22 +368,54 @@ private fun ScreenTimeout() {
OutlinedTextField(
value = inputContent,
label = { Text(stringResource(R.string.time_unit_ms)) },
onValueChange = {
inputContent = it
ableToApply = inputContent != ""
},
onValueChange = { inputContent = it },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
enabled = isDeviceOwner(dpm),
modifier = Modifier.focusable().fillMaxWidth()
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus(); dpm.setMaximumTimeToLock(receiver,inputContent.toLong()) },
onClick = { focusMgr.clearFocus(); dpm.setMaximumTimeToLock(receiver, inputContent.toLong()) },
modifier = Modifier.fillMaxWidth(),
enabled = inputContent != ""
) {
Text(stringResource(R.string.apply))
}
}
}

@SuppressLint("NewApi")
@Composable
private fun RequiredStrongAuthTimeout() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val focusMgr = LocalFocusManager.current
var input by remember { mutableStateOf("") }
LaunchedEffect(Unit) { input = dpm.getRequiredStrongAuthTimeout(receiver).toString() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.required_strong_auth_timeout), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
OutlinedTextField(
value = input,
label = { Text(stringResource(R.string.time_unit_ms)) },
onValueChange = { input = it },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
modifier = Modifier.fillMaxWidth()
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus(); dpm.setRequiredStrongAuthTimeout(receiver, input.toLong()) },
modifier = Modifier.fillMaxWidth(),
enabled = input != ""
) {
Text(stringResource(R.string.apply))
}
Spacer(Modifier.padding(vertical = 10.dp))
Information { Text(stringResource(R.string.zero_means_no_control)) }
Spacer(Modifier.padding(vertical = 60.dp))
}
}

Expand All @@ -385,8 +425,8 @@ private fun MaxFailedPasswordForWipe() {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val focusMgr = LocalFocusManager.current
var inputContent by remember { mutableStateOf(if(isDeviceOwner(dpm)) dpm.getMaximumFailedPasswordsForWipe(receiver).toString() else "") }
var ableToApply by remember { mutableStateOf(inputContent != "" && inputContent != "0") }
var inputContent by remember { mutableStateOf("") }
LaunchedEffect(Unit) { inputContent = dpm.getMaximumFailedPasswordsForWipe(receiver).toString() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.max_pwd_fail), style = typography.headlineLarge)
Expand All @@ -396,19 +436,16 @@ private fun MaxFailedPasswordForWipe() {
OutlinedTextField(
value = inputContent,
label = { Text(stringResource(R.string.max_pwd_fail_textfield)) },
onValueChange = {
inputContent = it
ableToApply = inputContent != "" && inputContent != "0"
},
onValueChange = { inputContent = it },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
enabled = isDeviceOwner(dpm),
modifier = Modifier.focusable().fillMaxWidth()
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus(); dpm.setMaximumFailedPasswordsForWipe(receiver,inputContent.toInt()) },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
enabled = inputContent != ""
) {
Text(stringResource(R.string.apply))
}
Expand All @@ -421,8 +458,8 @@ private fun PasswordExpiration() {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val focusMgr = LocalFocusManager.current
var inputContent by remember { mutableStateOf(if(isDeviceOwner(dpm)) dpm.getPasswordExpirationTimeout(receiver).toString() else "") }
var ableToApply by remember { mutableStateOf(inputContent != "") }
var inputContent by remember { mutableStateOf("") }
LaunchedEffect(Unit) { inputContent = dpm.getPasswordExpirationTimeout(receiver).toString() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.pwd_timeout), style = typography.headlineLarge)
Expand All @@ -432,19 +469,16 @@ private fun PasswordExpiration() {
OutlinedTextField(
value = inputContent,
label = { Text(stringResource(R.string.time_unit_ms)) },
onValueChange = {
inputContent = it
ableToApply = inputContent != ""
},
onValueChange = { inputContent = it },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
enabled = isDeviceOwner(dpm),
modifier = Modifier.focusable().fillMaxWidth()
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus() ; dpm.setPasswordExpirationTimeout(receiver,inputContent.toLong()) },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
enabled = inputContent != ""
) {
Text(stringResource(R.string.apply))
}
Expand All @@ -457,8 +491,8 @@ private fun PasswordHistoryLength() {
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val focusMgr = LocalFocusManager.current
var inputContent by remember { mutableStateOf(if(isDeviceOwner(dpm)) dpm.getPasswordHistoryLength(receiver).toString() else "") }
var ableToApply by remember { mutableStateOf(inputContent!="") }
var inputContent by remember { mutableStateOf("") }
LaunchedEffect(Unit) { inputContent = dpm.getPasswordHistoryLength(receiver).toString() }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.pwd_history), style = typography.headlineLarge)
Expand All @@ -468,19 +502,16 @@ private fun PasswordHistoryLength() {
OutlinedTextField(
value = inputContent,
label = { Text(stringResource(R.string.length)) },
onValueChange = {
inputContent = it
ableToApply = inputContent != ""
},
onValueChange = { inputContent = it },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusMgr.clearFocus() }),
enabled = isDeviceOwner(dpm),
modifier = Modifier.focusable().fillMaxWidth()
)
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = { focusMgr.clearFocus() ; dpm.setPasswordHistoryLength(receiver,inputContent.toInt()) },
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
enabled = inputContent != ""
) {
Text(stringResource(R.string.apply))
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/fingerprint_off_fill0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M833,919 L435,520q-19,11 -29,28.5T396,586q0,92 55.5,161T601,840q8,2 12,9.5t2,15.5q-2,8 -9,12t-15,2q-108,-28 -171.5,-107.5T356,586q0,-28 13,-52.5t37,-41.5l-42,-42q-34,26 -52,61t-18,75q0,75 25.5,132T405,837q6,6 6,14.5T405,866q-6,6 -14.5,6T376,866q-66,-67 -94,-130.5T254,586q0,-48 22,-91.5t60,-73.5l-44,-43q-58,54 -80,99t-22,109q0,36 6.5,73t20.5,72q3,8 0,15t-11,10q-8,3 -15.5,0T180,745q-15,-42 -22,-81t-7,-78q0,-73 25.5,-127.5T264,349l-41,-41q-20,17 -36.5,34.5T156,380q-4,7 -12,8.5t-16,-3.5q-7,-5 -8,-13t4,-15q14,-21 32,-40t39,-37L42,126l42,-42L876,876l-43,43ZM688,606q-8,0 -14,-5.5t-6,-14.5q0,-72 -51,-121t-121,-54l-40,-40q6,-1 12.5,-1L481,370q93,0 160,62.5T708,586q0,9 -5.5,14.5T688,606ZM481,81q64,0 125,15.5T724,141q9,5 10.5,12t-1.5,14q-3,7 -10,11t-17,-1q-53,-27 -109.5,-41.5T481,121q-58,0 -113.5,13T261,176l-29,-29q57,-32 120,-49t129,-17ZM481,179q106,0 200,45.5T838,356q7,9 4.5,16t-8.5,12q-6,5 -14,4.5t-14,-8.5q-55,-78 -141.5,-119.5T481,219q-39,0 -76.5,7T332,247l-30,-30q42,-19 86.5,-28.5T481,179ZM481,273q135,0 232,90t97,223q0,29 -13,52.5T763,678l-28,-28q16,-11 25.5,-27.5T770,586q0,-116 -85,-195t-203,-79q-20,0 -38.5,2.5T407,322l-32,-32q25,-8 51.5,-12.5T481,273ZM674,798q-89,0 -152.5,-61T458,587q0,-8 5.5,-14t14.5,-6q9,0 14.5,6t5.5,14q0,72 52,121t124,49q6,0 17,-0.5t23,-2.5q9,-2 15.5,2.5T738,770q2,8 -3,14t-13,8q-18,5 -31.5,5.5t-16.5,0.5Z"
android:fillColor="#000000"/>
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@
<string name="max_pwd_fail_textfield">错误次数</string>
<string name="pwd_timeout">密码失效超时时间</string>
<string name="max_time_to_lock">屏幕超时</string>
<string name="required_strong_auth_timeout">要求强验证超时</string>
<string name="zero_means_no_control">值为0表示OwnDroid不参与控制超时</string>
<string name="max_time_to_lock_desc">超时后锁屏(毫秒),0为由用户决定</string>
<string name="pwd_timeout_desc">超时后用户需重新设置密码(毫秒),0为无限制</string>
<string name="pwd_history">密码历史记录长度</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@
<string name="max_pwd_fail_textfield">Maximum failed attempts</string>
<string name="pwd_timeout">Password timeout</string>
<string name="max_time_to_lock">Screen timeout</string>
<string name="required_strong_auth_timeout">Required strong auth timeout</string>
<string name="zero_means_no_control">A value of 0 means the admin is not participating in controlling the timeout</string>
<string name="max_time_to_lock_desc">Enter 0 to allow user decision, unit: millisecond</string>
<string name="pwd_timeout_desc">When reach this limit, user should set a new password. Enter 0 to allow user decision, unit: millisecond</string>
<string name="pwd_history">Password history length</string>
Expand Down

0 comments on commit 5f4df48

Please sign in to comment.