Some optimizations
This commit is contained in:
parent
07bd36c94b
commit
e92d77bbec
@ -52,19 +52,20 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
) : KoinComponent {
|
) : KoinComponent {
|
||||||
|
|
||||||
protected lateinit var installDir: File
|
protected lateinit var installDir: File
|
||||||
private lateinit var srcBoot: String
|
private lateinit var srcBoot: File
|
||||||
|
|
||||||
private var tarOut: TarOutputStream? = null
|
private var tarOut: TarOutputStream? = null
|
||||||
private val service: NetworkService by inject()
|
private val service: NetworkService by inject()
|
||||||
protected val context: Context by inject(Protected)
|
protected val context: Context by inject(Protected)
|
||||||
|
|
||||||
private fun findImage(): Boolean {
|
private fun findImage(): Boolean {
|
||||||
srcBoot = "find_boot_image; echo \"\$BOOTIMAGE\"".fsh()
|
val bootPath = "find_boot_image; echo \"\$BOOTIMAGE\"".fsh()
|
||||||
if (srcBoot.isEmpty()) {
|
if (bootPath.isEmpty()) {
|
||||||
console.add("! Unable to detect target image")
|
console.add("! Unable to detect target image")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
console.add("- Target image: $srcBoot")
|
srcBoot = SuFile(bootPath)
|
||||||
|
console.add("- Target image: $bootPath")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,16 +73,17 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
val slot = "echo \$SLOT".fsh()
|
val slot = "echo \$SLOT".fsh()
|
||||||
val target = if (slot == "_a") "_b" else "_a"
|
val target = if (slot == "_a") "_b" else "_a"
|
||||||
console.add("- Target slot: $target")
|
console.add("- Target slot: $target")
|
||||||
srcBoot = arrayOf(
|
val bootPath = arrayOf(
|
||||||
"SLOT=$target",
|
"SLOT=$target",
|
||||||
"find_boot_image",
|
"find_boot_image",
|
||||||
"SLOT=$slot",
|
"SLOT=$slot",
|
||||||
"echo \"\$BOOTIMAGE\"").fsh()
|
"echo \"\$BOOTIMAGE\"").fsh()
|
||||||
if (srcBoot.isEmpty()) {
|
if (bootPath.isEmpty()) {
|
||||||
console.add("! Unable to detect target image")
|
console.add("! Unable to detect target image")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
console.add("- Target image: $srcBoot")
|
srcBoot = SuFile(bootPath)
|
||||||
|
console.add("- Target image: $bootPath")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,29 +215,29 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
tarIn.copyTo(tarOut, bufferSize = 1024 * 1024)
|
tarIn.copyTo(tarOut, bufferSize = 1024 * 1024)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val boot = installDirFile("boot.img")
|
}
|
||||||
val recovery = installDirFile("recovery.img")
|
val boot = installDirFile("boot.img")
|
||||||
if (Config.recovery && recovery.exists() && boot.exists()) {
|
val recovery = installDirFile("recovery.img")
|
||||||
// Install Magisk to recovery
|
if (Config.recovery && recovery.exists() && boot.exists()) {
|
||||||
srcBoot = recovery.path
|
// Install Magisk to recovery
|
||||||
// Repack boot image to prevent restore
|
srcBoot = recovery
|
||||||
arrayOf(
|
// Repack boot image to prevent restore
|
||||||
"./magiskboot unpack boot.img",
|
arrayOf(
|
||||||
"./magiskboot repack boot.img",
|
"./magiskboot unpack boot.img",
|
||||||
"./magiskboot cleanup",
|
"./magiskboot repack boot.img",
|
||||||
"mv new-boot.img boot.img").sh()
|
"./magiskboot cleanup",
|
||||||
SuFileInputStream(boot).use {
|
"mv new-boot.img boot.img").sh()
|
||||||
tarOut.putNextEntry(newEntry("boot.img", boot.length()))
|
SuFileInputStream(boot).use {
|
||||||
it.copyTo(tarOut)
|
tarOut.putNextEntry(newEntry("boot.img", boot.length()))
|
||||||
}
|
it.copyTo(tarOut)
|
||||||
boot.delete()
|
|
||||||
} else {
|
|
||||||
if (!boot.exists()) {
|
|
||||||
console.add("! No boot image found")
|
|
||||||
throw IOException()
|
|
||||||
}
|
|
||||||
srcBoot = boot.path
|
|
||||||
}
|
}
|
||||||
|
boot.delete()
|
||||||
|
} else {
|
||||||
|
if (!boot.exists()) {
|
||||||
|
console.add("! No boot image found")
|
||||||
|
throw IOException()
|
||||||
|
}
|
||||||
|
srcBoot = boot
|
||||||
}
|
}
|
||||||
return tarOut
|
return tarOut
|
||||||
}
|
}
|
||||||
@ -258,21 +260,21 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
val alpha = "abcdefghijklmnopqrstuvwxyz"
|
val alpha = "abcdefghijklmnopqrstuvwxyz"
|
||||||
val alphaNum = "$alpha${alpha.toUpperCase(Locale.ROOT)}0123456789"
|
val alphaNum = "$alpha${alpha.toUpperCase(Locale.ROOT)}0123456789"
|
||||||
val random = SecureRandom()
|
val random = SecureRandom()
|
||||||
val suffix = StringBuilder()
|
val filename = StringBuilder("magisk_patched_").run {
|
||||||
for (i in 1..5) {
|
for (i in 1..5) {
|
||||||
suffix.append(alphaNum[random.nextInt(alphaNum.length)])
|
append(alphaNum[random.nextInt(alphaNum.length)])
|
||||||
|
}
|
||||||
|
toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val filename = "magisk_patched_$suffix"
|
|
||||||
outStream = if (magic.contentEquals("ustar".toByteArray())) {
|
outStream = if (magic.contentEquals("ustar".toByteArray())) {
|
||||||
outFile = MediaStoreUtils.getFile("$filename.tar", true)
|
outFile = MediaStoreUtils.getFile("$filename.tar", true)
|
||||||
handleTar(src, outFile!!.uri.outputStream())
|
handleTar(src, outFile!!.uri.outputStream())
|
||||||
} else {
|
} else {
|
||||||
// Raw image
|
// Raw image
|
||||||
val image = installDirFile("boot.img")
|
srcBoot = installDirFile("boot.img")
|
||||||
srcBoot = image.path
|
|
||||||
console.add("- Copying image to cache")
|
console.add("- Copying image to cache")
|
||||||
SuFileOutputStream(image).use { src.copyTo(it) }
|
SuFileOutputStream(srcBoot).use { src.copyTo(it) }
|
||||||
outFile = MediaStoreUtils.getFile("$filename.img", true)
|
outFile = MediaStoreUtils.getFile("$filename.img", true)
|
||||||
outFile!!.uri.outputStream()
|
outFile!!.uri.outputStream()
|
||||||
}
|
}
|
||||||
@ -292,9 +294,9 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
|
|
||||||
// Output file
|
// Output file
|
||||||
try {
|
try {
|
||||||
val patched = SuFile.open(installDir, "new-boot.img")
|
val patched = installDirFile("new-boot.img")
|
||||||
if (outStream is TarOutputStream) {
|
if (outStream is TarOutputStream) {
|
||||||
val name = if (srcBoot.contains("recovery")) "recovery.img" else "boot.img"
|
val name = if (srcBoot.path.contains("recovery")) "recovery.img" else "boot.img"
|
||||||
outStream.putNextEntry(newEntry(name, patched.length()))
|
outStream.putNextEntry(newEntry(name, patched.length()))
|
||||||
}
|
}
|
||||||
withStreams(SuFileInputStream(patched), outStream) { src, out -> src.copyTo(out) }
|
withStreams(SuFileInputStream(patched), outStream) { src, out -> src.copyTo(out) }
|
||||||
@ -325,10 +327,10 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
private fun patchBoot(): Boolean {
|
private fun patchBoot(): Boolean {
|
||||||
"cd $installDir".sh()
|
"cd $installDir".sh()
|
||||||
|
|
||||||
var srcNand = ""
|
var srcNand: File? = null
|
||||||
if ("[ -c $srcBoot ] && nanddump -f boot.img $srcBoot".sh().isSuccess) {
|
if ("[ -c $srcBoot ] && nanddump -f boot.img $srcBoot".sh().isSuccess) {
|
||||||
srcNand = srcBoot
|
srcNand = srcBoot
|
||||||
srcBoot = File(installDir, "boot.img").path
|
srcBoot = installDirFile("boot.img")
|
||||||
}
|
}
|
||||||
|
|
||||||
var isSigned: Boolean
|
var isSigned: Boolean
|
||||||
@ -352,7 +354,7 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
if (!"$FLAGS sh boot_patch.sh $srcBoot".sh().isSuccess)
|
if (!"$FLAGS sh boot_patch.sh $srcBoot".sh().isSuccess)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if (srcNand.isNotEmpty())
|
if (srcNand != null)
|
||||||
srcBoot = srcNand
|
srcBoot = srcNand
|
||||||
|
|
||||||
val job = Shell.sh("./magiskboot cleanup", "cd /")
|
val job = Shell.sh("./magiskboot cleanup", "cd /")
|
||||||
|
@ -28,6 +28,6 @@ kapt.incremental.apt=true
|
|||||||
|
|
||||||
# Magisk
|
# Magisk
|
||||||
magisk.stubVersion=16
|
magisk.stubVersion=16
|
||||||
magisk.versionCode=21404
|
magisk.versionCode=21405
|
||||||
magisk.ndkVersion=21d
|
magisk.ndkVersion=21d
|
||||||
magisk.fullNdkVersion=21.3.6528147
|
magisk.fullNdkVersion=21.3.6528147
|
||||||
|
Loading…
x
Reference in New Issue
Block a user