use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class OmahaClient method postRequest.
/**
* Posts the request to the Omaha server.
* @return the XML response as a String.
* @throws RequestFailureException if the request fails.
*/
@VisibleForTesting
String postRequest(long timestamp, String xml) throws RequestFailureException {
String response = null;
HttpURLConnection urlConnection = null;
try {
urlConnection = createConnection();
setUpPostRequest(timestamp, urlConnection, xml);
sendRequestToServer(urlConnection, xml);
response = readResponseFromServer(urlConnection);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
return response;
}
use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class MinidumpUploadService method getCrashType.
@ProcessType
@VisibleForTesting
protected static String getCrashType(String fileName) {
// Read file and get the line containing name="ptype".
BufferedReader fileReader = null;
try {
fileReader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = fileReader.readLine()) != null) {
if (line.equals("Content-Disposition: form-data; name=\"ptype\"")) {
// Crash type is on the line after the next line.
fileReader.readLine();
String crashType = fileReader.readLine();
if (crashType == null) {
return OTHER;
}
if (crashType.equals("browser")) {
return BROWSER;
}
if (crashType.equals("renderer")) {
return RENDERER;
}
if (crashType.equals("gpu-process")) {
return GPU;
}
return OTHER;
}
}
} catch (IOException e) {
Log.w(TAG, "Error while reading crash file.", e.toString());
} finally {
StreamUtil.closeQuietly(fileReader);
}
return OTHER;
}
use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class CrashFileManager method getMatchingFiles.
@VisibleForTesting
File[] getMatchingFiles(final Pattern pattern) {
// Get dump dir and get all files with specified suffix. The path
// constructed here must match chrome_paths.cc (see case
// chrome::DIR_CRASH_DUMPS).
File crashDir = getCrashDirectoryIfExists();
if (crashDir == null) {
return new File[] {};
}
File[] minidumps = crashDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
Matcher match = pattern.matcher(filename);
int tries = readAttemptNumber(filename);
return match.find() && tries < MinidumpUploadService.MAX_TRIES_ALLOWED;
}
});
return minidumps;
}
use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class CrashFileManager method getAllFilesSorted.
@VisibleForTesting
protected File[] getAllFilesSorted() {
File crashDir = getCrashDirectoryIfExists();
if (crashDir == null) {
return new File[] {};
}
File[] files = crashDir.listFiles();
Arrays.sort(files, sFileComparator);
return files;
}
use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.
the class LogcatExtractionCallable method getLogcat.
@VisibleForTesting
protected List<String> getLogcat() throws IOException, InterruptedException {
// Grab the last lines of the logcat output, with a generous buffer to compensate for any
// microdumps that might be in the logcat output, since microdumps are stripped in the
// extraction code. Note that the repeated check of the process exit value is to account for
// the fact that the process might not finish immediately. And, it's not appropriate to
// call p.waitFor(), because this call will block *forever* if the process's output buffer
// fills up.
Process p = Runtime.getRuntime().exec("logcat -d");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
LinkedList<String> rawLogcat = new LinkedList<>();
Integer exitValue = null;
try {
while (exitValue == null) {
String logLn;
while ((logLn = reader.readLine()) != null) {
rawLogcat.add(logLn);
if (rawLogcat.size() > LOGCAT_SIZE * 4) {
rawLogcat.removeFirst();
}
}
try {
exitValue = p.exitValue();
} catch (IllegalThreadStateException itse) {
Thread.sleep(HALF_SECOND);
}
}
} finally {
reader.close();
}
if (exitValue != 0) {
String msg = "Logcat failed: " + exitValue;
Log.w(TAG, msg);
throw new IOException(msg);
}
return trimLogcat(rawLogcat, LOGCAT_SIZE);
}
Aggregations