mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 12:47:38 +00:00
Use global Magisk native busybox for Magisk Manager
This commit is contained in:
parent
ea884e7fa1
commit
001f8657f6
@ -12,6 +12,7 @@ import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
|
||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||
@ -40,8 +41,6 @@ public class MagiskManager extends Application {
|
||||
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";
|
||||
|
||||
// Topics
|
||||
public final Topic magiskHideDone = new Topic();
|
||||
@ -144,7 +143,6 @@ public class MagiskManager extends Application {
|
||||
// Locale
|
||||
defaultLocale = Locale.getDefault();
|
||||
setLocale();
|
||||
new LoadLocale(this).exec();
|
||||
|
||||
isDarkTheme = prefs.getBoolean("dark_theme", false);
|
||||
if (BuildConfig.DEBUG) {
|
||||
@ -176,6 +174,8 @@ public class MagiskManager extends Application {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
new LoadLocale(this).exec();
|
||||
new DownloadBusybox(this).exec();
|
||||
getMagiskInfo();
|
||||
updateBlockInfo();
|
||||
|
||||
|
@ -8,15 +8,12 @@ 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;
|
||||
@ -49,12 +46,6 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
loadModuleTask.exec();
|
||||
|
@ -3,7 +3,7 @@ package com.topjohnwu.magisk.asyncs;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.magisk.utils.WebService;
|
||||
|
||||
import java.io.File;
|
||||
@ -13,39 +13,58 @@ import java.io.InputStream;
|
||||
|
||||
public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
||||
|
||||
private static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-arm";
|
||||
private static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-x86";
|
||||
private static final String BUSYBOXPATH = "/dev/magisk/bin";
|
||||
|
||||
private File busybox;
|
||||
|
||||
public DownloadBusybox(Context context, File bb) {
|
||||
public DownloadBusybox(Context context) {
|
||||
super(context);
|
||||
busybox = bb;
|
||||
busybox = new File(context.getCacheDir(), "busybox");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
getShell().su_raw("export PATH=" + BUSYBOXPATH + ":$PATH");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
getShell().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);
|
||||
Context context = getMagiskManager();
|
||||
if (!Utils.itemExist(getShell(), BUSYBOXPATH + "/busybox")) {
|
||||
if (!busybox.exists() && Utils.checkNetworkStatus(context)) {
|
||||
Utils.removeItem(getShell(), context.getApplicationInfo().dataDir + "/busybox");
|
||||
try {
|
||||
FileOutputStream out = new FileOutputStream(busybox);
|
||||
InputStream in = WebService.request(WebService.GET,
|
||||
Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ?
|
||||
BUSYBOX_X86 :
|
||||
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();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (busybox.exists()) {
|
||||
getShell().su_raw(
|
||||
"rm -rf " + BUSYBOXPATH,
|
||||
"mkdir -p " + BUSYBOXPATH,
|
||||
"cp " + busybox + " " + BUSYBOXPATH,
|
||||
"chmod -R 755 " + BUSYBOXPATH,
|
||||
BUSYBOXPATH + "/busybox --install -s " + BUSYBOXPATH
|
||||
);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
getShell().su_raw(
|
||||
"chmod -R 755 " + busybox.getParent(),
|
||||
busybox + " --install -s " + busybox.getParent()
|
||||
);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user