Search in sources :

Example 16 with LogWriter

use of android.util.LogWriter in project platform_frameworks_base by android.

the class BatteryStatsImpl method getNextOldHistoryLocked.

@Override
public boolean getNextOldHistoryLocked(HistoryItem out) {
    boolean end = mHistoryBuffer.dataPosition() >= mHistoryBuffer.dataSize();
    if (!end) {
        readHistoryDelta(mHistoryBuffer, mHistoryReadTmp);
        mReadOverflow |= mHistoryReadTmp.cmd == HistoryItem.CMD_OVERFLOW;
    }
    HistoryItem cur = mHistoryIterator;
    if (cur == null) {
        if (!mReadOverflow && !end) {
            Slog.w(TAG, "Old history ends before new history!");
        }
        return false;
    }
    out.setTo(cur);
    mHistoryIterator = cur.next;
    if (!mReadOverflow) {
        if (end) {
            Slog.w(TAG, "New history ends before old history!");
        } else if (!out.same(mHistoryReadTmp)) {
            PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG));
            pw.println("Histories differ!");
            pw.println("Old history:");
            (new HistoryPrinter()).printNextItem(pw, out, 0, false, true);
            pw.println("New history:");
            (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false, true);
            pw.flush();
        }
    }
    return true;
}
Also used : LogWriter(android.util.LogWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter) PrintWriter(java.io.PrintWriter) FastPrintWriter(com.android.internal.util.FastPrintWriter)

Example 17 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by ParanoidAndroid.

the class BackStackRecord method commitInternal.

int commitInternal(boolean allowStateLoss) {
    if (mCommitted)
        throw new IllegalStateException("commit already called");
    if (FragmentManagerImpl.DEBUG) {
        Log.v(TAG, "Commit: " + this);
        LogWriter logw = new LogWriter(Log.VERBOSE, TAG);
        PrintWriter pw = new PrintWriter(logw);
        dump("  ", null, pw, null);
    }
    mCommitted = true;
    if (mAddToBackStack) {
        mIndex = mManager.allocBackStackIndex(this);
    } else {
        mIndex = -1;
    }
    mManager.enqueueAction(this, allowStateLoss);
    return mIndex;
}
Also used : LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter)

Example 18 with LogWriter

use of android.util.LogWriter in project android_frameworks_base by ParanoidAndroid.

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 PrintWriter(logw);
    if (mActivity != null) {
        Log.e(TAG, "Activity state:");
        try {
            mActivity.dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            Log.e(TAG, "Failed dumping state", e);
        }
    } else {
        Log.e(TAG, "Fragment manager state:");
        try {
            dump("  ", null, pw, new String[] {});
        } catch (Exception e) {
            Log.e(TAG, "Failed dumping state", e);
        }
    }
    throw ex;
}
Also used : LogWriter(android.util.LogWriter) PrintWriter(java.io.PrintWriter)

Example 19 with LogWriter

use of android.util.LogWriter in project platform_frameworks_base by android.

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 20 with LogWriter

use of android.util.LogWriter in project platform_frameworks_base by android.

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)

Aggregations

LogWriter (android.util.LogWriter)31 PrintWriter (java.io.PrintWriter)31 FastPrintWriter (com.android.internal.util.FastPrintWriter)24 NotFoundException (android.content.res.Resources.NotFoundException)5 SuperNotCalledException (android.util.SuperNotCalledException)5 Bundle (android.os.Bundle)1