From a5b573eaaa5b5e799dcd12d929a13d8d46a226a0 Mon Sep 17 00:00:00 2001 From: tonymanou Date: Sun, 15 Jan 2017 23:45:43 +0100 Subject: [PATCH] Read only the first line instead of loading the whole file --- .../main/java/com/topjohnwu/magisk/utils/Async.java | 5 ++--- .../main/java/com/topjohnwu/magisk/utils/Utils.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 5989c324e..f408e3dff 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -218,9 +218,8 @@ public class Async { protected boolean unzipAndCheck() { ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android"); - List ret; - ret = Utils.readFile(mCachedFile.getParent() + "/META-INF/com/google/android/updater-script"); - return Utils.isValidShellResponse(ret) && ret.get(0).contains("#MAGISK"); + String line = Utils.readFirstLine(mCachedFile.getParent() + "/META-INF/com/google/android/updater-script"); + return line != null && line.contains("#MAGISK"); } @Override diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 36a90e652..08aeddd1a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -75,6 +75,17 @@ public class Utils { return ret; } + public static String readFirstLine(String path) { + List ret; + String command = "head -1 " + path; + if (Shell.rootAccess()) { + ret = Shell.su(command); + } else { + ret = Shell.sh(command); + } + return isValidShellResponse(ret) ? ret.get(0) : null; + } + public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) { if (isDownloading) { return;