Fix-up previous commit.

pull/27/head
Fox2Code 3 years ago
parent 0026388f65
commit faf3e3caab

@ -83,14 +83,16 @@ public enum NotificationType implements NotificationTypeCst {
try { try {
boolean needPatch; boolean needPatch;
try (ZipFile zipFile = new ZipFile(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 (needPatch) {
Files.patchModuleSimple(Files.read(d), Files.patchModuleSimple(Files.read(d),
new FileOutputStream(d)); new FileOutputStream(d));
} }
try (ZipFile zipFile = new ZipFile(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 (needPatch) {
if (d.exists() && !d.delete()) if (d.exists() && !d.delete())

@ -122,18 +122,17 @@ public class InstallerActivity extends CompatActivity {
this.getWindow().setFlags( // Note: Doesn't require WAKELOCK permission this.getWindow().setFlags( // Note: Doesn't require WAKELOCK permission
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
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.progressIndicator.setVisibility(View.VISIBLE);
this.installerTerminal.addLine("- Downloading " + name); if (urlMode) this.installerTerminal.addLine("- Downloading " + name);
new Thread(() -> { new Thread(() -> {
File moduleCache = this.toDelete = urlMode ? File moduleCache = this.toDelete = urlMode ?
new File(this.moduleCache, "module.zip") : moduleFile; new File(this.moduleCache, "module.zip") : new File(target);
if (moduleCache.exists() && !moduleCache.delete() && if (urlMode && moduleCache.exists() && !moduleCache.delete() &&
!new SuFile(moduleCache.getAbsolutePath()).delete()) !new SuFile(moduleCache.getAbsolutePath()).delete())
Log.e(TAG, "Failed to delete module cache"); Log.e(TAG, "Failed to delete module cache");
String errMessage = "Failed to download module zip"; String errMessage = "Failed to download module zip";
try { try {
Log.i(TAG, "Downloading: " + target); Log.i(TAG, (urlMode ? "Downloading: " : "Loading: ") + target);
byte[] rawModule = urlMode ? Http.doHttpGet(target, (progress, max, done) -> { byte[] rawModule = urlMode ? Http.doHttpGet(target, (progress, max, done) -> {
if (max <= 0 && this.progressIndicator.isIndeterminate()) if (max <= 0 && this.progressIndicator.isIndeterminate())
return; return;
@ -142,7 +141,7 @@ public class InstallerActivity extends CompatActivity {
this.progressIndicator.setMax(max); this.progressIndicator.setMax(max);
this.progressIndicator.setProgressCompat(progress, true); this.progressIndicator.setProgressCompat(progress, true);
}); });
}) : Files.readSU(moduleFile); }) : Files.readSU(moduleCache);
this.runOnUiThread(() -> { this.runOnUiThread(() -> {
this.progressIndicator.setVisibility(View.GONE); this.progressIndicator.setVisibility(View.GONE);
this.progressIndicator.setIndeterminate(true); this.progressIndicator.setIndeterminate(true);

@ -1,6 +1,7 @@
package com.fox2code.mmm.utils; package com.fox2code.mmm.utils;
import android.os.Build; import android.os.Build;
import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -45,6 +46,11 @@ public class Files {
} }
public static byte[] readSU(File file) throws IOException { 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)) { try (InputStream inputStream = SuFileInputStream.open(file)) {
return readAllBytes(inputStream); return readAllBytes(inputStream);
} }

@ -371,6 +371,7 @@ public class IntentHelper {
} }
outputStream = new FileOutputStream(destination); outputStream = new FileOutputStream(destination);
Files.copy(inputStream, outputStream); Files.copy(inputStream, outputStream);
Log.d(TAG, "File saved at " + destination);
success = true; success = true;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "failed copy of " + uri, e); Log.e(TAG, "failed copy of " + uri, e);

Loading…
Cancel
Save