mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Add Superuser detail screen with policy row component
Redesign the Superuser list with a clickable card + vertical divider + switch layout. Tapping the left area navigates to a new detail screen showing app info, notification/logging switches, restricted root capabilities toggle (when enabled globally), and a revoke action. Made-with: Cursor
This commit is contained in:
@@ -45,6 +45,8 @@ import com.topjohnwu.magisk.ui.install.InstallScreen
|
||||
import com.topjohnwu.magisk.ui.install.InstallViewModel
|
||||
import com.topjohnwu.magisk.ui.module.ActionScreen
|
||||
import com.topjohnwu.magisk.ui.module.ActionViewModel
|
||||
import com.topjohnwu.magisk.ui.superuser.SuperuserDetailScreen
|
||||
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
|
||||
import com.topjohnwu.magisk.ui.navigation.CollectNavEvents
|
||||
import com.topjohnwu.magisk.ui.navigation.LocalNavigator
|
||||
import com.topjohnwu.magisk.ui.navigation.Navigator
|
||||
@@ -146,6 +148,13 @@ class MainActivity : UIActivity(), SplashScreenHost {
|
||||
ObserveViewEvents(vm)
|
||||
FlashScreen(vm, onBack = { navigator.pop() })
|
||||
}
|
||||
entry<Route.SuperuserDetail> { key ->
|
||||
val vm: SuperuserViewModel = androidx.lifecycle.viewmodel.compose.viewModel(
|
||||
viewModelStoreOwner = this@MainActivity, factory = VMFactory
|
||||
)
|
||||
ObserveViewEvents(vm)
|
||||
SuperuserDetailScreen(uid = key.uid, viewModel = vm, onBack = { navigator.pop() })
|
||||
}
|
||||
entry<Route.Action> { key ->
|
||||
val vm: ActionViewModel = androidx.lifecycle.viewmodel.compose.viewModel(factory = VMFactory)
|
||||
LaunchedEffect(key) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
@@ -90,7 +91,8 @@ fun MainScreen(initialTab: Int = 0) {
|
||||
HomeScreen(vm)
|
||||
}
|
||||
Tab.SUPERUSER -> {
|
||||
val vm: SuperuserViewModel = viewModel(factory = VMFactory)
|
||||
val activity = LocalContext.current as androidx.activity.ComponentActivity
|
||||
val vm: SuperuserViewModel = viewModel(viewModelStoreOwner = activity, factory = VMFactory)
|
||||
LaunchedEffect(Unit) { vm.startLoading() }
|
||||
ObserveViewEvents(vm)
|
||||
SuperuserScreen(vm)
|
||||
|
||||
@@ -27,6 +27,10 @@ sealed interface Route : NavKey, Parcelable {
|
||||
val additionalData: String? = null,
|
||||
) : Route
|
||||
|
||||
@Parcelize
|
||||
@Serializable
|
||||
data class SuperuserDetail(val uid: Int) : Route
|
||||
|
||||
@Parcelize
|
||||
@Serializable
|
||||
data class Action(
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
package com.topjohnwu.magisk.ui.superuser
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.topjohnwu.magisk.ui.util.rememberDrawablePainter
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.Icon
|
||||
import top.yukonga.miuix.kmp.basic.IconButton
|
||||
import top.yukonga.miuix.kmp.basic.MiuixScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||
import top.yukonga.miuix.kmp.basic.Switch
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.icon.MiuixIcons
|
||||
import top.yukonga.miuix.kmp.icon.extended.Back
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
|
||||
@Composable
|
||||
fun SuperuserDetailScreen(
|
||||
uid: Int,
|
||||
viewModel: SuperuserViewModel,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val items = uiState.policies.filter { it.policy.uid == uid }
|
||||
val item = items.firstOrNull()
|
||||
val scrollBehavior = MiuixScrollBehavior()
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = item?.title ?: "",
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
imageVector = MiuixIcons.Back,
|
||||
contentDescription = stringResource(CoreR.string.back),
|
||||
)
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
},
|
||||
popupHost = { }
|
||||
) { padding ->
|
||||
if (item == null) return@Scaffold
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.nestedScroll(scrollBehavior.nestedScrollConnection)
|
||||
.padding(padding)
|
||||
.padding(horizontal = 12.dp),
|
||||
contentPadding = PaddingValues(bottom = 88.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
item {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
}
|
||||
|
||||
item {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Row(
|
||||
modifier = Modifier.padding(16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Image(
|
||||
painter = rememberDrawablePainter(item.icon),
|
||||
contentDescription = item.appName,
|
||||
modifier = Modifier.size(48.dp)
|
||||
)
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = item.title,
|
||||
style = MiuixTheme.textStyles.headline2,
|
||||
)
|
||||
Text(
|
||||
text = item.packageName,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
Text(
|
||||
text = "UID: ${item.policy.uid}",
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column {
|
||||
if (item.showSlider) {
|
||||
SwitchRow(
|
||||
title = stringResource(CoreR.string.settings_su_restrict_title),
|
||||
summary = stringResource(
|
||||
if (item.isRestricted) CoreR.string.enabled else CoreR.string.disabled
|
||||
),
|
||||
checked = item.isRestricted,
|
||||
onCheckedChange = { viewModel.toggleRestrict(item) }
|
||||
)
|
||||
}
|
||||
SwitchRow(
|
||||
title = stringResource(CoreR.string.superuser_toggle_notification),
|
||||
summary = stringResource(
|
||||
if (item.notification) CoreR.string.enabled else CoreR.string.disabled
|
||||
),
|
||||
checked = item.notification,
|
||||
onCheckedChange = { viewModel.updateNotify(item) }
|
||||
)
|
||||
SwitchRow(
|
||||
title = stringResource(CoreR.string.logs),
|
||||
summary = stringResource(
|
||||
if (item.logging) CoreR.string.enabled else CoreR.string.disabled
|
||||
),
|
||||
checked = item.logging,
|
||||
onCheckedChange = { viewModel.updateLogging(item) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
viewModel.deletePressed(item)
|
||||
onBack()
|
||||
}
|
||||
) {
|
||||
RevokeRow()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SwitchRow(
|
||||
title: String,
|
||||
summary: String,
|
||||
checked: Boolean,
|
||||
onCheckedChange: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
)
|
||||
Text(
|
||||
text = summary,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary,
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(16.dp))
|
||||
Switch(
|
||||
checked = checked,
|
||||
onCheckedChange = { onCheckedChange() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RevokeRow() {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.superuser_toggle_revoke),
|
||||
style = MiuixTheme.textStyles.body1,
|
||||
color = MiuixTheme.colorScheme.error,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||
)
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.topjohnwu.magisk.ui.superuser
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -20,23 +22,21 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import com.topjohnwu.magisk.ui.util.rememberDrawablePainter
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.topjohnwu.magisk.core.model.su.SuPolicy
|
||||
import com.topjohnwu.magisk.ui.navigation.LocalNavigator
|
||||
import com.topjohnwu.magisk.ui.navigation.Route
|
||||
import com.topjohnwu.magisk.ui.util.rememberDrawablePainter
|
||||
import top.yukonga.miuix.kmp.basic.Card
|
||||
import top.yukonga.miuix.kmp.basic.CircularProgressIndicator
|
||||
import top.yukonga.miuix.kmp.basic.MiuixScrollBehavior
|
||||
import top.yukonga.miuix.kmp.basic.Scaffold
|
||||
import top.yukonga.miuix.kmp.basic.Slider
|
||||
import top.yukonga.miuix.kmp.basic.Switch
|
||||
import top.yukonga.miuix.kmp.basic.Text
|
||||
import top.yukonga.miuix.kmp.basic.TextButton
|
||||
import top.yukonga.miuix.kmp.basic.TopAppBar
|
||||
import top.yukonga.miuix.kmp.theme.MiuixTheme
|
||||
import com.topjohnwu.magisk.core.R as CoreR
|
||||
@@ -45,6 +45,7 @@ import com.topjohnwu.magisk.core.R as CoreR
|
||||
fun SuperuserScreen(viewModel: SuperuserViewModel) {
|
||||
val uiState by viewModel.uiState.collectAsState()
|
||||
val scrollBehavior = MiuixScrollBehavior()
|
||||
val navigator = LocalNavigator.current
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -94,7 +95,11 @@ fun SuperuserScreen(viewModel: SuperuserViewModel) {
|
||||
) {
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
items(uiState.policies, key = { "${it.policy.uid}_${it.packageName}" }) { item ->
|
||||
PolicyCard(item = item, viewModel = viewModel)
|
||||
PolicyCard(
|
||||
item = item,
|
||||
onToggle = { viewModel.togglePolicy(item) },
|
||||
onDetail = { navigator.push(Route.SuperuserDetail(item.policy.uid)) },
|
||||
)
|
||||
}
|
||||
item { Spacer(Modifier.height(4.dp)) }
|
||||
}
|
||||
@@ -102,16 +107,26 @@ fun SuperuserScreen(viewModel: SuperuserViewModel) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PolicyCard(item: PolicyItem, viewModel: SuperuserViewModel) {
|
||||
private fun PolicyCard(
|
||||
item: PolicyItem,
|
||||
onToggle: () -> Unit,
|
||||
onDetail: () -> Unit,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.alpha(if (item.isEnabled) 1f else 0.5f)
|
||||
) {
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(IntrinsicSize.Min),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { item.isExpanded = !item.isExpanded }
|
||||
.weight(1f)
|
||||
.clickable(onClick = onDetail)
|
||||
.padding(16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
@@ -132,85 +147,27 @@ private fun PolicyCard(item: PolicyItem, viewModel: SuperuserViewModel) {
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(8.dp))
|
||||
if (item.showSlider) {
|
||||
PolicySlider(
|
||||
value = item.policyValue,
|
||||
onValueChange = { viewModel.updatePolicy(item, it) }
|
||||
)
|
||||
} else {
|
||||
Switch(
|
||||
checked = item.isEnabled,
|
||||
onCheckedChange = { viewModel.togglePolicy(item) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedVisibility(visible = item.isExpanded) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp, vertical = 4.dp),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.superuser_toggle_notification),
|
||||
onClick = { viewModel.updateNotify(item) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.logs),
|
||||
onClick = { viewModel.updateLogging(item) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
TextButton(
|
||||
text = stringResource(CoreR.string.superuser_toggle_revoke),
|
||||
onClick = { viewModel.deletePressed(item) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.padding(vertical = 12.dp)
|
||||
.width(0.5.dp)
|
||||
.background(MiuixTheme.colorScheme.dividerLine)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clickable(onClick = onToggle)
|
||||
.padding(horizontal = 20.dp, vertical = 16.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Switch(
|
||||
checked = item.isEnabled,
|
||||
onCheckedChange = { onToggle() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PolicySlider(value: Int, onValueChange: (Int) -> Unit) {
|
||||
val sliderValue = when (value) {
|
||||
SuPolicy.DENY -> 0f
|
||||
SuPolicy.RESTRICT -> 0.5f
|
||||
SuPolicy.ALLOW -> 1f
|
||||
else -> 0f
|
||||
}
|
||||
val label = when (value) {
|
||||
SuPolicy.DENY -> stringResource(CoreR.string.deny)
|
||||
SuPolicy.RESTRICT -> stringResource(CoreR.string.restrict)
|
||||
SuPolicy.ALLOW -> stringResource(CoreR.string.grant)
|
||||
else -> stringResource(CoreR.string.deny)
|
||||
}
|
||||
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.width(96.dp)
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
style = MiuixTheme.textStyles.body2,
|
||||
color = MiuixTheme.colorScheme.onSurfaceVariantSummary
|
||||
)
|
||||
Slider(
|
||||
value = sliderValue,
|
||||
onValueChange = { newVal ->
|
||||
val newPolicy = when {
|
||||
newVal < 0.25f -> SuPolicy.DENY
|
||||
newVal < 0.75f -> SuPolicy.RESTRICT
|
||||
else -> SuPolicy.ALLOW
|
||||
}
|
||||
if (newPolicy != value) onValueChange(newPolicy)
|
||||
},
|
||||
steps = 1,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class PolicyItem(
|
||||
var logging by mutableStateOf(policy.logging)
|
||||
|
||||
val isEnabled get() = policyValue >= SuPolicy.ALLOW
|
||||
val isRestricted get() = policyValue == SuPolicy.RESTRICT
|
||||
}
|
||||
|
||||
class SuperuserViewModel(
|
||||
@@ -175,4 +176,9 @@ class SuperuserViewModel(
|
||||
val newPolicy = if (item.isEnabled) SuPolicy.DENY else SuPolicy.ALLOW
|
||||
updatePolicy(item, newPolicy)
|
||||
}
|
||||
|
||||
fun toggleRestrict(item: PolicyItem) {
|
||||
val newPolicy = if (item.isRestricted) SuPolicy.ALLOW else SuPolicy.RESTRICT
|
||||
updatePolicy(item, newPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@
|
||||
<string name="logs_cleared">Log successfully cleared</string>
|
||||
<string name="save_log">Save log</string>
|
||||
<string name="clear_log">Clear log</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="enabled">Enabled</string>
|
||||
<string name="disabled">Disabled</string>
|
||||
<string name="pid">PID: %1$d</string>
|
||||
<string name="target_uid">Target UID: %1$d</string>
|
||||
<string name="target_pid">Target PID: %s</string>
|
||||
|
||||
Reference in New Issue
Block a user