diff --git a/README.md b/README.md index 8fdab290b..f5a13a5ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Magisk Manager -I used Java 8 features in the app, and official supported is added in Android Studio 2.4 -Aware that Android Studio 2.4 is currently in the Preview Channel +# Magisk Manager You need to install CMake and NDK to build the zipadjust library for zip preprocessing + +## Pre-built Binaries +Busybox (arm and x86) compiled by osm0sis (`libbusybox.so` under `app\src\main\jniLibs`) +Source and more info: [osm0sis' Odds and Ends](https://forum.xda-developers.com/showthread.php?t=2239421) diff --git a/app/build.gradle b/app/build.gradle index 7438b501d..03a182766 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ android { versionName "4.3.3" ndk { moduleName 'zipadjust' - abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' + abiFilters 'x86', 'armeabi-v7a' } } diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index cd86edaf8..772c25074 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.os.Handler; import android.preference.PreferenceManager; +import android.text.TextUtils; import android.util.SparseArray; import android.widget.Toast; @@ -12,6 +13,7 @@ import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.superuser.Policy; import com.topjohnwu.magisk.utils.CallbackEvent; +import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ValueSortedMap; @@ -26,6 +28,7 @@ public class MagiskManager extends Application { public static final String TMP_FOLDER_PATH = "/dev/tmp"; public static final String MAGISK_PATH = "/magisk"; public static final String INTENT_SECTION = "section"; + public static final String BUSYBOX_VERSION = "1.26.2"; // Events public final CallbackEvent blockDetectionDone = new CallbackEvent<>(); @@ -65,7 +68,6 @@ public class MagiskManager extends Application { public boolean magiskHide; public boolean isDarkTheme; public boolean updateNotification; - public boolean busybox; public int suRequestTimeout; public int suLogTimeout = 14; public int suAccessState; @@ -106,19 +108,31 @@ public class MagiskManager extends Application { updateMagiskInfo(); initSuAccess(); initSuConfigs(); + // Initialize busybox + File busybox = new File(getApplicationInfo().dataDir + "/busybox/busybox"); + if (!busybox.exists() || !TextUtils.equals(prefs.getString("busybox_version", ""), BUSYBOX_VERSION)) { + busybox.getParentFile().mkdirs(); + Shell.su( + "cp -f " + new File(getApplicationInfo().nativeLibraryDir, "libbusybox.so") + " " + busybox, + "chmod -R 755 " + busybox.getParent(), + busybox + " --install -s " + busybox.getParent() + ); + } // Initialize prefs prefs.edit() .putBoolean("dark_theme", isDarkTheme) .putBoolean("magiskhide", magiskHide) .putBoolean("notification", updateNotification) - .putBoolean("busybox", busybox) .putBoolean("hosts", new File("/magisk/.core/hosts").exists()) .putBoolean("disable", Utils.itemExist(MAGISK_DISABLE_FILE)) .putString("su_request_timeout", String.valueOf(suRequestTimeout)) .putString("su_auto_response", String.valueOf(suResponseType)) .putString("su_notification", String.valueOf(suNotificationType)) .putString("su_access", String.valueOf(suAccessState)) + .putString("busybox_version", BUSYBOX_VERSION) .apply(); + // Add busybox to PATH + Shell.su("PATH=$PATH:" + busybox.getParent()); } public void initSuConfigs() { @@ -162,12 +176,6 @@ public class MagiskManager extends Application { magiskVersionCode = Integer.parseInt(ret.get(0)); } catch (NumberFormatException ignored) {} } - ret = Shell.sh("getprop persist.magisk.busybox"); - try { - busybox = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0; - } catch (NumberFormatException e) { - busybox = false; - } ret = Shell.sh("getprop ro.magisk.disable"); try { disabled = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0; diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java index cbb6fb30d..d39672424 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/FlashZip.java @@ -68,7 +68,7 @@ public class FlashZip extends SerialTask { } } - protected boolean unzipAndCheck() throws Exception { + private boolean unzipAndCheck() throws Exception { ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android"); List ret; ret = Utils.readFile(mCheckFile.getPath()); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessMagiskZip.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessMagiskZip.java index 5f075e9a2..607934e4f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessMagiskZip.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessMagiskZip.java @@ -38,27 +38,13 @@ public class ProcessMagiskZip extends ParallelTask { @Override protected Boolean doInBackground(Void... params) { if (Shell.rootAccess()) { - try { - // We might not have busybox yet, unzip with Java - // We shall have complete busybox after Magisk installation - File tempdir = new File(magiskManager.getCacheDir(), "magisk"); - ZipUtils.unzip(magiskManager.getContentResolver().openInputStream(mUri), tempdir); - // Running in parallel mode, open new shell - Shell.su(true, - "rm -f /dev/.magisk", - (mBoot != null) ? "echo \"BOOTIMAGE=/dev/block/" + mBoot + "\" >> /dev/.magisk" : "", - "echo \"KEEPFORCEENCRYPT=" + String.valueOf(mEnc) + "\" >> /dev/.magisk", - "echo \"KEEPVERITY=" + String.valueOf(mVerity) + "\" >> /dev/.magisk", - "mkdir -p " + MagiskManager.TMP_FOLDER_PATH, - "cp -af " + tempdir + "/. " + MagiskManager.TMP_FOLDER_PATH + "/magisk", - "mv -f " + tempdir + "/META-INF " + magiskManager.getCacheDir() + "/META-INF", - "rm -rf " + tempdir - ); - } catch (Exception e) { - Logger.error("ProcessMagiskZip: Error!"); - e.printStackTrace(); - return false; - } + // Running in parallel mode, open new shell + Shell.su(true, + "rm -f /dev/.magisk", + (mBoot != null) ? "echo \"BOOTIMAGE=/dev/block/" + mBoot + "\" >> /dev/.magisk" : "", + "echo \"KEEPFORCEENCRYPT=" + String.valueOf(mEnc) + "\" >> /dev/.magisk", + "echo \"KEEPVERITY=" + String.valueOf(mVerity) + "\" >> /dev/.magisk" + ); return true; } return false; @@ -68,27 +54,7 @@ public class ProcessMagiskZip extends ParallelTask { protected void onPostExecute(Boolean result) { progressDialog.dismiss(); if (result) { - new FlashZip(activity, mUri) { - @Override - protected boolean unzipAndCheck() throws Exception { - // Don't need to check, as it is downloaded in correct form - return true; - } - - @Override - protected void onSuccess() { - new SerialTask(activity) { - @Override - protected Void doInBackground(Void... params) { - Shell.su("setprop magisk.version " - + String.valueOf(magiskManager.remoteMagiskVersionCode)); - magiskManager.updateCheckDone.trigger(); - return null; - } - }.exec(); - super.onSuccess(); - } - }.exec(); + new FlashZip(activity, mUri).exec(); } else { Utils.showUriSnack(activity, mUri); } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java index c095cdca2..623693eee 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java @@ -34,7 +34,7 @@ public class Logger { public static void shell(boolean root, String msg) { if (MagiskManager.shellLogging) { - Log.d(TAG, root ? "MANAGERSU" : "MANAGERSH" + msg); + Log.d(TAG, (root ? "MANAGERSU " : "MANAGERSH ") + msg); } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java index 9701bde2d..7baec8574 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java @@ -40,7 +40,6 @@ public class Shell { // Setup umask and PATH su("umask 022"); - su("PATH=`[ -e /dev/busybox ] && echo /dev/busybox || echo /data/busybox`:$PATH"); List ret = su("echo -BOC-", "id"); @@ -138,9 +137,6 @@ public class Shell { // Run the new shell with busybox and proper umask STDIN.write(("umask 022\n").getBytes("UTF-8")); STDIN.flush(); - STDIN.write(("PATH=`[ -e /dev/busybox ] && echo /dev/busybox || " + - "echo /data/busybox`:$PATH\n").getBytes("UTF-8")); - STDIN.flush(); } catch (IOException err) { return null; } diff --git a/app/src/main/jniLibs/armeabi-v7a/libbusybox.so b/app/src/main/jniLibs/armeabi-v7a/libbusybox.so new file mode 100644 index 000000000..b0e490cf3 Binary files /dev/null and b/app/src/main/jniLibs/armeabi-v7a/libbusybox.so differ diff --git a/app/src/main/jniLibs/x86/libbusybox.so b/app/src/main/jniLibs/x86/libbusybox.so new file mode 100644 index 000000000..ccc3d7de7 Binary files /dev/null and b/app/src/main/jniLibs/x86/libbusybox.so differ diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 7925d00c8..d5ffc6f54 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -31,11 +31,12 @@ android:title="@string/settings_core_only_title" android:summary="@string/settings_core_only_summary" /> - + + + + + +