set MTE policy

This commit is contained in:
BinTianqi
2024-02-03 11:47:47 +08:00
parent 6a933443f1
commit 5e433fff0c
8 changed files with 113 additions and 109 deletions

View File

@@ -11,8 +11,8 @@ android {
applicationId = "com.binbin.androidowner" applicationId = "com.binbin.androidowner"
minSdk = 21 minSdk = 21
targetSdk = 34 targetSdk = 34
versionCode = 9 versionCode = 10
versionName = "2.2" versionName = "2.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {

View File

@@ -29,6 +29,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity import androidx.core.content.ContextCompat.startActivity
@@ -178,7 +179,7 @@ fun ApplicationManage(){
} }
}, },
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm), enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp) modifier = Modifier.fillMaxWidth().padding(horizontal = 10.dp)
) { ) {
Text("设为默认拨号应用") Text("设为默认拨号应用")
} }
@@ -222,7 +223,7 @@ private fun AppManageItem(
modifier = sections() modifier = sections()
) { ) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
Text(text = stringResource(itemName)) Text(text = stringResource(itemName), fontWeight = FontWeight.SemiBold, style = typography.titleMedium)
Switch( Switch(
checked = isEnabled, checked = isEnabled,
onCheckedChange = { onCheckedChange = {

View File

@@ -1,39 +1,28 @@
package com.binbin.androidowner package com.binbin.androidowner
import android.app.admin.DevicePolicyManager import android.app.admin.DevicePolicyManager
import android.app.admin.DevicePolicyManager.MTE_DISABLED
import android.app.admin.DevicePolicyManager.MTE_ENABLED
import android.app.admin.DevicePolicyManager.MTE_NOT_CONTROLLED_BY_POLICY
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
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.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button import androidx.compose.material3.*
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.MaterialTheme.colorScheme
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.Switch import androidx.compose.runtime.*
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -90,7 +79,7 @@ fun DeviceControl(){
} }
if(VERSION.SDK_INT>=28){ if(VERSION.SDK_INT>=28){
Column(modifier = sections()) { Column(modifier = sections()) {
Text(text = "锁屏方式", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer) Text(text = "锁屏方式", style = typography.titleLarge,color = colorScheme.onPrimaryContainer)
Text(text = "禁用需要无密码",style=bodyTextStyle) Text(text = "禁用需要无密码",style=bodyTextStyle)
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@@ -136,25 +125,57 @@ fun DeviceControl(){
) { ) {
Text(text = "清除用户Ca证书") Text(text = "清除用户Ca证书")
}} }}
if(VERSION.SDK_INT>=34&&isDeviceOwner(myDpm)){
Column(modifier = sections()){
Text(text = "MTE策略", style = typography.titleLarge, color = colorScheme.onPrimaryContainer)
Text("MTE内存标记拓展安卓14和ARMv9的高端功能")
var selectedMtePolicy by remember{mutableIntStateOf(myDpm.mtePolicy)}
RadioButtonItem("由用户决定", {selectedMtePolicy==MTE_NOT_CONTROLLED_BY_POLICY}, {selectedMtePolicy= MTE_NOT_CONTROLLED_BY_POLICY})
RadioButtonItem("开启", {selectedMtePolicy==MTE_ENABLED}, {selectedMtePolicy=MTE_ENABLED})
RadioButtonItem("关闭", {selectedMtePolicy==MTE_DISABLED}, {selectedMtePolicy=MTE_DISABLED})
Button(
onClick = {
try {
myDpm.mtePolicy = selectedMtePolicy
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
}catch(e:java.lang.UnsupportedOperationException){
Toast.makeText(myContext, "不支持", Toast.LENGTH_SHORT).show()
}
selectedMtePolicy = myDpm.mtePolicy
},
modifier = Modifier.fillMaxWidth()
) {
Text("应用")
}
}
}
if(isDeviceOwner(myDpm)){ if(isDeviceOwner(myDpm)){
SysUpdatePolicy(myDpm,myComponent,myContext) SysUpdatePolicy(myDpm,myComponent,myContext)
} }
Column(modifier = sections(if(isSystemInDarkTheme()){MaterialTheme.colorScheme.errorContainer}else{MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6F)})) { Column(modifier = sections(if(isSystemInDarkTheme()){
colorScheme.errorContainer}else{
colorScheme.errorContainer.copy(alpha = 0.6F)})) {
var flag by remember{ mutableIntStateOf(0) } var flag by remember{ mutableIntStateOf(0) }
var confirmed by remember{ mutableStateOf(false) } var confirmed by remember{ mutableStateOf(false) }
Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = MaterialTheme.colorScheme.onErrorContainer) Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = colorScheme.onErrorContainer)
RadioButtonItem("默认",{flag==0},{flag=0},MaterialTheme.colorScheme.onErrorContainer) RadioButtonItem("默认",{flag==0},{flag=0}, colorScheme.onErrorContainer)
RadioButtonItem("WIPE_EXTERNAL_STORAGE",{flag==0x0001},{flag=0x0001},MaterialTheme.colorScheme.onErrorContainer) RadioButtonItem("WIPE_EXTERNAL_STORAGE",{flag==0x0001},{flag=0x0001}, colorScheme.onErrorContainer)
RadioButtonItem("WIPE_RESET_PROTECTION_DATA",{flag==0x0002},{flag=0x0002},MaterialTheme.colorScheme.onErrorContainer) RadioButtonItem("WIPE_RESET_PROTECTION_DATA",{flag==0x0002},{flag=0x0002}, colorScheme.onErrorContainer)
RadioButtonItem("WIPE_EUICC",{flag==0x0004},{flag=0x0004},MaterialTheme.colorScheme.onErrorContainer) RadioButtonItem("WIPE_EUICC",{flag==0x0004},{flag=0x0004}, colorScheme.onErrorContainer)
RadioButtonItem("WIPE_SILENTLY",{flag==0x0008},{flag=0x0008},MaterialTheme.colorScheme.onErrorContainer) RadioButtonItem("WIPE_SILENTLY",{flag==0x0008},{flag=0x0008}, colorScheme.onErrorContainer)
Text(text = "清空数据的不能是系统用户",color = MaterialTheme.colorScheme.onErrorContainer, Text(text = "清空数据的不能是系统用户",color = colorScheme.onErrorContainer,
style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}) style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium})
Button( Button(
onClick = {confirmed=!confirmed}, onClick = {confirmed=!confirmed},
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
containerColor = if(confirmed){MaterialTheme.colorScheme.primary}else{MaterialTheme.colorScheme.error}, containerColor = if(confirmed){
contentColor = if(confirmed){MaterialTheme.colorScheme.onPrimary}else{MaterialTheme.colorScheme.onError} colorScheme.primary}else{
colorScheme.error},
contentColor = if(confirmed){
colorScheme.onPrimary}else{
colorScheme.onError}
), ),
enabled = myDpm.isAdminActive(myComponent) enabled = myDpm.isAdminActive(myComponent)
) { ) {
@@ -164,8 +185,8 @@ fun DeviceControl(){
Button( Button(
onClick = {myDpm.wipeData(flag)}, onClick = {myDpm.wipeData(flag)},
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.error, containerColor = colorScheme.error,
contentColor = MaterialTheme.colorScheme.onError contentColor = colorScheme.onError
), ),
enabled = confirmed enabled = confirmed
) { ) {
@@ -175,8 +196,8 @@ fun DeviceControl(){
Button( Button(
onClick = {myDpm.wipeDevice(flag)}, onClick = {myDpm.wipeDevice(flag)},
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.error, containerColor = colorScheme.error,
contentColor = MaterialTheme.colorScheme.onError contentColor = colorScheme.onError
), ),
enabled = confirmed enabled = confirmed
) { ) {
@@ -209,20 +230,21 @@ private fun DeviceCtrlItem(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = if(isWear){Modifier.fillMaxWidth(0.65F)}else{Modifier.fillMaxWidth(0.75F)} modifier = if(isWear){Modifier.fillMaxWidth(0.65F)}else{Modifier.fillMaxWidth(0.75F)}
){ ){
if(!sharedPref.getBoolean("isWear",false)){ if(!isWear){
Icon( Icon(
painter = painterResource(leadIcon), painter = painterResource(leadIcon),
contentDescription = null, contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer, tint = colorScheme.onPrimaryContainer,
modifier = Modifier.padding(start = 5.dp, end = 9.dp) modifier = Modifier.padding(start = 5.dp, end = 9.dp)
)} )}
Column { Column {
Text( Text(
text = stringResource(itemName), text = stringResource(itemName),
style = if(!sharedPref.getBoolean("isWear",false)){typography.titleLarge}else{typography.bodyLarge}, style = if(!isWear){typography.titleLarge}else{typography.titleMedium},
color = MaterialTheme.colorScheme.onPrimaryContainer color = colorScheme.onPrimaryContainer,
fontWeight = if(isWear){ FontWeight.SemiBold }else{ FontWeight.Medium }
) )
if(itemDesc!=R.string.place_holder&&!sharedPref.getBoolean("isWear",false)){ Text(stringResource(itemDesc)) } if(itemDesc!=R.string.place_holder){ Text(stringResource(itemDesc)) }
} }
} }
isEnabled = getMethod() isEnabled = getMethod()

View File

@@ -266,7 +266,7 @@ fun CheckBoxItem(
) { ) {
Checkbox( Checkbox(
checked = checked(), checked = checked(),
onCheckedChange = {b:Boolean->operation()}, onCheckedChange = {operation()},
modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier} 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,

View File

@@ -11,28 +11,16 @@ import android.widget.Toast
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.animation.AnimatedVisibility 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.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Check import androidx.compose.material.icons.outlined.Check
import androidx.compose.material3.Button import androidx.compose.material3.*
import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
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.TextField
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -55,7 +43,7 @@ fun Password(){
var newPwd by remember{ mutableStateOf("") } var newPwd by remember{ mutableStateOf("") }
val focusMgr = LocalFocusManager.current val focusMgr = LocalFocusManager.current
val isWear = sharedPref.getBoolean("isWear",false) val isWear = sharedPref.getBoolean("isWear",false)
val titleColor = MaterialTheme.colorScheme.onPrimaryContainer val titleColor = colorScheme.onPrimaryContainer
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge} val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
Column( Column(
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
@@ -64,22 +52,20 @@ fun Password(){
val myByteArray by remember{ mutableStateOf(byteArrayOf(1,1,4,5,1,4,1,9,1,9,8,1,0,1,1,4,5,1,4,1,9,1,9,8,1,0,1,1,4,5,1,4,1,9,1,9,8,1,0)) } val myByteArray by remember{ mutableStateOf(byteArrayOf(1,1,4,5,1,4,1,9,1,9,8,1,0,1,1,4,5,1,4,1,9,1,9,8,1,0,1,1,4,5,1,4,1,9,1,9,8,1,0)) }
Text( Text(
text = "以下操作可能会造成不可挽回的损失,请先备份好数据。执行操作时一定要谨慎!!!", text = "以下操作可能会造成不可挽回的损失,请先备份好数据。执行操作时一定要谨慎!!!",
color = MaterialTheme.colorScheme.onErrorContainer, color = colorScheme.onErrorContainer,
modifier = sections(MaterialTheme.colorScheme.errorContainer), modifier = sections(colorScheme.errorContainer),
style=bodyTextStyle style=bodyTextStyle
) )
if(isWear){ if(isWear){
Text( Text(
text = "警告手表不支持带字母的密码也不支持超过4位的PIN码如果你设置了这样的密码或密码复杂度要求你将无法解锁你的手表", text = "警告手表不支持带字母的密码也不支持超过4位的PIN码如果你设置了这样的密码或密码复杂度要求你将无法解锁你的手表",
color = MaterialTheme.colorScheme.onErrorContainer, color = colorScheme.onErrorContainer,
modifier = sections(MaterialTheme.colorScheme.errorContainer), modifier = sections(colorScheme.errorContainer),
style = typography.bodyMedium style = typography.bodyMedium
) )
} }
if(myDpm.isDeviceOwnerApp("com.binbin.androidowner")){ if(myDpm.isDeviceOwnerApp("com.binbin.androidowner")){
Column( Column(modifier = sections()) {
modifier = sections()
) {
if(VERSION.SDK_INT>=29){ if(VERSION.SDK_INT>=29){
val passwordComplexity = mapOf( val passwordComplexity = mapOf(
PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)", PASSWORD_COMPLEXITY_NONE to "无(允许不设密码)",
@@ -186,7 +172,7 @@ fun Password(){
}else{ Toast.makeText(myContext, "设置失败", Toast.LENGTH_SHORT).show() } }else{ Toast.makeText(myContext, "设置失败", Toast.LENGTH_SHORT).show() }
confirmed=false confirmed=false
}, },
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error, contentColor = MaterialTheme.colorScheme.onError), colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError),
enabled = confirmed&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm)), enabled = confirmed&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm)),
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.42F)} modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.42F)}
) { ) {
@@ -201,7 +187,7 @@ fun Password(){
confirmed=false confirmed=false
}, },
enabled = confirmed, enabled = confirmed,
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error, contentColor = MaterialTheme.colorScheme.onError), colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError),
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.9F)} modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.9F)}
) { ) {
Text("应用(旧)") Text("应用(旧)")
@@ -234,7 +220,9 @@ fun Password(){
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})
RadioButtonItem(passwordComplexity[3].second,{selectedItem==passwordComplexity[3].first},{selectedItem=passwordComplexity[3].first}, RadioButtonItem(passwordComplexity[3].second,{selectedItem==passwordComplexity[3].first},{selectedItem=passwordComplexity[3].first},
if(isWear){MaterialTheme.colorScheme.error}else{MaterialTheme.colorScheme.onBackground}) if(isWear){
colorScheme.error}else{
colorScheme.onBackground})
Text(text = "连续性密码重复6666或密码递增递减4321、2468", modifier = Modifier.padding(vertical = 3.dp), style = bodyTextStyle) Text(text = "连续性密码重复6666或密码递增递减4321、2468", modifier = Modifier.padding(vertical = 3.dp), style = bodyTextStyle)
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween){ Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween){
Button( Button(
@@ -355,9 +343,7 @@ fun Password(){
} }
} }
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(
PASSWORD_QUALITY_UNSPECIFIED to "未指定", PASSWORD_QUALITY_UNSPECIFIED to "未指定",
@@ -379,7 +365,7 @@ fun Password(){
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 = colorScheme.error, style = bodyTextStyle)
} }
if(expanded){ if(expanded){
RadioButtonItem(passwordQuality[0].second,{selectedItem==passwordQuality[0].first},{selectedItem=passwordQuality[0].first}) RadioButtonItem(passwordQuality[0].second,{selectedItem==passwordQuality[0].first},{selectedItem=passwordQuality[0].first})
@@ -416,7 +402,7 @@ fun Password(){
} }
@Composable @Composable
fun PasswordItem( private fun PasswordItem(
itemName:Int, itemName:Int,
itemDesc:Int, itemDesc:Int,
textFieldLabel:Int, textFieldLabel:Int,
@@ -431,7 +417,7 @@ fun PasswordItem(
var inputContentEdited by remember{ mutableStateOf(false) } var inputContentEdited by remember{ mutableStateOf(false) }
var ableToApply by remember{ mutableStateOf(true) } var ableToApply by remember{ mutableStateOf(true) }
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Text(text = stringResource(itemName), style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer) Text(text = stringResource(itemName), style = typography.titleLarge,color = colorScheme.onPrimaryContainer)
Text(text= stringResource(itemDesc),modifier=Modifier.padding(vertical = 2.dp), Text(text= stringResource(itemDesc),modifier=Modifier.padding(vertical = 2.dp),
style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}) style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium})
if(!sharedPref.getBoolean("isWear",false)){Spacer(Modifier.padding(vertical = 2.dp))} if(!sharedPref.getBoolean("isWear",false)){Spacer(Modifier.padding(vertical = 2.dp))}
@@ -462,8 +448,8 @@ fun PasswordItem(
onClick = { focusMgr.clearFocus() ; setMethod(inputContent) ; inputContentEdited=inputContent!=getMethod() }, onClick = { focusMgr.clearFocus() ; setMethod(inputContent) ; inputContentEdited=inputContent!=getMethod() },
enabled = isDeviceOwner(myDpm)&&ableToApply, enabled = isDeviceOwner(myDpm)&&ableToApply,
colors = IconButtonDefaults.iconButtonColors( colors = IconButtonDefaults.iconButtonColors(
contentColor = if(inputContentEdited){MaterialTheme.colorScheme.onError}else{MaterialTheme.colorScheme.onPrimary}, contentColor = if(inputContentEdited){ colorScheme.onError}else{ colorScheme.onPrimary},
containerColor = if(inputContentEdited){MaterialTheme.colorScheme.error}else{MaterialTheme.colorScheme.primary}, containerColor = if(inputContentEdited){ colorScheme.error}else{ colorScheme.primary},
disabledContentColor = Color.Transparent, disabledContentColor = Color.Transparent,
disabledContainerColor = Color.Transparent disabledContainerColor = Color.Transparent
) )

View File

@@ -56,7 +56,7 @@ fun SysUpdatePolicy(myDpm:DevicePolicyManager,myComponent:ComponentName,myContex
if(VERSION.SDK_INT>=23){ if(VERSION.SDK_INT>=23){
Column(modifier = sections()) { Column(modifier = sections()) {
var selectedPolicy by remember{ mutableStateOf(myDpm.systemUpdatePolicy?.policyType) } var selectedPolicy by remember{ mutableStateOf(myDpm.systemUpdatePolicy?.policyType) }
Text(text = "系统更新策略", style = MaterialTheme.typography.titleLarge) Text(text = "系统更新策略", style = MaterialTheme.typography.titleLarge, color = MaterialTheme.colorScheme.onPrimaryContainer)
RadioButtonItem("准备好后立即更新",{selectedPolicy==SystemUpdatePolicy.TYPE_INSTALL_AUTOMATIC},{selectedPolicy=SystemUpdatePolicy.TYPE_INSTALL_AUTOMATIC}) RadioButtonItem("准备好后立即更新",{selectedPolicy==SystemUpdatePolicy.TYPE_INSTALL_AUTOMATIC},{selectedPolicy=SystemUpdatePolicy.TYPE_INSTALL_AUTOMATIC})
RadioButtonItem("在某段时间里更新",{selectedPolicy==SystemUpdatePolicy.TYPE_INSTALL_WINDOWED},{selectedPolicy=SystemUpdatePolicy.TYPE_INSTALL_WINDOWED}) RadioButtonItem("在某段时间里更新",{selectedPolicy==SystemUpdatePolicy.TYPE_INSTALL_WINDOWED},{selectedPolicy=SystemUpdatePolicy.TYPE_INSTALL_WINDOWED})
RadioButtonItem("延迟30天",{selectedPolicy==SystemUpdatePolicy.TYPE_POSTPONE},{selectedPolicy=SystemUpdatePolicy.TYPE_POSTPONE}) RadioButtonItem("延迟30天",{selectedPolicy==SystemUpdatePolicy.TYPE_POSTPONE},{selectedPolicy=SystemUpdatePolicy.TYPE_POSTPONE})

View File

@@ -307,7 +307,7 @@ fun UserManage(navCtrl:NavHostController){
} }
@Composable @Composable
fun UserSessionMessage( private fun UserSessionMessage(
text:String, text:String,
textField:String, textField:String,
profileOwner:Boolean, profileOwner:Boolean,
@@ -362,7 +362,7 @@ fun UserSessionMessage(
} }
} }
fun userOperationResultCode(result:Int): String { private fun userOperationResultCode(result:Int): String {
return when(result){ return when(result){
UserManager.USER_OPERATION_SUCCESS->"成功" UserManager.USER_OPERATION_SUCCESS->"成功"
UserManager.USER_OPERATION_ERROR_UNKNOWN->"未知结果(失败)" UserManager.USER_OPERATION_ERROR_UNKNOWN->"未知结果(失败)"

View File

@@ -11,31 +11,23 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.*
import androidx.compose.runtime.getValue
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.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@@ -64,7 +56,7 @@ fun UserRestriction(){
items(1){ items(1){
Text(text = "打开开关后会禁用对应的功能",modifier = Modifier.padding(3.dp), style = bodyTextStyle) Text(text = "打开开关后会禁用对应的功能",modifier = Modifier.padding(3.dp), style = bodyTextStyle)
if(VERSION.SDK_INT<24){ if(VERSION.SDK_INT<24){
Text(text = "所有的用户限制都需要API24你的设备低于API24无法使用。", style = bodyTextStyle, color = MaterialTheme.colorScheme.error) Text(text = "所有的用户限制都需要API24你的设备低于API24无法使用。", style = bodyTextStyle, color = colorScheme.error)
} }
if(isProfileOwner(myDpm)){ if(isProfileOwner(myDpm)){
Text(text = "Profile owner无法使用部分功能", style = bodyTextStyle) Text(text = "Profile owner无法使用部分功能", style = bodyTextStyle)
@@ -75,42 +67,42 @@ fun UserRestriction(){
} }
items(1){ SectionTab("网络和互联网",{internetVisible}, { internetVisible=!internetVisible}) } items(1){ SectionTab("网络和互联网",{internetVisible}, { internetVisible=!internetVisible}) }
items(restrictionData().internet()){data-> items(RestrictionData().internet()){data->
if(internetVisible){ if(internetVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
} }
items(1){ SectionTab("更多连接",{connectivityVisible}) { connectivityVisible=!connectivityVisible } } items(1){ SectionTab("更多连接",{connectivityVisible}) { connectivityVisible=!connectivityVisible } }
items(restrictionData().connectivity()){data-> items(RestrictionData().connectivity()){data->
if(connectivityVisible){ if(connectivityVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
} }
items(1){ SectionTab("应用",{applicationVisible}) { applicationVisible=!applicationVisible } } items(1){ SectionTab("应用",{applicationVisible}) { applicationVisible=!applicationVisible } }
items(restrictionData().application()){data-> items(RestrictionData().application()){data->
if(applicationVisible){ if(applicationVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
} }
items(1){ SectionTab("用户",{userVisible}) { userVisible=!userVisible } } items(1){ SectionTab("用户",{userVisible}) { userVisible=!userVisible } }
items(restrictionData().user()){data-> items(RestrictionData().user()){data->
if(userVisible){ if(userVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
} }
items(1){ SectionTab("媒体",{mediaVisible}) { mediaVisible=!mediaVisible } } items(1){ SectionTab("媒体",{mediaVisible}) { mediaVisible=!mediaVisible } }
items(restrictionData().media()){data-> items(RestrictionData().media()){data->
if(mediaVisible){ if(mediaVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
} }
items(1){ SectionTab("其他",{otherVisible}) { otherVisible=!otherVisible } } items(1){ SectionTab("其他",{otherVisible}) { otherVisible=!otherVisible } }
items(restrictionData().other()){data-> items(RestrictionData().other()){data->
if(otherVisible){ if(otherVisible){
UserRestrictionItem(data.restriction,data.name,data.desc,data.ico) UserRestrictionItem(data.restriction,data.name,data.desc,data.ico)
} }
@@ -137,7 +129,9 @@ fun SectionTab(txt:String,getSection:()->Boolean,setSection:()->Unit){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Text( Text(
text = txt, text = txt,
color = if(getSection()){MaterialTheme.colorScheme.onTertiaryContainer}else{MaterialTheme.colorScheme.onPrimaryContainer}, color = if(getSection()){
colorScheme.onTertiaryContainer}else{
colorScheme.onPrimaryContainer},
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
style = if(!sharedPref.getBoolean("isWear",false)){typography.headlineMedium}else{typography.titleLarge}, style = if(!sharedPref.getBoolean("isWear",false)){typography.headlineMedium}else{typography.titleLarge},
modifier = Modifier modifier = Modifier
@@ -147,9 +141,9 @@ fun SectionTab(txt:String,getSection:()->Boolean,setSection:()->Unit){
.clip(RoundedCornerShape(15.dp)) .clip(RoundedCornerShape(15.dp))
.background( .background(
color = if (getSection()) { color = if (getSection()) {
MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F) colorScheme.tertiaryContainer.copy(alpha = 0.8F)
} else { } else {
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.8F) colorScheme.primaryContainer.copy(alpha = 0.8F)
} }
) )
.clickable(onClick = setSection) .clickable(onClick = setSection)
@@ -170,7 +164,7 @@ private fun UserRestrictionItem(
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false) val isWear = sharedPref.getBoolean("isWear",false)
Row( Row(
modifier = sections(MaterialTheme.colorScheme.secondaryContainer), modifier = sections(colorScheme.secondaryContainer),
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
){ ){
@@ -178,21 +172,22 @@ private fun UserRestrictionItem(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = if(isWear){Modifier.fillMaxWidth(0.65F)}else{Modifier.fillMaxWidth(0.8F)} modifier = if(isWear){Modifier.fillMaxWidth(0.65F)}else{Modifier.fillMaxWidth(0.8F)}
) { ) {
if(!sharedPref.getBoolean("isWear",false)){ if(!isWear){
Icon( Icon(
painter = painterResource(leadIcon), painter = painterResource(leadIcon),
contentDescription = null, contentDescription = null,
modifier = Modifier.padding(start = 4.dp, end = 8.dp), modifier = Modifier.padding(start = 4.dp, end = 8.dp),
tint = MaterialTheme.colorScheme.secondary tint = colorScheme.secondary
)} )}
Column{ Column{
Text( Text(
text = stringResource(itemName), text = stringResource(itemName),
style = if(!isWear){typography.titleLarge}else{typography.titleMedium}, style = if(!isWear){typography.titleLarge}else{typography.titleMedium},
color = MaterialTheme.colorScheme.onSecondaryContainer color = colorScheme.onSecondaryContainer,
fontWeight = if(isWear){ FontWeight.SemiBold }else{ FontWeight.Medium }
) )
if(restrictionDescription!=""){ if(restrictionDescription!=""){
Text(text = restrictionDescription, color = MaterialTheme.colorScheme.onSecondaryContainer, style = if(isWear){typography.bodyMedium}else{typography.bodyLarge}) Text(text = restrictionDescription, color = colorScheme.onSecondaryContainer, style = if(isWear){typography.bodyMedium}else{typography.bodyLarge})
} }
} }
} }
@@ -224,7 +219,7 @@ private fun UserRestrictionItem(
} }
} }
private class restrictionData{ private class RestrictionData{
fun internet():List<Restriction>{ fun internet():List<Restriction>{
val list:MutableList<Restriction> = mutableListOf() val list:MutableList<Restriction> = mutableListOf()
list += Restriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,R.string.config_mobile_network,"",R.drawable.signal_cellular_alt_fill0) list += Restriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,R.string.config_mobile_network,"",R.drawable.signal_cellular_alt_fill0)