@Override public void onCallback(Context context) { SuperUserHelper.requestRoot(context); } }),
public static void destroy(Process process) { // if we're in JellyBean, then we need to kill the process as root, which requires all this // extra UnixProcess logic if (VersionHelper.getVersionSdkIntCompat() >= VersionHelper.VERSION_JELLYBEAN && !SuperUserHelper.isFailedToObtainRoot()) { SuperUserHelper.destroy(process); } else { process.destroy(); } }
public static void destroy(Process process) { // stupid method for getting the pid, but it actually works Matcher matcher = PID_PATTERN.matcher(process.toString()); matcher.find(); int pid = Integer.parseInt(matcher.group()); List<Integer> allRelatedPids = getAllRelatedPids(pid); log.d("Killing %s", allRelatedPids); for (Integer relatedPid : allRelatedPids) { destroyPid(relatedPid); } }
public static void requestRoot(Context context) { showToast(context, R.string.toast_request_root); showToast(context, R.string.toast_no_root); failedToObtainRoot = true; } else { showToast(context, R.string.toast_no_root); failedToObtainRoot = true; } catch (InterruptedException e) { log.w(e, "Cannot obtain root"); showToast(context, R.string.toast_no_root); failedToObtainRoot = true;
/** * Exec the arguments, using root if necessary. * @param args */ public static Process exec(List<String> args) throws IOException { // since JellyBean, sudo is required to read other apps' logs if (VersionHelper.getVersionSdkIntCompat() >= VersionHelper.VERSION_JELLYBEAN && !SuperUserHelper.isFailedToObtainRoot()) { Process process = Runtime.getRuntime().exec("su"); PrintStream outputStream = null; try { outputStream = new PrintStream(new BufferedOutputStream(process.getOutputStream(), 8192)); outputStream.println(TextUtils.join(" ", args)); outputStream.flush(); } finally { if (outputStream != null) { outputStream.close(); } } return process; } return Runtime.getRuntime().exec(ArrayUtil.toArray(args, String.class)); }
SuperUserHelper.requestRoot(this); break;