mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-14 08:37:25 +00:00
Refactor sepolicy.rules resolve app
This commit is contained in:
@@ -10,7 +10,7 @@ import com.topjohnwu.magisk.ui.home.HomeViewModel
|
|||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class EnvFixDialog(private val vm: HomeViewModel) : DialogEvent() {
|
class EnvFixDialog(private val vm: HomeViewModel, private val code: Int) : DialogEvent() {
|
||||||
|
|
||||||
override fun build(dialog: MagiskDialog) {
|
override fun build(dialog: MagiskDialog) {
|
||||||
dialog.apply {
|
dialog.apply {
|
||||||
@@ -38,8 +38,10 @@ class EnvFixDialog(private val vm: HomeViewModel) : DialogEvent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.env.versionCode != BuildConfig.VERSION_CODE ||
|
if (code == 2 || // No rules block, module policy not loaded
|
||||||
|
Info.env.versionCode != BuildConfig.VERSION_CODE ||
|
||||||
Info.env.versionString != BuildConfig.VERSION_NAME) {
|
Info.env.versionString != BuildConfig.VERSION_NAME) {
|
||||||
|
dialog.setMessage(R.string.env_full_fix_msg)
|
||||||
dialog.setButton(MagiskDialog.ButtonType.POSITIVE) {
|
dialog.setButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||||
text = android.R.string.ok
|
text = android.R.string.ok
|
||||||
onClick {
|
onClick {
|
||||||
|
@@ -135,8 +135,9 @@ class HomeViewModel(
|
|||||||
private suspend fun ensureEnv() {
|
private suspend fun ensureEnv() {
|
||||||
if (magiskState == State.INVALID || checkedEnv) return
|
if (magiskState == State.INVALID || checkedEnv) return
|
||||||
val cmd = "env_check ${Info.env.versionString} ${Info.env.versionCode}"
|
val cmd = "env_check ${Info.env.versionString} ${Info.env.versionCode}"
|
||||||
if (!Shell.cmd(cmd).await().isSuccess) {
|
val code = Shell.cmd(cmd).await().code
|
||||||
EnvFixDialog(this).publish()
|
if (code != 0) {
|
||||||
|
EnvFixDialog(this, code).publish()
|
||||||
}
|
}
|
||||||
checkedEnv = true
|
checkedEnv = true
|
||||||
}
|
}
|
||||||
|
@@ -13,8 +13,11 @@ env_check() {
|
|||||||
if [ "$2" -ge 25000 ]; then
|
if [ "$2" -ge 25000 ]; then
|
||||||
[ -f "$MAGISKBIN/magiskpolicy" ] || return 1
|
[ -f "$MAGISKBIN/magiskpolicy" ] || return 1
|
||||||
fi
|
fi
|
||||||
grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 1
|
if [ "$2" -ge 25210 ]; then
|
||||||
grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 1
|
[ -b "$MAGISKTMP/block/rules" ] || return 2
|
||||||
|
fi
|
||||||
|
grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 3
|
||||||
|
grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 3
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ fix_env() {
|
|||||||
rm -rf $MAGISKBIN/*
|
rm -rf $MAGISKBIN/*
|
||||||
mkdir -p $MAGISKBIN 2>/dev/null
|
mkdir -p $MAGISKBIN 2>/dev/null
|
||||||
chmod 700 $NVBASE
|
chmod 700 $NVBASE
|
||||||
rm $1/stub.apk
|
rm $1/stub.apk 2>/dev/null
|
||||||
cp_readlink $1 $MAGISKBIN
|
cp_readlink $1 $MAGISKBIN
|
||||||
rm -rf $1
|
rm -rf $1
|
||||||
chown -R 0:0 $MAGISKBIN
|
chown -R 0:0 $MAGISKBIN
|
||||||
|
@@ -219,6 +219,7 @@
|
|||||||
<string name="setup_fail">Setup failed</string>
|
<string name="setup_fail">Setup failed</string>
|
||||||
<string name="env_fix_title">Requires Additional Setup</string>
|
<string name="env_fix_title">Requires Additional Setup</string>
|
||||||
<string name="env_fix_msg">Your device needs additional setup for Magisk to work properly. Do you want to proceed and reboot?</string>
|
<string name="env_fix_msg">Your device needs additional setup for Magisk to work properly. Do you want to proceed and reboot?</string>
|
||||||
|
<string name="env_full_fix_msg">Your device needs reflash Magisk to work properly. Please reinstall Magisk within app, recovery mode cannot get correct device info.</string>
|
||||||
<string name="setup_msg">Running environment setup…</string>
|
<string name="setup_msg">Running environment setup…</string>
|
||||||
<string name="authenticate">Authenticate</string>
|
<string name="authenticate">Authenticate</string>
|
||||||
<string name="unsupport_magisk_title">Unsupported Magisk Version</string>
|
<string name="unsupport_magisk_title">Unsupported Magisk Version</string>
|
||||||
|
Reference in New Issue
Block a user