Skip to content

Commit

Permalink
adapt for wearables, change app icon
Browse files Browse the repository at this point in the history
  • Loading branch information
BinTianqi committed Jan 24, 2024
1 parent e75a094 commit 1f79994
Show file tree
Hide file tree
Showing 34 changed files with 379 additions and 163 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.binbin.androidowner"
minSdk = 23
targetSdk = 34
versionCode = 6
versionName = "1.5"
versionCode = 7
versionName = "2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_WIPE_DATA"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_ACROSS_USERS"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_RESET_PASSWORD"/>
<uses-permission android:name="android.permission.REQUEST_PASSWORD_COMPLEXITY"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_INPUT_METHODS"/>
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS"/>
<application
Expand Down
29 changes: 27 additions & 2 deletions app/src/main/java/com/binbin/androidowner/ApplicationManage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun ApplicationManage(){
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
var pkgName by remember { mutableStateOf("") }
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -87,10 +88,10 @@ fun ApplicationManage(){
{b -> myDpm.setUninstallBlocked(myComponent,pkgName,b)})*/
Row(
modifier = sections(),
horizontalArrangement = Arrangement.SpaceAround
horizontalArrangement = if(!sharedPref.getBoolean("isWear",false)){Arrangement.SpaceAround}else{Arrangement.SpaceBetween}
) {
Button(onClick = {myDpm.setUninstallBlocked(myComponent,pkgName,false)}, enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)) {
Text("取消防卸载")
Text("允许卸载")
}
Button(onClick = {myDpm.setUninstallBlocked(myComponent,pkgName,true)}, enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)) {
Text("防卸载")
Expand Down Expand Up @@ -155,6 +156,8 @@ private fun AppManageItem(
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
isEnabled = getMethod()
}
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
if(!sharedPref.getBoolean("isWear",false)){
Row(
modifier = sections(),
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -177,6 +180,28 @@ private fun AppManageItem(
},
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)
)
}}else{
Column(
modifier = sections()
) {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(itemName)
)
Switch(
checked = isEnabled,
onCheckedChange = {
setMethod(!isEnabled)
isEnabled = getMethod()
},
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)
)
}
if(itemDesc!=R.string.place_holder){
Text(text = stringResource(itemDesc),
style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
}
}
}

Expand Down
51 changes: 33 additions & 18 deletions app/src/main/java/com/binbin/androidowner/DeviceControl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.binbin.androidowner

import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.os.Build.VERSION
import android.widget.Toast
import androidx.activity.ComponentActivity
Expand Down Expand Up @@ -39,6 +40,8 @@ fun DeviceControl(){
val myContext = LocalContext.current
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
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())
Expand Down Expand Up @@ -70,13 +73,17 @@ fun DeviceControl(){
if(myDpm.canUsbDataSignalingBeDisabled()){
DeviceCtrlItem(R.string.usb_signal,R.string.place_holder,R.drawable.usb_fill0,myDpm,{myDpm.isUsbDataSignalingEnabled},{b -> myDpm.isUsbDataSignalingEnabled = b })
}else{
Text("你的设备不支持关闭USB信号")
Text(text = "你的设备不支持关闭USB信号",
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
}
if(VERSION.SDK_INT>=28){
Column(modifier = sections()) {
Text(text = "锁屏方式", style = MaterialTheme.typography.titleLarge)
Text(text = "禁用需要无密码")
Row(
modifier = sections(),
horizontalArrangement = Arrangement.SpaceEvenly
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = if(!isWear){Arrangement.SpaceEvenly}else{Arrangement.SpaceBetween}
) {
Button(
onClick = {
Expand All @@ -88,9 +95,9 @@ fun DeviceControl(){
},
enabled = isDeviceOwner(myDpm)|| (isProfileOwner(myDpm)&&myDpm.isAffiliatedUser)
) {
Text("禁用锁屏(需无密码)")
Text("禁用")
}
Spacer(Modifier.padding(horizontal = 5.dp))
if(!isWear){Spacer(Modifier.padding(horizontal = 5.dp))}
Button(
onClick = {
if(myDpm.setKeyguardDisabled(myComponent,false)){
Expand All @@ -101,13 +108,13 @@ fun DeviceControl(){
},
enabled = isDeviceOwner(myDpm)|| (isProfileOwner(myDpm)&&myDpm.isAffiliatedUser)
) {
Text("启用锁屏")
Text("启用")
}
}
}}
}

Row(
horizontalArrangement = Arrangement.SpaceAround,
horizontalArrangement = if(!isWear){Arrangement.SpaceAround}else{Arrangement.SpaceBetween},
modifier = sections(),
) {
if(VERSION.SDK_INT>=24){
Expand All @@ -128,20 +135,25 @@ fun DeviceControl(){
Text(text = "WiFi MAC: $wifimac",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center)
}
if(VERSION.SDK_INT<24){
Text("重启和WiFi Mac需要API24")
Text(text = "重启和WiFi Mac需要API24",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
if(VERSION.SDK_INT<26){
Text("备份服务需要API26")
Text(text = "备份服务需要API26",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
if(VERSION.SDK_INT<30){
Text("自动设置时间和自动设置时区需要API30")
Text(text = "自动设置时间和自动设置时区需要API30",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
if(VERSION.SDK_INT<31){Text("关闭USB信号需API31")}
if(VERSION.SDK_INT<31){Text(text = "关闭USB信号需API31",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})}
if(VERSION.SDK_INT<34){
Text("隐藏状态栏需要API34")
Text(text = "隐藏状态栏需要API34",modifier=Modifier.fillMaxWidth(), textAlign = TextAlign.Center,
style = if(!isWear){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
Button(
onClick = {myDpm.uninstallAllUserCaCerts(myComponent)},
onClick = {myDpm.uninstallAllUserCaCerts(myComponent);Toast.makeText(myContext, "成功", Toast.LENGTH_SHORT).show()},
modifier = Modifier.align(Alignment.CenterHorizontally),
enabled = isDeviceOwner(myDpm)|| isProfileOwner(myDpm)
) {
Expand All @@ -159,7 +171,8 @@ fun DeviceControl(){
RadioButtonItem("WIPE_RESET_PROTECTION_DATA",{flag==0x0002},{flag=0x0002})
RadioButtonItem("WIPE_EUICC",{flag==0x0004},{flag=0x0004})
RadioButtonItem("WIPE_SILENTLY",{flag==0x0008},{flag=0x0008})
Text("清空数据的不能是系统用户")
Text(text = "清空数据的不能是系统用户",
style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
Button(
onClick = {confirmed=!confirmed},
colors = ButtonDefaults.buttonColors(
Expand Down Expand Up @@ -210,6 +223,7 @@ private fun DeviceCtrlItem(
setMethod:(b:Boolean)->Unit
){
var isEnabled by remember{ mutableStateOf(false) }
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Row(
modifier = sections(),
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -218,18 +232,19 @@ private fun DeviceCtrlItem(
Row(
verticalAlignment = Alignment.CenterVertically
){
if(!sharedPref.getBoolean("isWear",false)){
Icon(
painter = painterResource(leadIcon),
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.padding(start = 5.dp, end = 9.dp)
)
)}
Column {
Text(
text = stringResource(itemName),
style = MaterialTheme.typography.titleLarge
style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.titleLarge}else{MaterialTheme.typography.bodyLarge}
)
if(itemDesc!=R.string.place_holder){
if(itemDesc!=R.string.place_holder&&!sharedPref.getBoolean("isWear",false)){
Text(stringResource(itemDesc))
}
}
Expand Down
Loading

1 comment on commit 1f79994

@BinTianqi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20240124_154609
Screenshot_20240124_154618

Please sign in to comment.