fix crash when wipe data

This commit is contained in:
BinTianqi
2024-05-02 18:37:10 +08:00
parent 3d09eb958b
commit 57e5021f1e
6 changed files with 19 additions and 13 deletions

View File

@@ -191,7 +191,7 @@ private fun ResetPasswordToken(){
if(!myDpm.isResetPasswordTokenActive(myComponent)){
try{ activateToken(myContext) }
catch(e:NullPointerException){ Toast.makeText(myContext, myContext.getString(R.string.please_set_a_token), Toast.LENGTH_SHORT).show() }
}else{ Toast.makeText(myContext, "已经激活", Toast.LENGTH_SHORT).show() }
}else{ Toast.makeText(myContext, myContext.getString(R.string.token_already_activated), Toast.LENGTH_SHORT).show() }
},
enabled = isDeviceOwner(myDpm)||isProfileOwner(myDpm),
modifier = Modifier.fillMaxWidth()

View File

@@ -88,9 +88,9 @@ fun DpmPermissions(navCtrl:NavHostController){
){
composable(route = "Home"){Home(localNavCtrl,scrollState)}
composable(route = "Shizuku"){ShizukuActivate()}
composable(route = "DeviceAdmin"){DeviceAdmin(navCtrl)}
composable(route = "DeviceAdmin"){DeviceAdmin()}
composable(route = "ProfileOwner"){ProfileOwner()}
composable(route = "DeviceOwner"){DeviceOwner(navCtrl)}
composable(route = "DeviceOwner"){DeviceOwner()}
composable(route = "DeviceInfo"){DeviceInfo()}
composable(route = "SpecificID"){SpecificID()}
composable(route = "OrgName"){OrgName()}
@@ -187,7 +187,7 @@ private fun LockScreenInfo(){
}
@Composable
private fun DeviceAdmin(navCtrl: NavHostController){
private fun DeviceAdmin(){
val myContext = LocalContext.current
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val myComponent = ComponentName(myContext,Receiver::class.java)
@@ -261,7 +261,7 @@ private fun ProfileOwner(){
}
@Composable
private fun DeviceOwner(navCtrl: NavHostController){
private fun DeviceOwner(){
val myContext = LocalContext.current
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val co = rememberCoroutineScope()

View File

@@ -733,9 +733,7 @@ private fun WipeData(){
value = reason, onValueChange = {reason=it},
label = {Text(stringResource(R.string.reason))},
enabled = !confirmed,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()}),
modifier = Modifier.focusable().fillMaxWidth().padding(vertical = 3.dp)
modifier = Modifier.fillMaxWidth().padding(vertical = 3.dp)
)
}
Spacer(Modifier.padding(vertical = 5.dp))
@@ -761,8 +759,11 @@ private fun WipeData(){
}
Button(
onClick = {
if(VERSION.SDK_INT>=28){myDpm.wipeData(flag,reason)}
else{myDpm.wipeData(flag)}
if(VERSION.SDK_INT>=28&&reason!=""){
myDpm.wipeData(flag,reason)
}else{
myDpm.wipeData(flag)
}
},
colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError),
enabled = confirmed&&(VERSION.SDK_INT<34||(VERSION.SDK_INT>=34&&!userManager.isSystemUser)),