Java Code Examples for com.topjohnwu.superuser.Shell#Result
The following examples show how to use
com.topjohnwu.superuser.Shell#Result .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompileDialogFragment.java From EdXposedManager with GNU General Public License v3.0 | 6 votes |
@Override protected String doInBackground(String... commands) { if (outerRef.get() == null) { return outerRef.get().requireContext().getString(R.string.compile_failed); } // Also get STDERR List<String> stdout = new ArrayList<>(); List<String> stderr = new ArrayList<>(); Shell.Result result = Shell.su(commands).to(stdout, stderr).exec(); List<String> ret; if(stderr.size() > 0) { return "Error: " + TextUtils.join("\n", stderr); } else if(!result.isSuccess()) { // they might don't write to stderr return "Error: " + TextUtils.join("\n", stdout); } else { return TextUtils.join("\n", stdout); } }
Example 2
Source File: InstallApkUtil.java From EdXposedManager with GNU General Public License v3.0 | 6 votes |
@Override protected Integer doInBackground(Void... params) { int returnCode = 0; if (isApkRootInstallOn) { try { String path = "/data/local/tmp/"; String fileName = new File(info.localFilename).getName(); output = Shell.su("cat \"" + info.localFilename + "\">" + path + fileName).exec().getOut(); Shell.Result result = Shell.su("pm install -r -f \"" + path + fileName + "\"").exec(); returnCode = result.getCode(); output = result.getOut(); Shell.su("rm -f " + path + fileName).exec(); } catch (IllegalStateException e) { returnCode = ERROR_ROOT_NOT_GRANTED; } } return returnCode; }
Example 3
Source File: BaseFragment.java From EdXposedManager with GNU General Public License v3.0 | 6 votes |
private void reboot(String mode) { if (startShell()) return; List<String> messages = new LinkedList<>(); String command = "/system/bin/svc power reboot"; if (mode != null) { command += " " + mode; if (mode.equals("recovery")) // create a flag used by some kernels to boot into recovery Shell.su("touch /cache/recovery/boot").exec(); } Shell.Result result = Shell.su(command).exec(); if (result.getCode() != 0) { messages.add(result.getOut().toString()); messages.add(""); messages.add(getString(R.string.reboot_failed)); showAlert(TextUtils.join("\n", messages).trim()); } }
Example 4
Source File: JobImpl.java From libsu with Apache License 2.0 | 6 votes |
private Shell.Result exec0() { if (out instanceof NOPList) out = new ArrayList<>(); ResultImpl result = new ResultImpl(); result.out = out; result.err = redirect ? out : err; Shell.Task task = shell.newTask(handlers, result); try { shell.execTask(task); } catch (IOException e) { if (e instanceof ShellTerminatedException) { return ResultImpl.SHELL_ERR; } else { InternalUtils.stackTrace(e); return ResultImpl.INSTANCE; } } if (redirect) result.err = null; return result; }
Example 5
Source File: PendingJob.java From libsu with Apache License 2.0 | 6 votes |
@NonNull @Override public Shell.Result exec() { try { shell = (ShellImpl) Shell.getShell(); } catch (NoShellException e) { return ResultImpl.INSTANCE; } if (isSU && !shell.isRoot()) return ResultImpl.INSTANCE; Shell.Result res = super.exec(); if (!retry && res == ResultImpl.SHELL_ERR) { // The cached shell is terminated, try to re-run this task retry = true; return exec(); } return res; }
Example 6
Source File: NotificationUtil.java From EdXposedManager with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { /* * Close the notification bar in order to see the toast that module * was enabled successfully. Furthermore, if SU permissions haven't * been granted yet, the SU dialog will be prompted behind the * expanded notification panel and is therefore not visible to the * user. */ sContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); cancelAll(); if (intent.hasExtra(EXTRA_ACTIVATE_MODULE)) { String packageName = intent.getStringExtra(EXTRA_ACTIVATE_MODULE); ModuleUtil moduleUtil = ModuleUtil.getInstance(); moduleUtil.setModuleEnabled(packageName, true); moduleUtil.updateModulesList(false, null); Toast.makeText(sContext, R.string.module_activated, Toast.LENGTH_SHORT).show(); if (intent.hasExtra(EXTRA_ACTIVATE_MODULE_AND_RETURN)) return; } if (!Shell.rootAccess()) { Log.e(TAG, "NotificationUtil -> Could not start root shell"); return; } boolean isSoftReboot = intent.getBooleanExtra(EXTRA_SOFT_REBOOT, false); Shell.Result result = isSoftReboot ? Shell.su("setprop ctl.restart surfaceflinger; setprop ctl.restart zygote").exec() : Shell.su("svc power reboot").exec(); int returnCode = result.getCode(); if (returnCode != 0) { Log.e(TAG, "NotificationUtil -> Could not reboot:"); for (String line : result.getOut()) { Log.e(TAG, line); } } }
Example 7
Source File: BaseFragment.java From EdXposedManager with GNU General Public License v3.0 | 5 votes |
private void softReboot() { if (startShell()) return; List<String> messages = new LinkedList<>(); Shell.Result result = Shell.su("setprop ctl.restart surfaceflinger; setprop ctl.restart zygote").exec(); if (result.getCode() != 0) { messages.add(result.getOut().toString()); messages.add(""); messages.add(getString(R.string.reboot_failed)); showAlert(TextUtils.join("\n", messages).trim()); } }
Example 8
Source File: JobImpl.java From libsu with Apache License 2.0 | 4 votes |
@NonNull @Override public Shell.Result exec() { return exec0(); }
Example 9
Source File: SuShell.java From WADB with Apache License 2.0 | 4 votes |
public synchronized static Result run(String... commands) { Shell.Result result = Shell.su(commands).exec(); return new Result(result.getCode(), result.getOut()); }