mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
Add security section, backward compatible to API23
This commit is contained in:
@@ -2,7 +2,7 @@ package com.binbin.androidowner
|
||||
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION
|
||||
import android.os.UserManager
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -34,15 +34,19 @@ import androidx.compose.ui.unit.dp
|
||||
fun UserRestriction(myDpm: DevicePolicyManager, myComponent: ComponentName){
|
||||
val verticalScrolling = rememberScrollState()
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.verticalScroll(verticalScrolling)
|
||||
.padding(bottom = 20.dp)
|
||||
) {
|
||||
Text("打开开关后会禁用对应的功能")
|
||||
UserRestrictionItem(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,R.string.config_mobile_network,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_CONFIG_WIFI,R.string.config_wifi,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_BLUETOOTH,R.string.bluetooth,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_BLUETOOTH_SHARING,R.string.bt_share,"",myComponent, myDpm)
|
||||
if(Build.VERSION.SDK_INT>=28){
|
||||
if(VERSION.SDK_INT>=26){
|
||||
UserRestrictionItem(UserManager.DISALLOW_BLUETOOTH,R.string.bluetooth,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_BLUETOOTH_SHARING,R.string.bt_share,"",myComponent, myDpm)
|
||||
}
|
||||
if(VERSION.SDK_INT>=28){
|
||||
UserRestrictionItem(UserManager.DISALLOW_AIRPLANE_MODE,R.string.airplane_mode,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_CONFIG_LOCATION,R.string.config_location,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_CONFIG_BRIGHTNESS,R.string.config_brightness,"",myComponent, myDpm)
|
||||
@@ -51,17 +55,23 @@ fun UserRestriction(myDpm: DevicePolicyManager, myComponent: ComponentName){
|
||||
UserRestrictionItem(UserManager.DISALLOW_CREATE_WINDOWS,R.string.create_windows, stringResource(R.string.create_windows_description),myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_ADJUST_VOLUME,R.string.adjust_volume,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_INSTALL_APPS,R.string.install_apps,"",myComponent, myDpm)
|
||||
if(Build.VERSION.SDK_INT>=31){
|
||||
if(VERSION.SDK_INT>=31){
|
||||
UserRestrictionItem(UserManager.DISALLOW_CAMERA_TOGGLE,R.string.camera_toggle,"",myComponent, myDpm)
|
||||
}
|
||||
UserRestrictionItem(UserManager.DISALLOW_SMS,R.string.sms,"",myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_APPS_CONTROL,R.string.apps_ctrl, stringResource(R.string.apps_ctrl_description),myComponent, myDpm)
|
||||
UserRestrictionItem(UserManager.DISALLOW_AUTOFILL,R.string.autofill, "",myComponent, myDpm)
|
||||
if(Build.VERSION.SDK_INT<28){
|
||||
if(VERSION.SDK_INT>=26){
|
||||
UserRestrictionItem(UserManager.DISALLOW_AUTOFILL,R.string.autofill, "",myComponent, myDpm)
|
||||
}
|
||||
UserRestrictionItem(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES,R.string.inst_unknown_src,"",myComponent, myDpm)
|
||||
if(VERSION.SDK_INT<26){
|
||||
Text("以下功能需要安卓8或以上:蓝牙、自动填充服务")
|
||||
}
|
||||
if(VERSION.SDK_INT<28){
|
||||
Text("以下功能需要安卓9或以上:飞行模式、位置信息、调整亮度")
|
||||
}
|
||||
if(Build.VERSION.SDK_INT<31){
|
||||
Text("以下功能需要安卓12或以上:相机切换")
|
||||
if(VERSION.SDK_INT<31){
|
||||
Text("以下功能需要安卓12或以上:切换相机")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,21 +108,26 @@ private fun UserRestrictionItem(restriction:String, itemName:Int, restrictionDes
|
||||
if(restrictionDescription!=""){Text(restrictionDescription)}
|
||||
}
|
||||
}
|
||||
if(isdo){
|
||||
if(isdo&&VERSION.SDK_INT>=24){
|
||||
strictState = myDpm.getUserRestrictions(myComponent).getBoolean(restriction)
|
||||
}
|
||||
Switch(
|
||||
checked = strictState,
|
||||
onCheckedChange = {
|
||||
strictState=it
|
||||
if(strictState){
|
||||
myDpm.addUserRestriction(myComponent,restriction)
|
||||
}else{
|
||||
myDpm.clearUserRestriction(myComponent,restriction)
|
||||
}
|
||||
strictState = myDpm.getUserRestrictions(myComponent).getBoolean(restriction)
|
||||
},
|
||||
enabled = isdo
|
||||
)
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Switch(
|
||||
checked = strictState,
|
||||
onCheckedChange = {
|
||||
strictState=it
|
||||
if(strictState){
|
||||
myDpm.addUserRestriction(myComponent,restriction)
|
||||
}else{
|
||||
myDpm.clearUserRestriction(myComponent,restriction)
|
||||
}
|
||||
strictState = myDpm.getUserRestrictions(myComponent).getBoolean(restriction)
|
||||
|
||||
},
|
||||
enabled = isdo
|
||||
)
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user