mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 11:05:59 +00:00
clean up code
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
- 用户和工作资料:禁止添加/切换/移除用户,禁止添加/移除工作资料
|
||||
- 杂项:禁止自动填充服务、禁止调试
|
||||
- 用户管理
|
||||
- 添加用户并切换至新用户
|
||||
- 添加、启动、切换、停止、移除用户
|
||||
- 修改当前用户的名称
|
||||
- 设置切换用户时的提示
|
||||
- 密码
|
||||
@@ -51,6 +51,7 @@
|
||||
- Managed Profile,工作资料和多用户相关
|
||||
- 安装/卸载应用,清除应用的存储空间
|
||||
- 应用管理的包选择器(目前只能手动输入包名)
|
||||
- 用户选择器(目前只能手动输入序列号)
|
||||
|
||||
### 许可证
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ android {
|
||||
applicationId = "com.binbin.androidowner"
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = 8
|
||||
versionName = "2.1"
|
||||
versionCode = 9
|
||||
versionName = "2.2"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
package com.binbin.androidowner
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentSender
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import android.net.Uri
|
||||
import android.os.Build.VERSION
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -19,12 +12,12 @@ 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.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
@@ -38,9 +31,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat.startActivity
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
|
||||
@Composable
|
||||
@@ -52,42 +42,25 @@ fun ApplicationManage(){
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
TextField(
|
||||
value = pkgName,
|
||||
onValueChange = {
|
||||
pkgName = it
|
||||
},
|
||||
onValueChange = { pkgName = it },
|
||||
label = { Text("包名") },
|
||||
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = if(isWear){2.dp}else{12.dp},vertical = if(isWear){2.dp}else{6.dp})
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = if(isWear){2.dp}else{12.dp},vertical = if(isWear){2.dp}else{6.dp})
|
||||
)
|
||||
if(VERSION.SDK_INT>=24){
|
||||
val isSuspended = {
|
||||
try{
|
||||
myDpm.isPackageSuspended(myComponent,pkgName)
|
||||
}catch(e:NameNotFoundException){
|
||||
false
|
||||
val isSuspended = { try{ myDpm.isPackageSuspended(myComponent,pkgName) }catch(e:NameNotFoundException){ false } }
|
||||
AppManageItem(R.string.suspend,R.string.place_holder,myDpm, isSuspended) { b -> myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName), b) }
|
||||
}
|
||||
}
|
||||
AppManageItem(R.string.suspend,R.string.place_holder,myDpm, isSuspended,
|
||||
{b -> myDpm.setPackagesSuspended(myComponent, arrayOf(pkgName) ,b)})
|
||||
}
|
||||
AppManageItem(R.string.hide,R.string.isapphidden_desc,myDpm, {myDpm.isApplicationHidden(myComponent,pkgName)},
|
||||
{b -> myDpm.setApplicationHidden(myComponent,pkgName,b)})
|
||||
AppManageItem(R.string.hide,R.string.isapphidden_desc,myDpm, {myDpm.isApplicationHidden(myComponent,pkgName)}, {b -> myDpm.setApplicationHidden(myComponent,pkgName,b)})
|
||||
if(VERSION.SDK_INT>=30){
|
||||
AppManageItem(R.string.user_ctrl_disabled,R.string.user_ctrl_disabled_desc,myDpm, {pkgName in myDpm.getUserControlDisabledPackages(myComponent)},
|
||||
{b->myDpm.setUserControlDisabledPackages(myComponent, mutableListOf(if(b){pkgName}else{null}))})
|
||||
}
|
||||
/*AppManageItem(R.string.block_unins,R.string.sometimes_not_available,myDpm, {myDpm.isUninstallBlocked(myComponent,pkgName)},
|
||||
{b -> myDpm.setUninstallBlocked(myComponent,pkgName,b)})*/
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = if(isWear){sections().horizontalScroll(rememberScrollState())}else{sections()}
|
||||
@@ -103,7 +76,7 @@ fun ApplicationManage(){
|
||||
}
|
||||
}
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "许可的输入法", style = MaterialTheme.typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(text = "许可的输入法", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
var imeList = mutableListOf<String>()
|
||||
var imeListText by remember{ mutableStateOf("") }
|
||||
val refreshList = {
|
||||
@@ -113,15 +86,11 @@ fun ApplicationManage(){
|
||||
}
|
||||
}
|
||||
imeListText = ""
|
||||
for(eachIme in imeList){
|
||||
imeListText += "$eachIme \n"
|
||||
Log.e("",eachIme)
|
||||
}
|
||||
for(eachIme in imeList){ imeListText += "$eachIme \n" }
|
||||
}
|
||||
refreshList()
|
||||
Text(imeListText)
|
||||
Row(modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.fillMaxWidth().horizontalScroll(rememberScrollState())}
|
||||
,horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Row(modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.fillMaxWidth().horizontalScroll(rememberScrollState())},horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
imeList.plus(pkgName)
|
||||
@@ -133,6 +102,7 @@ fun ApplicationManage(){
|
||||
) {
|
||||
Text("加入列表")
|
||||
}
|
||||
if(isWear){Spacer(Modifier.padding(horizontal = 2.dp))}
|
||||
Button(
|
||||
onClick = {
|
||||
imeList.remove(pkgName)
|
||||
@@ -145,13 +115,7 @@ fun ApplicationManage(){
|
||||
Text("从列表中移除")
|
||||
}}
|
||||
}
|
||||
/*Button(
|
||||
onClick = {
|
||||
uninstallPkg(pkgName,myContext)
|
||||
}) {
|
||||
Text("卸载")
|
||||
}*/
|
||||
Spacer(Modifier.padding(20.dp))
|
||||
Spacer(Modifier.padding(30.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,9 +128,7 @@ private fun AppManageItem(
|
||||
setMethod:(b:Boolean)->Unit
|
||||
){
|
||||
var isEnabled by remember{ mutableStateOf(false) }
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||
isEnabled = getMethod()
|
||||
}
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){ isEnabled = getMethod() }
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
if(!sharedPref.getBoolean("isWear",false)){
|
||||
Row(
|
||||
@@ -177,7 +139,7 @@ private fun AppManageItem(
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(itemName),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
style = typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
if(itemDesc!=R.string.place_holder){
|
||||
@@ -210,64 +172,8 @@ private fun AppManageItem(
|
||||
)
|
||||
}
|
||||
if(itemDesc!=R.string.place_holder){
|
||||
Text(text = stringResource(itemDesc),
|
||||
style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
|
||||
Text(text = stringResource(itemDesc), style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun uninstallPkg(pkgName:String,myContext:Context){
|
||||
val packageManager = myContext.packageManager
|
||||
try {
|
||||
val packageInfo = packageManager.getPackageInfo(pkgName, 0)
|
||||
val intent = Intent(Intent.ACTION_DELETE)
|
||||
intent.setData(Uri.parse("package:" + packageInfo.packageName))
|
||||
startActivity(myContext,intent,null)
|
||||
} catch (e: NameNotFoundException) {
|
||||
Toast.makeText(myContext, "应用未安装", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun uninstallApp(context: Context, packageName: String) {
|
||||
val packageUri = Uri.parse("package:$packageName")
|
||||
val uninstallIntent = Intent(Intent.ACTION_DELETE, packageUri)
|
||||
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(uninstallIntent)
|
||||
}
|
||||
|
||||
fun isAppInstalled(context: Context, packageName: String): Boolean {
|
||||
return try {
|
||||
context.packageManager.getApplicationInfo(packageName, 0)
|
||||
true
|
||||
} catch (e: NameNotFoundException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun installPackage(context: Context, inputStream: InputStream, packageName: String?): Boolean {
|
||||
val packageInstaller = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(
|
||||
PackageInstaller.SessionParams.MODE_FULL_INSTALL
|
||||
)
|
||||
params.setAppPackageName(packageName)
|
||||
val sessionId = packageInstaller.createSession(params)
|
||||
val session = packageInstaller.openSession(sessionId)
|
||||
val out = session.openWrite("COSU", 0, -1)
|
||||
val buffer = ByteArray(65536)
|
||||
var c: Int
|
||||
while (inputStream.read(buffer).also { c = it } != -1) {
|
||||
out.write(buffer, 0, c)
|
||||
}
|
||||
session.fsync(out)
|
||||
inputStream.close()
|
||||
out.close()
|
||||
session.commit(createIntentSender(context, sessionId))
|
||||
return true
|
||||
}
|
||||
|
||||
private fun createIntentSender(context: Context, sessionId: Int): IntentSender {
|
||||
val pendingIntent = PendingIntent.getBroadcast(context, sessionId, Intent(), PendingIntent.FLAG_IMMUTABLE)
|
||||
return pendingIntent.intentSender
|
||||
}
|
||||
|
||||
@@ -44,88 +44,67 @@ fun DeviceControl(){
|
||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState()).navigationBarsPadding()) {
|
||||
if(isDeviceOwner(myDpm)){
|
||||
DeviceCtrlItem(R.string.disable_cam,R.string.place_holder, R.drawable.photo_camera_fill0,myDpm,{myDpm.getCameraDisabled(null)},{b -> myDpm.setCameraDisabled(myComponent,b)})
|
||||
DeviceCtrlItem(R.string.disable_cam,R.string.place_holder, R.drawable.photo_camera_fill0,{myDpm.getCameraDisabled(null)},{b -> myDpm.setCameraDisabled(myComponent,b)})
|
||||
}
|
||||
if(isDeviceOwner(myDpm)){
|
||||
DeviceCtrlItem(R.string.disable_scrcap,R.string.aosp_scrrec_also_work,R.drawable.screenshot_fill0,myDpm,{myDpm.getScreenCaptureDisabled(null)},{b -> myDpm.setScreenCaptureDisabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.disable_scrcap,R.string.aosp_scrrec_also_work,R.drawable.screenshot_fill0,{myDpm.getScreenCaptureDisabled(null)},{b -> myDpm.setScreenCaptureDisabled(myComponent,b) })
|
||||
}
|
||||
if(VERSION.SDK_INT>=34&&(isDeviceOwner(myDpm)|| (isProfileOwner(myDpm)&&myDpm.isAffiliatedUser))){
|
||||
DeviceCtrlItem(R.string.hide_status_bar,R.string.may_hide_notifi_icon_only,R.drawable.notifications_fill0,myDpm,{myDpm.isStatusBarDisabled},{b -> myDpm.setStatusBarDisabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.hide_status_bar,R.string.may_hide_notifi_icon_only,R.drawable.notifications_fill0,{myDpm.isStatusBarDisabled},{b -> myDpm.setStatusBarDisabled(myComponent,b) })
|
||||
}
|
||||
if(VERSION.SDK_INT>=30&&isDeviceOwner(myDpm)){
|
||||
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,myDpm,{myDpm.getAutoTimeEnabled(myComponent)},{b -> myDpm.setAutoTimeEnabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.auto_timezone,R.string.place_holder,R.drawable.globe_fill0,myDpm,{myDpm.getAutoTimeZoneEnabled(myComponent)},{b -> myDpm.setAutoTimeZoneEnabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.auto_time,R.string.place_holder,R.drawable.schedule_fill0,{myDpm.getAutoTimeEnabled(myComponent)},{b -> myDpm.setAutoTimeEnabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.auto_timezone,R.string.place_holder,R.drawable.globe_fill0,{myDpm.getAutoTimeZoneEnabled(myComponent)},{b -> myDpm.setAutoTimeZoneEnabled(myComponent,b) })
|
||||
}
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||
DeviceCtrlItem(R.string.master_mute,R.string.place_holder,R.drawable.volume_up_fill0,myDpm,{myDpm.isMasterVolumeMuted(myComponent)},{b -> myDpm.setMasterVolumeMuted(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.master_mute,R.string.place_holder,R.drawable.volume_up_fill0,{myDpm.isMasterVolumeMuted(myComponent)},{b -> myDpm.setMasterVolumeMuted(myComponent,b) })
|
||||
}
|
||||
if(VERSION.SDK_INT>=26&&(isDeviceOwner(myDpm)|| isProfileOwner(myDpm))){
|
||||
DeviceCtrlItem(R.string.backup_service,R.string.place_holder,R.drawable.backup_fill0,myDpm,{myDpm.isBackupServiceEnabled(myComponent)},{b -> myDpm.setBackupServiceEnabled(myComponent,b) })
|
||||
DeviceCtrlItem(R.string.backup_service,R.string.place_holder,R.drawable.backup_fill0,{myDpm.isBackupServiceEnabled(myComponent)},{b -> myDpm.setBackupServiceEnabled(myComponent,b) })
|
||||
}
|
||||
if(VERSION.SDK_INT>=23&&(isDeviceOwner(myDpm)|| isProfileOwner(myDpm))){
|
||||
DeviceCtrlItem(R.string.disable_bt_contact_share,R.string.place_holder,R.drawable.account_circle_fill0,myDpm,{myDpm.getBluetoothContactSharingDisabled(myComponent)},{b -> myDpm.setBluetoothContactSharingDisabled(myComponent,b)})
|
||||
DeviceCtrlItem(R.string.disable_bt_contact_share,R.string.place_holder,R.drawable.account_circle_fill0,{myDpm.getBluetoothContactSharingDisabled(myComponent)},{b -> myDpm.setBluetoothContactSharingDisabled(myComponent,b)})
|
||||
}
|
||||
if(VERSION.SDK_INT>=31&&isDeviceOwner(myDpm)){
|
||||
if(myDpm.canUsbDataSignalingBeDisabled()){
|
||||
DeviceCtrlItem(R.string.usb_signal,R.string.place_holder,R.drawable.usb_fill0,myDpm,{myDpm.isUsbDataSignalingEnabled},{b -> myDpm.isUsbDataSignalingEnabled = b })
|
||||
DeviceCtrlItem(R.string.usb_signal,R.string.place_holder,R.drawable.usb_fill0,{myDpm.isUsbDataSignalingEnabled},{b -> myDpm.isUsbDataSignalingEnabled = b })
|
||||
}else{
|
||||
Text(text = "你的设备不支持关闭USB信号",modifier = Modifier.fillMaxWidth(),
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}, textAlign = TextAlign.Center)
|
||||
Text(text = "你的设备不支持关闭USB信号",modifier = Modifier.fillMaxWidth(), style = bodyTextStyle, textAlign = TextAlign.Center)
|
||||
}
|
||||
}
|
||||
if(VERSION.SDK_INT<24&&isDeviceOwner(myDpm)){
|
||||
Text(text = "重启和WiFi Mac需要API24",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "重启和WiFi Mac需要API24",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT<26&&isDeviceOwner(myDpm)){
|
||||
Text(text = "备份服务需要API26",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "备份服务需要API26",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT<30&&isDeviceOwner(myDpm)){
|
||||
Text(text = "自动设置时间和自动设置时区需要API30",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "自动设置时间和自动设置时区需要API30",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT<31&&isDeviceOwner(myDpm)){Text(text = "关闭USB信号需API31",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})}
|
||||
if(VERSION.SDK_INT<31&&isDeviceOwner(myDpm)){Text(text = "关闭USB信号需API31",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = bodyTextStyle)}
|
||||
if(VERSION.SDK_INT<34&&isDeviceOwner(myDpm)){
|
||||
Text(text = "隐藏状态栏需要API34",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "隐藏状态栏需要API34",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center, style = bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT>=28){
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "锁屏方式", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(text = "禁用需要无密码",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "禁用需要无密码",style=bodyTextStyle)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
if(myDpm.setKeyguardDisabled(myComponent,true)){
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
Toast.makeText(myContext, "失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
onClick = { Toast.makeText(myContext, if(myDpm.setKeyguardDisabled(myComponent,true)){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show() },
|
||||
enabled = isDeviceOwner(myDpm)|| (isProfileOwner(myDpm)&&myDpm.isAffiliatedUser),
|
||||
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.48F)}
|
||||
) {
|
||||
Text("禁用")
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
if(myDpm.setKeyguardDisabled(myComponent,false)){
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
Toast.makeText(myContext, "失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
onClick = { Toast.makeText(myContext, if(myDpm.setKeyguardDisabled(myComponent,false)){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show() },
|
||||
enabled = isDeviceOwner(myDpm)|| (isProfileOwner(myDpm)&&myDpm.isAffiliatedUser),
|
||||
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.92F)}
|
||||
) {
|
||||
@@ -134,10 +113,7 @@ fun DeviceControl(){
|
||||
}}
|
||||
}
|
||||
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = sections(),
|
||||
) {
|
||||
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = sections()) {
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Button(onClick = {myDpm.reboot(myComponent)}, enabled = isDeviceOwner(myDpm),
|
||||
modifier = if(isWear){Modifier}else{Modifier.fillMaxWidth(0.48F)}) {
|
||||
@@ -150,12 +126,8 @@ fun DeviceControl(){
|
||||
}
|
||||
}
|
||||
if(VERSION.SDK_INT>=24){
|
||||
val wifimac = try {
|
||||
myDpm.getWifiMacAddress(myComponent).toString()
|
||||
}catch(e:SecurityException){
|
||||
"没有权限"
|
||||
}
|
||||
Text(text = "WiFi MAC: $wifimac",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
val wifimac = try { myDpm.getWifiMacAddress(myComponent).toString() }catch(e:SecurityException){ "没有权限" }
|
||||
Text(text = "WiFi MAC: $wifimac",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,style=bodyTextStyle)
|
||||
}
|
||||
if(isDeviceOwner(myDpm)||isProfileOwner(myDpm)){
|
||||
Button(
|
||||
@@ -167,9 +139,7 @@ fun DeviceControl(){
|
||||
if(isDeviceOwner(myDpm)){
|
||||
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()){MaterialTheme.colorScheme.errorContainer}else{MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6F)})) {
|
||||
var flag by remember{ mutableIntStateOf(0) }
|
||||
var confirmed by remember{ mutableStateOf(false) }
|
||||
Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = MaterialTheme.colorScheme.onErrorContainer)
|
||||
@@ -224,7 +194,6 @@ private fun DeviceCtrlItem(
|
||||
itemName:Int,
|
||||
itemDesc:Int,
|
||||
leadIcon:Int,
|
||||
myDpm: DevicePolicyManager,
|
||||
getMethod:()->Boolean,
|
||||
setMethod:(b:Boolean)->Unit
|
||||
){
|
||||
@@ -253,9 +222,7 @@ private fun DeviceCtrlItem(
|
||||
style = if(!sharedPref.getBoolean("isWear",false)){typography.titleLarge}else{typography.bodyLarge},
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
if(itemDesc!=R.string.place_holder&&!sharedPref.getBoolean("isWear",false)){
|
||||
Text(stringResource(itemDesc))
|
||||
}
|
||||
if(itemDesc!=R.string.place_holder&&!sharedPref.getBoolean("isWear",false)){ Text(stringResource(itemDesc)) }
|
||||
}
|
||||
}
|
||||
isEnabled = getMethod()
|
||||
|
||||
@@ -27,6 +27,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
@@ -96,12 +97,7 @@ fun MyScaffold(){
|
||||
topBar = {
|
||||
if(!sharedPref.getBoolean("isWear",false)){
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = stringResource(topBarName) ,
|
||||
color = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
},
|
||||
title = { Text(text = stringResource(topBarName) , color = MaterialTheme.colorScheme.onSurface) },
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
@@ -151,9 +147,7 @@ fun MyScaffold(){
|
||||
NavHost(
|
||||
navController = navCtrl,
|
||||
startDestination = "HomePage",
|
||||
modifier = Modifier
|
||||
.padding(top = it.calculateTopPadding())
|
||||
.imePadding()
|
||||
modifier = Modifier.padding(top = it.calculateTopPadding()).imePadding()
|
||||
){
|
||||
composable(route = "HomePage", content = { HomePage(navCtrl)})
|
||||
composable(route = "DeviceControl", content = { DeviceControl()})
|
||||
@@ -174,44 +168,35 @@ fun HomePage(navCtrl:NavHostController){
|
||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||
val activateType = if(isDeviceOwner(myDpm)){"Device Owner"}else if(isProfileOwner(myDpm)){"Profile Owner"}else if(myDpm.isAdminActive(myComponent)){"Device Admin"}else{""}
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
if(sharedPref.getBoolean("isWear",false)){
|
||||
Spacer(Modifier.padding(vertical = 3.dp))
|
||||
}
|
||||
if(isWear){ Spacer(Modifier.padding(vertical = 3.dp)) }
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = if (!sharedPref.getBoolean("isWear", false)) { 5.dp } else { 2.dp }, horizontal = if (!sharedPref.getBoolean("isWear", false)) { 8.dp } else { 4.dp })
|
||||
.padding(vertical = if (!isWear) { 5.dp } else { 2.dp }, horizontal = if (!isWear) { 8.dp } else { 4.dp })
|
||||
.clip(RoundedCornerShape(15))
|
||||
.background(color = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F))
|
||||
.clickable(onClick = { navCtrl.navigate("Permissions") })
|
||||
.padding(
|
||||
horizontal = 5.dp,
|
||||
vertical = if (!sharedPref.getBoolean("isWear", false)) { 14.dp } else { 2.dp }
|
||||
vertical = if (!isWear) { 14.dp } else { 2.dp }
|
||||
),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(
|
||||
painter = if(myDpm.isAdminActive(myComponent)){
|
||||
painterResource(R.drawable.check_fill0)
|
||||
}else{
|
||||
painterResource(R.drawable.block_fill0)
|
||||
},
|
||||
painter = painterResource(if(myDpm.isAdminActive(myComponent)){ R.drawable.check_fill0 }else{ R.drawable.block_fill0 }),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.padding(horizontal = if(!sharedPref.getBoolean("isWear",false)){10.dp}else{6.dp}),
|
||||
modifier = Modifier.padding(horizontal = if(!isWear){10.dp}else{6.dp}),
|
||||
tint = MaterialTheme.colorScheme.tertiary
|
||||
)
|
||||
Column {
|
||||
Text(
|
||||
text = if(isDeviceOwner(myDpm)||myDpm.isAdminActive(myComponent)||isProfileOwner(myDpm)){"已激活"}else{"未激活"},
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
style = typography.headlineSmall,
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer
|
||||
)
|
||||
if(activateType!=""){
|
||||
Text(
|
||||
text = activateType
|
||||
)
|
||||
}
|
||||
if(activateType!=""){ Text(activateType) }
|
||||
}
|
||||
}
|
||||
HomePageItem(R.string.device_ctrl, R.drawable.mobile_phone_fill0, "DeviceControl", navCtrl)
|
||||
@@ -248,7 +233,7 @@ fun HomePageItem(name:Int, imgVector:Int, navTo:String, myNav:NavHostController)
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(name),
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
style = typography.headlineSmall,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
Spacer(Modifier.padding(top = 2.dp))
|
||||
@@ -271,8 +256,8 @@ fun RadioButtonItem(
|
||||
.clickable(onClick = operation)
|
||||
) {
|
||||
RadioButton(selected = selected(), onClick = operation,modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier})
|
||||
Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium},
|
||||
color = textColor)
|
||||
Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){typography.bodyLarge}else{typography.bodyMedium}, color = textColor,
|
||||
modifier = Modifier.padding(bottom = 1.dp))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,19 +59,17 @@ fun Password(){
|
||||
val focusMgr = LocalFocusManager.current
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
val titleColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.navigationBarsPadding()
|
||||
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()).navigationBarsPadding()
|
||||
) {
|
||||
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 = "以下操作可能会造成不可挽回的损失,请先备份好数据。执行操作时一定要谨慎!!!",
|
||||
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||
modifier = sections(MaterialTheme.colorScheme.errorContainer),
|
||||
style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium}
|
||||
style=bodyTextStyle
|
||||
)
|
||||
if(isWear){
|
||||
Text(
|
||||
@@ -93,24 +91,21 @@ fun Password(){
|
||||
DevicePolicyManager.PASSWORD_COMPLEXITY_HIGH to "高(无连续性,至少6位)"
|
||||
)
|
||||
val pwdComplex = passwordComplexity[myDpm.passwordComplexity]
|
||||
Text(text = "当前密码复杂度:$pwdComplex",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "当前密码复杂度:$pwdComplex",style=bodyTextStyle)
|
||||
}
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||
Text("密码达到要求:${myDpm.isActivePasswordSufficient}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("密码达到要求:${myDpm.isActivePasswordSufficient}",style=bodyTextStyle)
|
||||
}
|
||||
val pwdFailedAttempts = myDpm.currentFailedPasswordAttempts
|
||||
Text(text = "密码已错误次数:$pwdFailedAttempts",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "密码已错误次数:$pwdFailedAttempts",style=bodyTextStyle)
|
||||
if(VERSION.SDK_INT>=28&&(myDpm.isManagedProfile(myComponent)||myDpm.isProfileOwnerApp("com.binbin.androidowner"))){
|
||||
val unifiedPwd = myDpm.isUsingUnifiedPassword(myComponent)
|
||||
Text("个人与工作应用密码一致:$unifiedPwd",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("个人与工作应用密码一致:$unifiedPwd",style=bodyTextStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
if(VERSION.SDK_INT>=26){
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
modifier = sections()
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.Start, modifier = sections()) {
|
||||
Text(text = "密码重置令牌", style = typography.titleLarge,color = titleColor)
|
||||
Row(
|
||||
modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.horizontalScroll(rememberScrollState())},
|
||||
@@ -149,11 +144,9 @@ fun Password(){
|
||||
Text("激活")
|
||||
}
|
||||
}
|
||||
if(isWear){
|
||||
Text(text = "(可以水平滚动)",style=typography.bodyMedium)
|
||||
}
|
||||
Text("没有密码时会自动激活令牌",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("有可能无法设置密码重置令牌,因机而异",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
if(isWear){ Text(text = "(可以水平滚动)",style=typography.bodyMedium) }
|
||||
Text("没有密码时会自动激活令牌",style=bodyTextStyle)
|
||||
Text("有可能无法设置密码重置令牌,因机而异",style=bodyTextStyle)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
@@ -170,7 +163,7 @@ fun Password(){
|
||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()}),
|
||||
modifier = Modifier.padding(vertical = if(isWear){0.dp}else{5.dp}).fillMaxWidth()
|
||||
)
|
||||
Text(text = stringResource(R.string.reset_pwd_desc), modifier = Modifier.padding(vertical = 3.dp),style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = stringResource(R.string.reset_pwd_desc), modifier = Modifier.padding(vertical = 3.dp),style=bodyTextStyle)
|
||||
var resetPwdFlag by remember{ mutableIntStateOf(0) }
|
||||
if(VERSION.SDK_INT>=23){
|
||||
RadioButtonItem("开机时不要求密码(如果有指纹等其他解锁方式)",
|
||||
@@ -243,16 +236,15 @@ fun Password(){
|
||||
}
|
||||
Text(text = "密码复杂度要求", style = typography.titleLarge,color = titleColor)
|
||||
Text(text = "不是实际密码复杂度",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
style = bodyTextStyle)
|
||||
Text(text = "设置密码复杂度将会取代密码质量",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
style = bodyTextStyle)
|
||||
RadioButtonItem(passwordComplexity[0].second,{selectedItem==passwordComplexity[0].first},{selectedItem=passwordComplexity[0].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[3].second,{selectedItem==passwordComplexity[3].first},{selectedItem=passwordComplexity[3].first},
|
||||
if(isWear){MaterialTheme.colorScheme.error}else{MaterialTheme.colorScheme.onBackground})
|
||||
Text(text = "连续性:密码重复(6666)或密码递增递减(4321、2468)", modifier = Modifier.padding(vertical = 3.dp),
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "连续性:密码重复(6666)或密码递增递减(4321、2468)", modifier = Modifier.padding(vertical = 3.dp), style = bodyTextStyle)
|
||||
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -304,11 +296,9 @@ fun Password(){
|
||||
}
|
||||
Text(text = "密码质量要求", style = typography.titleLarge,color = titleColor)
|
||||
if(expanded){
|
||||
Text(text = "不是实际密码质量",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})}
|
||||
Text(text = "不是实际密码质量", style = bodyTextStyle)}
|
||||
if(VERSION.SDK_INT>=31){
|
||||
Text(text = "已弃用,请使用上面的”密码复杂度要求“", color = MaterialTheme.colorScheme.error,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "已弃用,请使用上面的”密码复杂度要求“", color = MaterialTheme.colorScheme.error, style = bodyTextStyle)
|
||||
}
|
||||
if(expanded){
|
||||
RadioButtonItem(passwordQuality[0].second,{selectedItem==passwordQuality[0].first},{selectedItem=passwordQuality[0].first})
|
||||
@@ -319,8 +309,7 @@ fun Password(){
|
||||
RadioButtonItem(passwordQuality[5].second,{selectedItem==passwordQuality[5].first},{selectedItem=passwordQuality[5].first})
|
||||
RadioButtonItem(passwordQuality[6].second,{selectedItem==passwordQuality[6].first},{selectedItem=passwordQuality[6].first})
|
||||
RadioButtonItem(passwordQuality[7].second,{selectedItem==passwordQuality[7].first},{selectedItem=passwordQuality[7].first})
|
||||
Text(text = "连续性:密码重复(6666)或密码递增递减(4321、2468)", modifier = Modifier.padding(vertical = 3.dp),
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "连续性:密码重复(6666)或密码递增递减(4321、2468)", modifier = Modifier.padding(vertical = 3.dp), style = bodyTextStyle)
|
||||
Button(
|
||||
onClick = {
|
||||
myDpm.setPasswordQuality(myComponent,selectedItem)
|
||||
|
||||
@@ -53,14 +53,13 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
val titleColor = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
|
||||
Column(
|
||||
modifier = Modifier.verticalScroll(rememberScrollState()),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
if(!myDpm.isAdminActive(myComponent)&&isWear){
|
||||
Button(onClick = { activateDeviceAdmin(myContext,myComponent) },modifier = Modifier
|
||||
.padding(horizontal = 3.dp)
|
||||
.fillMaxWidth()) {
|
||||
Button(onClick = { activateDeviceAdmin(myContext,myComponent) },modifier = Modifier.padding(horizontal = 3.dp).fillMaxWidth()) {
|
||||
Text("激活Device admin")
|
||||
}
|
||||
}
|
||||
@@ -100,11 +99,9 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
) {
|
||||
SelectionContainer {
|
||||
Text("adb shell dpm set-active-admin com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver",
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer, style = bodyTextStyle)
|
||||
}
|
||||
Text(text = "或者进入设置(原生安卓) -> 安全 -> 更多安全设置 -> 设备管理应用 -> Android Owner",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "或者进入设置(原生安卓) -> 安全 -> 更多安全设置 -> 设备管理应用 -> Android Owner", style = bodyTextStyle)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
@@ -139,15 +136,12 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
if(!isDeviceOwner(myDpm)){
|
||||
SelectionContainer {
|
||||
Text("adb shell dpm set-profile-owner com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver",
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer, style = bodyTextStyle)
|
||||
}
|
||||
Text(text = "Device owner和Profile owner不能同时存在,强烈建议激活Device owner",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "Device owner和Profile owner不能同时存在,强烈建议激活Device owner", style = bodyTextStyle)
|
||||
}
|
||||
if(isDeviceOwner(myDpm)){
|
||||
Text(text = "Device owner创建其他用户后,这个应用会成为新用户的Profile owner",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "Device owner创建其他用户后,这个应用会成为新用户的Profile owner", style = bodyTextStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,12 +176,10 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
) {
|
||||
SelectionContainer {
|
||||
Text(text = "adb shell dpm set-device-owner com.binbin.androidowner/com.binbin.androidowner.MyDeviceAdminReceiver",
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer,
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
color = MaterialTheme.colorScheme.onTertiaryContainer, style = bodyTextStyle)
|
||||
}
|
||||
if(!isda){
|
||||
Text(text = "使用此命令也会激活Device Admin",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "使用此命令也会激活Device Admin", style = bodyTextStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +188,7 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
text = "注意!在这里撤销权限不会清除配置。比如:被停用的应用会保持停用状态",
|
||||
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||
modifier = sections(MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.8F)),
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}
|
||||
style = bodyTextStyle
|
||||
)
|
||||
}
|
||||
if(VERSION.SDK_INT>=30){
|
||||
@@ -205,17 +197,17 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
) {
|
||||
Text(text = "设备信息", style = typography.titleLarge,color = titleColor)
|
||||
val orgDevice = myDpm.isOrganizationOwnedDeviceWithManagedProfile
|
||||
Text("由组织拥有的受管理资料设备:$orgDevice",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("由组织拥有的受管理资料设备:$orgDevice",style=bodyTextStyle)
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||
Text("Managed profile: ${myDpm.isManagedProfile(myComponent)}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("Managed profile: ${myDpm.isManagedProfile(myComponent)}",style=bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT>=34&&(isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&myDpm.isOrganizationOwnedDeviceWithManagedProfile))){
|
||||
val financed = myDpm.isDeviceFinanced
|
||||
Text("企业资产 : $financed",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("企业资产 : $financed",style=bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT>=33){
|
||||
Text("最小WiFi安全等级:${myDpm.minimumRequiredWifiSecurityLevel}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("设备策略管理器角色:${myDpm.devicePolicyManagementRoleHolderPackage}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("最小WiFi安全等级:${myDpm.minimumRequiredWifiSecurityLevel}",style=bodyTextStyle)
|
||||
Text("设备策略管理器角色:${myDpm.devicePolicyManagementRoleHolderPackage}",style=bodyTextStyle)
|
||||
}
|
||||
val encryptionStatus = mapOf(
|
||||
DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE to "未使用",
|
||||
@@ -225,9 +217,9 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER to "每个用户分别加密",
|
||||
DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING to "未知"
|
||||
)
|
||||
Text("加密状态:${encryptionStatus[myDpm.storageEncryptionStatus]}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("加密状态:${encryptionStatus[myDpm.storageEncryptionStatus]}",style=bodyTextStyle)
|
||||
if(isDeviceOwner(myDpm)&&VERSION.SDK_INT>=34){
|
||||
Text("MTE策略:${myDpm.mtePolicy}",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("MTE策略:${myDpm.mtePolicy}",style=bodyTextStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,21 +227,21 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
Column(modifier = sections()) {
|
||||
val specificId:String = myDpm.enrollmentSpecificId
|
||||
Text(text = "设备唯一标识码", style = typography.titleLarge,color = titleColor)
|
||||
Text("(恢复出厂设置不变)",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("(恢复出厂设置不变)",style=bodyTextStyle)
|
||||
if(specificId!=""){
|
||||
Text(specificId)
|
||||
Button(onClick = {myDpm.setOrganizationId(specificId)}) {
|
||||
Text("设置为组织ID")
|
||||
}
|
||||
}else{
|
||||
Text("你的设备不支持",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("你的设备不支持",style=bodyTextStyle)
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "不受控制的账号类型", style = typography.titleLarge,color = titleColor)
|
||||
Text("作用未知",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("作用未知",style=bodyTextStyle)
|
||||
var noManageAccount = myDpm.accountTypesWithManagementDisabled?.toMutableList()
|
||||
var accountlist by remember{ mutableStateOf("") }
|
||||
val refreshList = {
|
||||
@@ -264,7 +256,7 @@ fun DpmPermissions(navCtrl:NavHostController){
|
||||
if(accountlist!=""){
|
||||
Text(accountlist)
|
||||
}else{
|
||||
Text("列表为空 \n",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text("列表为空 \n",style=bodyTextStyle)
|
||||
}
|
||||
var inputText by remember{ mutableStateOf("") }
|
||||
TextField(
|
||||
@@ -394,9 +386,7 @@ fun DeviceOwnerInfo(
|
||||
value = if(inputContent!=null){ inputContent.toString() }else{""},
|
||||
label = {Text(stringResource(textfield))},
|
||||
onValueChange = { inputContent=it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp)
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.padding(vertical = if(isWear){2.dp}else{6.dp}),
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -33,11 +34,12 @@ fun AppSetting(navCtrl:NavHostController){
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
val myContext = LocalContext.current
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Column(modifier = sections()) {
|
||||
Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 3.dp),horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(text = "Wear", style = MaterialTheme.typography.titleLarge)
|
||||
Switch(
|
||||
checked = sharedPref.getBoolean("isWear",false),
|
||||
checked = isWear,
|
||||
onCheckedChange = {
|
||||
sharedPref.edit().putBoolean("isWear",!sharedPref.getBoolean("isWear",false)).apply()
|
||||
navCtrl.navigate("HomePage") {
|
||||
@@ -61,7 +63,7 @@ fun AppSetting(navCtrl:NavHostController){
|
||||
}
|
||||
)
|
||||
}
|
||||
Text("打开或关闭动态取色需要重启应用")
|
||||
Text(text = "打开或关闭动态取色需要重启应用", style = if(isWear){typography.bodyMedium}else{typography.bodyLarge})
|
||||
}
|
||||
}
|
||||
Column(modifier = sections()) {
|
||||
|
||||
@@ -32,7 +32,6 @@ import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import java.util.Date
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SysUpdatePolicy(myDpm:DevicePolicyManager,myComponent:ComponentName,myContext: Context){
|
||||
val focusMgr = LocalFocusManager.current
|
||||
@@ -103,28 +102,5 @@ fun SysUpdatePolicy(myDpm:DevicePolicyManager,myComponent:ComponentName,myContex
|
||||
Text("应用")
|
||||
}
|
||||
}}
|
||||
/*val policy = myDpm.systemUpdatePolicy
|
||||
if(VERSION.SDK_INT>=28&&policy!=null){
|
||||
Column {
|
||||
var dateState = rememberDateRangePickerState()
|
||||
DateRangePicker(state = dateState)
|
||||
val frzPeriod = FreezePeriod(
|
||||
MonthDay.of(6, 1),
|
||||
MonthDay.of(7, 31))
|
||||
policy.freezePeriods = listOf(frzPeriod)
|
||||
Button(
|
||||
onClick = {
|
||||
try{
|
||||
myDpm.setSystemUpdatePolicy(myComponent, policy)
|
||||
}catch (e:SystemUpdatePolicy.ValidationFailedException){
|
||||
Toast.makeText(myContext, "正在冷却期", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text("设置更新冻结期")
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.MaterialTheme.colorScheme
|
||||
import androidx.compose.material3.MaterialTheme.typography
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -36,7 +37,6 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
@@ -45,7 +45,6 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.core.os.UserManagerCompat
|
||||
import androidx.navigation.NavHostController
|
||||
|
||||
|
||||
@Composable
|
||||
fun UserManage(navCtrl:NavHostController){
|
||||
Column(
|
||||
@@ -58,34 +57,33 @@ fun UserManage(navCtrl:NavHostController){
|
||||
val userManager = myContext.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
val bodyTextStyle = if(isWear){ typography.bodyMedium}else{ typography.bodyLarge}
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "用户信息", style = MaterialTheme.typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text("用户已解锁:${UserManagerCompat.isUserUnlocked(myContext)}",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text(text = "用户信息", style = typography.titleLarge,color = colorScheme.onPrimaryContainer)
|
||||
Text("用户已解锁:${UserManagerCompat.isUserUnlocked(myContext)}",style = bodyTextStyle)
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Text("支持多用户:${UserManager.supportsMultipleUsers()}",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
}
|
||||
if(VERSION.SDK_INT>=31){
|
||||
Text("系统用户: ${UserManager.isHeadlessSystemUserMode()}",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text("支持多用户:${UserManager.supportsMultipleUsers()}",style = bodyTextStyle)
|
||||
if(isWear&&UserManager.supportsMultipleUsers()){Text(text = "实际上手表可能不支持", style = typography.bodyMedium, color = colorScheme.error)}
|
||||
}
|
||||
if(VERSION.SDK_INT>=31){ Text("系统用户: ${UserManager.isHeadlessSystemUserMode()}",style = bodyTextStyle) }
|
||||
Spacer(Modifier.padding(vertical = if(isWear){2.dp}else{5.dp}))
|
||||
if (VERSION.SDK_INT >= 28) {
|
||||
val logoutable = myDpm.isLogoutEnabled
|
||||
Text(text = "用户可以退出 : $logoutable",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text(text = "用户可以退出 : $logoutable",style = bodyTextStyle)
|
||||
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
|
||||
val ephemeralUser = myDpm.isEphemeralUser(myComponent)
|
||||
Text(text = "临时用户: $ephemeralUser",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text(text = "临时用户: $ephemeralUser",style = bodyTextStyle)
|
||||
}
|
||||
val affiliatedUser = myDpm.isAffiliatedUser
|
||||
Text(text = "次级用户: $affiliatedUser",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text(text = "次级用户: ${myDpm.isAffiliatedUser}",style = bodyTextStyle)
|
||||
}
|
||||
Spacer(Modifier.padding(vertical = if(isWear){2.dp}else{5.dp}))
|
||||
Text("当前UID:${android.os.Process.myUid()}")
|
||||
Text("当前UserID:${getCurrentUserId()}")
|
||||
Text("当前用户序列号:${userManager.getSerialNumberForUser(android.os.Process.myUserHandle())}")
|
||||
Text(text = "当前UID:${android.os.Process.myUid()}",style = bodyTextStyle)
|
||||
Text(text = "当前UserID:${getCurrentUserId()}",style = bodyTextStyle)
|
||||
Text(text = "当前用户序列号:${userManager.getSerialNumberForUser(android.os.Process.myUserHandle())}",style = bodyTextStyle)
|
||||
}
|
||||
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "用户操作", style = MaterialTheme.typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(text = "用户操作", style = typography.titleLarge,color = colorScheme.onPrimaryContainer)
|
||||
var idInput by remember{ mutableStateOf("") }
|
||||
var userHandleById:UserHandle by remember{ mutableStateOf(android.os.Process.myUserHandle()) }
|
||||
var useUid by remember{ mutableStateOf(false) }
|
||||
@@ -120,7 +118,7 @@ fun UserManage(navCtrl:NavHostController){
|
||||
onCheckedChange = {useUid=it},
|
||||
enabled = VERSION.SDK_INT>=24&& isDeviceOwner(myDpm)
|
||||
)
|
||||
Text(text = "使用UID(不靠谱)",modifier = Modifier.padding(bottom = 2.dp))
|
||||
Text(text = "使用UID(不靠谱)",modifier = Modifier.padding(bottom = 2.dp), style = bodyTextStyle)
|
||||
}
|
||||
if(VERSION.SDK_INT>28){
|
||||
if(isProfileOwner(myDpm)&&myDpm.isAffiliatedUser){
|
||||
@@ -135,17 +133,20 @@ fun UserManage(navCtrl:NavHostController){
|
||||
Text("登出当前用户")
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
if(VERSION.SDK_INT>=28){
|
||||
val result = myDpm.startUserInBackground(myComponent,userHandleById)
|
||||
Toast.makeText(myContext, userOperationResultCode(result), Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
){
|
||||
Text("在后台启动用户")
|
||||
}
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm)&&VERSION.SDK_INT>=28,
|
||||
modifier = Modifier.fillMaxWidth(0.48F)
|
||||
){
|
||||
Text(if(isWear){"启动"}else{"在后台启动"})
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -158,17 +159,12 @@ fun UserManage(navCtrl:NavHostController){
|
||||
}
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = Modifier.fillMaxWidth(0.92F)
|
||||
) {
|
||||
Text("切换至用户")
|
||||
Text("切换")
|
||||
}
|
||||
Row(
|
||||
modifier = if(isWear){
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.horizontalScroll(rememberScrollState())}else{Modifier.fillMaxWidth()},
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
){
|
||||
}
|
||||
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween){
|
||||
Button(
|
||||
onClick = {
|
||||
focusMgr.clearFocus()
|
||||
@@ -184,7 +180,7 @@ fun UserManage(navCtrl:NavHostController){
|
||||
enabled = isDeviceOwner(myDpm)&&VERSION.SDK_INT>=28,
|
||||
modifier = Modifier.fillMaxWidth(0.48F)
|
||||
) {
|
||||
Text("停止用户")
|
||||
Text("停止")
|
||||
}
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -199,21 +195,18 @@ fun UserManage(navCtrl:NavHostController){
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = Modifier.fillMaxWidth(0.92F)
|
||||
) {
|
||||
Text("移除用户")
|
||||
Text("移除")
|
||||
}
|
||||
}
|
||||
if(VERSION.SDK_INT<28){
|
||||
Text("停止用户需API28")
|
||||
Text(text = "停止用户需API28", style = bodyTextStyle)
|
||||
}
|
||||
}
|
||||
|
||||
Column(modifier = sections()) {
|
||||
Text(text = "工作资料", style = MaterialTheme.typography.titleLarge)
|
||||
Text(text = "工作资料", style = typography.titleLarge)
|
||||
Row(
|
||||
modifier = if(isWear){
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.horizontalScroll(rememberScrollState())}else{Modifier.fillMaxWidth()},
|
||||
modifier = if(isWear){ Modifier.fillMaxWidth().horizontalScroll(rememberScrollState())}else{Modifier.fillMaxWidth()},
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
){
|
||||
Button(
|
||||
@@ -236,21 +229,21 @@ fun UserManage(navCtrl:NavHostController){
|
||||
Text(text = "启用")
|
||||
}
|
||||
}
|
||||
Text("可能无法创建工作资料",style = if(isWear){MaterialTheme.typography.bodyMedium}else{MaterialTheme.typography.bodyLarge})
|
||||
Text("可能无法创建工作资料",style = bodyTextStyle)
|
||||
}
|
||||
|
||||
if(VERSION.SDK_INT>=24){
|
||||
Column(modifier = sections()) {
|
||||
var userName by remember{ mutableStateOf("") }
|
||||
Text(text = "创建用户", style = MaterialTheme.typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(text = "创建用户", style = typography.titleLarge,color = colorScheme.onPrimaryContainer)
|
||||
TextField(
|
||||
value = userName,
|
||||
onValueChange = {userName=it},
|
||||
label = {Text("用户名")},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 4.dp),
|
||||
enabled = isDeviceOwner(myDpm)
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()})
|
||||
)
|
||||
var selectedFlag by remember{ mutableIntStateOf(0) }
|
||||
RadioButtonItem("无",{selectedFlag==0},{selectedFlag=0})
|
||||
@@ -261,23 +254,24 @@ fun UserManage(navCtrl:NavHostController){
|
||||
}
|
||||
var newUserHandle: UserHandle? by remember{ mutableStateOf(null) }
|
||||
Row(
|
||||
modifier = if(isWear){Modifier.fillMaxWidth().horizontalScroll(rememberScrollState())}else{Modifier.fillMaxWidth()},
|
||||
modifier = if(isWear){ if(newUserHandle==null){Modifier.fillMaxWidth()}else{
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.horizontalScroll(rememberScrollState())} }else{Modifier.fillMaxWidth()},
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
newUserHandle=myDpm.createAndManageUser(myComponent,userName,myComponent,null,selectedFlag)
|
||||
focusMgr.clearFocus()
|
||||
if(newUserHandle!=null){
|
||||
Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
Toast.makeText(myContext, "失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
Toast.makeText(myContext, if(newUserHandle!=null){"成功"}else{"失败"}, Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm),
|
||||
modifier = if(!isWear){
|
||||
if(newUserHandle==null){Modifier.fillMaxWidth(1F)}else{Modifier.fillMaxWidth(0.4F)}
|
||||
}else{Modifier}
|
||||
modifier = if(isWear){
|
||||
if(newUserHandle==null){Modifier.fillMaxWidth()}else{Modifier}
|
||||
}else{
|
||||
if(newUserHandle==null){Modifier.fillMaxWidth()}else{Modifier.fillMaxWidth(0.4F)}
|
||||
}
|
||||
) {
|
||||
Text("创建")
|
||||
}
|
||||
@@ -298,12 +292,10 @@ fun UserManage(navCtrl:NavHostController){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(newUserHandle!=null){
|
||||
Text("新用户的序列号:${userManager.getSerialNumberForUser(newUserHandle)}")
|
||||
}
|
||||
if(newUserHandle!=null){ Text(text = "新用户的序列号:${userManager.getSerialNumberForUser(newUserHandle)}", style = bodyTextStyle) }
|
||||
}
|
||||
}else{
|
||||
Text("创建用户需安卓7")
|
||||
Text(text = "创建用户需安卓7", style = bodyTextStyle)
|
||||
}
|
||||
UserSessionMessage("用户名","用户名",true,myDpm,myContext,{null},{msg -> myDpm.setProfileName(myComponent, msg.toString())})
|
||||
if(VERSION.SDK_INT>=28){
|
||||
@@ -331,16 +323,14 @@ fun UserSessionMessage(
|
||||
var msg by remember{ mutableStateOf(if(isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&profileOwner)){ if(get()==null){""}else{get().toString()} }else{""}) }
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Text(text = text, style = MaterialTheme.typography.titleLarge, color = MaterialTheme.colorScheme.onPrimaryContainer)
|
||||
Text(text = text, style = typography.titleLarge, color = colorScheme.onPrimaryContainer)
|
||||
TextField(
|
||||
value = msg,
|
||||
onValueChange = {msg=it},
|
||||
label = {Text(textField)},
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||
keyboardActions = KeyboardActions(onDone = {focusMgr.clearFocus()}),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 6.dp),
|
||||
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp),
|
||||
enabled = isDeviceOwner(myDpm)||(isProfileOwner(myDpm)&&profileOwner)
|
||||
)
|
||||
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween) {
|
||||
|
||||
@@ -59,20 +59,15 @@ fun UserRestriction(){
|
||||
var otherVisible by remember{ mutableStateOf(false) }
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
LazyColumn(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
){
|
||||
val bodyTextStyle = if(isWear){typography.bodyMedium}else{typography.bodyLarge}
|
||||
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally){
|
||||
items(1){
|
||||
Text(text = "打开开关后会禁用对应的功能",modifier = Modifier.padding(3.dp),
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "打开开关后会禁用对应的功能",modifier = Modifier.padding(3.dp), style = bodyTextStyle)
|
||||
if(VERSION.SDK_INT<24){
|
||||
Text(text = "所有的用户限制都需要API24,你的设备低于API24,无法使用。",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium},
|
||||
color = MaterialTheme.colorScheme.error)
|
||||
Text(text = "所有的用户限制都需要API24,你的设备低于API24,无法使用。", style = bodyTextStyle, color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
if(isProfileOwner(myDpm)){
|
||||
Text(text = "Profile owner无法使用部分功能",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
|
||||
Text(text = "Profile owner无法使用部分功能", style = bodyTextStyle)
|
||||
}
|
||||
if(isWear){
|
||||
Text(text = "部分功能在手表上无效", style = typography.bodyMedium)
|
||||
@@ -124,20 +119,13 @@ fun UserRestriction(){
|
||||
items(1){
|
||||
Spacer(Modifier.padding(vertical = 5.dp))
|
||||
Column(modifier = Modifier.padding(horizontal = if(!isWear){10.dp}else{3.dp})) {
|
||||
if(VERSION.SDK_INT<24){ Text(text = "以下功能需要安卓7或以上:数据漫游、修改用户头像、更换壁纸",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<26){ Text(text = "以下功能需要安卓8或以上:蓝牙、自动填充服务、添加/移除工作资料",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<28){ Text(text = "以下功能需要安卓9或以上:飞行模式、位置信息、调整亮度、修改语言、修改日期时间、修改屏幕超时、打印、分享至工作应用、切换用户",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<29){ Text(text = "以下功能需要安卓10或以上:配置私人DNS、内容捕获、内容建议",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<31){ Text(text = "以下功能需要安卓12或以上:切换摄像头使用权限、切换麦克风使用权限",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<33){ Text(text = "以下功能需要安卓13或以上:添加WiFi配置、分享设备管理器配置的WiFi、WiFi共享",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<34){ Text(text = "以下功能需要安卓14或以上:2G信号、启用设备管理器、超宽频段无线电",
|
||||
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}) }
|
||||
if(VERSION.SDK_INT<24){ Text(text = "以下功能需要安卓7或以上:数据漫游、修改用户头像、更换壁纸", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<26){ Text(text = "以下功能需要安卓8或以上:蓝牙、自动填充服务、添加/移除工作资料", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<28){ Text(text = "以下功能需要安卓9或以上:飞行模式、位置信息、调整亮度、修改语言、修改日期时间、修改屏幕超时、打印、分享至工作应用、切换用户", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<29){ Text(text = "以下功能需要安卓10或以上:配置私人DNS、内容捕获、内容建议", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<31){ Text(text = "以下功能需要安卓12或以上:切换摄像头使用权限、切换麦克风使用权限", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<33){ Text(text = "以下功能需要安卓13或以上:添加WiFi配置、分享设备管理器配置的WiFi、WiFi共享", style = bodyTextStyle) }
|
||||
if(VERSION.SDK_INT<34){ Text(text = "以下功能需要安卓14或以上:2G信号、启用设备管理器、超宽频段无线电", style = bodyTextStyle) }
|
||||
}
|
||||
Spacer(Modifier.padding(vertical = 30.dp))
|
||||
}
|
||||
@@ -180,6 +168,7 @@ private fun UserRestrictionItem(
|
||||
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
|
||||
var strictState by remember{ mutableStateOf(false) }
|
||||
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
val isWear = sharedPref.getBoolean("isWear",false)
|
||||
Row(
|
||||
modifier = sections(MaterialTheme.colorScheme.secondaryContainer),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -187,7 +176,7 @@ private fun UserRestrictionItem(
|
||||
){
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = if(sharedPref.getBoolean("isWear",false)){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)){
|
||||
Icon(
|
||||
@@ -199,10 +188,12 @@ private fun UserRestrictionItem(
|
||||
Column{
|
||||
Text(
|
||||
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.onSecondaryContainer
|
||||
)
|
||||
if(restrictionDescription!=""){Text(text = restrictionDescription, color = MaterialTheme.colorScheme.onSecondaryContainer)}
|
||||
if(restrictionDescription!=""){
|
||||
Text(text = restrictionDescription, color = MaterialTheme.colorScheme.onSecondaryContainer, style = if(isWear){typography.bodyMedium}else{typography.bodyLarge})
|
||||
}
|
||||
}
|
||||
}
|
||||
if(VERSION.SDK_INT>=24&&(isDeviceOwner(myDpm)|| isProfileOwner(myDpm))){
|
||||
@@ -227,7 +218,7 @@ private fun UserRestrictionItem(
|
||||
strictState = myDpm.getUserRestrictions(myComponent).getBoolean(restriction)
|
||||
},
|
||||
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm),
|
||||
modifier = Modifier.padding(end = if(!sharedPref.getBoolean("isWear",false)){5.dp}else{0.dp})
|
||||
modifier = Modifier.padding(end = if(!isWear){5.dp}else{0.dp})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user