Search in sources :

Example 76 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project platform_frameworks_base by android.

the class BinderProxy method dumpAsync.

/**
     * Like {@link #dump(FileDescriptor, String[])}, but ensures the target
     * executes asynchronously.
     */
public void dumpAsync(final FileDescriptor fd, final String[] args) {
    final FileOutputStream fout = new FileOutputStream(fd);
    final PrintWriter pw = new FastPrintWriter(fout);
    Thread thr = new Thread("Binder.dumpAsync") {

        public void run() {
            try {
                dump(fd, pw, args);
            } finally {
                pw.flush();
            }
        }
    };
    thr.start();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 77 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project platform_frameworks_base by android.

the class BinderProxy method dump.

/**
     * Implemented to call the more convenient version
     * {@link #dump(FileDescriptor, PrintWriter, String[])}.
     */
public void dump(FileDescriptor fd, String[] args) {
    FileOutputStream fout = new FileOutputStream(fd);
    PrintWriter pw = new FastPrintWriter(fout);
    try {
        doDump(fd, pw, args);
    } finally {
        pw.flush();
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 78 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project platform_frameworks_base by android.

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)

Example 79 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project platform_frameworks_base by android.

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 80 with FastPrintWriter

use of com.android.internal.util.FastPrintWriter in project platform_frameworks_base by android.

the class StrictMode method readAndHandleBinderCallViolations.

/**
     * Called from Parcel.readException() when the exception is EX_STRICT_MODE_VIOLATIONS,
     * we here read back all the encoded violations.
     */
/* package */
static void readAndHandleBinderCallViolations(Parcel p) {
    // Our own stack trace to append
    StringWriter sw = new StringWriter();
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    new LogStackTrace().printStackTrace(pw);
    pw.flush();
    String ourStack = sw.toString();
    int policyMask = getThreadPolicyMask();
    boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
    int numViolations = p.readInt();
    for (int i = 0; i < numViolations; ++i) {
        if (LOG_V)
            Log.d(TAG, "strict mode violation stacks read from binder call.  i=" + i);
        ViolationInfo info = new ViolationInfo(p, !currentlyGathering);
        if (info.crashInfo.stackTrace != null && info.crashInfo.stackTrace.length() > 30000) {
            String front = info.crashInfo.stackTrace.substring(0, 256);
            // 30000 characters is way too large for this to be any sane kind of
            // strict mode collection of stacks.  We've had a problem where we leave
            // strict mode violations associated with the thread, and it keeps tacking
            // more and more stacks on to the violations.  Looks like we're in this casse,
            // so we'll report it and bail on all of the current strict mode violations
            // we currently are maintaining for this thread.
            // First, drain the remaining violations from the parcel.
            // Skip the current entry.
            i++;
            for (; i < numViolations; i++) {
                info = new ViolationInfo(p, !currentlyGathering);
            }
            // Next clear out all gathered violations.
            clearGatheredViolations();
            // Now report the problem.
            Slog.wtfStack(TAG, "Stack is too large: numViolations=" + numViolations + " policy=#" + Integer.toHexString(policyMask) + " front=" + front);
            return;
        }
        info.crashInfo.stackTrace += "# via Binder call with stack:\n" + ourStack;
        BlockGuard.Policy policy = BlockGuard.getThreadPolicy();
        if (policy instanceof AndroidBlockGuardPolicy) {
            ((AndroidBlockGuardPolicy) policy).handleViolationWithTimingAttempt(info);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) BlockGuard(dalvik.system.BlockGuard) 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