mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 09:27:47 +00:00
Update root shell preparation
This commit is contained in:
parent
5fb071d80b
commit
e85d5e54e2
@ -8,7 +8,7 @@ import com.topjohnwu.magisk.extensions.subscribeK
|
|||||||
import com.topjohnwu.magisk.utils.CachedValue
|
import com.topjohnwu.magisk.utils.CachedValue
|
||||||
import com.topjohnwu.magisk.utils.KObservableField
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import com.topjohnwu.superuser.ShellUtils
|
import com.topjohnwu.superuser.ShellUtils.fastCmd
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@ -56,12 +56,11 @@ object Info {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadState() = runCatching {
|
private fun loadState() = Env(
|
||||||
val str = ShellUtils.fastCmd("magisk -v").split(":".toRegex())[0]
|
fastCmd("magisk -v").split(":".toRegex())[0],
|
||||||
val code = ShellUtils.fastCmd("magisk -V").toInt()
|
runCatching { fastCmd("magisk -V").toInt() }.getOrDefault(-1),
|
||||||
val hide = Shell.su("magiskhide --status").exec().isSuccess
|
Shell.su("magiskhide --status").exec().isSuccess
|
||||||
Env(str, code, hide)
|
)
|
||||||
}.getOrElse { Env() }
|
|
||||||
|
|
||||||
class Env(
|
class Env(
|
||||||
val magiskVersionString: String = "",
|
val magiskVersionString: String = "",
|
||||||
@ -71,7 +70,7 @@ object Info {
|
|||||||
val magiskHide get() = Config.magiskHide
|
val magiskHide get() = Config.magiskHide
|
||||||
val magiskVersionCode = when (code) {
|
val magiskVersionCode = when (code) {
|
||||||
in Int.MIN_VALUE..Const.Version.MIN_VERCODE -> -1
|
in Int.MIN_VALUE..Const.Version.MIN_VERCODE -> -1
|
||||||
else -> if(Shell.rootAccess()) code else -1
|
else -> if (Shell.rootAccess()) code else -1
|
||||||
}
|
}
|
||||||
val isUnsupported = code > 0 && code < Const.Version.MIN_VERCODE
|
val isUnsupported = code > 0 && code < Const.Version.MIN_VERCODE
|
||||||
val isActive = magiskVersionCode >= 0
|
val isActive = magiskVersionCode >= 0
|
||||||
|
@ -4,12 +4,12 @@ import android.app.Activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.topjohnwu.magisk.BuildConfig
|
import com.topjohnwu.magisk.BuildConfig
|
||||||
|
import com.topjohnwu.magisk.core.tasks.patchDTB
|
||||||
import com.topjohnwu.magisk.core.utils.Utils
|
import com.topjohnwu.magisk.core.utils.Utils
|
||||||
import com.topjohnwu.magisk.core.view.Notifications
|
import com.topjohnwu.magisk.core.view.Notifications
|
||||||
import com.topjohnwu.magisk.core.view.Shortcuts
|
import com.topjohnwu.magisk.core.view.Shortcuts
|
||||||
import com.topjohnwu.magisk.model.navigation.Navigation
|
import com.topjohnwu.magisk.model.navigation.Navigation
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import com.topjohnwu.superuser.ShellUtils
|
|
||||||
|
|
||||||
open class SplashActivity : Activity() {
|
open class SplashActivity : Activity() {
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ open class SplashActivity : Activity() {
|
|||||||
Shell.getShell { initAndStart() }
|
Shell.getShell { initAndStart() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initAndStart() {
|
private fun handleRepackage() {
|
||||||
val pkg = Config.suManager
|
val pkg = Config.suManager
|
||||||
if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) {
|
if (Config.suManager.isNotEmpty() && packageName == BuildConfig.APPLICATION_ID) {
|
||||||
Config.suManager = ""
|
Config.suManager = ""
|
||||||
@ -35,31 +35,17 @@ open class SplashActivity : Activity() {
|
|||||||
Shell.su("pm uninstall " + BuildConfig.APPLICATION_ID).submit()
|
Shell.su("pm uninstall " + BuildConfig.APPLICATION_ID).submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Info.keepVerity = ShellUtils.fastCmd("echo \$KEEPVERITY").toBoolean()
|
private fun initAndStart() {
|
||||||
Info.keepEnc = ShellUtils.fastCmd("echo \$KEEPFORCEENCRYPT").toBoolean()
|
|
||||||
Info.recovery = ShellUtils.fastCmd("echo \$RECOVERYMODE").toBoolean()
|
|
||||||
|
|
||||||
// Set default configs
|
|
||||||
Config.initialize()
|
Config.initialize()
|
||||||
|
handleRepackage()
|
||||||
// Create notification channel on Android O
|
|
||||||
Notifications.setup(this)
|
Notifications.setup(this)
|
||||||
|
|
||||||
// Schedule periodic update checks
|
|
||||||
Utils.scheduleUpdateCheck(this)
|
Utils.scheduleUpdateCheck(this)
|
||||||
|
|
||||||
// Setup shortcuts
|
|
||||||
Shortcuts.setup(this)
|
Shortcuts.setup(this)
|
||||||
|
|
||||||
if (Info.isNewReboot) {
|
// Patch DTB partitions if needed
|
||||||
val shell = Shell.newInstance()
|
patchDTB(this)
|
||||||
shell.newJob().add("mm_patch_dtb").submit {
|
|
||||||
if (it.isSuccess)
|
|
||||||
Notifications.dtboPatched(this)
|
|
||||||
shell.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DONE = true
|
DONE = true
|
||||||
Navigation.start(intent, this)
|
Navigation.start(intent, this)
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.topjohnwu.magisk.core.tasks
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
|
import com.topjohnwu.magisk.core.Const
|
||||||
|
import com.topjohnwu.magisk.core.Info
|
||||||
|
import com.topjohnwu.magisk.core.base.BaseReceiver
|
||||||
|
import com.topjohnwu.magisk.core.view.Notifications
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
private const val DTB_PATCH_RESULT = "dtb_result"
|
||||||
|
private const val DTB_PATCH_ACTION = "com.topjohnwu.magisk.DTBO_PATCH"
|
||||||
|
|
||||||
|
private class DTBPatchReceiver : BaseReceiver() {
|
||||||
|
override fun onReceive(context: ContextWrapper, intent: Intent?) {
|
||||||
|
intent?.also {
|
||||||
|
val result = it.getIntExtra(DTB_PATCH_RESULT, 1)
|
||||||
|
Timber.d("result=[$result]")
|
||||||
|
if (result == 0)
|
||||||
|
Notifications.dtboPatched(context)
|
||||||
|
}
|
||||||
|
context.unregisterReceiver(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun patchDTB(context: Context) {
|
||||||
|
if (Info.isNewReboot) {
|
||||||
|
val c = context.applicationContext
|
||||||
|
c.registerReceiver(DTBPatchReceiver(), IntentFilter(DTB_PATCH_ACTION))
|
||||||
|
val broadcastCmd = "am broadcast --user ${Const.USER_ID} -p ${c.packageName} " +
|
||||||
|
"-a $DTB_PATCH_ACTION --ei $DTB_PATCH_RESULT \$result"
|
||||||
|
Shell.su("mm_patch_dtb '$broadcastCmd'").submit()
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,11 @@ package com.topjohnwu.magisk.core.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.wrap
|
import com.topjohnwu.magisk.core.wrap
|
||||||
import com.topjohnwu.magisk.extensions.rawResource
|
import com.topjohnwu.magisk.extensions.rawResource
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
import com.topjohnwu.superuser.io.SuFile
|
import com.topjohnwu.superuser.io.SuFile
|
||||||
|
|
||||||
class RootInit : Shell.Initializer() {
|
class RootInit : Shell.Initializer() {
|
||||||
@ -30,6 +32,12 @@ class RootInit : Shell.Initializer() {
|
|||||||
"export BOOTMODE=true"
|
"export BOOTMODE=true"
|
||||||
).exec()
|
).exec()
|
||||||
|
|
||||||
|
fun getvar(name: String) = ShellUtils.fastCmd(shell, "echo \$$name").toBoolean()
|
||||||
|
|
||||||
|
Info.keepVerity = getvar("KEEPVERITY")
|
||||||
|
Info.keepEnc = getvar("KEEPFORCEENCRYPT")
|
||||||
|
Info.recovery = getvar("RECOVERYMODE")
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ direct_install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mm_patch_dtb() {
|
mm_patch_dtb() {
|
||||||
local result=1
|
(local result=1
|
||||||
local PATCHED=$TMPDIR/dt.patched
|
local PATCHED=$TMPDIR/dt.patched
|
||||||
for name in dtb dtbo; do
|
for name in dtb dtbo; do
|
||||||
local IMAGE=`find_block $name$SLOT`
|
local IMAGE=`find_block $name$SLOT`
|
||||||
@ -55,7 +55,9 @@ mm_patch_dtb() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
return $result
|
# Run broadcast command passed from app
|
||||||
|
eval $1
|
||||||
|
)& >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_imgs() {
|
restore_imgs() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user