diff --git a/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt b/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt index 05fd1f4..9c14f22 100644 --- a/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt +++ b/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt @@ -131,9 +131,8 @@ fun Home(materialYou:MutableState, blackTheme:MutableState) { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() - val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) + val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE) val focusMgr = LocalFocusManager.current - val pkgName = remember { mutableStateOf("") } val dialogStatus = remember { mutableIntStateOf(0) } val backToHome by backToHomeStateFlow.collectAsState() LaunchedEffect(backToHome) { @@ -152,17 +151,17 @@ fun Home(materialYou:MutableState, blackTheme:MutableState) { popEnterTransition = Animations.navHostPopEnterTransition, popExitTransition = Animations.navHostPopExitTransition ) { - composable(route = "HomePage") { HomePage(navCtrl, pkgName) } + composable(route = "HomePage") { HomePage(navCtrl) } composable(route = "SystemManage") { SystemManage(navCtrl) } composable(route = "ManagedProfile") { ManagedProfile(navCtrl) } composable(route = "Permissions") { DpmPermissions(navCtrl) } - composable(route = "ApplicationManage") { ApplicationManage(navCtrl, pkgName, dialogStatus) } + composable(route = "ApplicationManage") { ApplicationManage(navCtrl, dialogStatus) } composable(route = "UserRestriction") { UserRestriction(navCtrl) } composable(route = "UserManage") { UserManage(navCtrl) } composable(route = "Password") { Password(navCtrl) } composable(route = "AppSetting") { AppSetting(navCtrl, materialYou, blackTheme) } composable(route = "Network") { Network(navCtrl) } - composable(route = "PackageSelector") { PackageSelector(navCtrl, pkgName) } + composable(route = "PackageSelector") { PackageSelector(navCtrl) } } LaunchedEffect(Unit) { val profileInited = sharedPref.getBoolean("ManagedProfileActivated", false) @@ -177,24 +176,26 @@ fun Home(materialYou:MutableState, blackTheme:MutableState) { } @Composable -private fun HomePage(navCtrl:NavHostController, pkgName: MutableState) { +private fun HomePage(navCtrl:NavHostController) { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() - val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) - val refreshStatus by dhizukuErrorStatus.collectAsState() + val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE) var activateType by remember { mutableStateOf("") } + val deviceAdmin = context.isDeviceAdmin + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner + val refreshStatus by dhizukuErrorStatus.collectAsState() LaunchedEffect(refreshStatus) { activateType = if(sharedPref.getBoolean("dhizuku", false)) context.getString(R.string.dhizuku) + " - " else "" activateType += context.getString( - if(context.isDeviceOwner) { R.string.device_owner } - else if(context.isProfileOwner) { + if(deviceOwner) { R.string.device_owner } + else if(profileOwner) { if(VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)) R.string.work_profile_owner else R.string.profile_owner } - else if(context.isDeviceAdmin) R.string.device_admin else R.string.click_to_activate + else if(deviceAdmin) R.string.device_admin else R.string.click_to_activate ) } - LaunchedEffect(Unit) { pkgName.value = "" } Column(modifier = Modifier.background(colorScheme.background).statusBarsPadding().verticalScroll(rememberScrollState())) { Spacer(Modifier.padding(vertical = 25.dp)) Text( @@ -214,14 +215,14 @@ private fun HomePage(navCtrl:NavHostController, pkgName: MutableState) { ) { Spacer(modifier = Modifier.padding(start = 22.dp)) Icon( - painter = painterResource(if(context.isDeviceAdmin) R.drawable.check_circle_fill1 else R.drawable.block_fill0), + painter = painterResource(if(deviceAdmin) R.drawable.check_circle_fill1 else R.drawable.block_fill0), contentDescription = null, tint = colorScheme.onPrimary ) Spacer(modifier = Modifier.padding(start = 10.dp)) Column { Text( - text = stringResource(if(context.isDeviceAdmin) R.string.activated else R.string.deactivated), + text = stringResource(if(deviceAdmin) R.string.activated else R.string.deactivated), style = typography.headlineSmall, color = colorScheme.onPrimary, modifier = Modifier.padding(bottom = 2.dp) @@ -230,17 +231,17 @@ private fun HomePage(navCtrl:NavHostController, pkgName: MutableState) { } } HomePageItem(R.string.system_manage, R.drawable.mobile_phone_fill0, "SystemManage", navCtrl) - if(context.isDeviceOwner || context.isProfileOwner) { HomePageItem(R.string.network, R.drawable.wifi_fill0, "Network", navCtrl) } + if(deviceOwner || profileOwner) { HomePageItem(R.string.network, R.drawable.wifi_fill0, "Network", navCtrl) } if( - (VERSION.SDK_INT < 24 && !context.isDeviceOwner) || ( + (VERSION.SDK_INT < 24 && !deviceOwner) || ( VERSION.SDK_INT >= 24 && (dpm.isProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE) || - (context.isProfileOwner && dpm.isManagedProfile(receiver))) + (profileOwner && dpm.isManagedProfile(receiver))) ) ) { HomePageItem(R.string.work_profile, R.drawable.work_fill0, "ManagedProfile", navCtrl) } HomePageItem(R.string.app_manager, R.drawable.apps_fill0, "ApplicationManage", navCtrl) - if(VERSION.SDK_INT >= 24 && (context.isProfileOwner || context.isDeviceOwner)) { + if(VERSION.SDK_INT >= 24 && (profileOwner || deviceOwner)) { HomePageItem(R.string.user_restrict, R.drawable.person_off, "UserRestriction", navCtrl) } HomePageItem(R.string.user_manager,R.drawable.manage_accounts_fill0,"UserManage", navCtrl) diff --git a/app/src/main/java/com/bintianqi/owndroid/PkgSelector.kt b/app/src/main/java/com/bintianqi/owndroid/PkgSelector.kt index 9ff180b..a44dab1 100644 --- a/app/src/main/java/com/bintianqi/owndroid/PkgSelector.kt +++ b/app/src/main/java/com/bintianqi/owndroid/PkgSelector.kt @@ -31,7 +31,6 @@ import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults 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.mutableStateOf @@ -55,6 +54,7 @@ import com.bintianqi.owndroid.ui.NavIcon import com.google.accompanist.drawablepainter.rememberDrawablePainter import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -67,9 +67,11 @@ private data class PkgInfo( private val pkgs = mutableListOf() +val selectedPackage = MutableStateFlow("") + @OptIn(ExperimentalMaterial3Api::class) @Composable -fun PackageSelector(navCtrl: NavHostController, pkgName: MutableState) { +fun PackageSelector(navCtrl: NavHostController) { val context = LocalContext.current val pm = context.packageManager val apps = pm.getInstalledApplications(0) @@ -182,10 +184,10 @@ fun PackageSelector(navCtrl: NavHostController, pkgName: MutableState) { if(system == it.system) { if(search != "") { if(it.pkgName.contains(search, ignoreCase = true) || it.label.contains(search, ignoreCase = true)) { - PackageItem(it, navCtrl, pkgName) + PackageItem(it, navCtrl) } } else { - PackageItem(it, navCtrl, pkgName) + PackageItem(it, navCtrl) } } } @@ -204,15 +206,15 @@ fun PackageSelector(navCtrl: NavHostController, pkgName: MutableState) { } @Composable -private fun PackageItem(pkg: PkgInfo, navCtrl: NavHostController, pkgName: MutableState) { +private fun PackageItem(pkg: PkgInfo, navCtrl: NavHostController) { val focusMgr = LocalFocusManager.current Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() .clickable{ - pkgName.value = pkg.pkgName focusMgr.clearFocus() + selectedPackage.value = pkg.pkgName navCtrl.navigateUp() } .padding(vertical = 6.dp) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt index 4f4bdcc..1e236aa 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt @@ -84,6 +84,7 @@ import com.bintianqi.owndroid.PackageInstallerReceiver import com.bintianqi.owndroid.R import com.bintianqi.owndroid.fileUriFlow import com.bintianqi.owndroid.getFile +import com.bintianqi.owndroid.selectedPackage import com.bintianqi.owndroid.toText import com.bintianqi.owndroid.ui.Animations import com.bintianqi.owndroid.ui.Information @@ -98,10 +99,18 @@ private var dialogDismissButtonAction = {} private var dialogGetStatus = { false } @Composable -fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, dialogStatus: MutableIntState) { +fun ApplicationManage(navCtrl:NavHostController, dialogStatus: MutableIntState) { val focusMgr = LocalFocusManager.current val localNavCtrl = rememberNavController() val backStackEntry by localNavCtrl.currentBackStackEntryAsState() + var pkgName by remember { mutableStateOf("") } + val updatePackage by selectedPackage.collectAsState() + LaunchedEffect(updatePackage) { + if(updatePackage != "") { + pkgName = updatePackage + selectedPackage.value = "" + } + } val titleMap = mapOf( "BlockUninstall" to R.string.block_uninstall, "UserControlDisabled" to R.string.ucd, @@ -132,8 +141,8 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, ) { if(backStackEntry?.destination?.route!="InstallApp") { TextField( - value = pkgName.value, - onValueChange = { pkgName.value = it }, + value = pkgName, + onValueChange = { pkgName = it }, label = { Text(stringResource(R.string.package_name)) }, modifier = Modifier.fillMaxWidth(), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Done), @@ -159,19 +168,19 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, popExitTransition = Animations.navHostPopExitTransition ) { composable(route = "Home") { - Home(localNavCtrl, pkgName.value, dialogStatus, clearAppDataDialog, defaultDialerAppDialog, enableSystemAppDialog) + Home(localNavCtrl, pkgName, dialogStatus, clearAppDataDialog, defaultDialerAppDialog, enableSystemAppDialog) } - composable(route = "AlwaysOnVpn") { AlwaysOnVPNPackage(pkgName.value) } - composable(route = "UserControlDisabled") { UserCtrlDisabledPkg(pkgName.value) } - composable(route = "PermissionManage") { PermissionManage(pkgName.value) } - composable(route = "CrossProfilePackage") { CrossProfilePkg(pkgName.value) } - composable(route = "CrossProfileWidget") { CrossProfileWidget(pkgName.value) } - composable(route = "CredentialManagePolicy") { CredentialManagePolicy(pkgName.value) } - composable(route = "Accessibility") { PermittedAccessibility(pkgName.value) } - composable(route = "IME") { PermittedIME(pkgName.value) } - composable(route = "KeepUninstalled") { KeepUninstalledApp(pkgName.value) } + composable(route = "AlwaysOnVpn") { AlwaysOnVPNPackage(pkgName) } + composable(route = "UserControlDisabled") { UserCtrlDisabledPkg(pkgName) } + composable(route = "PermissionManage") { PermissionManage(pkgName) } + composable(route = "CrossProfilePackage") { CrossProfilePkg(pkgName) } + composable(route = "CrossProfileWidget") { CrossProfileWidget(pkgName) } + composable(route = "CredentialManagePolicy") { CredentialManagePolicy(pkgName) } + composable(route = "Accessibility") { PermittedAccessibility(pkgName) } + composable(route = "IME") { PermittedIME(pkgName) } + composable(route = "KeepUninstalled") { KeepUninstalledApp(pkgName) } composable(route = "InstallApp") { InstallApp() } - composable(route = "UninstallApp") { UninstallApp(pkgName.value) } + composable(route = "UninstallApp") { UninstallApp(pkgName) } } } } @@ -180,13 +189,13 @@ fun ApplicationManage(navCtrl:NavHostController, pkgName: MutableState, AppControlDialog(dialogStatus) } if(clearAppDataDialog.value) { - ClearAppDataDialog(clearAppDataDialog, pkgName.value) + ClearAppDataDialog(clearAppDataDialog, pkgName) } if(defaultDialerAppDialog.value) { - DefaultDialerAppDialog(defaultDialerAppDialog, pkgName.value) + DefaultDialerAppDialog(defaultDialerAppDialog, pkgName) } if(enableSystemAppDialog.value) { - EnableSystemAppDialog(enableSystemAppDialog, pkgName.value) + EnableSystemAppDialog(enableSystemAppDialog, pkgName) } } @@ -199,14 +208,16 @@ private fun Home( defaultDialerAppDialog: MutableState, enableSystemAppDialog: MutableState ) { + val context = LocalContext.current + val dpm = context.getDPM() + val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column( modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(start = 30.dp, end = 12.dp) ) { - val context = LocalContext.current - val dpm = context.getDPM() - val receiver = context.getReceiver() Spacer(Modifier.padding(vertical = 5.dp)) - if(VERSION.SDK_INT >= 24&&context.isProfileOwner&&dpm.isManagedProfile(receiver)) { + if(VERSION.SDK_INT >= 24 && profileOwner && dpm.isManagedProfile(receiver)) { Text(text = stringResource(R.string.scope_is_work_profile), textAlign = TextAlign.Center,modifier = Modifier.fillMaxWidth()) } SubPageItem(R.string.app_info,"", R.drawable.open_in_new) { @@ -214,7 +225,7 @@ private fun Home( intent.setData(Uri.parse("package:$pkgName")) startActivity(context, intent, null) } - if(VERSION.SDK_INT>=24 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT>=24 && (deviceOwner || profileOwner)) { val getSuspendStatus = { try{ dpm.isPackageSuspended(receiver, pkgName) } catch(e:NameNotFoundException) { false } @@ -232,7 +243,7 @@ private fun Home( } ) } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SwitchItem( title = R.string.hide, desc = stringResource(R.string.isapphidden_desc), icon = R.drawable.visibility_off_fill0, getState = { dpm.isApplicationHidden(receiver,pkgName) }, @@ -245,7 +256,7 @@ private fun Home( } ) } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SwitchItem( title = R.string.block_uninstall, desc = "", icon = R.drawable.delete_forever_fill0, getState = { dpm.isUninstallBlocked(receiver,pkgName) }, @@ -258,44 +269,44 @@ private fun Home( } ) } - if(VERSION.SDK_INT>=24 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT>=24 && (deviceOwner || profileOwner)) { SubPageItem(R.string.always_on_vpn, "", R.drawable.vpn_key_fill0) { navCtrl.navigate("AlwaysOnVpn") } } - if((VERSION.SDK_INT>=33&&context.isProfileOwner)||(VERSION.SDK_INT>=30&&context.isDeviceOwner)) { + if((VERSION.SDK_INT>=33&&profileOwner)||(VERSION.SDK_INT>=30&&deviceOwner)) { SubPageItem(R.string.ucd, "", R.drawable.do_not_touch_fill0) { navCtrl.navigate("UserControlDisabled") } } - if(VERSION.SDK_INT>=23&&(context.isDeviceOwner||context.isProfileOwner)) { + if(VERSION.SDK_INT>=23&&(deviceOwner||profileOwner)) { SubPageItem(R.string.permission_manage, "", R.drawable.key_fill0) { navCtrl.navigate("PermissionManage") } } - if(VERSION.SDK_INT>=30&&context.isProfileOwner&&dpm.isManagedProfile(receiver)) { + if(VERSION.SDK_INT>=30&&profileOwner&&dpm.isManagedProfile(receiver)) { SubPageItem(R.string.cross_profile_package, "", R.drawable.work_fill0) { navCtrl.navigate("CrossProfilePackage") } } - if(context.isProfileOwner) { + if(profileOwner) { SubPageItem(R.string.cross_profile_widget, "", R.drawable.widgets_fill0) { navCtrl.navigate("CrossProfileWidget") } } - if(VERSION.SDK_INT>=34&&context.isDeviceOwner) { + if(VERSION.SDK_INT>=34&&deviceOwner) { SubPageItem(R.string.credential_manage_policy, "", R.drawable.license_fill0) { navCtrl.navigate("CredentialManagePolicy") } } - if(context.isProfileOwner||context.isDeviceOwner) { + if(profileOwner||deviceOwner) { SubPageItem(R.string.permitted_accessibility_services, "", R.drawable.settings_accessibility_fill0) { navCtrl.navigate("Accessibility") } } - if(context.isDeviceOwner||context.isProfileOwner) { + if(deviceOwner||profileOwner) { SubPageItem(R.string.permitted_ime, "", R.drawable.keyboard_fill0) { navCtrl.navigate("IME") } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.enable_system_app, "", R.drawable.enable_fill0) { enableSystemAppDialog.value = true } } - if(VERSION.SDK_INT>=28&&context.isDeviceOwner) { + if(VERSION.SDK_INT>=28&&deviceOwner) { SubPageItem(R.string.keep_uninstalled_packages, "", R.drawable.delete_fill0) { navCtrl.navigate("KeepUninstalled") } } - if(VERSION.SDK_INT>=28 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT>=28 && (deviceOwner || profileOwner)) { SubPageItem(R.string.clear_app_storage, "", R.drawable.mop_fill0) { if(pkgName != "") { clearAppDataDialog.value = true } } } SubPageItem(R.string.install_app, "", R.drawable.install_mobile_fill0) { navCtrl.navigate("InstallApp") } SubPageItem(R.string.uninstall_app, "", R.drawable.delete_fill0) { navCtrl.navigate("UninstallApp") } - if(VERSION.SDK_INT >= 34 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 34 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.set_default_dialer, "", R.drawable.call_fill0) { defaultDialerAppDialog.value = true } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -412,7 +423,6 @@ private fun PermissionManage(pkgName: String) { var showDialog by remember { mutableStateOf(false) } var selectedPermission by remember { mutableStateOf(PermissionItem("", R.string.unknown, R.drawable.block_fill0)) } val statusMap = remember { mutableStateMapOf() } - val profileOwner = context.isProfileOwner val grantState = mapOf( PERMISSION_GRANT_STATE_DEFAULT to stringResource(R.string.default_stringres), PERMISSION_GRANT_STATE_GRANTED to stringResource(R.string.granted), @@ -493,7 +503,7 @@ private fun PermissionManage(pkgName: String) { Column { Text(selectedPermission.permission) Spacer(Modifier.padding(vertical = 4.dp)) - if(!(VERSION.SDK_INT >=31 && profileOwner && selectedPermission.profileOwnerRestricted)) { + if(!(VERSION.SDK_INT >=31 && context.isProfileOwner && selectedPermission.profileOwnerRestricted)) { GrantPermissionItem(R.string.grant, PERMISSION_GRANT_STATE_GRANTED) } GrantPermissionItem(R.string.deny, PERMISSION_GRANT_STATE_DENIED) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt index f6dcfe0..e6f90c8 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt @@ -96,6 +96,7 @@ private fun Home(navCtrl: NavHostController) { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val profileOwner = context.isProfileOwner Column( modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(start = 30.dp, end = 12.dp) ) { @@ -104,7 +105,7 @@ private fun Home(navCtrl: NavHostController) { style = typography.headlineLarge, modifier = Modifier.padding(top = 8.dp, bottom = 5.dp).offset(x = (-8).dp) ) - if(VERSION.SDK_INT >= 30 && context.isProfileOwner && dpm.isManagedProfile(receiver)) { + if(VERSION.SDK_INT >= 30 && profileOwner && dpm.isManagedProfile(receiver)) { SubPageItem(R.string.org_owned_work_profile, "", R.drawable.corporate_fare_fill0) { navCtrl.navigate("OrgOwnedWorkProfile") } } if(VERSION.SDK_INT<24 || (VERSION.SDK_INT>=24 && dpm.isProvisioningAllowed(ACTION_PROVISION_MANAGED_PROFILE))) { @@ -113,10 +114,10 @@ private fun Home(navCtrl: NavHostController) { if(dpm.isOrgProfile(receiver)) { SubPageItem(R.string.suspend_personal_app, "", R.drawable.block_fill0) { navCtrl.navigate("SuspendPersonalApp") } } - if(context.isProfileOwner && (VERSION.SDK_INT < 24 || (VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)))) { + if(profileOwner && (VERSION.SDK_INT < 24 || (VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)))) { SubPageItem(R.string.intent_filter, "", R.drawable.filter_alt_fill0) { navCtrl.navigate("IntentFilter") } } - if(context.isProfileOwner && (VERSION.SDK_INT < 24 || (VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)))) { + if(profileOwner && (VERSION.SDK_INT < 24 || (VERSION.SDK_INT >= 24 && dpm.isManagedProfile(receiver)))) { SubPageItem(R.string.delete_work_profile, "", R.drawable.delete_forever_fill0) { navCtrl.navigate("DeleteWorkProfile") } } Spacer(Modifier.padding(vertical = 30.dp)) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt index aa03285..42e0341 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt @@ -39,7 +39,6 @@ import android.telephony.data.ApnSetting.PROTOCOL_PPP import android.telephony.data.ApnSetting.PROTOCOL_UNSTRUCTURED import android.util.Log import android.widget.Toast -import androidx.activity.ComponentActivity import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.animateContentSize import androidx.compose.foundation.ScrollState @@ -156,37 +155,39 @@ private fun Home(navCtrl:NavHostController, scrollState: ScrollState, wifiMacDia val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState).padding(start = 30.dp, end = 12.dp)) { Text( text = stringResource(R.string.network), style = typography.headlineLarge, modifier = Modifier.padding(top = 8.dp, bottom = 5.dp).offset(x = (-8).dp) ) - if(VERSION.SDK_INT >= 24 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 24 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.wifi_mac_addr, "", R.drawable.wifi_fill0) { wifiMacDialog.value = true } } if(VERSION.SDK_INT >= 30) { SubPageItem(R.string.options, "", R.drawable.tune_fill0) { navCtrl.navigate("Switches") } } - if(VERSION.SDK_INT >= 33 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 33 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.min_wifi_security_level, "", R.drawable.wifi_password_fill0) { navCtrl.navigate("MinWifiSecurityLevel") } } - if(VERSION.SDK_INT >= 33 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 33 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.wifi_ssid_policy, "", R.drawable.wifi_fill0) { navCtrl.navigate("WifiSsidPolicy") } } - if(VERSION.SDK_INT >= 29 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 29 && deviceOwner) { SubPageItem(R.string.private_dns, "", R.drawable.dns_fill0) { navCtrl.navigate("PrivateDNS") } } - if(context.isDeviceOwner) { + if(deviceOwner) { SubPageItem(R.string.recommended_global_proxy, "", R.drawable.vpn_key_fill0) { navCtrl.navigate("RecommendedGlobalProxy") } } - if(VERSION.SDK_INT >= 26&&(context.isDeviceOwner || (context.isProfileOwner && dpm.isManagedProfile(receiver)))) { + if(VERSION.SDK_INT >= 26&&(deviceOwner || (profileOwner && dpm.isManagedProfile(receiver)))) { SubPageItem(R.string.retrieve_net_logs, "", R.drawable.description_fill0) { navCtrl.navigate("NetworkLog") } } - if(VERSION.SDK_INT >= 31 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 31 && (deviceOwner || profileOwner)) { SubPageItem(R.string.wifi_auth_keypair, "", R.drawable.key_fill0) { navCtrl.navigate("WifiAuthKeypair") } } - if(VERSION.SDK_INT >= 28 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 28 && deviceOwner) { SubPageItem(R.string.override_apn_settings, "", R.drawable.cell_tower_fill0) { navCtrl.navigate("APN") } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -198,15 +199,16 @@ private fun Switches() { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner Column(modifier = Modifier.fillMaxSize().padding(start = 20.dp, end = 12.dp)) { Spacer(Modifier.padding(vertical = 5.dp)) - if(VERSION.SDK_INT >= 33 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 33 && deviceOwner) { SwitchItem( R.string.preferential_network_service, stringResource(R.string.developing), R.drawable.globe_fill0, { dpm.isPreferentialNetworkServiceEnabled }, { dpm.isPreferentialNetworkServiceEnabled = it } ) } - if(VERSION.SDK_INT>=30 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT>=30 && (deviceOwner || dpm.isOrgProfile(receiver))) { SwitchItem(R.string.lockdown_admin_configured_network, "", R.drawable.wifi_password_fill0, { dpm.hasLockdownAdminConfiguredNetworks(receiver) }, { dpm.setConfiguredNetworksLockdownState(receiver,it) } ) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt index 7f63e8e..5c98da3 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt @@ -133,6 +133,9 @@ fun Password(navCtrl: NavHostController) { private fun Home(navCtrl:NavHostController,scrollState: ScrollState) { val context = LocalContext.current val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE) + val deviceAdmin = context.isDeviceAdmin + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState).padding(start = 30.dp, end = 12.dp)) { Text( text = stringResource(R.string.password_and_keyguard), @@ -141,31 +144,31 @@ private fun Home(navCtrl:NavHostController,scrollState: ScrollState) { ) SubPageItem(R.string.password_info, "", R.drawable.info_fill0) { navCtrl.navigate("PasswordInfo") } if(sharedPrefs.getBoolean("dangerous_features", false)) { - if(VERSION.SDK_INT >= 26 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 26 && (deviceOwner || profileOwner)) { SubPageItem(R.string.reset_password_token, "", R.drawable.key_vertical_fill0) { navCtrl.navigate("ResetPasswordToken") } } - if(context.isDeviceAdmin || context.isDeviceOwner || context.isProfileOwner) { + if(deviceAdmin || deviceOwner || profileOwner) { SubPageItem(R.string.reset_password, "", R.drawable.lock_reset_fill0) { navCtrl.navigate("ResetPassword") } } } - if(VERSION.SDK_INT >= 31 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 31 && (deviceOwner || profileOwner)) { SubPageItem(R.string.required_password_complexity, "", R.drawable.password_fill0) { navCtrl.navigate("RequirePasswordComplexity") } } - if(context.isDeviceAdmin) { + if(deviceAdmin) { SubPageItem(R.string.disable_keyguard_features, "", R.drawable.screen_lock_portrait_fill0) { navCtrl.navigate("DisableKeyguardFeatures") } } - if(context.isDeviceOwner) { + if(deviceOwner) { SubPageItem(R.string.max_time_to_lock, "", R.drawable.schedule_fill0) { navCtrl.navigate("MaxTimeToLock") } SubPageItem(R.string.pwd_expiration_timeout, "", R.drawable.lock_clock_fill0) { navCtrl.navigate("PasswordTimeout") } SubPageItem(R.string.max_pwd_fail, "", R.drawable.no_encryption_fill0) { navCtrl.navigate("MaxPasswordFail") } } - if(context.isDeviceAdmin){ + if(deviceAdmin){ SubPageItem(R.string.pwd_history, "", R.drawable.history_fill0) { navCtrl.navigate("PasswordHistoryLength") } } - if(VERSION.SDK_INT >= 26 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 26 && (deviceOwner || profileOwner)) { SubPageItem(R.string.required_strong_auth_timeout, "", R.drawable.fingerprint_off_fill0) { navCtrl.navigate("RequiredStrongAuthTimeout") } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.required_password_quality, "", R.drawable.password_fill0) { navCtrl.navigate("RequirePasswordQuality") } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -177,6 +180,8 @@ private fun PasswordInfo() { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.password_info), style = typography.headlineLarge) @@ -191,14 +196,14 @@ private fun PasswordInfo() { val pwdComplex = passwordComplexity[dpm.passwordComplexity] Text(text = stringResource(R.string.current_password_complexity_is, pwdComplex?:stringResource(R.string.unknown))) } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { Text(stringResource(R.string.is_password_sufficient, dpm.isActivePasswordSufficient)) } if(context.isDeviceAdmin) { val pwdFailedAttempts = dpm.currentFailedPasswordAttempts Text(text = stringResource(R.string.password_failed_attempts_is, pwdFailedAttempts)) } - if(VERSION.SDK_INT >= 28 && context.isProfileOwner && dpm.isManagedProfile(receiver)) { + if(VERSION.SDK_INT >= 28 && profileOwner && dpm.isManagedProfile(receiver)) { val unifiedPwd = dpm.isUsingUnifiedPassword(receiver) Text(stringResource(R.string.is_using_unified_password, unifiedPwd)) } @@ -290,7 +295,7 @@ private fun ResetPassword() { var useToken by remember { mutableStateOf(false) } var token by remember { mutableStateOf("") } val tokenByteArray = token.toByteArray() - var flags = remember { mutableStateListOf() } + val flags = remember { mutableStateListOf() } var confirmDialog by remember { mutableStateOf(false) } Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) { Spacer(Modifier.padding(vertical = 10.dp)) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt index ccbd0e7..a212032 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Permissions.kt @@ -91,6 +91,9 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) { val receiver = context.getReceiver() val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) var dhizukuStatus by remember { mutableStateOf(sharedPref.getBoolean("dhizuku", false)) } + val deviceAdmin = context.isDeviceAdmin + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(listScrollState).padding(start = 30.dp, end = 12.dp)) { Text( text = stringResource(R.string.permission), @@ -108,40 +111,40 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) { ) } SubPageItem( - R.string.device_admin, stringResource(if(context.isDeviceAdmin) R.string.activated else R.string.deactivated), + R.string.device_admin, stringResource(if(deviceAdmin) R.string.activated else R.string.deactivated), operation = { localNavCtrl.navigate("DeviceAdmin") } ) - if(!context.isDeviceOwner) { + if(!deviceOwner) { SubPageItem( - R.string.profile_owner, stringResource(if(context.isProfileOwner) R.string.activated else R.string.deactivated), + R.string.profile_owner, stringResource(if(profileOwner) R.string.activated else R.string.deactivated), operation = { localNavCtrl.navigate("ProfileOwner") } ) } - if(!context.isProfileOwner) { + if(!profileOwner) { SubPageItem( - R.string.device_owner, stringResource(if(context.isDeviceOwner) R.string.activated else R.string.deactivated), + R.string.device_owner, stringResource(if(deviceOwner) R.string.activated else R.string.deactivated), operation = { localNavCtrl.navigate("DeviceOwner") } ) } SubPageItem(R.string.shizuku,"") { localNavCtrl.navigate("Shizuku") } SubPageItem(R.string.device_info, "", R.drawable.perm_device_information_fill0) { localNavCtrl.navigate("DeviceInfo") } - if((VERSION.SDK_INT >= 26 && context.isDeviceOwner) || (VERSION.SDK_INT>=24 && context.isProfileOwner)) { + if((VERSION.SDK_INT >= 26 && deviceOwner) || (VERSION.SDK_INT>=24 && profileOwner)) { SubPageItem(R.string.org_name, "", R.drawable.corporate_fare_fill0) { localNavCtrl.navigate("OrgName") } } - if(VERSION.SDK_INT >= 31 && (context.isProfileOwner || context.isDeviceOwner)) { + if(VERSION.SDK_INT >= 31 && (profileOwner || deviceOwner)) { SubPageItem(R.string.org_id, "", R.drawable.corporate_fare_fill0) { localNavCtrl.navigate("OrgID") } SubPageItem(R.string.enrollment_specific_id, "", R.drawable.id_card_fill0) { localNavCtrl.navigate("SpecificID") } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.disable_account_management, "", R.drawable.account_circle_fill0) { localNavCtrl.navigate("DisableAccountManagement") } } - if(VERSION.SDK_INT >= 24 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 24 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.device_owner_lock_screen_info, "", R.drawable.screen_lock_portrait_fill0) { localNavCtrl.navigate("LockScreenInfo") } } - if(VERSION.SDK_INT >= 24 && context.isDeviceAdmin) { + if(VERSION.SDK_INT >= 24 && deviceAdmin) { SubPageItem(R.string.support_msg, "", R.drawable.chat_fill0) { localNavCtrl.navigate("SupportMsg") } } - if(VERSION.SDK_INT >= 28 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 28 && (deviceOwner || profileOwner)) { SubPageItem(R.string.transfer_ownership, "", R.drawable.admin_panel_settings_fill0) { localNavCtrl.navigate("TransformOwnership") } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -222,12 +225,13 @@ private fun DeviceAdmin() { val dpm = context.getDPM() val receiver = context.getReceiver() var deactivateDialog by remember { mutableStateOf(false) } + val deviceAdmin = context.isDeviceAdmin Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.device_admin), style = typography.headlineLarge) Text(text = stringResource(if(context.isDeviceAdmin) R.string.activated else R.string.deactivated), style = typography.titleLarge) Spacer(Modifier.padding(vertical = 5.dp)) - AnimatedVisibility(context.isDeviceAdmin) { + AnimatedVisibility(deviceAdmin) { Button( onClick = { deactivateDialog = true }, enabled = !context.isProfileOwner && !context.isDeviceOwner, @@ -236,7 +240,7 @@ private fun DeviceAdmin() { Text(stringResource(R.string.deactivate)) } } - AnimatedVisibility(!context.isDeviceAdmin) { + AnimatedVisibility(!deviceAdmin) { Column { Button(onClick = { activateDeviceAdmin(context, receiver) }, modifier = Modifier.fillMaxWidth()) { Text(stringResource(R.string.activate_jump)) @@ -280,13 +284,14 @@ private fun ProfileOwner() { val dpm = context.getDPM() val receiver = context.getReceiver() var deactivateDialog by remember { mutableStateOf(false) } + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.profile_owner), style = typography.headlineLarge) - Text(stringResource(if(context.isProfileOwner) R.string.activated else R.string.deactivated), style = typography.titleLarge) + Text(stringResource(if(profileOwner) R.string.activated else R.string.deactivated), style = typography.titleLarge) Spacer(Modifier.padding(vertical = 5.dp)) if(VERSION.SDK_INT >= 24) { - if(context.isProfileOwner) { + if(profileOwner) { Button( onClick = { deactivateDialog = true }, enabled = !dpm.isManagedProfile(receiver), @@ -328,12 +333,13 @@ private fun DeviceOwner() { val dpm = context.getDPM() var deactivateDialog by remember { mutableStateOf(false) } var resetPolicy by remember { mutableStateOf(true) } + val deviceOwner = context.isDeviceOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.device_owner), style = typography.headlineLarge) - Text(text = stringResource(if(context.isDeviceOwner) R.string.activated else R.string.deactivated), style = typography.titleLarge) + Text(text = stringResource(if(deviceOwner) R.string.activated else R.string.deactivated), style = typography.titleLarge) Spacer(Modifier.padding(vertical = 5.dp)) - AnimatedVisibility(context.isDeviceOwner) { + AnimatedVisibility(deviceOwner) { Button( onClick = { deactivateDialog = true }, colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError) @@ -341,7 +347,7 @@ private fun DeviceOwner() { Text(text = stringResource(R.string.deactivate)) } } - AnimatedVisibility(!context.isDeviceOwner) { + AnimatedVisibility(!deviceOwner) { Column { SelectionContainer{ Text(text = stringResource(R.string.activate_device_owner_command)) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ShizukuActivate.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ShizukuActivate.kt index 81d97a0..5fc77ec 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ShizukuActivate.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ShizukuActivate.kt @@ -133,22 +133,6 @@ fun ShizukuActivate() { } } - AnimatedVisibility(showProfileOwnerButton&&showDeviceOwnerButton) { - Button( - onClick = { - coScope.launch{ - outputText = service!!.execute(context.getString(R.string.dpm_activate_po_command)) - outputTextScrollState.animateScrollTo(0) - delay(500) - showProfileOwnerButton = !context.isProfileOwner - } - }, - enabled = enabled - ) { - Text(text = stringResource(R.string.activate_profile_owner)) - } - } - AnimatedVisibility(showDeviceOwnerButton && showProfileOwnerButton) { Button( onClick = { diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt index 579c366..309b553 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt @@ -42,7 +42,6 @@ import android.os.Build.VERSION import android.os.UserManager import android.util.Log import android.widget.Toast -import androidx.activity.ComponentActivity import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.animateContentSize import androidx.compose.foundation.ScrollState @@ -176,54 +175,56 @@ private fun Home(navCtrl: NavHostController, scrollState: ScrollState, rebootDia val receiver = context.getReceiver() val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE) val dangerousFeatures = sharedPref.getBoolean("dangerous_features", false) + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState).padding(start = 30.dp, end = 12.dp)) { Text( text = stringResource(R.string.system_manage), style = typography.headlineLarge, modifier = Modifier.padding(top = 8.dp, bottom = 5.dp).offset(x = (-8).dp) ) - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.options, "", R.drawable.tune_fill0) { navCtrl.navigate("Switches") } } SubPageItem(R.string.keyguard, "", R.drawable.screen_lock_portrait_fill0) { navCtrl.navigate("Keyguard") } - if(VERSION.SDK_INT >= 24 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 24 && deviceOwner) { SubPageItem(R.string.reboot, "", R.drawable.restart_alt_fill0) { rebootDialog.value = true } } - if(context.isDeviceOwner && ((VERSION.SDK_INT >= 28 && dpm.isAffiliatedUser) || VERSION.SDK_INT >= 24)) { + if(deviceOwner && ((VERSION.SDK_INT >= 28 && dpm.isAffiliatedUser) || VERSION.SDK_INT >= 24)) { SubPageItem(R.string.bug_report, "", R.drawable.bug_report_fill0) { bugReportDialog.value = true } } - if(VERSION.SDK_INT >= 28 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 28 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.edit_time, "", R.drawable.schedule_fill0) { navCtrl.navigate("EditTime") } SubPageItem(R.string.edit_timezone, "", R.drawable.schedule_fill0) { navCtrl.navigate("EditTimeZone") } } - if(VERSION.SDK_INT >= 23 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 23 && (deviceOwner || profileOwner)) { SubPageItem(R.string.permission_policy, "", R.drawable.key_fill0) { navCtrl.navigate("PermissionPolicy") } } - if(VERSION.SDK_INT >= 34 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 34 && deviceOwner) { SubPageItem(R.string.mte_policy, "", R.drawable.memory_fill0) { navCtrl.navigate("MTEPolicy") } } - if(VERSION.SDK_INT >= 31 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 31 && (deviceOwner || profileOwner)) { SubPageItem(R.string.nearby_streaming_policy, "", R.drawable.share_fill0) { navCtrl.navigate("NearbyStreamingPolicy") } } - if(VERSION.SDK_INT >= 28 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 28 && deviceOwner) { SubPageItem(R.string.lock_task_mode, "", R.drawable.lock_fill0) { navCtrl.navigate("LockTaskMode") } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.ca_cert, "", R.drawable.license_fill0) { navCtrl.navigate("CaCert") } } - if(VERSION.SDK_INT >= 26 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 26 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.security_logs, "", R.drawable.description_fill0) { navCtrl.navigate("SecurityLogs") } } - if(VERSION.SDK_INT >= 23 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 23 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.system_update_policy, "", R.drawable.system_update_fill0) { navCtrl.navigate("SystemUpdatePolicy") } } - if(VERSION.SDK_INT >= 29 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 29 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.install_system_update, "", R.drawable.system_update_fill0) { navCtrl.navigate("InstallSystemUpdate") } } - if(VERSION.SDK_INT >= 30 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 30 && (deviceOwner || dpm.isOrgProfile(receiver))) { SubPageItem(R.string.frp_policy, "", R.drawable.device_reset_fill0) { navCtrl.navigate("FRP") } } - if(dangerousFeatures && context.isDeviceAdmin && !(VERSION.SDK_INT >= 24 && context.isProfileOwner && dpm.isManagedProfile(receiver))) { + if(dangerousFeatures && context.isDeviceAdmin && !(VERSION.SDK_INT >= 24 && profileOwner && dpm.isManagedProfile(receiver))) { SubPageItem(R.string.wipe_data, "", R.drawable.device_reset_fill0) { navCtrl.navigate("WipeData") } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -236,24 +237,26 @@ private fun Switches() { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(start = 20.dp, end = 12.dp)) { Spacer(Modifier.padding(vertical = 10.dp)) - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SwitchItem(R.string.disable_cam,"", R.drawable.photo_camera_fill0, { dpm.getCameraDisabled(null) }, { dpm.setCameraDisabled(receiver,it) } ) } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SwitchItem(R.string.disable_screen_capture, stringResource(R.string.also_disable_aosp_screen_record), R.drawable.screenshot_fill0, { dpm.getScreenCaptureDisabled(null) }, { dpm.setScreenCaptureDisabled(receiver,it) } ) } - if(VERSION.SDK_INT >= 34 && (context.isDeviceOwner || (context.isProfileOwner && dpm.isAffiliatedUser))) { + if(VERSION.SDK_INT >= 34 && (deviceOwner || (profileOwner && dpm.isAffiliatedUser))) { SwitchItem(R.string.disable_status_bar, "", R.drawable.notifications_fill0, { dpm.isStatusBarDisabled}, { dpm.setStatusBarDisabled(receiver,it) } ) } - if(context.isDeviceOwner || dpm.isOrgProfile(receiver)) { + if(deviceOwner || dpm.isOrgProfile(receiver)) { if(VERSION.SDK_INT >= 30) { SwitchItem(R.string.auto_time, "", R.drawable.schedule_fill0, { dpm.getAutoTimeEnabled(receiver) }, { dpm.setAutoTimeEnabled(receiver,it) } @@ -265,27 +268,27 @@ private fun Switches() { SwitchItem(R.string.require_auto_time, "", R.drawable.schedule_fill0, { dpm.autoTimeRequired}, { dpm.setAutoTimeRequired(receiver,it) }) } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SwitchItem(R.string.master_mute, "", R.drawable.volume_up_fill0, { dpm.isMasterVolumeMuted(receiver) }, { dpm.setMasterVolumeMuted(receiver,it) } ) } - if(VERSION.SDK_INT >= 26 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 26 && (deviceOwner || profileOwner)) { SwitchItem(R.string.backup_service, "", R.drawable.backup_fill0, { dpm.isBackupServiceEnabled(receiver) }, { dpm.setBackupServiceEnabled(receiver,it) } ) } - if(VERSION.SDK_INT >= 23 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 23 && (deviceOwner || profileOwner)) { SwitchItem(R.string.disable_bt_contact_share, "", R.drawable.account_circle_fill0, { dpm.getBluetoothContactSharingDisabled(receiver) }, { dpm.setBluetoothContactSharingDisabled(receiver,it) } ) } - if(VERSION.SDK_INT >= 30 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 30 && deviceOwner) { SwitchItem(R.string.common_criteria_mode, stringResource(R.string.common_criteria_mode_desc),R.drawable.security_fill0, { dpm.isCommonCriteriaModeEnabled(receiver) }, { dpm.setCommonCriteriaModeEnabled(receiver,it) } ) } - if(VERSION.SDK_INT >= 31 && (context.isDeviceOwner || dpm.isOrgProfile(receiver))) { + if(VERSION.SDK_INT >= 31 && (deviceOwner || dpm.isOrgProfile(receiver))) { SwitchItem( R.string.usb_signal, "", R.drawable.usb_fill0, { dpm.isUsbDataSignalingEnabled }, { @@ -306,6 +309,8 @@ private fun Keyguard() { val context = LocalContext.current val dpm = context.getDPM() val receiver = context.getReceiver() + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.keyguard), style = typography.headlineLarge) @@ -315,7 +320,7 @@ private fun Keyguard() { onClick = { Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,true)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() }, - enabled = context.isDeviceOwner || (VERSION.SDK_INT >= 28 && context.isProfileOwner && dpm.isAffiliatedUser), + enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), modifier = Modifier.fillMaxWidth() ) { Text(stringResource(R.string.disable)) @@ -324,7 +329,7 @@ private fun Keyguard() { onClick = { Toast.makeText(context, if(dpm.setKeyguardDisabled(receiver,false)) R.string.success else R.string.failed, Toast.LENGTH_SHORT).show() }, - enabled = context.isDeviceOwner || (VERSION.SDK_INT >= 28 && context.isProfileOwner && dpm.isAffiliatedUser), + enabled = deviceOwner || (VERSION.SDK_INT >= 28 && profileOwner && dpm.isAffiliatedUser), modifier = Modifier.fillMaxWidth() ) { Text(stringResource(R.string.enable)) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt index 8e823de..71107b4 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt @@ -107,6 +107,8 @@ fun UserManage(navCtrl: NavHostController) { @Composable private fun Home(navCtrl: NavHostController,scrollState: ScrollState) { val context = LocalContext.current + val deviceOwner = context.isDeviceOwner + val profileOwner = context.isProfileOwner Column(modifier = Modifier.fillMaxSize().verticalScroll(scrollState).padding(start = 30.dp, end = 12.dp)) { Text( text = stringResource(R.string.user_manager), @@ -114,22 +116,22 @@ private fun Home(navCtrl: NavHostController,scrollState: ScrollState) { modifier = Modifier.padding(top = 8.dp, bottom = 5.dp).offset(x = (-8).dp) ) SubPageItem(R.string.user_info, "", R.drawable.person_fill0) { navCtrl.navigate("UserInfo") } - if(context.isDeviceOwner) { + if(deviceOwner) { SubPageItem(R.string.user_operation, "", R.drawable.sync_alt_fill0) { navCtrl.navigate("UserOperation") } } - if(VERSION.SDK_INT >= 24 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 24 && deviceOwner) { SubPageItem(R.string.create_user, "", R.drawable.person_add_fill0) { navCtrl.navigate("CreateUser") } } - if(context.isDeviceOwner || context.isProfileOwner) { + if(deviceOwner || profileOwner) { SubPageItem(R.string.edit_username, "", R.drawable.edit_fill0) { navCtrl.navigate("EditUsername") } } - if(VERSION.SDK_INT >= 23 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 23 && (deviceOwner || profileOwner)) { SubPageItem(R.string.change_user_icon, "", R.drawable.account_circle_fill0) { navCtrl.navigate("ChangeUserIcon") } } - if(VERSION.SDK_INT >= 28 && context.isDeviceOwner) { + if(VERSION.SDK_INT >= 28 && deviceOwner) { SubPageItem(R.string.user_session_msg, "", R.drawable.notifications_fill0) { navCtrl.navigate("UserSessionMessage") } } - if(VERSION.SDK_INT >= 26 && (context.isDeviceOwner || context.isProfileOwner)) { + if(VERSION.SDK_INT >= 26 && (deviceOwner || profileOwner)) { SubPageItem(R.string.affiliation_id, "", R.drawable.id_card_fill0) { navCtrl.navigate("AffiliationID") } } Spacer(Modifier.padding(vertical = 30.dp)) @@ -206,7 +208,7 @@ private fun UserOperation() { } Spacer(Modifier.padding(vertical = 5.dp)) if(VERSION.SDK_INT > 28) { - if(context.isProfileOwner&&dpm.isAffiliatedUser) { + if(context.isProfileOwner && dpm.isAffiliatedUser) { Button( onClick = { val result = dpm.logoutUser(receiver) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/UserRestriction.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/UserRestriction.kt index ab58e1f..203562b 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/UserRestriction.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/UserRestriction.kt @@ -196,7 +196,7 @@ private fun UserRestrictionItem( Box(modifier = Modifier.padding(start = 22.dp, end = 16.dp)) { SwitchItem( itemName,restrictionDescription,leadIcon, - { if(context.isDeviceOwner||context.isProfileOwner) { dpm.getUserRestrictions(receiver).getBoolean(restriction) }else{ false } }, + { dpm.getUserRestrictions(receiver).getBoolean(restriction) }, { try{ if(it) { @@ -204,7 +204,7 @@ private fun UserRestrictionItem( }else{ dpm.clearUserRestriction(receiver,restriction) } - }catch(e:SecurityException) { + } catch(e:SecurityException) { if(context.isProfileOwner) { Toast.makeText(context, R.string.require_device_owner, Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index b6a415e..342c8e5 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -85,7 +85,7 @@ Hesap Yönetimini Devre Dışı Bırak Hesap Türleri: Sahipliği Devret - Cihaz sahibi veya profil sahibi ayrıcalığını başka bir uygulamaya devredin. Hedef uygulama cihaz yöneticisi olmalıdır. + Cihaz sahibi veya profil sahibi ayrıcalığını başka bir uygulamaya devredin. Hedef Paket Adı Hedef Sınıf Adı Ekran Kilidi Bilgisi @@ -112,7 +112,6 @@ Shizuku Başlatılmadı. İzin Verildi (Kabuk) İzin Verildi (Root) - Profil Sahibini Etkinleştir Cihaz Sahibini Etkinleştir Kuruluş Profili Sahibini Etkinleştir Shizuku Hizmeti Bağlantısı Kesildi diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 4e691d9..9d9222c 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -80,7 +80,7 @@ 禁用账号管理 账号类型: 转移所有权 - 把Device owner或Profile owner权限转移到另一个应用 (目标必须是Device admin) + 把Device owner或Profile owner权限转移到另一个应用 目标包名 目标类名 锁屏提示信息 @@ -107,7 +107,6 @@ 服务未启动 已授权(Shell) 已授权(Root) - 激活Profile owner 激活Device owner 激活由组织拥有的工作资料 Shizuku服务断开连接 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6ea5950..bff6f5a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,7 +86,7 @@ Disable account management Account types: Transfer Ownership - Transfer device owner or profile owner privilege to another app. The target app must be a device admin. + Transfer device owner or profile owner privilege to another app. Target package name Target class name Lockscreen info @@ -113,11 +113,9 @@ List owners Shizuku not started. dpm set-device-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver - dpm set-profile-owner com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver dpm set-active-admin com.bintianqi.owndroid/com.bintianqi.owndroid.Receiver Permission granted (Shell) Permission granted (Root) - Activate Profile owner Activate Device owner Activate organization-owned work profile Shizuku service disconnected