diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt index 028b5330f..b39764c9f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt @@ -31,7 +31,11 @@ sealed class DownloadSubject : Parcelable { ) : DownloadSubject() { override val url: String get() = magisk.link - override val fileName get() = "Magisk-v${magisk.version}(${magisk.versionCode}).zip" + override val fileName get() = + if (configuration is Configuration.Flash) + "magisk.zip" + else + "Magisk-v${magisk.version}(${magisk.versionCode}).zip" } diff --git a/app/src/main/java/com/topjohnwu/magisk/model/flash/Patching.kt b/app/src/main/java/com/topjohnwu/magisk/model/flash/Patching.kt index e8e4bbd77..1973320bb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/flash/Patching.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/flash/Patching.kt @@ -9,7 +9,7 @@ sealed class Patching( private val console: MutableList, logs: MutableList, private val resultListener: FlashResultListener -) : MagiskInstaller(console, logs, file) { +) : MagiskInstaller(console, logs) { override fun onResult(success: Boolean) { if (success) { diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java index 99fd005b3..2a5325a75 100644 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java +++ b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java @@ -4,11 +4,13 @@ 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; import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.net.DownloadProgressListener; import com.topjohnwu.net.Networking; import com.topjohnwu.signing.SignBoot; import com.topjohnwu.superuser.Shell; @@ -38,55 +40,28 @@ 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; + protected File zipFile = new File(App.self.getCacheDir(), "magisk.zip"); - @Nullable - private final Uri preDownloadedFile; private final List console; private final List logs; private boolean isTar = false; - private class ProgressLog implements DownloadProgressListener { - - private int prev = -1; - private int location; - - @Override - public void onProgress(long bytesDownloaded, long totalBytes) { - if (prev < 0) { - location = console.size(); - console.add("... 0%"); - } - int curr = (int) (100 * bytesDownloaded / totalBytes); - if (prev != curr) { - prev = curr; - console.set(location, "... " + prev + "%"); - } - } - } - protected MagiskInstaller() { console = NOPList.getInstance(); logs = NOPList.getInstance(); - preDownloadedFile = null; } - public MagiskInstaller(List out, List err, @NonNull Uri magisk) { + public MagiskInstaller(List out, List err) { 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() { @@ -128,27 +103,9 @@ 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"); - - InstallerHelper.copyFileTo(preDownloadedFile, zip); - } else { - 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 { ZipInputStream zi = new ZipInputStream(new BufferedInputStream( - new FileInputStream(zip), (int) zip.length())); + new FileInputStream(zipFile), (int) zipFile.length())); ZipEntry ze; while ((ze = zi.getNextEntry()) != null) { if (ze.isDirectory()) diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt index 521d61b27..7ee303395 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/EnvFixDialog.kt @@ -3,11 +3,14 @@ package com.topjohnwu.magisk.view.dialogs import android.app.Activity import android.app.ProgressDialog import android.widget.Toast +import com.topjohnwu.magisk.Info import com.topjohnwu.magisk.R import com.topjohnwu.magisk.tasks.MagiskInstaller import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.reboot +import com.topjohnwu.net.Networking import com.topjohnwu.superuser.Shell +import com.topjohnwu.superuser.ShellUtils import com.topjohnwu.superuser.internal.UiThreadHandler import com.topjohnwu.superuser.io.SuFile @@ -25,6 +28,8 @@ class EnvFixDialog(activity: Activity) : CustomAlertDialog(activity) { override fun operations(): Boolean { installDir = SuFile("/data/adb/magisk") Shell.su("rm -rf /data/adb/magisk/*").exec() + if (!ShellUtils.checkSum("MD5", zipFile, Info.remote.magisk.hash)) + Networking.get(Info.remote.magisk.link).execForFile(zipFile) return extractZip() && Shell.su("fix_env").exec().isSuccess }