Search in sources :

Example 51 with FastPrintWriter

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

the class FragmentManagerImpl method restoreAllState.

void restoreAllState(Parcelable state, FragmentManagerNonConfig nonConfig) {
    // any nonConfig fragments either, so that is that.
    if (state == null)
        return;
    FragmentManagerState fms = (FragmentManagerState) state;
    if (fms.mActive == null)
        return;
    List<FragmentManagerNonConfig> childNonConfigs = null;
    // to their saved state, so we don't try to instantiate them again.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        childNonConfigs = nonConfig.getChildNonConfigs();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: re-attaching retained " + f);
            FragmentState fs = fms.mActive[f.mIndex];
            fs.mInstance = f;
            f.mSavedViewState = null;
            f.mBackStackNesting = 0;
            f.mInLayout = false;
            f.mAdded = false;
            f.mTarget = null;
            if (fs.mSavedFragmentState != null) {
                fs.mSavedFragmentState.setClassLoader(mHost.getContext().getClassLoader());
                f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(FragmentManagerImpl.VIEW_STATE_TAG);
                f.mSavedFragmentState = fs.mSavedFragmentState;
            }
        }
    }
    // Build the full list of active fragments, instantiating them from
    // their saved state.
    mActive = new ArrayList<>(fms.mActive.length);
    if (mAvailIndices != null) {
        mAvailIndices.clear();
    }
    for (int i = 0; i < fms.mActive.length; i++) {
        FragmentState fs = fms.mActive[i];
        if (fs != null) {
            FragmentManagerNonConfig childNonConfig = null;
            if (childNonConfigs != null && i < childNonConfigs.size()) {
                childNonConfig = childNonConfigs.get(i);
            }
            Fragment f = fs.instantiate(mHost, mParent, childNonConfig);
            if (DEBUG)
                Log.v(TAG, "restoreAllState: active #" + i + ": " + f);
            mActive.add(f);
            // Now that the fragment is instantiated (or came from being
            // retained above), clear mInstance in case we end up re-restoring
            // from this FragmentState again.
            fs.mInstance = null;
        } else {
            mActive.add(null);
            if (mAvailIndices == null) {
                mAvailIndices = new ArrayList<>();
            }
            if (DEBUG)
                Log.v(TAG, "restoreAllState: avail #" + i);
            mAvailIndices.add(i);
        }
    }
    // Update the target of all retained fragments.
    if (nonConfig != null) {
        List<Fragment> nonConfigFragments = nonConfig.getFragments();
        final int count = nonConfigFragments != null ? nonConfigFragments.size() : 0;
        for (int i = 0; i < count; i++) {
            Fragment f = nonConfigFragments.get(i);
            if (f.mTargetIndex >= 0) {
                if (f.mTargetIndex < mActive.size()) {
                    f.mTarget = mActive.get(f.mTargetIndex);
                } else {
                    Log.w(TAG, "Re-attaching retained fragment " + f + " target no longer exists: " + f.mTargetIndex);
                    f.mTarget = null;
                }
            }
        }
    }
    // Build the list of currently added fragments.
    if (fms.mAdded != null) {
        mAdded = new ArrayList<Fragment>(fms.mAdded.length);
        for (int i = 0; i < fms.mAdded.length; i++) {
            Fragment f = mActive.get(fms.mAdded[i]);
            if (f == null) {
                throwException(new IllegalStateException("No instantiated fragment for index #" + fms.mAdded[i]));
            }
            f.mAdded = true;
            if (DEBUG)
                Log.v(TAG, "restoreAllState: added #" + i + ": " + f);
            if (mAdded.contains(f)) {
                throw new IllegalStateException("Already added!");
            }
            mAdded.add(f);
        }
    } else {
        mAdded = null;
    }
    // Build the back stack.
    if (fms.mBackStack != null) {
        mBackStack = new ArrayList<BackStackRecord>(fms.mBackStack.length);
        for (int i = 0; i < fms.mBackStack.length; i++) {
            BackStackRecord bse = fms.mBackStack[i].instantiate(this);
            if (DEBUG) {
                Log.v(TAG, "restoreAllState: back stack #" + i + " (index " + bse.mIndex + "): " + bse);
                LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
                PrintWriter pw = new FastPrintWriter(logw, false, 1024);
                bse.dump("  ", pw, false);
                pw.flush();
            }
            mBackStack.add(bse);
            if (bse.mIndex >= 0) {
                setBackStackIndex(bse.mIndex, bse);
            }
        }
    } else {
        mBackStack = null;
    }
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 52 with FastPrintWriter

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

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

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

the class WindowLeaked method dumpGfxInfo.

public void dumpGfxInfo(FileDescriptor fd, String[] args) {
    FileOutputStream fout = new FileOutputStream(fd);
    PrintWriter pw = new FastPrintWriter(fout);
    try {
        synchronized (mLock) {
            final int count = mViews.size();
            pw.println("Profile data in ms:");
            for (int i = 0; i < count; i++) {
                ViewRootImpl root = mRoots.get(i);
                String name = getWindowName(root);
                pw.printf("\n\t%s (visibility=%d)", name, root.getHostVisibility());
                ThreadedRenderer renderer = root.getView().mAttachInfo.mHardwareRenderer;
                if (renderer != null) {
                    renderer.dumpGfxInfo(pw, fd, args);
                }
            }
            pw.println("\nView hierarchy:\n");
            int viewsCount = 0;
            int displayListsSize = 0;
            int[] info = new int[2];
            for (int i = 0; i < count; i++) {
                ViewRootImpl root = mRoots.get(i);
                root.dumpGfxInfo(info);
                String name = getWindowName(root);
                pw.printf("  %s\n  %d views, %.2f kB of display lists", name, info[0], info[1] / 1024.0f);
                pw.printf("\n\n");
                viewsCount += info[0];
                displayListsSize += info[1];
            }
            pw.printf("\nTotal ViewRootImpl: %d\n", count);
            pw.printf("Total Views:        %d\n", viewsCount);
            pw.printf("Total DisplayList:  %.2f kB\n\n", displayListsSize / 1024.0f);
        }
    } 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 54 with FastPrintWriter

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

the class CompilerStats method write.

// I/O
// The encoding is simple:
//
// 1) The first line is a line consisting of the version header and the version number.
//
// 2) The rest of the file is package data.
// 2.1) A package is started by any line not starting with "-";
// 2.2) Any line starting with "-" is code path data. The format is:
//      '-'{code-path}':'{compile-time}
public void write(Writer out) {
    @SuppressWarnings("resource") FastPrintWriter fpw = new FastPrintWriter(out);
    fpw.print(COMPILER_STATS_VERSION_HEADER);
    fpw.println(COMPILER_STATS_VERSION);
    synchronized (packageStats) {
        for (PackageStats pkg : packageStats.values()) {
            synchronized (pkg.compileTimePerCodePath) {
                if (!pkg.compileTimePerCodePath.isEmpty()) {
                    fpw.println(pkg.getPackageName());
                    for (Map.Entry<String, Long> e : pkg.compileTimePerCodePath.entrySet()) {
                        fpw.println("-" + e.getKey() + ":" + e.getValue());
                    }
                }
            }
        }
    }
    fpw.flush();
}
Also used : FastPrintWriter(com.android.internal.util.FastPrintWriter) HashMap(java.util.HashMap) Map(java.util.Map) ArrayMap(android.util.ArrayMap)

Example 55 with FastPrintWriter

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

the class ActivityThread method handleDumpService.

private void handleDumpService(DumpComponentInfo info) {
    final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        Service s = mServices.get(info.token);
        if (s != null) {
            PrintWriter pw = new FastPrintWriter(new FileOutputStream(info.fd.getFileDescriptor()));
            s.dump(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)

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