From faf3e3caab0621faf759fa01a9c7a9a56998d357 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Tue, 3 May 2022 16:18:58 +0200 Subject: [PATCH] Fix-up previous commit. --- .../main/java/com/fox2code/mmm/NotificationType.java | 6 ++++-- .../com/fox2code/mmm/installer/InstallerActivity.java | 11 +++++------ app/src/main/java/com/fox2code/mmm/utils/Files.java | 6 ++++++ .../java/com/fox2code/mmm/utils/IntentHelper.java | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/fox2code/mmm/NotificationType.java b/app/src/main/java/com/fox2code/mmm/NotificationType.java index ab1f86f..4059681 100644 --- a/app/src/main/java/com/fox2code/mmm/NotificationType.java +++ b/app/src/main/java/com/fox2code/mmm/NotificationType.java @@ -83,14 +83,16 @@ public enum NotificationType implements NotificationTypeCst { try { boolean needPatch; try (ZipFile zipFile = new ZipFile(d)) { - needPatch = zipFile.getEntry("module.prop") == null; + needPatch = zipFile.getEntry("module.prop") == null && + zipFile.getEntry("anykernel.sh") == null; } if (needPatch) { Files.patchModuleSimple(Files.read(d), new FileOutputStream(d)); } try (ZipFile zipFile = new ZipFile(d)) { - needPatch = zipFile.getEntry("module.prop") == null; + needPatch = zipFile.getEntry("module.prop") == null && + zipFile.getEntry("anykernel.sh") == null; } if (needPatch) { if (d.exists() && !d.delete()) diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java index 288bb53..52cb3e2 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java @@ -122,18 +122,17 @@ public class InstallerActivity extends CompatActivity { this.getWindow().setFlags( // Note: Doesn't require WAKELOCK permission WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - final File moduleFile = urlMode ? null : new File(target); this.progressIndicator.setVisibility(View.VISIBLE); - this.installerTerminal.addLine("- Downloading " + name); + if (urlMode) this.installerTerminal.addLine("- Downloading " + name); new Thread(() -> { File moduleCache = this.toDelete = urlMode ? - new File(this.moduleCache, "module.zip") : moduleFile; - if (moduleCache.exists() && !moduleCache.delete() && + new File(this.moduleCache, "module.zip") : new File(target); + if (urlMode && moduleCache.exists() && !moduleCache.delete() && !new SuFile(moduleCache.getAbsolutePath()).delete()) Log.e(TAG, "Failed to delete module cache"); String errMessage = "Failed to download module zip"; try { - Log.i(TAG, "Downloading: " + target); + Log.i(TAG, (urlMode ? "Downloading: " : "Loading: ") + target); byte[] rawModule = urlMode ? Http.doHttpGet(target, (progress, max, done) -> { if (max <= 0 && this.progressIndicator.isIndeterminate()) return; @@ -142,7 +141,7 @@ public class InstallerActivity extends CompatActivity { this.progressIndicator.setMax(max); this.progressIndicator.setProgressCompat(progress, true); }); - }) : Files.readSU(moduleFile); + }) : Files.readSU(moduleCache); this.runOnUiThread(() -> { this.progressIndicator.setVisibility(View.GONE); this.progressIndicator.setIndeterminate(true); diff --git a/app/src/main/java/com/fox2code/mmm/utils/Files.java b/app/src/main/java/com/fox2code/mmm/utils/Files.java index edf6b83..d6d9ae1 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/Files.java +++ b/app/src/main/java/com/fox2code/mmm/utils/Files.java @@ -1,6 +1,7 @@ package com.fox2code.mmm.utils; import android.os.Build; +import android.util.Log; import androidx.annotation.NonNull; @@ -45,6 +46,11 @@ public class Files { } public static byte[] readSU(File file) throws IOException { + if (file.isFile() && file.canRead()) { + try { // Read as app if su not required + return read(file); + } catch (IOException ignored) {} + } try (InputStream inputStream = SuFileInputStream.open(file)) { return readAllBytes(inputStream); } diff --git a/app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java b/app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java index 4d751e0..0026fd1 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java +++ b/app/src/main/java/com/fox2code/mmm/utils/IntentHelper.java @@ -371,6 +371,7 @@ public class IntentHelper { } outputStream = new FileOutputStream(destination); Files.copy(inputStream, outputStream); + Log.d(TAG, "File saved at " + destination); success = true; } catch (Exception e) { Log.e(TAG, "failed copy of " + uri, e);