Improve UI

This commit is contained in:
BinTianqi
2025-05-17 14:03:17 +08:00
parent fdcb7c179f
commit b547c8add8
9 changed files with 112 additions and 68 deletions

View File

@@ -32,7 +32,6 @@ import com.bintianqi.owndroid.backToHomeStateFlow
import com.bintianqi.owndroid.createShortcuts
import com.bintianqi.owndroid.myPrivilege
import com.rosan.dhizuku.api.Dhizuku
import com.rosan.dhizuku.api.Dhizuku.binderWrapper
import com.rosan.dhizuku.api.DhizukuBinderWrapper
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.serialization.encodeToString
@@ -73,7 +72,7 @@ fun binderWrapperDevicePolicyManager(appContext: Context): DevicePolicyManager?
val oldInterface = field[manager] as IDevicePolicyManager
if (oldInterface is DhizukuBinderWrapper) return manager
val oldBinder = oldInterface.asBinder()
val newBinder = binderWrapper(oldBinder)
val newBinder = Dhizuku.binderWrapper(oldBinder)
val newInterface = IDevicePolicyManager.Stub.asInterface(newBinder)
field[manager] = newInterface
return manager
@@ -93,7 +92,7 @@ private fun binderWrapperPackageInstaller(appContext: Context): PackageInstaller
val oldInterface = field[installer] as IPackageInstaller
if (oldInterface is DhizukuBinderWrapper) return installer
val oldBinder = oldInterface.asBinder()
val newBinder = binderWrapper(oldBinder)
val newBinder = Dhizuku.binderWrapper(oldBinder)
val newInterface = IPackageInstaller.Stub.asInterface(newBinder)
field[installer] = newInterface
return installer
@@ -107,7 +106,6 @@ fun Context.getPackageInstaller(): PackageInstaller {
if(SharedPrefs(this).dhizuku) {
if (!dhizukuPermissionGranted()) {
dhizukuErrorStatus.value = 2
backToHomeStateFlow.value = true
return this.packageManager.packageInstaller
}
return binderWrapperPackageInstaller(this) ?: this.packageManager.packageInstaller
@@ -120,7 +118,6 @@ fun Context.getDPM(): DevicePolicyManager {
if(SharedPrefs(this).dhizuku) {
if (!dhizukuPermissionGranted()) {
dhizukuErrorStatus.value = 2
backToHomeStateFlow.value = true
return this.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
}
return binderWrapperDevicePolicyManager(this) ?: this.getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager

View File

@@ -295,7 +295,7 @@ fun WorkModesScreen(
Spacer(Modifier.padding(horizontal = 2.dp))
Button({ dialog = 5 }) { Text(stringResource(R.string.adb_command)) }
Spacer(Modifier.padding(horizontal = 2.dp))
if (VERSION.SDK_INT == 35) Button({
if (VERSION.SDK_INT >= 33) Button({
dialog = 6
}) {
Text(stringResource(R.string.root_force_activate))
@@ -575,6 +575,7 @@ fun LockScreenInfoScreen(onNavigateUp: () -> Unit) {
onClick = {
focusMgr.clearFocus()
dpm.setDeviceOwnerLockScreenInfo(receiver, null)
infoText = ""
context.showOperationResultToast(true)
},
modifier = Modifier.fillMaxWidth()

View File

@@ -10,8 +10,12 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -73,14 +77,30 @@ data class UserRestrictionOptions(
@RequiresApi(24)
@Composable
fun UserRestrictionOptionsScreen(
data: UserRestrictionOptions, restrictions: Bundle,
onNavigateUp: () -> Unit, onRestrictionChange: (String, Boolean) -> Unit
data: UserRestrictionOptions, onNavigateUp: () -> Unit
) {
val context = LocalContext.current
val dpm = context.getDPM()
val receiver = context.getReceiver()
val status = remember { mutableStateMapOf<String, Boolean>() }
LaunchedEffect(Unit) {
val restrictions = dpm.getUserRestrictions(receiver)
data.items.forEach {
status.put(it.id, restrictions.getBoolean(it.id))
}
}
MyScaffold(data.title, onNavigateUp, 0.dp) {
data.items.filter { Build.VERSION.SDK_INT >= it.requiresApi }.forEach { restriction ->
SwitchItem(
restriction.name, restriction.id, restriction.icon,
restrictions.getBoolean(restriction.id), { onRestrictionChange(restriction.id, it) }, padding = true
restriction.name, restriction.id, restriction.icon, status[restriction.id] == true,
{
if (it) {
dpm.addUserRestriction(receiver, restriction.id)
} else {
dpm.clearUserRestriction(receiver, restriction.id)
}
status[restriction.id] = dpm.getUserRestrictions(receiver).getBoolean(restriction.id)
}, padding = true
)
}
}