Search in sources :

Example 41 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class Log method getStackTraceString.

/**
     * Handy function to get a loggable stack trace from a Throwable
     * @param tr An exception to log
     */
public static String getStackTraceString(Throwable tr) {
    if (tr == null) {
        return "";
    }
    // This is to reduce the amount of log spew that apps do in the non-error
    // condition of the network being unavailable.
    Throwable t = tr;
    while (t != null) {
        if (t instanceof UnknownHostException) {
            return "";
        }
        t = t.getCause();
    }
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    tr.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}
Also used : UnknownHostException(java.net.UnknownHostException) StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 42 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class ActivityThread method handleDumpActivity.

private void handleDumpActivity(DumpComponentInfo info) {
    final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        ActivityClientRecord r = mActivities.get(info.token);
        if (r != null && r.activity != null) {
            PrintWriter pw = new FastPrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
            r.activity.dump(info.prefix, info.fd.getFileDescriptor(), pw, info.args);
            pw.flush();
        }
    } finally {
        IoUtils.closeQuietly(info.fd);
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
Also used : StrictMode(android.os.StrictMode) FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 43 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class Debug method stopNativeTracing.

/**
     * Stop qemu tracing.  See {@link #startNativeTracing()} to start tracing.
     *
     * <p>Tracing can be started and stopped as many times as desired.  When
     * the qemu emulator itself is stopped then the buffered trace records
     * are flushed and written to the trace file.  In fact, it is not necessary
     * to call this method at all; simply killing qemu is sufficient.  But
     * starting and stopping a trace is useful for examining a specific
     * region of code.</p>
     */
public static void stopNativeTracing() {
    VMDebug.stopEmulatorTracing();
    // Open the sysfs file for writing and write "0" to it.
    PrintWriter outStream = null;
    try {
        FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
        outStream = new FastPrintWriter(fos);
        outStream.println("0");
    } catch (Exception e) {
    // We could print an error message here but we probably want
    // to quietly ignore errors if we are not running in the emulator.
    } finally {
        if (outStream != null)
            outStream.close();
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 44 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class Debug method startNativeTracing.

/**
     * Enable qemu tracing. For this to work requires running everything inside
     * the qemu emulator; otherwise, this method will have no effect. The trace
     * file is specified on the command line when the emulator is started. For
     * example, the following command line <br />
     * <code>emulator -trace foo</code><br />
     * will start running the emulator and create a trace file named "foo". This
     * method simply enables writing the trace records to the trace file.
     *
     * <p>
     * The main differences between this and {@link #startMethodTracing()} are
     * that tracing in the qemu emulator traces every cpu instruction of every
     * process, including kernel code, so we have more complete information,
     * including all context switches. We can also get more detailed information
     * such as cache misses. The sequence of calls is determined by
     * post-processing the instruction trace. The qemu tracing is also done
     * without modifying the application or perturbing the timing of calls
     * because no instrumentation is added to the application being traced.
     * </p>
     *
     * <p>
     * One limitation of using this method compared to using
     * {@link #startMethodTracing()} on the real device is that the emulator
     * does not model all of the real hardware effects such as memory and
     * bus contention.  The emulator also has a simple cache model and cannot
     * capture all the complexities of a real cache.
     * </p>
     */
public static void startNativeTracing() {
    // Open the sysfs file for writing and write "1" to it.
    PrintWriter outStream = null;
    try {
        FileOutputStream fos = new FileOutputStream(SYSFS_QEMU_TRACE_STATE);
        outStream = new FastPrintWriter(fos);
        outStream.println("1");
    } catch (Exception e) {
    } finally {
        if (outStream != null)
            outStream.close();
    }
    VMDebug.startEmulatorTracing();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 45 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project android_frameworks_base by AOSPA.

the class BinderProxy method onShellCommand.

/**
     * Handle a call to {@link #shellCommand}.  The default implementation simply prints
     * an error message.  Override and replace with your own.
     * <p class="caution">Note: no permission checking is done before calling this method; you must
     * apply any security checks as appropriate for the command being executed.
     * Consider using {@link ShellCommand} to help in the implementation.</p>
     * @hide
     */
public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ResultReceiver resultReceiver) throws RemoteException {
    FileOutputStream fout = new FileOutputStream(err != null ? err : out);
    PrintWriter pw = new FastPrintWriter(fout);
    pw.println("No shell command implementation.");
    pw.flush();
    resultReceiver.send(0, null);
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Aggregations

FastPrintWriter (com.android.internal.util.FastPrintWriter)128 PrintWriter (java.io.PrintWriter)122 FileOutputStream (java.io.FileOutputStream)61 StringWriter (java.io.StringWriter)34 LogWriter (android.util.LogWriter)24 StrictMode (android.os.StrictMode)17 IOException (java.io.IOException)16 FileNotFoundException (java.io.FileNotFoundException)12 Date (java.util.Date)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Uri (android.net.Uri)7 Message (android.os.Message)7 ArrayMap (android.util.ArrayMap)7 PrintWriterPrinter (android.util.PrintWriterPrinter)7 SimpleDateFormat (java.text.SimpleDateFormat)7 NotFoundException (android.content.res.Resources.NotFoundException)5 Point (android.graphics.Point)5 LogPrinter (android.util.LogPrinter)5 Printer (android.util.Printer)5