Init
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material.AlertDialog
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import me.weishu.kernelsu.HyperlinkText
|
||||
|
||||
@Composable
|
||||
fun AboutDialog(openDialog: Boolean, onDismiss: () -> Unit) {
|
||||
|
||||
if (openDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
onDismiss()
|
||||
},
|
||||
title = {
|
||||
Text(text = "About")
|
||||
},
|
||||
text = {
|
||||
Column {
|
||||
|
||||
HyperlinkText(
|
||||
fullText = "Author: weishu",
|
||||
hyperLinks = mutableMapOf(
|
||||
"weishu" to "https://github.com/tiann",
|
||||
),
|
||||
textStyle = TextStyle(
|
||||
textAlign = TextAlign.Center,
|
||||
color = Color.Gray
|
||||
),
|
||||
linkTextColor = MaterialTheme.colors.secondary,
|
||||
)
|
||||
|
||||
HyperlinkText(
|
||||
fullText = "Github: https://github.com/tiann/KernelSU",
|
||||
hyperLinks = mutableMapOf(
|
||||
"https://github.com/tiann/KernelSU" to "https://github.com/tiann/KernelSU",
|
||||
),
|
||||
textStyle = TextStyle(
|
||||
textAlign = TextAlign.Center,
|
||||
color = Color.Gray
|
||||
),
|
||||
linkTextColor = MaterialTheme.colors.secondary,
|
||||
)
|
||||
|
||||
HyperlinkText(
|
||||
fullText = "Telegram: https://t.me/KernelSU",
|
||||
hyperLinks = mutableMapOf(
|
||||
"https://t.me/KernelSU" to "https://t.me/KernelSU",
|
||||
),
|
||||
textStyle = TextStyle(
|
||||
textAlign = TextAlign.Center,
|
||||
color = Color.Gray
|
||||
),
|
||||
linkTextColor = MaterialTheme.colors.secondary,
|
||||
)
|
||||
|
||||
HyperlinkText(
|
||||
fullText = "QQ: https://pd.qq.com/s/8lipl1brp",
|
||||
hyperLinks = mutableMapOf(
|
||||
"https://pd.qq.com/s/8lipl1brp" to "https://pd.qq.com/s/8lipl1brp",
|
||||
),
|
||||
textStyle = TextStyle(
|
||||
textAlign = TextAlign.Center,
|
||||
color = Color.Gray
|
||||
),
|
||||
linkTextColor = MaterialTheme.colors.secondary,
|
||||
)
|
||||
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = {
|
||||
onDismiss()
|
||||
}) {
|
||||
Text("OK")
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
118
manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt
Normal file
118
manager/app/src/main/java/me/weishu/kernelsu/ui/screen/Home.kt
Normal file
@@ -0,0 +1,118 @@
|
||||
import android.os.Build
|
||||
import android.system.Os
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Done
|
||||
import androidx.compose.material.icons.filled.Warning
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ClipboardManager
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import me.weishu.kernelsu.Natives
|
||||
import java.util.*
|
||||
|
||||
@Composable
|
||||
fun Info(label: String, value: String) {
|
||||
Text(
|
||||
buildAnnotatedString {
|
||||
append("$label: ")
|
||||
withStyle(
|
||||
style = SpanStyle(
|
||||
fontWeight = FontWeight.W900,
|
||||
color = MaterialTheme.colors.secondary
|
||||
)
|
||||
) {
|
||||
append(value)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Home() {
|
||||
|
||||
val isManager = Natives.becomeManager()
|
||||
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(6.dp)
|
||||
.clickable { },
|
||||
elevation = 10.dp,
|
||||
backgroundColor = MaterialTheme.colors.secondary
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
) {
|
||||
Image(
|
||||
if (isManager) Icons.Filled.Done else Icons.Filled.Warning,
|
||||
null,
|
||||
modifier = Modifier
|
||||
.size(64.dp)
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 10.dp),
|
||||
) {
|
||||
Text(
|
||||
text = if (isManager) "Installed" else "Not Installed",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Text(
|
||||
text = if (isManager) "Version: ${Natives.getVersion()}" else "Click to Install",
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.Normal
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(6.dp)
|
||||
.clickable { },
|
||||
elevation = 10.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(10.dp)
|
||||
) {
|
||||
|
||||
Os.uname().let { uname ->
|
||||
Info("Kernel", uname.release)
|
||||
Info("Arch", uname.machine)
|
||||
Info("Version", uname.version)
|
||||
}
|
||||
|
||||
Info("API Level", Build.VERSION.SDK_INT.toString())
|
||||
|
||||
Info("ABI", Build.SUPPORTED_ABIS.joinToString(", "))
|
||||
|
||||
Info("Fingerprint", Build.FINGERPRINT)
|
||||
|
||||
Info("Security Patch", Build.VERSION.SECURITY_PATCH)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun Module() {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(6.dp)
|
||||
.clickable { },
|
||||
elevation = 10.dp
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(10.dp)
|
||||
) {
|
||||
|
||||
|
||||
Text("Coming Soon..")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.Checkbox
|
||||
import androidx.compose.material.Switch
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||
import me.weishu.kernelsu.Natives
|
||||
import java.util.*
|
||||
|
||||
class SuperUserData(
|
||||
val name: CharSequence,
|
||||
val description: String,
|
||||
val icon: Drawable,
|
||||
val uid: Int,
|
||||
initialChecked: Boolean = false
|
||||
) {
|
||||
var checked: Boolean by mutableStateOf(initialChecked)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SuperUserItem(
|
||||
superUserData: SuperUserData,
|
||||
checked: Boolean,
|
||||
onCheckedChange: (Boolean) -> Unit,
|
||||
onItemClick: () -> Unit
|
||||
) {
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
onItemClick()
|
||||
}) {
|
||||
|
||||
Image(
|
||||
painter = rememberDrawablePainter(drawable = superUserData.icon),
|
||||
contentDescription = superUserData.name.toString(),
|
||||
modifier = Modifier
|
||||
.padding(4.dp)
|
||||
.width(48.dp)
|
||||
.height(48.dp)
|
||||
)
|
||||
|
||||
Column {
|
||||
Text(
|
||||
superUserData.name.toString(),
|
||||
modifier = Modifier.padding(4.dp),
|
||||
color = Color.Black,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
Text(
|
||||
superUserData.description,
|
||||
modifier = Modifier.padding(4.dp),
|
||||
color = Color.Gray,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Switch(
|
||||
checked = checked,
|
||||
onCheckedChange = onCheckedChange,
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAppList(context: Context): List<SuperUserData> {
|
||||
val pm = context.packageManager
|
||||
val allowList = Natives.getAllowList()
|
||||
val denyList = Natives.getDenyList();
|
||||
|
||||
Log.i("mylog", "allowList: ${Arrays.toString(allowList)}")
|
||||
Log.i("mylog", "denyList: ${Arrays.toString(denyList)}")
|
||||
|
||||
val result = mutableListOf<SuperUserData>()
|
||||
|
||||
// add allow list
|
||||
for (uid in allowList) {
|
||||
val packagesForUid = pm.getPackagesForUid(uid)
|
||||
if (packagesForUid == null || packagesForUid.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
|
||||
packagesForUid.forEach { packageName ->
|
||||
val applicationInfo = pm.getApplicationInfo(packageName, 0)
|
||||
result.add(
|
||||
SuperUserData(
|
||||
name = applicationInfo.loadLabel(pm),
|
||||
description = applicationInfo.packageName,
|
||||
icon = applicationInfo.loadIcon(pm),
|
||||
uid = uid,
|
||||
initialChecked = true
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// add deny list
|
||||
for (uid in denyList) {
|
||||
val packagesForUid = pm.getPackagesForUid(uid)
|
||||
if (packagesForUid == null || packagesForUid.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
|
||||
packagesForUid.forEach { packageName ->
|
||||
val applicationInfo = pm.getApplicationInfo(packageName, 0)
|
||||
result.add(
|
||||
SuperUserData(
|
||||
name = applicationInfo.loadLabel(pm),
|
||||
description = applicationInfo.packageName,
|
||||
icon = applicationInfo.loadIcon(pm),
|
||||
uid = uid,
|
||||
initialChecked = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@SuppressLint("QueryPermissionsNeeded")
|
||||
@Composable
|
||||
fun SuperUser() {
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
val list = getAppList(context)
|
||||
val apps = remember { list.toMutableStateList() }
|
||||
|
||||
if (apps.isEmpty()) {
|
||||
Text("No apps found")
|
||||
return
|
||||
}
|
||||
|
||||
LazyColumn() {
|
||||
items(apps, key = { it.description }) { app ->
|
||||
SuperUserItem(
|
||||
superUserData = app,
|
||||
checked = app.checked,
|
||||
onCheckedChange = { checked ->
|
||||
val success = Natives.allowRoot(app.uid, checked)
|
||||
if (success) {
|
||||
app.checked = checked
|
||||
} else {
|
||||
Toast.makeText(
|
||||
context,
|
||||
"Failed to allow root: ${app.uid}",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
},
|
||||
onItemClick = {
|
||||
// TODO
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package me.weishu.kernelsu.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val YELLOW = Color(0xFFeed502)
|
||||
val YELLOW_LIGHT = Color(0xFFffff52)
|
||||
val SECONDARY_LIGHT = Color(0xffa9817f)
|
||||
|
||||
val YELLOW_DARK = Color(0xFFb7a400)
|
||||
val SECONDARY_DARK = Color(0xFF4c2b2b)
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.weishu.kernelsu.ui.theme
|
||||
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
val Shapes = Shapes(
|
||||
small = RoundedCornerShape(4.dp),
|
||||
medium = RoundedCornerShape(4.dp),
|
||||
large = RoundedCornerShape(0.dp)
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.weishu.kernelsu.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
private val DarkColorPalette = darkColors(
|
||||
primary = YELLOW,
|
||||
primaryVariant = YELLOW_DARK,
|
||||
secondary = SECONDARY_DARK
|
||||
)
|
||||
|
||||
private val LightColorPalette = lightColors(
|
||||
primary = YELLOW,
|
||||
primaryVariant = YELLOW_LIGHT,
|
||||
secondary = SECONDARY_LIGHT
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun KernelSUTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
val colors = if (darkTheme) {
|
||||
DarkColorPalette
|
||||
} else {
|
||||
LightColorPalette
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colors = colors,
|
||||
typography = Typography,
|
||||
shapes = Shapes,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.weishu.kernelsu.ui.theme
|
||||
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
body1 = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp
|
||||
)
|
||||
/* Other default text styles to override
|
||||
button = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.W500,
|
||||
fontSize = 14.sp
|
||||
),
|
||||
caption = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 12.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
Reference in New Issue
Block a user