Skip to content

Commit

Permalink
1. fix os error when install module
Browse files Browse the repository at this point in the history
2. fix uninstall androidpatch will lose all root config
  • Loading branch information
bmax committed Mar 18, 2024
1 parent af04cbb commit ff97125
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/me/bmax/apatch/APatchApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.lifecycle.MutableLiveData
import coil.Coil
import coil.ImageLoader
import com.topjohnwu.superuser.CallbackList
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.internal.MainShell
import me.bmax.apatch.util.*
import me.zhanghai.android.appiconloader.coil.AppIconFetcher
import me.zhanghai.android.appiconloader.coil.AppIconKeyer
Expand Down Expand Up @@ -86,7 +88,9 @@ class APApplication : Application() {
val cmds = arrayOf(
"rm -f $APD_PATH",
"rm -f $KPATCH_PATH",
"rm -rf $APATCH_FOLDER",
"rm -rf $APATCH_BIN_FOLDER",
"rm -rf $APATCH_LOG_FOLDER",
"rm -rf $APATCH_VERSION_PATH",
)

val shell = getRootShell()
Expand Down Expand Up @@ -139,12 +143,15 @@ class APApplication : Application() {
"echo ${Version.getManagerVersion().second} > $APATCH_VERSION_PATH",
"restorecon -R $APATCH_FOLDER",

"$KPATCH_PATH $superKey android_user init",
"${nativeDir}/libmagiskpolicy.so --magisk --live",
)

val shell = getRootShell()
shell.newJob().add(*cmds).to(logCallback, logCallback).exec()

// clear shell cache
APatchCli.refresh()

Log.d(TAG, "APatch installed...")
_apStateLiveData.postValue(State.ANDROIDPATCH_INSTALLED)
}
Expand All @@ -155,6 +162,7 @@ class APApplication : Application() {
Log.d(TAG, "mark reboot ${result.code}")
}


var superKey: String = ""
set(value) {
field = value
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/me/bmax/apatch/util/APatchCli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ fun createRootShell(): Shell {
}

object APatchCli {
val SHELL: Shell = createRootShell()
var SHELL: Shell = createRootShell()
fun refresh() {
SHELL.close()
SHELL = createRootShell()
}
}

fun getRootShell(): Shell {
Expand Down

0 comments on commit ff97125

Please sign in to comment.