Support Dhizuku mode

This commit is contained in:
BinTianqi
2024-07-21 08:56:03 +08:00
parent b6d7844732
commit 8fd1d9e4fe
13 changed files with 398 additions and 300 deletions

View File

@@ -10,7 +10,6 @@ import android.content.pm.PackageManager
import android.os.Build.VERSION
import android.os.RemoteException
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
@@ -90,8 +89,8 @@ fun DpmPermissions(navCtrl:NavHostController) {
@Composable
private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context, Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
var dhizukuStatus by remember { mutableStateOf(sharedPref.getBoolean("dhizuku", false)) }
Column(modifier = Modifier.fillMaxSize().verticalScroll(listScrollState)) {
@@ -132,37 +131,37 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) {
R.string.device_admin, stringResource(if(dpm.isAdminActive(receiver)) R.string.activated else R.string.deactivated),
operation = { localNavCtrl.navigate("DeviceAdmin") }
)
if(!isDeviceOwner(dpm)) {
if(!dpm.isDeviceOwner(context)) {
SubPageItem(
R.string.profile_owner, stringResource(if(isProfileOwner(dpm)) R.string.activated else R.string.deactivated),
R.string.profile_owner, stringResource(if(dpm.isProfileOwner(context)) R.string.activated else R.string.deactivated),
operation = { localNavCtrl.navigate("ProfileOwner") }
)
}
if(!isProfileOwner(dpm)) {
if(!dpm.isProfileOwner(context)) {
SubPageItem(
R.string.device_owner, stringResource(if(isDeviceOwner(dpm)) R.string.activated else R.string.deactivated),
R.string.device_owner, stringResource(if(dpm.isDeviceOwner(context)) 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 && isDeviceOwner(dpm)) || (VERSION.SDK_INT>=24 && isProfileOwner(dpm))) {
if((VERSION.SDK_INT >= 26 && dpm.isDeviceOwner(context)) || (VERSION.SDK_INT>=24 && dpm.isProfileOwner(context))) {
SubPageItem(R.string.org_name, "", R.drawable.corporate_fare_fill0) { localNavCtrl.navigate("OrgName") }
}
if(VERSION.SDK_INT >= 31 && (isProfileOwner(dpm) || isDeviceOwner(dpm))) {
if(VERSION.SDK_INT >= 31 && (dpm.isProfileOwner(context) || dpm.isDeviceOwner(context))) {
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(isDeviceOwner(dpm) || isProfileOwner(dpm)) {
if(dpm.isDeviceOwner(context) || dpm.isProfileOwner(context)) {
SubPageItem(R.string.disable_account_management, "", R.drawable.account_circle_fill0) { localNavCtrl.navigate("DisableAccountManagement") }
}
if(VERSION.SDK_INT >= 24 && (isDeviceOwner(dpm) || dpm.isOrgProfile(receiver))) {
if(VERSION.SDK_INT >= 24 && (dpm.isDeviceOwner(context) || 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 && dpm.isAdminActive(receiver)) {
SubPageItem(R.string.support_msg, "", R.drawable.chat_fill0) { localNavCtrl.navigate("SupportMsg") }
}
if(VERSION.SDK_INT >= 28 && (isDeviceOwner(dpm) || isProfileOwner(dpm))) {
if(VERSION.SDK_INT >= 28 && (dpm.isDeviceOwner(context) || dpm.isProfileOwner(context))) {
SubPageItem(R.string.transfer_ownership, "", R.drawable.admin_panel_settings_fill0) { localNavCtrl.navigate("TransformOwnership") }
}
Spacer(Modifier.padding(vertical = 30.dp))
@@ -173,8 +172,8 @@ private fun Home(localNavCtrl:NavHostController,listScrollState:ScrollState) {
@Composable
private fun LockScreenInfo() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
var infoText by remember { mutableStateOf(dpm.deviceOwnerLockScreenInfo?.toString() ?: "") }
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
@@ -211,8 +210,8 @@ private fun LockScreenInfo() {
@Composable
private fun DeviceAdmin() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
var showDeactivateButton by remember { mutableStateOf(dpm.isAdminActive(receiver)) }
var deactivateDialog by remember { mutableStateOf(false) }
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
@@ -223,7 +222,7 @@ private fun DeviceAdmin() {
AnimatedVisibility(showDeactivateButton) {
Button(
onClick = { deactivateDialog = true },
enabled = !isProfileOwner(dpm) && !isDeviceOwner(dpm),
enabled = !dpm.isProfileOwner(context) && !dpm.isDeviceOwner(context),
colors = ButtonDefaults.buttonColors(containerColor = colorScheme.error, contentColor = colorScheme.onError)
) {
Text(stringResource(R.string.deactivate))
@@ -276,14 +275,14 @@ private fun DeviceAdmin() {
@Composable
private fun ProfileOwner() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
var showDeactivateButton by remember { mutableStateOf(isProfileOwner(dpm)) }
val dpm = context.getDPM()
val receiver = context.getReceiver()
var showDeactivateButton by remember { mutableStateOf(dpm.isProfileOwner(context)) }
var deactivateDialog by remember { mutableStateOf(false) }
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(isProfileOwner(dpm)) R.string.activated else R.string.deactivated), style = typography.titleLarge)
Text(stringResource(if(dpm.isProfileOwner(context)) R.string.activated else R.string.deactivated), style = typography.titleLarge)
Spacer(Modifier.padding(vertical = 5.dp))
if(VERSION.SDK_INT >= 24) {
AnimatedVisibility(showDeactivateButton) {
@@ -324,8 +323,8 @@ private fun ProfileOwner() {
co.launch{
delay(300)
deactivateDialog = false
showDeactivateButton = isProfileOwner(dpm)
backToHomeStateFlow.value = !isProfileOwner(dpm)
showDeactivateButton = dpm.isProfileOwner(context)
backToHomeStateFlow.value = !dpm.isProfileOwner(context)
}
}
) {
@@ -339,13 +338,13 @@ private fun ProfileOwner() {
@Composable
private fun DeviceOwner() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
var showDeactivateButton by remember { mutableStateOf(isDeviceOwner(dpm)) }
val dpm = context.getDPM()
var showDeactivateButton by remember { mutableStateOf(dpm.isDeviceOwner(context)) }
var deactivateDialog by remember { mutableStateOf(false) }
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(isDeviceOwner(dpm)) R.string.activated else R.string.deactivated), style = typography.titleLarge)
Text(text = stringResource(if(dpm.isDeviceOwner(context)) R.string.activated else R.string.deactivated), style = typography.titleLarge)
Spacer(Modifier.padding(vertical = 5.dp))
AnimatedVisibility(showDeactivateButton) {
Button(
@@ -383,8 +382,8 @@ private fun DeviceOwner() {
co.launch{
delay(300)
deactivateDialog = false
showDeactivateButton = isDeviceOwner(dpm)
backToHomeStateFlow.value = !isDeviceOwner(dpm)
showDeactivateButton = dpm.isDeviceOwner(context)
backToHomeStateFlow.value = !dpm.isDeviceOwner(context)
}
}
) {
@@ -398,13 +397,13 @@ private fun DeviceOwner() {
@Composable
fun DeviceInfo() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.device_info), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
if(VERSION.SDK_INT>=34 && (isDeviceOwner(dpm) || dpm.isOrgProfile(receiver))) {
if(VERSION.SDK_INT>=34 && (dpm.isDeviceOwner(context) || dpm.isOrgProfile(receiver))) {
val financed = dpm.isDeviceFinanced
Text(stringResource(R.string.is_device_financed, financed))
}
@@ -457,7 +456,7 @@ fun DeviceInfo() {
@Composable
private fun OrgID() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val dpm = context.getDPM()
val focusMgr = LocalFocusManager.current
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
var orgId by remember { mutableStateOf("") }
@@ -495,7 +494,7 @@ private fun OrgID() {
@Composable
private fun SpecificID() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val dpm = context.getDPM()
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
val specificId = dpm.enrollmentSpecificId
Spacer(Modifier.padding(vertical = 10.dp))
@@ -514,8 +513,8 @@ private fun SpecificID() {
@Composable
private fun OrgName() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
var orgName by remember { mutableStateOf(try{dpm.getOrganizationName(receiver).toString() }catch(e:SecurityException) {""}) }
@@ -546,8 +545,8 @@ private fun OrgName() {
@Composable
private fun SupportMsg() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
var shortMsg by remember { mutableStateOf(dpm.getShortSupportMessage(receiver)?.toString() ?: "") }
var longMsg by remember { mutableStateOf(dpm.getLongSupportMessage(receiver)?.toString() ?: "") }
@@ -605,8 +604,8 @@ private fun SupportMsg() {
@Composable
private fun DisableAccountManagement() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {
Spacer(Modifier.padding(vertical = 10.dp))
@@ -659,8 +658,8 @@ private fun DisableAccountManagement() {
@Composable
private fun TransformOwnership() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val receiver = ComponentName(context,Receiver::class.java)
val dpm = context.getDPM()
val receiver = context.getReceiver()
val focusMgr = LocalFocusManager.current
val focusRequester = FocusRequester()
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(horizontal = 8.dp)) {