Updated magisk installer so it uses predownloaded file
This commit is contained in:
parent
88a394836f
commit
6a0f6ab319
@ -5,10 +5,11 @@ import com.topjohnwu.magisk.tasks.MagiskInstaller
|
||||
import com.topjohnwu.superuser.Shell
|
||||
|
||||
sealed class Patching(
|
||||
file: Uri,
|
||||
private val console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
private val resultListener: FlashResultListener
|
||||
) : MagiskInstaller(console, logs) {
|
||||
) : MagiskInstaller(console, logs, file) {
|
||||
|
||||
override fun onResult(success: Boolean) {
|
||||
if (success) {
|
||||
@ -21,29 +22,32 @@ sealed class Patching(
|
||||
}
|
||||
|
||||
class File(
|
||||
file: Uri,
|
||||
private val uri: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(console, logs, resultListener) {
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() =
|
||||
extractZip() && handleFile(uri) && patchBoot() && storeBoot()
|
||||
}
|
||||
|
||||
class SecondSlot(
|
||||
file: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(console, logs, resultListener) {
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() =
|
||||
findSecondaryImage() && extractZip() && patchBoot() && flashBoot() && postOTA()
|
||||
}
|
||||
|
||||
class Direct(
|
||||
file: Uri,
|
||||
console: MutableList<String>,
|
||||
logs: MutableList<String>,
|
||||
resultListener: FlashResultListener
|
||||
) : Patching(console, logs, resultListener) {
|
||||
) : Patching(file, console, logs, resultListener) {
|
||||
override fun operations() =
|
||||
findImage() && extractZip() && patchBoot() && flashBoot()
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.topjohnwu.magisk.tasks
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import com.topjohnwu.magisk.utils.get
|
||||
import com.topjohnwu.magisk.utils.readUri
|
||||
import java.io.File
|
||||
|
||||
object InstallerHelper {
|
||||
@JvmStatic
|
||||
fun copyFileTo(uri: Uri, zip: File) {
|
||||
zip.deleteRecursively()
|
||||
|
||||
get<Context>().readUri(uri).use { input ->
|
||||
zip.outputStream().use { out -> input.copyTo(out) }
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,6 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.topjohnwu.magisk.App;
|
||||
import com.topjohnwu.magisk.Const;
|
||||
import com.topjohnwu.magisk.Info;
|
||||
@ -41,13 +38,21 @@ import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import androidx.annotation.MainThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
public abstract class MagiskInstaller {
|
||||
|
||||
protected String srcBoot;
|
||||
protected File destFile;
|
||||
protected File installDir;
|
||||
|
||||
private List<String> console, logs;
|
||||
@Nullable
|
||||
private final Uri preDownloadedFile;
|
||||
private final List<String> console;
|
||||
private final List<String> logs;
|
||||
private boolean isTar = false;
|
||||
|
||||
private class ProgressLog implements DownloadProgressListener {
|
||||
@ -72,14 +77,16 @@ public abstract class MagiskInstaller {
|
||||
protected MagiskInstaller() {
|
||||
console = NOPList.getInstance();
|
||||
logs = NOPList.getInstance();
|
||||
preDownloadedFile = null;
|
||||
}
|
||||
|
||||
public MagiskInstaller(List<String> out, List<String> err) {
|
||||
public MagiskInstaller(List<String> out, List<String> err, @NonNull Uri magisk) {
|
||||
console = out;
|
||||
logs = err;
|
||||
installDir = new File(App.deContext.getFilesDir().getParent(), "install");
|
||||
Shell.sh("rm -rf " + installDir).exec();
|
||||
installDir.mkdirs();
|
||||
preDownloadedFile = magisk;
|
||||
}
|
||||
|
||||
protected boolean findImage() {
|
||||
@ -94,7 +101,7 @@ public abstract class MagiskInstaller {
|
||||
|
||||
protected boolean findSecondaryImage() {
|
||||
String slot = ShellUtils.fastCmd("echo $SLOT");
|
||||
String target = (TextUtils.equals(slot, "_a") ? "_b" : "_a");
|
||||
String target = TextUtils.equals(slot, "_a") ? "_b" : "_a";
|
||||
console.add("- Target slot: " + target);
|
||||
srcBoot = ShellUtils.fastCmd(
|
||||
"SLOT=" + target,
|
||||
@ -122,14 +129,21 @@ public abstract class MagiskInstaller {
|
||||
console.add("- Device platform: " + Build.CPU_ABI);
|
||||
|
||||
File zip = new File(App.self.getCacheDir(), "magisk.zip");
|
||||
if (preDownloadedFile != null) {
|
||||
console.add("- Using already downloaded file");
|
||||
|
||||
if (!ShellUtils.checkSum("MD5", zip, Info.remote.getMagisk().getHash())) {
|
||||
console.add("- Downloading zip");
|
||||
Networking.get(Info.remote.getMagisk().getLink())
|
||||
.setDownloadProgressListener(new ProgressLog())
|
||||
.execForFile(zip);
|
||||
InstallerHelper.copyFileTo(preDownloadedFile, zip);
|
||||
} else {
|
||||
console.add("- Existing zip found");
|
||||
console.add("- Using legacy download method");
|
||||
|
||||
if (!ShellUtils.checkSum("MD5", zip, Info.remote.getMagisk().getHash())) {
|
||||
console.add("- Downloading zip");
|
||||
Networking.get(Info.remote.getMagisk().getLink())
|
||||
.setDownloadProgressListener(new ProgressLog())
|
||||
.execForFile(zip);
|
||||
} else {
|
||||
console.add("- Existing zip found");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@ -151,7 +165,7 @@ public abstract class MagiskInstaller {
|
||||
name = ze.getName();
|
||||
if (name == null)
|
||||
continue;
|
||||
File dest = (installDir instanceof SuFile) ?
|
||||
File dest = installDir instanceof SuFile ?
|
||||
new SuFile(installDir, name) :
|
||||
new File(installDir, name);
|
||||
dest.getParentFile().mkdirs();
|
||||
|
@ -28,7 +28,7 @@ import java.util.*
|
||||
|
||||
class FlashViewModel(
|
||||
action: String,
|
||||
file: Uri,
|
||||
installer: Uri,
|
||||
uri: Uri,
|
||||
private val resources: Resources
|
||||
) : MagiskViewModel(), FlashResultListener {
|
||||
@ -55,19 +55,19 @@ class FlashViewModel(
|
||||
|
||||
when (action) {
|
||||
Const.Value.FLASH_ZIP -> Flashing
|
||||
.Install(uri, outItems, logItems, this)
|
||||
.Install(installer, outItems, logItems, this)
|
||||
.exec()
|
||||
Const.Value.UNINSTALL -> Flashing
|
||||
.Uninstall(uri, outItems, logItems, this)
|
||||
.Uninstall(installer, outItems, logItems, this)
|
||||
.exec()
|
||||
Const.Value.FLASH_MAGISK -> Patching
|
||||
.Direct(outItems, logItems, this)
|
||||
.Direct(installer, outItems, logItems, this)
|
||||
.exec()
|
||||
Const.Value.FLASH_INACTIVE_SLOT -> Patching
|
||||
.SecondSlot(outItems, logItems, this)
|
||||
.SecondSlot(installer, outItems, logItems, this)
|
||||
.exec()
|
||||
Const.Value.PATCH_FILE -> Patching
|
||||
.File(uri, outItems, logItems, this)
|
||||
.File(installer, uri, outItems, logItems, this)
|
||||
.exec()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user