Handle sepolicy.rule when disable/remove in app

This commit is contained in:
topjohnwu 2019-12-27 19:03:45 +08:00
parent b336655a79
commit 33d62d7f21

View File

@ -13,17 +13,21 @@ class Module(path: String) : BaseModule() {
override var versionCode: Int = -1 override var versionCode: Int = -1
override var description: String = "" override var description: String = ""
private val removeFile: SuFile = SuFile(path, "remove") private val removeFile = SuFile(path, "remove")
private val disableFile: SuFile = SuFile(path, "disable") private val disableFile = SuFile(path, "disable")
private val updateFile: SuFile = SuFile(path, "update") private val updateFile = SuFile(path, "update")
private val ruleFile = SuFile(path, "sepolicy.rule")
val updated: Boolean = updateFile.exists() val updated: Boolean = updateFile.exists()
var enable: Boolean = !disableFile.exists() var enable: Boolean = !disableFile.exists()
set(enable) { set(enable) {
val dir = "$PERSIST/$id"
field = if (enable) { field = if (enable) {
Shell.su("mkdir -p $dir", "cp -af $ruleFile $dir").submit()
disableFile.delete() disableFile.delete()
} else { } else {
Shell.su("rm -rf $dir").submit()
!disableFile.createNewFile() !disableFile.createNewFile()
} }
} }
@ -31,8 +35,10 @@ class Module(path: String) : BaseModule() {
var remove: Boolean = removeFile.exists() var remove: Boolean = removeFile.exists()
set(remove) { set(remove) {
field = if (remove) { field = if (remove) {
Shell.su("rm -rf $PERSIST/$id").submit()
removeFile.createNewFile() removeFile.createNewFile()
} else { } else {
Shell.su("cp -af $ruleFile $PERSIST/$id").submit()
!removeFile.delete() !removeFile.delete()
} }
} }
@ -54,6 +60,8 @@ class Module(path: String) : BaseModule() {
companion object { companion object {
private const val PERSIST = "/sbin/.magisk/mirror/persist/magisk"
@WorkerThread @WorkerThread
fun loadModules(): List<Module> { fun loadModules(): List<Module> {
val moduleList = mutableListOf<Module>() val moduleList = mutableListOf<Module>()