Skip to content

Commit

Permalink
Network: use a dialog to show wifi mac address
Browse files Browse the repository at this point in the history
Permission: Device info: device ID attestation and unique device attestation
  • Loading branch information
BinTianqi committed Jun 1, 2024
1 parent 628f770 commit 7058495
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
26 changes: 20 additions & 6 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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() }
Expand All @@ -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)
Expand All @@ -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") }
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,22 @@ 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 = ""
Text(text = stringResource(R.string.activated_device_admin, adminList.size))
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())) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<string name="device_owner">Device owner</string>
<string name="activate_device_admin">激活Device admin</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="dpmrh">设备策略管理器角色(DPMRH):%1$s</string>
<string name="es_inactive">未使用</string>
Expand Down Expand Up @@ -198,6 +200,7 @@

<!--Network-->
<string name="network">网络</string>
<string name="wifi_mac_addr">Wi-Fi Mac地址</string>
<string name="min_wifi_security_level">最小WiFi安全等级</string>
<string name="wifi_security_level_open">开放</string>
<string name="preferential_network_service">优先网络服务</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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="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="dpmrh">Device policy manager role holder: %1$s</string>
<!--es: encryption status-->
Expand Down Expand Up @@ -209,6 +211,7 @@

<!--Network-->
<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="wifi_security_level_open">Open</string>
<string name="preferential_network_service">Preferential network service</string>
Expand Down

0 comments on commit 7058495

Please sign in to comment.