Use global Magisk native busybox for Magisk Manager

This commit is contained in:
topjohnwu 2017-08-12 02:25:55 +08:00
parent ea884e7fa1
commit 001f8657f6
3 changed files with 48 additions and 38 deletions

View File

@ -12,6 +12,7 @@ import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.database.RepoDatabaseHelper; import com.topjohnwu.magisk.database.RepoDatabaseHelper;
import com.topjohnwu.magisk.database.SuDatabaseHelper; 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 DISABLE_INDICATION_PROP = "ro.magisk.disable";
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice"; public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
public static final String BUSYBOX_VERSION = "1.27.1"; 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 // Topics
public final Topic magiskHideDone = new Topic(); public final Topic magiskHideDone = new Topic();
@ -144,7 +143,6 @@ public class MagiskManager extends Application {
// Locale // Locale
defaultLocale = Locale.getDefault(); defaultLocale = Locale.getDefault();
setLocale(); setLocale();
new LoadLocale(this).exec();
isDarkTheme = prefs.getBoolean("dark_theme", false); isDarkTheme = prefs.getBoolean("dark_theme", false);
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
@ -176,6 +174,8 @@ public class MagiskManager extends Application {
} }
public void init() { public void init() {
new LoadLocale(this).exec();
new DownloadBusybox(this).exec();
getMagiskInfo(); getMagiskInfo();
updateBlockInfo(); updateBlockInfo();

View File

@ -8,15 +8,12 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import com.topjohnwu.magisk.asyncs.DownloadBusybox;
import com.topjohnwu.magisk.asyncs.LoadModules; import com.topjohnwu.magisk.asyncs.LoadModules;
import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.asyncs.UpdateRepos;
import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.services.UpdateCheckService; import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File;
public class SplashActivity extends Activity{ public class SplashActivity extends Activity{
private static final int UPDATE_SERVICE_ID = 1; 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); ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
} }
loadModuleTask.setCallBack(() -> new UpdateRepos(getApplication()).exec()); 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(); loadModuleTask.exec();

View File

@ -3,7 +3,7 @@ package com.topjohnwu.magisk.asyncs;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebService; import com.topjohnwu.magisk.utils.WebService;
import java.io.File; import java.io.File;
@ -13,23 +13,34 @@ import java.io.InputStream;
public class DownloadBusybox extends ParallelTask<Void, Void, Void> { 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; private File busybox;
public DownloadBusybox(Context context, File bb) { public DownloadBusybox(Context context) {
super(context); super(context);
busybox = bb; busybox = new File(context.getCacheDir(), "busybox");
}
@Override
protected void onPreExecute() {
getShell().su_raw("export PATH=" + BUSYBOXPATH + ":$PATH");
} }
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
getShell().su("rm -rf " + busybox.getParentFile()); Context context = getMagiskManager();
busybox.getParentFile().mkdirs(); if (!Utils.itemExist(getShell(), BUSYBOXPATH + "/busybox")) {
if (!busybox.exists() && Utils.checkNetworkStatus(context)) {
Utils.removeItem(getShell(), context.getApplicationInfo().dataDir + "/busybox");
try { try {
FileOutputStream out = new FileOutputStream(busybox); FileOutputStream out = new FileOutputStream(busybox);
InputStream in = WebService.request(WebService.GET, InputStream in = WebService.request(WebService.GET,
Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ? Build.SUPPORTED_32_BIT_ABIS[0].contains("x86") ?
MagiskManager.BUSYBOX_X86 : BUSYBOX_X86 :
MagiskManager.BUSYBOX_ARM, BUSYBOX_ARM,
null null
); );
if (in == null) throw new IOException(); if (in == null) throw new IOException();
@ -40,13 +51,21 @@ public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
} }
out.close(); out.close();
in.close(); in.close();
getShell().su_raw(
"chmod -R 755 " + busybox.getParent(),
busybox + " --install -s " + busybox.getParent()
);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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
);
}
}
return null; return null;
} }
} }