@Override public Boolean apply(Context context) { boolean isJellyBean = VersionHelper.getVersionSdkIntCompat() >= VersionHelper.VERSION_JELLYBEAN; return isJellyBean && !PreferenceHelper.getJellybeanRootRan(context); } }, new Callback<Context>(){
public static Process getLogcatProcess(String buffer) throws IOException { List<String> args = getLogcatArgs(buffer); Process process = RuntimeHelper.exec(args); return process; }
@Override public Boolean apply(Context context) { return SaveLogHelper.checkIfSdCardExists() && SaveLogHelper.legacySavedLogsDirExists(); } }, 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(); } }
@Override public void onCallback(Context context) { SuperUserHelper.requestRoot(context); } }),
@Override public void onCallback(Context context) { if (SaveLogHelper.checkIfSdCardExists()) { SaveLogHelper.moveLogsFromLegacyDirIfNecessary(); } } }),
public static boolean areUpdatesNecessary(Context context) { for (Update update : Update.values()) { if (update.getIsNecessary().apply(context)) { return true; } } return false; }
@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"); } } }
public static synchronized boolean saveLog(CharSequence logString, String filename) { return saveLog(null, logString, filename); }
public static File getFile(String filename) { File catlogDir = getSavedLogsDirectory(); File file = new File(catlogDir, filename); return file; }
private static File getSavedLogsDirectory() { File catlogDir = getCatlogDirectory(); File savedLogsDir = new File(catlogDir, SAVED_LOGS_DIR); if (!savedLogsDir.exists()) { savedLogsDir.mkdir(); } return savedLogsDir; }
public static int getVersionSdkIntCompat() { try { Field field = getSdkIntField(); if (field != null) { return (Integer) field.get(null); } } catch (IllegalAccessException ignore) { // ignore } return VERSION_CUPCAKE; // cupcake }
public static boolean checkSdCard(Context context) { boolean result = SaveLogHelper.checkIfSdCardExists(); if (!result) { Toast.makeText(context, R.string.sd_card_not_found, Toast.LENGTH_LONG).show(); } return result; } public static boolean checkIfSdCardExists() {
private LogcatReaderLoader(List<String> buffers, boolean recordingMode) { this.recordingMode = recordingMode; this.multiple = buffers.size() > 1; for (String buffer : buffers) { // no need to grab the last line if this isn't recording mode String lastLine = recordingMode ? LogcatHelper.getLastLogLine(buffer) : null; lastLines.put(buffer, lastLine); } }
public static LogcatReaderLoader create(Context context, boolean recordingMode) { List<String> buffers = PreferenceHelper.getBuffers(context); LogcatReaderLoader loader = new LogcatReaderLoader(buffers, recordingMode); return loader; }
private static int getColorAt(int i, Context context) { ColorScheme colorScheme = PreferenceHelper.getColorScheme(context); int[] colorArray = colorScheme.getTagColors(context); return colorArray[i]; }
public static File saveTemporaryZipFile(String filename, List<File> files) { try { return saveTemporaryZipFileAndThrow(filename, files); } catch (IOException e) { log.e(e, "unexpected error"); } return null; }
public static synchronized boolean saveLog(List<CharSequence> logLines, String filename) { return saveLog(logLines, null, filename); }
public static void deleteLogIfExists(String filename) { File catlogDir = getSavedLogsDirectory(); File file = new File(catlogDir, filename); if (file.exists()) { file.delete(); } }
public static File getTempDirectory() { File catlogDir = getCatlogDirectory(); File tmpDir = new File(catlogDir, TMP_DIR); if (!tmpDir.exists()) { tmpDir.mkdir(); } return tmpDir; }