public static int getVersionSdkIntCompat() { try { Field field = getSdkIntField(); if (field != null) { return (Integer) field.get(null); } } catch (IllegalAccessException ignore) { // ignore } return VERSION_CUPCAKE; // cupcake }
@Override public Boolean apply(Context context) { boolean isJellyBean = VersionHelper.getVersionSdkIntCompat() >= VersionHelper.VERSION_JELLYBEAN; return isJellyBean && !PreferenceHelper.getJellybeanRootRan(context); } }, new Callback<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(); } }
/** * 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)); }
@Override public void killQuietly() { if (logcatProcess != null) { RuntimeHelper.destroy(logcatProcess); log.d("killed 1 logcat process"); } // post-jellybean, we just kill the process, so there's no need // to close the bufferedReader. Anyway, it just hangs. if (VersionHelper.getVersionSdkIntCompat() < VersionHelper.VERSION_JELLYBEAN && bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { log.e(e, "unexpected exception"); } } }
if (VersionHelper.getVersionSdkIntCompat() < VersionHelper.VERSION_JELLYBEAN && reader != null) { try {