set keyguard disabled features

This commit is contained in:
BinTianqi
2024-02-02 17:40:59 +08:00
parent f2a0a983e9
commit 6a933443f1
5 changed files with 151 additions and 57 deletions

View File

@@ -49,9 +49,9 @@
### 即将加入的功能 ### 即将加入的功能
- Managed Profile工作资料和多用户相关 - Managed Profile工作资料和多用户相关
- 安装/卸载应用,清除应用的存储空间 - 应用管理--安装/卸载应用
- 应用管理包选择器(目前只能手动输入包名) - 应用管理--包选择器(目前只能手动输入包名)
- 用户选择器(目前只能手动输入序列号) - 用户管理--用户选择器(目前只能手动输入序列号)
### 许可证 ### 许可证

View File

@@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_KEYGUARD"/>
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/> <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_WIPE_DATA"/> <uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_WIPE_DATA"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_ACROSS_USERS"/> <uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_ACROSS_USERS"/>
@@ -9,14 +10,13 @@
<uses-permission android:name="android.permission.REQUEST_PASSWORD_COMPLEXITY"/> <uses-permission android:name="android.permission.REQUEST_PASSWORD_COMPLEXITY"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_INPUT_METHODS"/> <uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_INPUT_METHODS"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS"/> <uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_APPS_CONTROL"/>
<application <application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidOwner" android:theme="@style/Theme.AndroidOwner"
android:enableOnBackInvokedCallback="true" android:enableOnBackInvokedCallback="true"
tools:targetApi="34"> tools:targetApi="34">

View File

@@ -23,19 +23,9 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.ArrowBack
import androidx.compose.material.icons.outlined.Home import androidx.compose.material.icons.outlined.Home
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.*
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.RadioButton import androidx.compose.runtime.*
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -257,7 +247,30 @@ fun RadioButtonItem(
) { ) {
RadioButton(selected = selected(), onClick = operation,modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier}) RadioButton(selected = selected(), onClick = operation,modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier})
Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}, color = textColor, Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}, color = textColor,
modifier = Modifier.padding(bottom = 1.dp)) modifier = Modifier.padding(bottom = 2.dp))
}
}
@Composable
fun CheckBoxItem(
text:String,
checked:()->Boolean,
operation:()->Unit,
textColor:Color = MaterialTheme.colorScheme.onBackground
){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Row(verticalAlignment = Alignment.CenterVertically,modifier = Modifier
.fillMaxWidth()
.padding(vertical = if(sharedPref.getBoolean("isWear",false)){3.dp}else{0.dp})
.clip(RoundedCornerShape(25))
.clickable(onClick = operation)
) {
Checkbox(
checked = checked(),
onCheckedChange = {b:Boolean->operation()},
modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier}
)
Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}, color = textColor,
modifier = Modifier.padding(bottom = 2.dp))
} }
} }

View File

@@ -2,12 +2,14 @@ package com.binbin.androidowner
import android.app.KeyguardManager import android.app.KeyguardManager
import android.app.admin.DevicePolicyManager import android.app.admin.DevicePolicyManager
import android.app.admin.DevicePolicyManager.*
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build.VERSION import android.os.Build.VERSION
import android.widget.Toast import android.widget.Toast
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@@ -31,12 +33,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusManager import androidx.compose.ui.focus.FocusManager
@@ -85,10 +82,10 @@ fun Password(){
) { ) {
if(VERSION.SDK_INT>=29){ if(VERSION.SDK_INT>=29){
val passwordComplexity = mapOf( val passwordComplexity = mapOf(
DevicePolicyManager.PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)", PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)",
DevicePolicyManager.PASSWORD_COMPLEXITY_LOW to "低(允许图案和连续性)", PASSWORD_COMPLEXITY_LOW to "低(允许图案和连续性)",
DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM to "无连续性至少4位", PASSWORD_COMPLEXITY_MEDIUM to "无连续性至少4位",
DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH to "无连续性至少6位" PASSWORD_COMPLEXITY_HIGH to "无连续性至少6位"
) )
val pwdComplex = passwordComplexity[myDpm.passwordComplexity] val pwdComplex = passwordComplexity[myDpm.passwordComplexity]
Text(text = "当前密码复杂度:$pwdComplex",style=bodyTextStyle) Text(text = "当前密码复杂度:$pwdComplex",style=bodyTextStyle)
@@ -166,12 +163,9 @@ fun Password(){
Text(text = stringResource(R.string.reset_pwd_desc), modifier = Modifier.padding(vertical = 3.dp),style=bodyTextStyle) Text(text = stringResource(R.string.reset_pwd_desc), modifier = Modifier.padding(vertical = 3.dp),style=bodyTextStyle)
var resetPwdFlag by remember{ mutableIntStateOf(0) } var resetPwdFlag by remember{ mutableIntStateOf(0) }
if(VERSION.SDK_INT>=23){ if(VERSION.SDK_INT>=23){
RadioButtonItem("开机时不要求密码(如果有指纹等其他解锁方式)", RadioButtonItem("开机时不要求密码(如果有指纹等其他解锁方式)", {resetPwdFlag==RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT}, {resetPwdFlag=RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT})
{resetPwdFlag==DevicePolicyManager.RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT},
{resetPwdFlag=DevicePolicyManager.RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT})
} }
RadioButtonItem("要求立即输入新密码",{resetPwdFlag==DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY}, RadioButtonItem("要求立即输入新密码",{resetPwdFlag==RESET_PASSWORD_REQUIRE_ENTRY}, {resetPwdFlag=RESET_PASSWORD_REQUIRE_ENTRY})
{resetPwdFlag=DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY})
RadioButtonItem("",{resetPwdFlag==0},{resetPwdFlag=0}) RadioButtonItem("",{resetPwdFlag==0},{resetPwdFlag=0})
Row(modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.horizontalScroll(rememberScrollState())},horizontalArrangement = Arrangement.SpaceBetween) { Row(modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.horizontalScroll(rememberScrollState())},horizontalArrangement = Arrangement.SpaceBetween) {
Button( Button(
@@ -225,20 +219,17 @@ fun Password(){
if(VERSION.SDK_INT>=31){ if(VERSION.SDK_INT>=31){
Column(modifier = sections()) { Column(modifier = sections()) {
val passwordComplexity = mapOf( val passwordComplexity = mapOf(
DevicePolicyManager.PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)", PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)",
DevicePolicyManager.PASSWORD_COMPLEXITY_LOW to "低(允许图案和连续性)", PASSWORD_COMPLEXITY_LOW to "低(允许图案和连续性)",
DevicePolicyManager.PASSWORD_COMPLEXITY_MEDIUM to "无连续性至少4位", PASSWORD_COMPLEXITY_MEDIUM to "无连续性至少4位",
DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH to "无连续性至少6位" PASSWORD_COMPLEXITY_HIGH to "无连续性至少6位"
).toList() ).toList()
var selectedItem by remember{ mutableIntStateOf(passwordComplexity[0].first) } var selectedItem by remember{ mutableIntStateOf(passwordComplexity[0].first) }
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){ if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
selectedItem=myDpm.requiredPasswordComplexity selectedItem=myDpm.requiredPasswordComplexity
} }
Text(text = "密码复杂度要求", style = typography.titleLarge,color = titleColor) Text(text = "密码复杂度要求", style = typography.titleLarge,color = titleColor)
Text(text = "不是实际密码复杂度", Text(text = "不是实际密码复杂度", style = bodyTextStyle)
style = bodyTextStyle)
Text(text = "设置密码复杂度将会取代密码质量",
style = bodyTextStyle)
RadioButtonItem(passwordComplexity[0].second,{selectedItem==passwordComplexity[0].first},{selectedItem=passwordComplexity[0].first}) RadioButtonItem(passwordComplexity[0].second,{selectedItem==passwordComplexity[0].first},{selectedItem=passwordComplexity[0].first})
RadioButtonItem(passwordComplexity[1].second,{selectedItem==passwordComplexity[1].first},{selectedItem=passwordComplexity[1].first}) RadioButtonItem(passwordComplexity[1].second,{selectedItem==passwordComplexity[1].first},{selectedItem=passwordComplexity[1].first})
RadioButtonItem(passwordComplexity[2].second,{selectedItem==passwordComplexity[2].first},{selectedItem=passwordComplexity[2].first}) RadioButtonItem(passwordComplexity[2].second,{selectedItem==passwordComplexity[2].first},{selectedItem=passwordComplexity[2].first})
@@ -258,7 +249,7 @@ fun Password(){
} }
if(!isWear){ if(!isWear){
Button( Button(
onClick = {myContext.startActivity(Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD))}, onClick = {myContext.startActivity(Intent(ACTION_SET_NEW_PASSWORD))},
modifier = Modifier.fillMaxWidth(0.95F) modifier = Modifier.fillMaxWidth(0.95F)
){ ){
Text("要求设置新密码") Text("要求设置新密码")
@@ -267,7 +258,7 @@ fun Password(){
} }
if(isWear){ if(isWear){
Button( Button(
onClick = {myContext.startActivity(Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD))}, onClick = {myContext.startActivity(Intent(ACTION_SET_NEW_PASSWORD))},
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
Text("要求设置新密码") Text("要求设置新密码")
@@ -276,19 +267,107 @@ fun Password(){
} }
} }
Column(modifier = sections()){
var state by remember{mutableIntStateOf(-1)}
var shortcuts by remember{mutableStateOf(false)}
var biometrics by remember{mutableStateOf(false)}
var iris by remember{mutableStateOf(false)}
var face by remember{mutableStateOf(false)}
var remote by remember{mutableStateOf(false)}
var fingerprint by remember{mutableStateOf(false)}
var agents by remember{mutableStateOf(false)}
var unredacted by remember{mutableStateOf(false)}
var notification by remember{mutableStateOf(false)}
var camera by remember{mutableStateOf(false)}
var widgets by remember{mutableStateOf(false)}
val calculateCustomFeature = {
var calculate = myDpm.getKeyguardDisabledFeatures(myComponent)
if(calculate==0){state=0}
else{
if(calculate-KEYGUARD_DISABLE_SHORTCUTS_ALL>=0 && VERSION.SDK_INT>=34){shortcuts=true;calculate-=KEYGUARD_DISABLE_SHORTCUTS_ALL}
if(calculate-KEYGUARD_DISABLE_BIOMETRICS>=0&&VERSION.SDK_INT>=28){biometrics=true;calculate -= KEYGUARD_DISABLE_BIOMETRICS}
if(calculate-KEYGUARD_DISABLE_IRIS>=0&&VERSION.SDK_INT>=28){iris=true;calculate -=KEYGUARD_DISABLE_IRIS }
if(calculate-KEYGUARD_DISABLE_FACE>=0&&VERSION.SDK_INT>=28){face=true;calculate -= KEYGUARD_DISABLE_FACE}
if(calculate-KEYGUARD_DISABLE_REMOTE_INPUT>=0&&VERSION.SDK_INT>=24){remote=true;calculate -= KEYGUARD_DISABLE_REMOTE_INPUT}
if(calculate-KEYGUARD_DISABLE_FINGERPRINT>=0){fingerprint=true;calculate -= KEYGUARD_DISABLE_FINGERPRINT}
if(calculate-KEYGUARD_DISABLE_TRUST_AGENTS>=0){agents=true;calculate -= KEYGUARD_DISABLE_TRUST_AGENTS}
if(calculate-KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS>=0){unredacted=true;calculate -= KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}
if(calculate-KEYGUARD_DISABLE_SECURE_NOTIFICATIONS>=0){notification=true;calculate -= KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}
if(calculate-KEYGUARD_DISABLE_SECURE_CAMERA>=0){camera=true;calculate -= KEYGUARD_DISABLE_SECURE_CAMERA}
if(calculate-KEYGUARD_DISABLE_WIDGETS_ALL>=0){widgets=true;calculate -= KEYGUARD_DISABLE_WIDGETS_ALL}
}
}
if(state==-1){
state = when(myDpm.getKeyguardDisabledFeatures(myComponent)){
KEYGUARD_DISABLE_FEATURES_NONE->0
KEYGUARD_DISABLE_FEATURES_ALL->1
else->2
}
calculateCustomFeature()
}
Text(text = "锁屏功能", style = typography.titleLarge)
RadioButtonItem("允许全部",{state==0},{state=0})
RadioButtonItem("禁用全部",{state==1},{state=1})
RadioButtonItem("自定义",{state==2},{state=2})
AnimatedVisibility(state==2) {
Column {
CheckBoxItem("禁用小工具(安卓5以下)",{widgets},{widgets=!widgets})
CheckBoxItem("禁用相机",{camera},{camera=!camera})
CheckBoxItem("禁用通知",{notification},{notification=!notification})
CheckBoxItem("禁用未经编辑的通知",{unredacted},{unredacted=!unredacted})
CheckBoxItem("禁用可信代理",{agents},{agents=!agents})
CheckBoxItem("禁用指纹解锁",{fingerprint},{fingerprint=!fingerprint})
if(VERSION.SDK_INT>=24){ CheckBoxItem("禁止在锁屏通知中输入(弃用)",{remote}, {remote=!remote}) }
if(VERSION.SDK_INT>=28){
CheckBoxItem("禁用人脸解锁",{face},{face=!face})
CheckBoxItem("禁用虹膜解锁(?)",{iris},{iris=!iris})
CheckBoxItem("禁用生物识别",{biometrics},{biometrics=!biometrics})
}
if(VERSION.SDK_INT>=34){ CheckBoxItem("禁用锁屏快捷方式",{shortcuts},{shortcuts=!shortcuts}) }
}
}
Button(
onClick = {
var result = 0
if(state==0){ result = 0 }
else if(state==1){ result = KEYGUARD_DISABLE_FEATURES_ALL }
else{
if(shortcuts&&VERSION.SDK_INT>=34){result+=KEYGUARD_DISABLE_SHORTCUTS_ALL}
if(biometrics&&VERSION.SDK_INT>=28){result+=KEYGUARD_DISABLE_BIOMETRICS}
if(iris&&VERSION.SDK_INT>=28){result+=KEYGUARD_DISABLE_IRIS}
if(face&&VERSION.SDK_INT>=28){result+=KEYGUARD_DISABLE_FACE}
if(remote&&VERSION.SDK_INT>=24){result+=KEYGUARD_DISABLE_REMOTE_INPUT}
if(fingerprint){result+=KEYGUARD_DISABLE_FINGERPRINT}
if(agents){result+=KEYGUARD_DISABLE_TRUST_AGENTS}
if(unredacted){result+=KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS}
if(notification){result+=KEYGUARD_DISABLE_SECURE_NOTIFICATIONS}
if(camera){result+=KEYGUARD_DISABLE_SECURE_CAMERA}
if(widgets){result+=KEYGUARD_DISABLE_WIDGETS_ALL}
}
myDpm.setKeyguardDisabledFeatures(myComponent,result)
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
calculateCustomFeature()
},
enabled = myDpm.isAdminActive(myComponent),
modifier = Modifier.fillMaxWidth()
) {
Text(text = "应用")
}
}
Column( Column(
modifier = sections() modifier = sections()
) { ) {
var expanded by remember{ mutableStateOf(VERSION.SDK_INT < 31) } var expanded by remember{ mutableStateOf(VERSION.SDK_INT < 31) }
val passwordQuality = mapOf( val passwordQuality = mapOf(
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED to "未指定", PASSWORD_QUALITY_UNSPECIFIED to "未指定",
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING to "需要密码或图案,不管复杂度", PASSWORD_QUALITY_SOMETHING to "需要密码或图案,不管复杂度",
DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC to "至少1个字母", PASSWORD_QUALITY_ALPHABETIC to "至少1个字母",
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC to "至少1个数字", PASSWORD_QUALITY_NUMERIC to "至少1个数字",
DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC to "数字字母各至少一个", PASSWORD_QUALITY_ALPHANUMERIC to "数字字母各至少一个",
DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK to "生物识别(弱)", PASSWORD_QUALITY_BIOMETRIC_WEAK to "生物识别(弱)",
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX to "复杂数字(无连续性)", PASSWORD_QUALITY_NUMERIC_COMPLEX to "复杂数字(无连续性)",
DevicePolicyManager.PASSWORD_QUALITY_COMPLEX to "自定义(暂不支持)", PASSWORD_QUALITY_COMPLEX to "自定义(暂不支持)",
).toList() ).toList()
var selectedItem by remember{ mutableIntStateOf(passwordQuality[0].first) } var selectedItem by remember{ mutableIntStateOf(passwordQuality[0].first) }
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){ if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
@@ -296,7 +375,9 @@ fun Password(){
} }
Text(text = "密码质量要求", style = typography.titleLarge,color = titleColor) Text(text = "密码质量要求", style = typography.titleLarge,color = titleColor)
if(expanded){ if(expanded){
Text(text = "不是实际密码质量", style = bodyTextStyle)} Text(text = "不是实际密码质量", style = bodyTextStyle)
Text(text = "设置密码复杂度将会取代密码质量", style = bodyTextStyle)
}
if(VERSION.SDK_INT>=31){ if(VERSION.SDK_INT>=31){
Text(text = "已弃用,请使用上面的”密码复杂度要求“", color = MaterialTheme.colorScheme.error, style = bodyTextStyle) Text(text = "已弃用,请使用上面的”密码复杂度要求“", color = MaterialTheme.colorScheme.error, style = bodyTextStyle)
} }
@@ -321,7 +402,7 @@ fun Password(){
Text("应用") Text("应用")
} }
if(VERSION.SDK_INT<31){ if(VERSION.SDK_INT<31){
Button(onClick = {myContext.startActivity(Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD))}){ Button(onClick = {myContext.startActivity(Intent(ACTION_SET_NEW_PASSWORD))}){
Text("要求设置新密码") Text("要求设置新密码")
}} }}
}else{ }else{
@@ -403,9 +484,9 @@ fun PasswordItem(
} }
fun activateToken(myContext: Context){ fun activateToken(myContext: Context){
val ACTIVATE_TOKEN_PROMPT = "在这里激活密码重置令牌" val desc = "在这里激活密码重置令牌"
val keyguardManager = myContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager val keyguardManager = myContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
val confirmIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, ACTIVATE_TOKEN_PROMPT) val confirmIntent = keyguardManager.createConfirmDeviceCredentialIntent(null, desc)
if (confirmIntent != null) { if (confirmIntent != null) {
startActivity(myContext,confirmIntent, null) startActivity(myContext,confirmIntent, null)
} else { } else {

View File

@@ -86,7 +86,7 @@
<string name="add_managed_profile">添加工作资料</string> <string name="add_managed_profile">添加工作资料</string>
<string name="remove_managed_profile">移除工作资料</string> <string name="remove_managed_profile">移除工作资料</string>
<string name="password">密码</string> <string name="password">密码与锁屏</string>
<string name="reset_pwd_desc">留空可以清除密码纯数字将使用PIN码</string> <string name="reset_pwd_desc">留空可以清除密码纯数字将使用PIN码</string>
<string name="max_pwd_fail">最大密码错误次数</string> <string name="max_pwd_fail">最大密码错误次数</string>
<string name="max_pwd_fail_desc">达到该限制会恢复出厂设置</string> <string name="max_pwd_fail_desc">达到该限制会恢复出厂设置</string>