Update Shell
This commit is contained in:
parent
8195a4d616
commit
2ecbca303b
@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 26
|
compileSdkVersion 26
|
||||||
buildToolsVersion "26.0.0"
|
buildToolsVersion "26.0.1"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.topjohnwu.magisk"
|
applicationId "com.topjohnwu.magisk"
|
||||||
|
@ -142,7 +142,7 @@ public class MagiskFragment extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Uri uri) {
|
public void onDownloadDone(Uri uri) {
|
||||||
if (Shell.rootAccess()) {
|
if (Shell.rootAccess()) {
|
||||||
magiskManager.shell.su_raw(
|
Shell.getShell(getActivity()).su_raw(
|
||||||
"rm -f /dev/.magisk",
|
"rm -f /dev/.magisk",
|
||||||
"echo \"BOOTIMAGE=" + boot + "\" >> /dev/.magisk",
|
"echo \"BOOTIMAGE=" + boot + "\" >> /dev/.magisk",
|
||||||
"echo \"KEEPFORCEENCRYPT=" + String.valueOf(enc) + "\" >> /dev/.magisk",
|
"echo \"KEEPFORCEENCRYPT=" + String.valueOf(enc) + "\" >> /dev/.magisk",
|
||||||
@ -206,7 +206,7 @@ public class MagiskFragment extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
progress.setMessage(getString(R.string.reboot_countdown, 0));
|
progress.setMessage(getString(R.string.reboot_countdown, 0));
|
||||||
magiskManager.shell.su_raw(
|
Shell.getShell(getActivity()).su_raw(
|
||||||
"mv -f " + uninstaller + " /cache/" + MagiskManager.UNINSTALLER,
|
"mv -f " + uninstaller + " /cache/" + MagiskManager.UNINSTALLER,
|
||||||
"mv -f " + utils + " /data/magisk/" + MagiskManager.UTIL_FUNCTIONS,
|
"mv -f " + utils + " /data/magisk/" + MagiskManager.UTIL_FUNCTIONS,
|
||||||
"reboot"
|
"reboot"
|
||||||
|
@ -135,11 +135,11 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0:
|
case 0:
|
||||||
StringBuildingList logList = new StringBuildingList();
|
StringBuildingList logList = new StringBuildingList();
|
||||||
magiskManager.shell.su(logList, "cat " + MAGISK_LOG);
|
Shell.getShell(magiskManager).su(logList, "cat " + MAGISK_LOG);
|
||||||
return logList.toString();
|
return logList.toString();
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
magiskManager.shell.su_raw("echo > " + MAGISK_LOG);
|
Shell.getShell(magiskManager).su_raw("echo > " + MAGISK_LOG);
|
||||||
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ public class MagiskLogFragment extends Fragment {
|
|||||||
|
|
||||||
try (FileWriter out = new FileWriter(targetFile)) {
|
try (FileWriter out = new FileWriter(targetFile)) {
|
||||||
FileWritingList fileWritingList = new FileWritingList(out);
|
FileWritingList fileWritingList = new FileWritingList(out);
|
||||||
magiskManager.shell.su(fileWritingList, "cat " + MAGISK_LOG);
|
Shell.getShell(magiskManager).su(fileWritingList, "cat " + MAGISK_LOG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
@ -188,28 +188,28 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
case "disable":
|
case "disable":
|
||||||
enabled = prefs.getBoolean("disable", false);
|
enabled = prefs.getBoolean("disable", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Utils.createFile(magiskManager.shell, MagiskManager.MAGISK_DISABLE_FILE);
|
Utils.createFile(Shell.getShell(magiskManager), MagiskManager.MAGISK_DISABLE_FILE);
|
||||||
} else {
|
} else {
|
||||||
Utils.removeItem(magiskManager.shell, MagiskManager.MAGISK_DISABLE_FILE);
|
Utils.removeItem(Shell.getShell(magiskManager), MagiskManager.MAGISK_DISABLE_FILE);
|
||||||
}
|
}
|
||||||
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
Toast.makeText(getActivity(), R.string.settings_reboot_toast, Toast.LENGTH_LONG).show();
|
||||||
break;
|
break;
|
||||||
case "magiskhide":
|
case "magiskhide":
|
||||||
enabled = prefs.getBoolean("magiskhide", false);
|
enabled = prefs.getBoolean("magiskhide", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Utils.enableMagiskHide(magiskManager.shell);
|
Utils.enableMagiskHide(Shell.getShell(magiskManager));
|
||||||
} else {
|
} else {
|
||||||
Utils.disableMagiskHide(magiskManager.shell);
|
Utils.disableMagiskHide(Shell.getShell(magiskManager));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "hosts":
|
case "hosts":
|
||||||
enabled = prefs.getBoolean("hosts", false);
|
enabled = prefs.getBoolean("hosts", false);
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
magiskManager.shell.su_raw(
|
Shell.getShell(magiskManager).su_raw(
|
||||||
"cp -af /system/etc/hosts /magisk/.core/hosts",
|
"cp -af /system/etc/hosts /magisk/.core/hosts",
|
||||||
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
"mount -o bind /magisk/.core/hosts /system/etc/hosts");
|
||||||
} else {
|
} else {
|
||||||
magiskManager.shell.su_raw(
|
Shell.getShell(magiskManager).su_raw(
|
||||||
"umount -l /system/etc/hosts",
|
"umount -l /system/etc/hosts",
|
||||||
"rm -f /magisk/.core/hosts");
|
"rm -f /magisk/.core/hosts");
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
filter = new ApplicationFilter();
|
filter = new ApplicationFilter();
|
||||||
pm = context.getPackageManager();
|
pm = context.getPackageManager();
|
||||||
magiskHideDone = Utils.getMagiskManager(context).magiskHideDone;
|
magiskHideDone = Utils.getMagiskManager(context).magiskHideDone;
|
||||||
shell = Utils.getMagiskManager(context).shell;
|
shell = Shell.getShell(context);
|
||||||
new LoadApps().exec();
|
new LoadApps().exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,8 @@ package com.topjohnwu.magisk.asyncs;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
|
||||||
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;
|
||||||
@ -17,16 +14,14 @@ import java.io.InputStream;
|
|||||||
public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
||||||
|
|
||||||
private File busybox;
|
private File busybox;
|
||||||
private Shell shell;
|
|
||||||
|
|
||||||
public DownloadBusybox(Context context, File bb) {
|
public DownloadBusybox(Context context, File bb) {
|
||||||
busybox = bb;
|
busybox = bb;
|
||||||
shell = Utils.getMagiskManager(context).shell;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
shell.su("rm -rf " + busybox.getParentFile());
|
getShell().su("rm -rf " + busybox.getParentFile());
|
||||||
busybox.getParentFile().mkdirs();
|
busybox.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
FileOutputStream out = new FileOutputStream(busybox);
|
FileOutputStream out = new FileOutputStream(busybox);
|
||||||
@ -44,7 +39,7 @@ public class DownloadBusybox extends ParallelTask<Void, Void, Void> {
|
|||||||
}
|
}
|
||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
shell.su_raw(
|
getShell().su_raw(
|
||||||
"chmod -R 755 " + busybox.getParent(),
|
"chmod -R 755 " + busybox.getParent(),
|
||||||
busybox + " --install -s " + busybox.getParent()
|
busybox + " --install -s " + busybox.getParent()
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.topjohnwu.magisk.asyncs;
|
package com.topjohnwu.magisk.asyncs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ public class FlashZip extends ParallelTask<Void, String, Integer> {
|
|||||||
}
|
}
|
||||||
if (!unzipAndCheck()) return 0;
|
if (!unzipAndCheck()) return 0;
|
||||||
mList.add(magiskManager.getString(R.string.zip_install_progress_msg, mFilename));
|
mList.add(magiskManager.getString(R.string.zip_install_progress_msg, mFilename));
|
||||||
magiskManager.shell.su(mList,
|
getShell().su(mList,
|
||||||
"BOOTMODE=true sh " + mScriptFile + " dummy 1 " + mCachedFile +
|
"BOOTMODE=true sh " + mScriptFile + " dummy 1 " + mCachedFile +
|
||||||
" && echo 'Success!' || echo 'Failed!'"
|
" && echo 'Success!' || echo 'Failed!'"
|
||||||
);
|
);
|
||||||
@ -100,7 +99,7 @@ public class FlashZip extends ParallelTask<Void, String, Integer> {
|
|||||||
protected void onPostExecute(Integer result) {
|
protected void onPostExecute(Integer result) {
|
||||||
MagiskManager magiskManager = getMagiskManager();
|
MagiskManager magiskManager = getMagiskManager();
|
||||||
if (magiskManager == null) return;
|
if (magiskManager == null) return;
|
||||||
magiskManager.shell.su_raw(
|
getShell().su_raw(
|
||||||
"rm -rf " + mCachedFile.getParent(),
|
"rm -rf " + mCachedFile.getParent(),
|
||||||
"rm -rf " + MagiskManager.TMP_FOLDER_PATH
|
"rm -rf " + MagiskManager.TMP_FOLDER_PATH
|
||||||
);
|
);
|
||||||
|
@ -23,10 +23,10 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
|||||||
|
|
||||||
magiskManager.moduleMap = new ValueSortedMap<>();
|
magiskManager.moduleMap = new ValueSortedMap<>();
|
||||||
|
|
||||||
for (String path : Utils.getModList(magiskManager.shell, MagiskManager.MAGISK_PATH)) {
|
for (String path : Utils.getModList(getShell(), MagiskManager.MAGISK_PATH)) {
|
||||||
Logger.dev("LoadModules: Adding modules from " + path);
|
Logger.dev("LoadModules: Adding modules from " + path);
|
||||||
try {
|
try {
|
||||||
Module module = new Module(magiskManager.shell, path);
|
Module module = new Module(getShell(), path);
|
||||||
magiskManager.moduleMap.put(module.getId(), module);
|
magiskManager.moduleMap.put(module.getId(), module);
|
||||||
} catch (BaseModule.CacheModException ignored) {}
|
} catch (BaseModule.CacheModException ignored) {}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P
|
|||||||
|
|
||||||
protected Shell getShell() {
|
protected Shell getShell() {
|
||||||
MagiskManager magiskManager = getMagiskManager();
|
MagiskManager magiskManager = getMagiskManager();
|
||||||
return magiskManager == null ? null : getMagiskManager().shell;
|
return magiskManager == null ? null : Shell.getShell(magiskManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -2,6 +2,8 @@ package com.topjohnwu.magisk.utils;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@ -87,7 +89,12 @@ public class Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Shell getShell(Context context) {
|
public static Shell getShell(Context context) {
|
||||||
return Utils.getMagiskManager(context).shell;
|
MagiskManager magiskManager = Utils.getMagiskManager(context);
|
||||||
|
if (!magiskManager.shell.isValid) {
|
||||||
|
// Get new shell if needed
|
||||||
|
magiskManager.shell = getShell();
|
||||||
|
}
|
||||||
|
return magiskManager.shell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean rootAccess() {
|
public static boolean rootAccess() {
|
||||||
@ -102,12 +109,16 @@ public class Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sh_raw(String... commands) {
|
public void sh_raw(String... commands) {
|
||||||
|
sh_raw(false, commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sh_raw(boolean stdout, String... commands) {
|
||||||
if (!isValid) return;
|
if (!isValid) return;
|
||||||
synchronized (shellProcess) {
|
synchronized (shellProcess) {
|
||||||
try {
|
try {
|
||||||
for (String command : commands) {
|
for (String command : commands) {
|
||||||
Logger.shell(command);
|
Logger.shell(command);
|
||||||
STDIN.write((command + "\n").getBytes("UTF-8"));
|
STDIN.write((command + (stdout ? "\n" : " >/dev/null\n")).getBytes("UTF-8"));
|
||||||
STDIN.flush();
|
STDIN.flush();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -130,8 +141,8 @@ public class Shell {
|
|||||||
synchronized (shellProcess) {
|
synchronized (shellProcess) {
|
||||||
StreamGobbler out = new StreamGobbler(STDOUT, output);
|
StreamGobbler out = new StreamGobbler(STDOUT, output);
|
||||||
out.start();
|
out.start();
|
||||||
sh_raw(commands);
|
sh_raw(true, commands);
|
||||||
sh_raw("echo \'-shell-done-\'");
|
sh_raw(true, "echo \'-shell-done-\'");
|
||||||
try { out.join(); } catch (InterruptedException ignored) {}
|
try { out.join(); } catch (InterruptedException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user