diff --git a/app/build.gradle b/app/build.gradle index f3a53f388..764dd17f2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { versionName "5.1.1" ndk { moduleName 'zipadjust' - abiFilters 'x86', 'armeabi-v7a' + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } } diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index c75093cbc..6effd5c77 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -10,7 +10,6 @@ import android.content.res.Resources; import android.os.Build; import android.os.Handler; import android.preference.PreferenceManager; -import android.text.TextUtils; import android.widget.Toast; import com.topjohnwu.magisk.asyncs.ParallelTask; @@ -37,10 +36,12 @@ public class MagiskManager extends Application { public static final String INTENT_SECTION = "section"; public static final String INTENT_VERSION = "version"; public static final String INTENT_LINK = "link"; - public static final String BUSYBOX_VERSION = "1.27.1"; public static final String MAGISKHIDE_PROP = "persist.magisk.hide"; public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable"; public static final String NOTIFICATION_CHANNEL = "magisk_update_notice"; + public static final String BUSYBOX_VERSION = "1.27.1"; + public static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-arm"; + public static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-x86"; // Events public final CallbackEvent magiskHideDone = new CallbackEvent(); @@ -162,17 +163,6 @@ public class MagiskManager extends Application { initSU(); updateMagiskInfo(); updateBlockInfo(); - // Initialize busybox - File busybox = new File(getApplicationInfo().dataDir + "/busybox/busybox"); - if (!busybox.exists() || !TextUtils.equals(prefs.getString("busybox_version", ""), BUSYBOX_VERSION)) { - shell.su("rm -rf " + busybox.getParentFile()); - busybox.getParentFile().mkdirs(); - shell.su_raw( - "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) @@ -189,8 +179,9 @@ public class MagiskManager extends Application { .putString("mnt_ns", String.valueOf(suNamespaceMode)) .putString("busybox_version", BUSYBOX_VERSION) .apply(); + // Add busybox to PATH - shell.su_raw("PATH=" + busybox.getParent() + ":$PATH"); + shell.su_raw("PATH=" + getApplicationInfo().dataDir + "/busybox:$PATH"); // Create notification channel on Android O if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index f28f5df24..e231e065f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -8,12 +8,15 @@ import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; +import com.topjohnwu.magisk.asyncs.DownloadBusybox; import com.topjohnwu.magisk.asyncs.LoadModules; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.utils.Utils; +import java.io.File; + public class SplashActivity extends Activity{ private static final int UPDATE_SERVICE_ID = 1; @@ -46,9 +49,14 @@ public class SplashActivity extends Activity{ ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo); } loadModuleTask.setCallBack(() -> new UpdateRepos(getApplication()).exec()); + File busybox = new File(magiskManager.getApplicationInfo().dataDir + "/busybox/busybox"); + if (!busybox.exists() || !TextUtils.equals( + magiskManager.prefs.getString("busybox_version", ""), + MagiskManager.BUSYBOX_VERSION)) { + new DownloadBusybox(this, busybox).exec(); + } } - // Now fire all async tasks loadModuleTask.exec(); Intent intent = new Intent(this, MainActivity.class); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/DownloadBusybox.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/DownloadBusybox.java new file mode 100644 index 000000000..08f0973fa --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/DownloadBusybox.java @@ -0,0 +1,56 @@ +package com.topjohnwu.magisk.asyncs; + +import android.content.Context; +import android.os.Build; +import android.text.TextUtils; + +import com.topjohnwu.magisk.MagiskManager; +import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.utils.WebService; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +public class DownloadBusybox extends ParallelTask { + + private File busybox; + private Shell shell; + + public DownloadBusybox(Context context, File bb) { + busybox = bb; + shell = Utils.getMagiskManager(context).shell; + } + + @Override + protected Void doInBackground(Void... voids) { + shell.su("rm -rf " + busybox.getParentFile()); + busybox.getParentFile().mkdirs(); + try { + FileOutputStream out = new FileOutputStream(busybox); + InputStream in = WebService.request(WebService.GET, + Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ? + MagiskManager.BUSYBOX_X86 : + MagiskManager.BUSYBOX_ARM, + null + ); + if (in == null) throw new IOException(); + byte[] buffer = new byte[4096]; + int read; + while ((read = in.read(buffer)) != -1) { + out.write(buffer, 0, read); + } + out.close(); + in.close(); + shell.su_raw( + "chmod -R 755 " + busybox.getParent(), + busybox + " --install -s " + busybox.getParent() + ); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +}