Search in sources :

Example 46 with FastPrintWriter

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

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

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

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

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

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();
    sw.append("# via Binder call with stack:\n");
    PrintWriter pw = new FastPrintWriter(sw, false, 256);
    new LogStackTrace().printStackTrace(pw);
    pw.flush();
    String ourStack = sw.toString();
    final int policyMask = getThreadPolicyMask();
    final boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
    final int size = p.readInt();
    for (int i = 0; i < size; i++) {
        final ViolationInfo info = new ViolationInfo(p, !currentlyGathering);
        info.crashInfo.appendStackTrace(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)

Example 49 with FastPrintWriter

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

the class FragmentManagerImpl method throwException.

private void throwException(RuntimeException ex) {
    Log.e(TAG, ex.getMessage());
    LogWriter logw = new LogWriter(Log.ERROR, TAG);
    PrintWriter pw = new FastPrintWriter(logw, false, 1024);
    if (mHost != null) {
        Log.e(TAG, "Activity state:");
        try {
            mHost.onDump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            pw.flush();
            Log.e(TAG, "Failed dumping state", e);
        }
    } else {
        Log.e(TAG, "Fragment manager state:");
        try {
            dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            pw.flush();
            Log.e(TAG, "Failed dumping state", e);
        }
    }
    pw.flush();
    throw ex;
}
Also used : LogWriter(android.util.LogWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) SuperNotCalledException(android.util.SuperNotCalledException) NotFoundException(android.content.res.Resources.NotFoundException) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 50 with FastPrintWriter

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

the class BackStackRecord method popFromBackStack.

public TransitionState popFromBackStack(boolean doStateMove, TransitionState state, SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments) {
    if (FragmentManagerImpl.DEBUG) {
        Log.v(TAG, "popFromBackStack: " + this);
        LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
        PrintWriter pw = new FastPrintWriter(logw, false, 1024);
        dump("  ", null, pw, null);
        pw.flush();
    }
    if (mManager.mCurState >= Fragment.CREATED) {
        if (state == null) {
            if (firstOutFragments.size() != 0 || lastInFragments.size() != 0) {
                state = beginTransition(firstOutFragments, lastInFragments, true);
            }
        } else if (!doStateMove) {
            setNameOverrides(state, mSharedElementTargetNames, mSharedElementSourceNames);
        }
    }
    bumpBackStackNesting(-1);
    Op op = mTail;
    while (op != null) {
        switch(op.cmd) {
            case OP_ADD:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_REPLACE:
                {
                    Fragment f = op.fragment;
                    if (f != null) {
                        f.mNextAnim = op.popExitAnim;
                        mManager.removeFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                    }
                    if (op.removed != null) {
                        for (int i = 0; i < op.removed.size(); i++) {
                            Fragment old = op.removed.get(i);
                            old.mNextAnim = op.popEnterAnim;
                            mManager.addFragment(old, false);
                        }
                    }
                }
                break;
            case OP_REMOVE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.addFragment(f, false);
                }
                break;
            case OP_HIDE:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.showFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_SHOW:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.hideFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_DETACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popEnterAnim;
                    mManager.attachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            case OP_ATTACH:
                {
                    Fragment f = op.fragment;
                    f.mNextAnim = op.popExitAnim;
                    mManager.detachFragment(f, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
                }
                break;
            default:
                {
                    throw new IllegalArgumentException("Unknown cmd: " + op.cmd);
                }
        }
        op = op.prev;
    }
    if (doStateMove) {
        mManager.moveToState(mManager.mCurState, FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle, true);
        state = null;
    }
    if (mIndex >= 0) {
        mManager.freeBackStackIndex(mIndex);
        mIndex = -1;
    }
    return state;
}
Also used : LogWriter(android.util.LogWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) 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