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.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
@@ -100,6 +103,7 @@ fun Network(navCtrl: NavHostController) {
val localNavCtrl = rememberNavController()
val backStackEntry by localNavCtrl.currentBackStackEntryAsState()
val scrollState = rememberScrollState()
val wifiMacDialog = remember { mutableStateOf(false) }
Scaffold(
topBar = {
TopBar(backStackEntry,navCtrl,localNavCtrl) {
@@ -120,7 +124,7 @@ fun Network(navCtrl: NavHostController) {
popExitTransition = Animations.navHostPopExitTransition,
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 = "MinWifiSecurityLevel") { WifiSecLevel() }
composable(route = "WifiSsidPolicy") { WifiSsidPolicy() }
@@ -130,10 +134,22 @@ fun Network(navCtrl: NavHostController) {
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
private fun Home(navCtrl:NavHostController,scrollState: ScrollState) {
private fun Home(navCtrl:NavHostController, scrollState: ScrollState, wifiMacDialog: MutableState<Boolean>) {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context, Receiver::class.java)
@@ -143,11 +159,9 @@ private fun Home(navCtrl:NavHostController,scrollState: ScrollState) {
style = typography.headlineLarge,
modifier = Modifier.padding(top = 8.dp, bottom = 5.dp, start = 15.dp)
)
if(VERSION.SDK_INT>=24&&isDeviceOwner(dpm)) {
val wifimac = dpm.getWifiMacAddress(receiver)
Text(text = "WiFi MAC: $wifimac", modifier = Modifier.padding(start = 15.dp))
if(VERSION.SDK_INT >= 24 && (isDeviceOwner(dpm) || (VERSION.SDK_INT >= 30 && isProfileOwner(dpm) && dpm.isManagedProfile(receiver) && dpm.isOrganizationOwnedDeviceWithManagedProfile))) {
SubPageItem(R.string.wifi_mac_addr, "", R.drawable.wifi_fill0) { wifiMacDialog.value = true }
}
Spacer(Modifier.padding(vertical = 3.dp))
if(VERSION.SDK_INT >= 30) {
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) }
Text(stringResource(R.string.encrypt_status_is)+encryptionStatus[dpm.storageEncryptionStatus])
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
if(adminList!=null) {
var adminListText = ""
@@ -318,7 +326,7 @@ fun DeviceInfo() {
var count = adminList.size
for(each in adminList) {
count -= 1
adminListText += "$each"
adminListText += "${each.packageName}/${each.className}"
if(count>0) {adminListText += "\n"}
}
SelectionContainer(modifier = Modifier.fillMaxWidth().padding(vertical = 2.dp).horizontalScroll(rememberScrollState())) {