manager: show profile info in superuser list

This commit is contained in:
weishu
2023-06-03 17:17:19 +08:00
parent 2a33433272
commit 66827ab7de
3 changed files with 64 additions and 11 deletions

View File

@@ -111,6 +111,10 @@ Java_me_weishu_kernelsu_Natives_getAppProfile(JNIEnv *env, jobject, jstring pkg,
strcpy(profile.key, key); strcpy(profile.key, key);
profile.current_uid = uid; profile.current_uid = uid;
// set default value, don't allow root and use default profile!
profile.allow_su = false;
profile.non_root_profile.use_default = true;
if (!get_app_profile(key, &profile)) { if (!get_app_profile(key, &profile)) {
return nullptr; return nullptr;
} }

View File

@@ -1,9 +1,11 @@
package me.weishu.kernelsu.ui.screen package me.weishu.kernelsu.ui.screen
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
@@ -14,9 +16,12 @@ import androidx.compose.material3.*
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
import coil.request.ImageRequest import coil.request.ImageRequest
@@ -119,6 +124,7 @@ fun SuperUserScreen(navigator: DestinationsNavigator) {
} }
} }
@OptIn(ExperimentalLayoutApi::class)
@Composable @Composable
private fun AppItem( private fun AppItem(
app: SuperUserViewModel.AppInfo, app: SuperUserViewModel.AppInfo,
@@ -127,7 +133,19 @@ private fun AppItem(
ListItem( ListItem(
modifier = Modifier.clickable(onClick = onClickListener), modifier = Modifier.clickable(onClick = onClickListener),
headlineContent = { Text(app.label) }, headlineContent = { Text(app.label) },
supportingContent = { Text(app.packageName) }, supportingContent = {
Column {
Text(app.packageName)
FlowRow {
if (app.allowSu) {
LabelText(label = "ROOT")
}
if (app.hasCustomProfile) {
LabelText(label = "CUSTOM")
}
}
}
},
leadingContent = { leadingContent = {
AsyncImage( AsyncImage(
model = ImageRequest.Builder(LocalContext.current) model = ImageRequest.Builder(LocalContext.current)
@@ -143,3 +161,24 @@ private fun AppItem(
}, },
) )
} }
@Composable
fun LabelText(label: String) {
Box(
modifier = Modifier
.padding(top = 4.dp, end = 4.dp)
.background(
Color.Black,
shape = RoundedCornerShape(4.dp)
)
) {
Text(
text = label,
modifier = Modifier.padding(vertical = 2.dp, horizontal = 5.dp),
style = TextStyle(
fontSize = 8.sp,
color = Color.White,
)
)
}
}

View File

@@ -40,13 +40,27 @@ class SuperUserViewModel : ViewModel() {
data class AppInfo( data class AppInfo(
val label: String, val label: String,
val packageInfo: PackageInfo, val packageInfo: PackageInfo,
val onAllowList: Boolean, val profile: Natives.Profile?,
val onDenyList: Boolean,
) : Parcelable { ) : Parcelable {
val packageName: String val packageName: String
get() = packageInfo.packageName get() = packageInfo.packageName
val uid: Int val uid: Int
get() = packageInfo.applicationInfo.uid get() = packageInfo.applicationInfo.uid
val allowSu: Boolean
get() = profile != null && profile.allowSu
val hasCustomProfile: Boolean
get() {
if (profile == null) {
return false
}
return if (profile.allowSu) {
!profile.rootUseDefault
} else {
!profile.nonRootUseDefault
}
}
} }
var search by mutableStateOf("") var search by mutableStateOf("")
@@ -57,8 +71,8 @@ class SuperUserViewModel : ViewModel() {
private val sortedList by derivedStateOf { private val sortedList by derivedStateOf {
val comparator = compareBy<AppInfo> { val comparator = compareBy<AppInfo> {
when { when {
it.onAllowList -> 0 it.allowSu -> 0
it.onDenyList -> 1 it.hasCustomProfile -> 1
else -> 2 else -> 2
} }
}.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label)) }.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label))
@@ -116,10 +130,6 @@ class SuperUserViewModel : ViewModel() {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val pm = ksuApp.packageManager val pm = ksuApp.packageManager
val allowList = Natives.allowList.toSet()
val denyList = Natives.denyList.toSet()
Log.i(TAG, "allowList: $allowList")
Log.i(TAG, "denyList: $denyList")
val start = SystemClock.elapsedRealtime() val start = SystemClock.elapsedRealtime()
val binder = result.first val binder = result.first
@@ -134,11 +144,11 @@ class SuperUserViewModel : ViewModel() {
apps = packages.map { apps = packages.map {
val appInfo = it.applicationInfo val appInfo = it.applicationInfo
val uid = appInfo.uid val uid = appInfo.uid
val profile = Natives.getAppProfile(it.packageName, uid)
AppInfo( AppInfo(
label = appInfo.loadLabel(pm).toString(), label = appInfo.loadLabel(pm).toString(),
packageInfo = it, packageInfo = it,
onAllowList = uid in allowList, profile = profile,
onDenyList = uid in denyList
) )
}.filter { it.packageName != ksuApp.packageName } }.filter { it.packageName != ksuApp.packageName }
Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}") Log.i(TAG, "load cost: ${SystemClock.elapsedRealtime() - start}")