mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
Add 'User Restrictions' section
This commit is contained in:
@@ -2,6 +2,7 @@ package com.binbin.androidowner
|
|||||||
|
|
||||||
import android.app.admin.DevicePolicyManager
|
import android.app.admin.DevicePolicyManager
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -17,6 +18,7 @@ import com.binbin.androidowner.ui.theme.AndroidOwnerTheme
|
|||||||
fun ApplicationManage(myDpm:DevicePolicyManager, myComponent:ComponentName){
|
fun ApplicationManage(myDpm:DevicePolicyManager, myComponent:ComponentName){
|
||||||
var pkgName by remember { mutableStateOf("com.mihoyo.yuanshen") }
|
var pkgName by remember { mutableStateOf("com.mihoyo.yuanshen") }
|
||||||
Column {
|
Column {
|
||||||
|
Text("以下功能都需要DeviceOwner权限")
|
||||||
TextField(value = pkgName, onValueChange = {pkgName = it}, label = { Text("包名") })
|
TextField(value = pkgName, onValueChange = {pkgName = it}, label = { Text("包名") })
|
||||||
Button(onClick = { myDpm.setApplicationHidden(myComponent,pkgName,true) }) {
|
Button(onClick = { myDpm.setApplicationHidden(myComponent,pkgName,true) }) {
|
||||||
Text("隐藏")
|
Text("隐藏")
|
||||||
@@ -24,6 +26,14 @@ fun ApplicationManage(myDpm:DevicePolicyManager, myComponent:ComponentName){
|
|||||||
Button(onClick = { myDpm.setApplicationHidden(myComponent,pkgName,false) }) {
|
Button(onClick = { myDpm.setApplicationHidden(myComponent,pkgName,false) }) {
|
||||||
Text("显示")
|
Text("显示")
|
||||||
}
|
}
|
||||||
|
val isAppHidden = myDpm.isApplicationHidden(myComponent,pkgName)
|
||||||
|
Text("应用隐藏:$isAppHidden ${if(isAppHidden==true){"(这个应用也许没有被安装)"}else{""}}")
|
||||||
|
Button(onClick = {myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName),true)}) {
|
||||||
|
Text("停用")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName),true)}) {
|
||||||
|
Text("启用")
|
||||||
|
}
|
||||||
Button(onClick = { myDpm.setUninstallBlocked(myComponent, pkgName, true) }) {
|
Button(onClick = { myDpm.setUninstallBlocked(myComponent, pkgName, true) }) {
|
||||||
Text("禁止卸载")
|
Text("禁止卸载")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,18 @@ fun DeviceControl(myDpm: DevicePolicyManager, myComponent: ComponentName){
|
|||||||
wifimac = myDpm.getWifiMacAddress(myComponent).toString()
|
wifimac = myDpm.getWifiMacAddress(myComponent).toString()
|
||||||
}
|
}
|
||||||
Column {
|
Column {
|
||||||
Text("WiFi MAC: $wifimac")
|
Text("WiFi MAC: $wifimac (需要DeviceOwner)")
|
||||||
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_BLUETOOTH)}) {
|
Button(onClick = {myDpm.setCameraDisabled(myComponent, true)}) {
|
||||||
Text("禁用蓝牙(未测试)")
|
Text("禁用相机")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.setCameraDisabled(myComponent, false)}) {
|
||||||
|
Text("启用相机")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.setScreenCaptureDisabled(myComponent,true)}) {
|
||||||
|
Text("禁止截屏")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.setScreenCaptureDisabled(myComponent,false)}) {
|
||||||
|
Text("允许截屏")
|
||||||
}
|
}
|
||||||
Button(onClick = {myDpm.reboot(myComponent)}) {
|
Button(onClick = {myDpm.reboot(myComponent)}) {
|
||||||
Text("重启")
|
Text("重启")
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ fun MyScaffold(mainDpm:DevicePolicyManager, mainComponent:ComponentName){
|
|||||||
composable(route = "Permissions", content = { DpmPermissions(mainDpm,mainComponent)})
|
composable(route = "Permissions", content = { DpmPermissions(mainDpm,mainComponent)})
|
||||||
composable(route = "UIControl", content = { UIControl(mainDpm,mainComponent)})
|
composable(route = "UIControl", content = { UIControl(mainDpm,mainComponent)})
|
||||||
composable(route = "ApplicationManage", content = { ApplicationManage(mainDpm,mainComponent)})
|
composable(route = "ApplicationManage", content = { ApplicationManage(mainDpm,mainComponent)})
|
||||||
|
composable(route = "UserRestriction", content = { UserRestrict(mainDpm,mainComponent)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,5 +83,8 @@ fun HomePage(navCtrl:NavHostController){
|
|||||||
Button(onClick = {navCtrl.navigate("ApplicationManage")}) {
|
Button(onClick = {navCtrl.navigate("ApplicationManage")}) {
|
||||||
Text("应用管理")
|
Text("应用管理")
|
||||||
}
|
}
|
||||||
|
Button(onClick = {navCtrl.navigate("UserRestriction")}) {
|
||||||
|
Text("用户限制")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,22 @@ fun DpmPermissions(myDpm: DevicePolicyManager, myComponent: ComponentName){
|
|||||||
//da:DeviceAdmin do:DeviceOwner
|
//da:DeviceAdmin do:DeviceOwner
|
||||||
val isda = myDpm.isAdminActive(myComponent)
|
val isda = myDpm.isAdminActive(myComponent)
|
||||||
val isdo = myDpm.isDeviceOwnerApp("com.binbin.androidowner")
|
val isdo = myDpm.isDeviceOwnerApp("com.binbin.androidowner")
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
Text("Device Admin: $isda")
|
Text("Device Admin: $isda")
|
||||||
Text("Device Owner: $isdo")
|
Text("Device Owner: $isdo")
|
||||||
|
Button(onClick = {Runtime.getRuntime().exec("su -c \"dpm set-active-admin com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver\"")}) {
|
||||||
|
Text("获取DeviceAdmin(需root,未测试)")
|
||||||
|
}
|
||||||
|
Button(onClick = {Runtime.getRuntime().exec("su -c \"dpm set-device-owner com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver\"")}) {
|
||||||
|
Text("获取DeviceOwner(需root,未测试)")
|
||||||
|
}
|
||||||
|
Text("注意!在这里清除权限不会清除配置。比如:被停用的应用会保持停用状态")
|
||||||
Button(onClick = {myDpm.clearDeviceOwnerApp("com.binbin.androidowner")}) {
|
Button(onClick = {myDpm.clearDeviceOwnerApp("com.binbin.androidowner")}) {
|
||||||
Text("不当Device Owner了")
|
Text("不当Device Owner了")
|
||||||
}
|
}
|
||||||
|
Button(onClick = {myDpm.removeActiveAdmin(myComponent)}) {
|
||||||
|
Text("不当Device Admin了(同时会取消DeviceOwner)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
app/src/main/java/com/binbin/androidowner/UserRestrict.kt
Normal file
75
app/src/main/java/com/binbin/androidowner/UserRestrict.kt
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package com.binbin.androidowner
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.admin.DevicePolicyManager
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.os.UserManager
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateMapOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
|
||||||
|
@SuppressLint("UnrememberedMutableState")
|
||||||
|
@Composable
|
||||||
|
fun UserRestrict(myDpm: DevicePolicyManager, myComponent: ComponentName){
|
||||||
|
Column {
|
||||||
|
val strictState = myDpm.getUserRestrictions(myComponent)
|
||||||
|
for (key in strictState.keySet()) {
|
||||||
|
val value = when (strictState[key]) {
|
||||||
|
is Boolean -> if (strictState.getBoolean(key)) "true" else "false"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
//println("Key: $key, Value: $value")
|
||||||
|
Log.e(">>>>>>>>>>>","Key: $key, Value: $value")
|
||||||
|
}
|
||||||
|
Text("限制蓝牙:${strictState.getBoolean("no_bluetooth")}")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_BLUETOOTH)}) {
|
||||||
|
Text("禁用蓝牙")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_BLUETOOTH)}) {
|
||||||
|
Text("允许蓝牙")
|
||||||
|
}
|
||||||
|
Text("限制Wi-Fi:${strictState.getBoolean("no_config_wifi")}")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_WIFI)}) {
|
||||||
|
Text("禁用Wi-Fi")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_WIFI)}) {
|
||||||
|
Text("允许Wi-Fi")
|
||||||
|
}
|
||||||
|
Text("限制调试:${strictState.getBoolean("no_debug_features")}")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_DEBUGGING_FEATURES)}) {
|
||||||
|
Text("禁用调试")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_DEBUGGING_FEATURES)}) {
|
||||||
|
Text("允许调试")
|
||||||
|
}
|
||||||
|
Text("限制定位:${strictState.getBoolean("no_config_location")}")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_LOCATION)}) {
|
||||||
|
Text("禁用定位(需安卓9)")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_LOCATION)}) {
|
||||||
|
Text("允许定位(需安卓9)")
|
||||||
|
}
|
||||||
|
Text("限制移动数据:${strictState.getBoolean("no_config_mobile_network")}")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)}) {
|
||||||
|
Text("禁用移动数据")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)}) {
|
||||||
|
Text("允许移动数据")
|
||||||
|
}
|
||||||
|
Text("限制弹窗:${strictState.getBoolean("no_create_windows")}")
|
||||||
|
Text("弹窗包括toast、通知和应用的“显示在其他应用上层”")
|
||||||
|
Button(onClick = {myDpm.addUserRestriction(myComponent, UserManager.DISALLOW_CREATE_WINDOWS)}) {
|
||||||
|
Text("禁止弹窗")
|
||||||
|
}
|
||||||
|
Button(onClick = {myDpm.clearUserRestriction(myComponent, UserManager.DISALLOW_CREATE_WINDOWS)}) {
|
||||||
|
Text("允许弹窗")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user