@@ -67,6 +67,9 @@ class SlotViewModel(
6767 private var inInit = true
6868 private var _error : String? = null
6969
70+ private val STOCK_MAGISKBOOT = " /data/adb/magisk/magiskboot"
71+ private var magiskboot: String = STOCK_MAGISKBOOT
72+
7073 val sha1: String
7174 get() = _sha1 !!
7275 val flashOutput: List <String >
@@ -89,7 +92,12 @@ class SlotViewModel(
8992 }
9093
9194 fun refresh (context : Context ) {
92- Shell .cmd(" /data/adb/magisk/magiskboot unpack $boot " ).exec()
95+ // init magiskboot
96+ if (! File (STOCK_MAGISKBOOT ).exists()) {
97+ magiskboot = context.filesDir.absolutePath + File .separator + " magiskboot"
98+ }
99+
100+ Shell .cmd(" $magiskboot unpack $boot " ).exec()
93101
94102 val ramdisk = File (context.filesDir, " ramdisk.cpio" )
95103
@@ -108,18 +116,18 @@ class SlotViewModel(
108116 }
109117 }
110118
111- val magiskboot = fileSystemManager.getFile(" /data/adb/magisk/ magiskboot" )
119+ val magiskboot = fileSystemManager.getFile(magiskboot)
112120 if (magiskboot.exists()) {
113121 if (ramdisk.exists()) {
114- when (Shell .cmd(" /data/adb/magisk/ magiskboot cpio ramdisk.cpio test" ).exec().code) {
115- 0 -> _sha1 = Shell .cmd(" /data/adb/magisk/ magiskboot sha1 $boot " ).exec().out .firstOrNull()
116- 1 -> _sha1 = Shell .cmd(" /data/adb/magisk/ magiskboot cpio ramdisk.cpio sha1" ).exec().out .firstOrNull()
122+ when (Shell .cmd(" $ magiskboot cpio ramdisk.cpio test" ).exec().code) {
123+ 0 -> _sha1 = Shell .cmd(" $ magiskboot sha1 $boot " ).exec().out .firstOrNull()
124+ 1 -> _sha1 = Shell .cmd(" $ magiskboot cpio ramdisk.cpio sha1" ).exec().out .firstOrNull()
117125 else -> log(context, " Invalid boot.img" , shouldThrow = true )
118126 }
119127 } else {
120128 log(context, " Invalid boot.img" , shouldThrow = true )
121129 }
122- Shell .cmd(" /data/adb/magisk/ magiskboot cleanup" ).exec()
130+ Shell .cmd(" $ magiskboot cleanup" ).exec()
123131 } else {
124132 log(context, " magiskboot is missing" , shouldThrow = true )
125133 }
@@ -238,15 +246,15 @@ class SlotViewModel(
238246
239247 @Suppress(" FunctionName" , " SameParameterValue" )
240248 private fun _getKernel (context : Context ) {
241- Shell .cmd(" /data/adb/magisk/ magiskboot unpack $boot " ).exec()
249+ Shell .cmd(" $ magiskboot unpack $boot " ).exec()
242250 val kernel = File (context.filesDir, " kernel" )
243251 if (kernel.exists()) {
244252 val result = Shell .cmd(" strings kernel | grep -E -m1 'Linux version.*#' | cut -d\\ -f3-" ).exec().out
245253 if (result.isNotEmpty()) {
246254 kernelVersion = result[0 ].replace(""" \(.+\)""" .toRegex(), " " ).replace(""" \s+""" .toRegex(), " " )
247255 }
248256 }
249- Shell .cmd(" /data/adb/magisk/ magiskboot cleanup" ).exec()
257+ Shell .cmd(" $ magiskboot cleanup" ).exec()
250258 }
251259
252260 fun getKernel (context : Context ) {
0 commit comments