Network: use a dialog to show wifi mac address

Permission: Device info: device ID attestation and unique device attestation
This commit is contained in:
BinTianqi
2024-06-01 21:11:46 +08:00
parent 628f770221
commit 70584959e2
4 changed files with 35 additions and 7 deletions

View File

@@ -56,15 +56,18 @@ import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateListOf
@@ -100,6 +103,7 @@ fun Network(navCtrl: NavHostController) {
val localNavCtrl = rememberNavController() val localNavCtrl = rememberNavController()
val backStackEntry by localNavCtrl.currentBackStackEntryAsState() val backStackEntry by localNavCtrl.currentBackStackEntryAsState()
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val wifiMacDialog = remember { mutableStateOf(false) }
Scaffold( Scaffold(
topBar = { topBar = {
TopBar(backStackEntry,navCtrl,localNavCtrl) { TopBar(backStackEntry,navCtrl,localNavCtrl) {
@@ -120,7 +124,7 @@ fun Network(navCtrl: NavHostController) {
popExitTransition = Animations.navHostPopExitTransition, popExitTransition = Animations.navHostPopExitTransition,
modifier = Modifier.padding(top = it.calculateTopPadding()) modifier = Modifier.padding(top = it.calculateTopPadding())
) { ) {
composable(route = "Home") { Home(localNavCtrl,scrollState) } composable(route = "Home") { Home(localNavCtrl, scrollState, wifiMacDialog) }
composable(route = "Switches") { Switches() } composable(route = "Switches") { Switches() }
composable(route = "MinWifiSecurityLevel") { WifiSecLevel() } composable(route = "MinWifiSecurityLevel") { WifiSecLevel() }
composable(route = "WifiSsidPolicy") { WifiSsidPolicy() } composable(route = "WifiSsidPolicy") { WifiSsidPolicy() }
@@ -130,10 +134,22 @@ fun Network(navCtrl: NavHostController) {
composable(route = "APN") { APN() } composable(route = "APN") { APN() }
} }
} }
if(wifiMacDialog.value && VERSION.SDK_INT >= 24) {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context, Receiver::class.java)
AlertDialog(
onDismissRequest = { wifiMacDialog.value = false },
confirmButton = { TextButton(onClick = { wifiMacDialog.value = false }) { Text(stringResource(R.string.confirm)) } },
title = { Text(stringResource(R.string.wifi_mac_addr)) },
text = { SelectionContainer { Text(dpm.getWifiMacAddress(receiver)?: stringResource(R.string.none)) } },
modifier = Modifier.fillMaxWidth()
)
}
} }
@Composable @Composable
private fun Home(navCtrl:NavHostController,scrollState: ScrollState) { private fun Home(navCtrl:NavHostController, scrollState: ScrollState, wifiMacDialog: MutableState<Boolean>) {
val context = LocalContext.current val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context, Receiver::class.java) val receiver = ComponentName(context, Receiver::class.java)
@@ -143,11 +159,9 @@ private fun Home(navCtrl:NavHostController,scrollState: ScrollState) {
style = typography.headlineLarge, style = typography.headlineLarge,
modifier = Modifier.padding(top = 8.dp, bottom = 5.dp, start = 15.dp) modifier = Modifier.padding(top = 8.dp, bottom = 5.dp, start = 15.dp)
) )
if(VERSION.SDK_INT>=24&&isDeviceOwner(dpm)) { if(VERSION.SDK_INT >= 24 && (isDeviceOwner(dpm) || (VERSION.SDK_INT >= 30 && isProfileOwner(dpm) && dpm.isManagedProfile(receiver) && dpm.isOrganizationOwnedDeviceWithManagedProfile))) {
val wifimac = dpm.getWifiMacAddress(receiver) SubPageItem(R.string.wifi_mac_addr, "", R.drawable.wifi_fill0) { wifiMacDialog.value = true }
Text(text = "WiFi MAC: $wifimac", modifier = Modifier.padding(start = 15.dp))
} }
Spacer(Modifier.padding(vertical = 3.dp))
if(VERSION.SDK_INT >= 30) { if(VERSION.SDK_INT >= 30) {
SubPageItem(R.string.options, "", R.drawable.tune_fill0) { navCtrl.navigate("Switches") } SubPageItem(R.string.options, "", R.drawable.tune_fill0) { navCtrl.navigate("Switches") }
} }

View File

@@ -311,6 +311,14 @@ fun DeviceInfo() {
if(VERSION.SDK_INT >= 24) { encryptionStatus[DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER] = stringResource(R.string.es_active_per_user) } if(VERSION.SDK_INT >= 24) { encryptionStatus[DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER] = stringResource(R.string.es_active_per_user) }
Text(stringResource(R.string.encrypt_status_is)+encryptionStatus[dpm.storageEncryptionStatus]) Text(stringResource(R.string.encrypt_status_is)+encryptionStatus[dpm.storageEncryptionStatus])
Spacer(Modifier.padding(vertical = 2.dp)) Spacer(Modifier.padding(vertical = 2.dp))
if(VERSION.SDK_INT >= 28) {
Text(stringResource(R.string.support_device_id_attestation) + dpm.isDeviceIdAttestationSupported)
}
Spacer(Modifier.padding(vertical = 2.dp))
if (VERSION.SDK_INT >= 30) {
Text(stringResource(R.string.support_unique_device_attestation) + dpm.isUniqueDeviceAttestationSupported)
}
Spacer(Modifier.padding(vertical = 2.dp))
val adminList = dpm.activeAdmins val adminList = dpm.activeAdmins
if(adminList!=null) { if(adminList!=null) {
var adminListText = "" var adminListText = ""
@@ -318,7 +326,7 @@ fun DeviceInfo() {
var count = adminList.size var count = adminList.size
for(each in adminList) { for(each in adminList) {
count -= 1 count -= 1
adminListText += "$each" adminListText += "${each.packageName}/${each.className}"
if(count>0) {adminListText += "\n"} if(count>0) {adminListText += "\n"}
} }
SelectionContainer(modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp).horizontalScroll(rememberScrollState())) { SelectionContainer(modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp).horizontalScroll(rememberScrollState())) {

View File

@@ -60,6 +60,8 @@
<string name="device_owner">Device owner</string> <string name="device_owner">Device owner</string>
<string name="activate_device_admin">激活Device admin</string> <string name="activate_device_admin">激活Device admin</string>
<string name="device_info">设备信息</string> <string name="device_info">设备信息</string>
<string name="support_device_id_attestation">支持设备ID认证</string>
<string name="support_unique_device_attestation">支持唯一设备认证:</string>
<string name="is_device_financed">Financed device: %1$s</string> <string name="is_device_financed">Financed device: %1$s</string>
<string name="dpmrh">设备策略管理器角色(DPMRH)%1$s</string> <string name="dpmrh">设备策略管理器角色(DPMRH)%1$s</string>
<string name="es_inactive">未使用</string> <string name="es_inactive">未使用</string>
@@ -198,6 +200,7 @@
<!--Network--> <!--Network-->
<string name="network">网络</string> <string name="network">网络</string>
<string name="wifi_mac_addr">Wi-Fi Mac地址</string>
<string name="min_wifi_security_level">最小WiFi安全等级</string> <string name="min_wifi_security_level">最小WiFi安全等级</string>
<string name="wifi_security_level_open">开放</string> <string name="wifi_security_level_open">开放</string>
<string name="preferential_network_service">优先网络服务</string> <string name="preferential_network_service">优先网络服务</string>

View File

@@ -66,6 +66,8 @@
<string name="activate_profile_owner_command" translatable="false">adb shell dpm set-profile-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver</string> <string name="activate_profile_owner_command" translatable="false">adb shell dpm set-profile-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver</string>
<string name="activate_device_owner_command" translatable="false">adb shell dpm set-device-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver</string> <string name="activate_device_owner_command" translatable="false">adb shell dpm set-device-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver</string>
<string name="device_info">Device info</string> <string name="device_info">Device info</string>
<string name="support_device_id_attestation">Support Device ID attestation: </string>
<string name="support_unique_device_attestation">Support unique device attestation: </string>
<string name="is_device_financed">Financed device: %1$s</string> <string name="is_device_financed">Financed device: %1$s</string>
<string name="dpmrh">Device policy manager role holder: %1$s</string> <string name="dpmrh">Device policy manager role holder: %1$s</string>
<!--es: encryption status--> <!--es: encryption status-->
@@ -209,6 +211,7 @@
<!--Network--> <!--Network-->
<string name="network">Network</string> <string name="network">Network</string>
<string name="wifi_mac_addr">Wi-Fi Mac address</string>
<string name="min_wifi_security_level">Min WiFi security level</string> <string name="min_wifi_security_level">Min WiFi security level</string>
<string name="wifi_security_level_open">Open</string> <string name="wifi_security_level_open">Open</string>
<string name="preferential_network_service">Preferential network service</string> <string name="preferential_network_service">Preferential network service</string>