Search in sources :

Example 11 with VisibleForTesting

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 12 with VisibleForTesting

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;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 13 with VisibleForTesting

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;
}
Also used : FilenameFilter(java.io.FilenameFilter) Matcher(java.util.regex.Matcher) File(java.io.File) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 14 with VisibleForTesting

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;
}
Also used : File(java.io.File) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 15 with VisibleForTesting

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) LinkedList(java.util.LinkedList) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2