mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
fix AppManage problems
This commit is contained in:
@@ -34,7 +34,6 @@ 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.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -77,22 +76,27 @@ fun ApplicationManage(){
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
if(VERSION.SDK_INT>=24&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){
|
if(VERSION.SDK_INT>=24&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){
|
||||||
val isSuspended: Boolean = try{ myDpm.isPackageSuspended(myComponent,pkgName) }
|
|
||||||
catch(e:NameNotFoundException){ false }
|
|
||||||
catch(w:NameNotFoundException){ false }
|
|
||||||
catch(e:IllegalArgumentException){ false }
|
|
||||||
AppManageItem(R.string.suspend,R.string.place_holder, {isSuspended}) { b -> myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName), b) }
|
|
||||||
}
|
|
||||||
AppManageItem(R.string.hide,R.string.isapphidden_desc, {myDpm.isApplicationHidden(myComponent,pkgName)}, {b -> myDpm.setApplicationHidden(myComponent,pkgName,b)})
|
|
||||||
if(VERSION.SDK_INT>=24){
|
|
||||||
AppManageItem(
|
AppManageItem(
|
||||||
R.string.always_on_vpn,R.string.experimental_feature,{pkgName == myDpm.getAlwaysOnVpnPackage(myComponent)},
|
R.string.suspend,R.string.place_holder,
|
||||||
{b ->
|
{try{ myDpm.isPackageSuspended(myComponent,pkgName) }
|
||||||
try{ myDpm.setAlwaysOnVpnPackage(myComponent,pkgName,b) }
|
catch(e:NameNotFoundException){ false }
|
||||||
catch(e:java.lang.UnsupportedOperationException){ Toast.makeText(myContext, "不支持", Toast.LENGTH_SHORT).show() }
|
catch(e:IllegalArgumentException){ false }}
|
||||||
catch(e:NameNotFoundException){ Toast.makeText(myContext, "未安装", Toast.LENGTH_SHORT).show() }
|
) { b -> myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName), b) }
|
||||||
|
}
|
||||||
|
if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){
|
||||||
|
AppManageItem(R.string.hide,R.string.isapphidden_desc, {myDpm.isApplicationHidden(myComponent,pkgName)}) {b-> myDpm.setApplicationHidden(myComponent, pkgName, b)}
|
||||||
|
}
|
||||||
|
if(VERSION.SDK_INT>=24&&(isDeviceOwner(myDpm)||isProfileOwner(myDpm))){
|
||||||
|
AppManageItem(
|
||||||
|
R.string.always_on_vpn,R.string.experimental_feature,{pkgName == myDpm.getAlwaysOnVpnPackage(myComponent)}) {b->
|
||||||
|
try {
|
||||||
|
myDpm.setAlwaysOnVpnPackage(myComponent, pkgName, b)
|
||||||
|
} catch(e: java.lang.UnsupportedOperationException) {
|
||||||
|
Toast.makeText(myContext, "不支持", Toast.LENGTH_SHORT).show()
|
||||||
|
} catch(e: NameNotFoundException) {
|
||||||
|
Toast.makeText(myContext, "未安装", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){
|
if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){
|
||||||
@@ -100,15 +104,16 @@ fun ApplicationManage(){
|
|||||||
var state by remember{mutableStateOf(myDpm.isUninstallBlocked(myComponent,pkgName))}
|
var state by remember{mutableStateOf(myDpm.isUninstallBlocked(myComponent,pkgName))}
|
||||||
Text(text = "防卸载", style = typography.titleLarge)
|
Text(text = "防卸载", style = typography.titleLarge)
|
||||||
Text("当前状态:${if(state){"打开"}else{"关闭"}}")
|
Text("当前状态:${if(state){"打开"}else{"关闭"}}")
|
||||||
Text("有时候无法正确获取防卸载状态")
|
Text(text = "有时候无法正确获取防卸载状态", style = bodyTextStyle)
|
||||||
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
|
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
focusMgr.clearFocus()
|
focusMgr.clearFocus()
|
||||||
myDpm.setUninstallBlocked(myComponent,pkgName,true)
|
myDpm.setUninstallBlocked(myComponent,pkgName,true)
|
||||||
|
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||||
state = myDpm.isUninstallBlocked(myComponent,pkgName)
|
state = myDpm.isUninstallBlocked(myComponent,pkgName)
|
||||||
},
|
},
|
||||||
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.49F)}
|
modifier = Modifier.fillMaxWidth(0.49F)
|
||||||
) {
|
) {
|
||||||
Text("打开")
|
Text("打开")
|
||||||
}
|
}
|
||||||
@@ -116,9 +121,11 @@ fun ApplicationManage(){
|
|||||||
onClick = {
|
onClick = {
|
||||||
focusMgr.clearFocus()
|
focusMgr.clearFocus()
|
||||||
myDpm.setUninstallBlocked(myComponent,pkgName,false)
|
myDpm.setUninstallBlocked(myComponent,pkgName,false)
|
||||||
|
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||||
state = myDpm.isUninstallBlocked(myComponent,pkgName)
|
state = myDpm.isUninstallBlocked(myComponent,pkgName)
|
||||||
},
|
},
|
||||||
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.96F)}){
|
modifier = Modifier.fillMaxWidth(0.96F)
|
||||||
|
){
|
||||||
Text("关闭")
|
Text("关闭")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,11 +140,7 @@ fun ApplicationManage(){
|
|||||||
pkgList = myDpm.getUserControlDisabledPackages(myComponent)
|
pkgList = myDpm.getUserControlDisabledPackages(myComponent)
|
||||||
listText = ""
|
listText = ""
|
||||||
var count = pkgList.size
|
var count = pkgList.size
|
||||||
for(pkg in pkgList){
|
for(pkg in pkgList){ count-=1; listText+=pkg; if(count>0){listText+="\n"} }
|
||||||
count-=1
|
|
||||||
listText+=pkg
|
|
||||||
if(count>0){listText+="\n"}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var inited by remember{mutableStateOf(false)}
|
var inited by remember{mutableStateOf(false)}
|
||||||
if(!inited){refresh();inited=true}
|
if(!inited){refresh();inited=true}
|
||||||
@@ -178,10 +181,7 @@ fun ApplicationManage(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = { myDpm.setUserControlDisabledPackages(myComponent, listOf()); refresh() },
|
||||||
myDpm.setUserControlDisabledPackages(myComponent, listOf())
|
|
||||||
refresh()
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
){
|
){
|
||||||
Text("清空列表")
|
Text("清空列表")
|
||||||
@@ -469,45 +469,21 @@ private fun AppManageItem(
|
|||||||
getMethod:()->Boolean,
|
getMethod:()->Boolean,
|
||||||
setMethod:(b:Boolean)->Unit
|
setMethod:(b:Boolean)->Unit
|
||||||
){
|
){
|
||||||
val myDpm = LocalContext.current.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
|
||||||
val focusMgr = LocalFocusManager.current
|
|
||||||
var isEnabled by remember{ mutableStateOf(false) }
|
|
||||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||||
if(!sharedPref.getBoolean("isWear",false)){
|
|
||||||
Row(
|
Row(
|
||||||
modifier = sections(),
|
modifier = sections(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Column {
|
var enabled by remember{mutableStateOf(getMethod())}
|
||||||
|
enabled = getMethod()
|
||||||
|
Column(modifier = if(sharedPref.getBoolean("isWear",false)){Modifier.fillMaxWidth(0.65F)}else{Modifier}){
|
||||||
Text(text = stringResource(itemName), style = typography.titleLarge, color = colorScheme.onPrimaryContainer)
|
Text(text = stringResource(itemName), style = typography.titleLarge, color = colorScheme.onPrimaryContainer)
|
||||||
if(itemDesc!=R.string.place_holder){ Text(stringResource(itemDesc)) }
|
if(itemDesc!=R.string.place_holder){ Text(stringResource(itemDesc)) }
|
||||||
}
|
}
|
||||||
Switch(
|
Switch(
|
||||||
checked = isEnabled,
|
checked = enabled,
|
||||||
onCheckedChange = {
|
onCheckedChange = { setMethod(!enabled); enabled=getMethod() }
|
||||||
setMethod(!isEnabled)
|
|
||||||
isEnabled = getMethod()
|
|
||||||
},
|
|
||||||
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)
|
|
||||||
)
|
)
|
||||||
}}else{
|
|
||||||
Column(
|
|
||||||
modifier = sections()
|
|
||||||
) {
|
|
||||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Text(text = stringResource(itemName), fontWeight = FontWeight.SemiBold, style = typography.titleMedium)
|
|
||||||
Switch(
|
|
||||||
checked = isEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
setMethod(!isEnabled)
|
|
||||||
isEnabled = getMethod()
|
|
||||||
focusMgr.clearFocus()
|
|
||||||
},
|
|
||||||
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if(itemDesc!=R.string.place_holder){ Text(text = stringResource(itemDesc), style = typography.bodyMedium) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<string name="backup_service">备份服务</string>
|
<string name="backup_service">备份服务</string>
|
||||||
|
|
||||||
<string name="app_manage">应用管理</string>
|
<string name="app_manage">应用管理</string>
|
||||||
<string name="suspend">停用</string>
|
<string name="suspend">挂起</string>
|
||||||
<string name="hide">隐藏</string>
|
<string name="hide">隐藏</string>
|
||||||
<string name="isapphidden_desc">如果隐藏,有可能是没安装</string>
|
<string name="isapphidden_desc">如果隐藏,有可能是没安装</string>
|
||||||
<string name="user_ctrl_disabled">禁止用户控制</string>
|
<string name="user_ctrl_disabled">禁止用户控制</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user