diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-08-17 15:18:29 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-08-17 17:35:00 -0700 |
commit | 4702a856973a553deb82f71b1d3b6c3db5dbf4ba (patch) | |
tree | 355aaea84ebfa78d9e712c1b46fb257e55000d0f /core/java/android/app | |
parent | 79af1dd54c16cde063152922b42c96d72ae9eca8 (diff) | |
download | frameworks_base-4702a856973a553deb82f71b1d3b6c3db5dbf4ba.zip frameworks_base-4702a856973a553deb82f71b1d3b6c3db5dbf4ba.tar.gz frameworks_base-4702a856973a553deb82f71b1d3b6c3db5dbf4ba.tar.bz2 |
More view hierarchy, fragment debugging.
Add a View.toString() method.
Rename all of the View private flags to have a PFLAG prefix to
avoid going insane trying to figure out which constant goes with
which flag.
Activity.dump() now includes a summary of the activity's view
hierarchy, using the View.toString() method.
All exceptions thrown by FragmentManager now perform a dump of
the owning activity state, where appropriate.
Change-Id: I6482e397e10cb5a0612ab02ce6ed5131823437a6
Diffstat (limited to 'core/java/android/app')
-rw-r--r-- | core/java/android/app/Activity.java | 23 | ||||
-rw-r--r-- | core/java/android/app/FragmentManager.java | 143 |
2 files changed, 59 insertions, 107 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 809acac..77107ee 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -4733,6 +4733,29 @@ public class Activity extends ContextThemeWrapper mLoaderManager.dump(prefix + " ", fd, writer, args); } mFragments.dump(prefix, fd, writer, args); + writer.print(prefix); writer.println("View Hierarchy:"); + dumpViewHierarchy(prefix + " ", writer, getWindow().getDecorView()); + } + + private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { + writer.print(prefix); + if (view == null) { + writer.println("null"); + return; + } + writer.println(view.toString()); + if (!(view instanceof ViewGroup)) { + return; + } + ViewGroup grp = (ViewGroup)view; + final int N = grp.getChildCount(); + if (N <= 0) { + return; + } + prefix = prefix + " "; + for (int i=0; i<N; i++) { + dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); + } } /** diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index c1e11bb..52a6557 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -428,92 +428,26 @@ final class FragmentManagerImpl extends FragmentManager { } }; - private void logViewHierarchy(String prefix, View view) { - StringBuilder builder = new StringBuilder(128); - builder.append(prefix); - DebugUtils.buildShortClassTag(view, builder); - int id = view.getId(); - if (id != -1) { - builder.append(" #"); - builder.append(Integer.toHexString(id)); - if (id != 0 && id != -1) { - try { - String pkgname; - switch (id&0xff000000) { - case 0x7f000000: - pkgname="app"; - break; - case 0x01000000: - pkgname="android"; - break; - default: - pkgname = view.getResources().getResourcePackageName(id); - break; - } - String typename = view.getResources().getResourceTypeName(id); - String entryname = view.getResources().getResourceEntryName(id); - builder.append(" ("); - builder.append(pkgname); - builder.append(":"); - builder.append(typename); - builder.append("/"); - builder.append(entryname); - builder.append(")"); - } catch (Resources.NotFoundException e) { - } - } - } - Object tag = view.getTag(); - if (tag != null) { - builder.append(" "); - builder.append(tag); - } - builder.append("}"); - Log.e(TAG, builder.toString()); - - if (!(view instanceof ViewGroup)) { - return; - } - ViewGroup grp = (ViewGroup)view; - final int N = grp.getChildCount(); - if (N <= 0) { - return; - } - prefix = prefix + " "; - for (int i=0; i<N; i++) { - logViewHierarchy(prefix, grp.getChildAt(i)); - } - } - - private void throwNoViewFound(Fragment f) { - String msg = "No view found for id 0x" - + Integer.toHexString(f.mContainerId) + " (" - + f.getResources().getResourceName(f.mContainerId) - + ") for fragment " + f; - Log.e(TAG, msg); - Log.e(TAG, "Activity state:"); - if (f.getActivity() != null) { + 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 { - LogWriter logw = new LogWriter(Log.ERROR, TAG); - PrintWriter pw = new PrintWriter(logw); - f.getActivity().dump(" ", null, pw, new String[] { }); + mActivity.dump(" ", null, pw, new String[] { }); } catch (Exception e) { Log.e(TAG, "Failed dumping state", e); } } else { - Log.e(TAG, " NULL ACTIVITY!"); - } - Log.e(TAG, "View hierarchy:"); - if (f.getActivity() != null) { + Log.e(TAG, "Fragment manager state:"); try { - logViewHierarchy(" ", f.getActivity().getWindow().getDecorView()); + dump(" ", null, pw, new String[] { }); } catch (Exception e) { - Log.e(TAG, "Failed dumping view hierarchy", e); + Log.e(TAG, "Failed dumping state", e); } - } else { - Log.e(TAG, " NULL ACTIVITY!"); } - throw new IllegalArgumentException(msg); + throw ex; } @Override @@ -608,8 +542,8 @@ final class FragmentManagerImpl extends FragmentManager { @Override public void putFragment(Bundle bundle, String key, Fragment fragment) { if (fragment.mIndex < 0) { - throw new IllegalStateException("Fragment " + fragment - + " is not currently in the FragmentManager"); + throwException(new IllegalStateException("Fragment " + fragment + + " is not currently in the FragmentManager")); } bundle.putInt(key, fragment.mIndex); } @@ -621,13 +555,13 @@ final class FragmentManagerImpl extends FragmentManager { return null; } if (index >= mActive.size()) { - throw new IllegalStateException("Fragement no longer exists for key " - + key + ": index " + index); + throwException(new IllegalStateException("Fragement no longer exists for key " + + key + ": index " + index)); } Fragment f = mActive.get(index); if (f == null) { - throw new IllegalStateException("Fragement no longer exists for key " - + key + ": index " + index); + throwException(new IllegalStateException("Fragement no longer exists for key " + + key + ": index " + index)); } return f; } @@ -635,8 +569,8 @@ final class FragmentManagerImpl extends FragmentManager { @Override public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) { if (fragment.mIndex < 0) { - throw new IllegalStateException("Fragment " + fragment - + " is not currently in the FragmentManager"); + throwException(new IllegalStateException("Fragment " + fragment + + " is not currently in the FragmentManager")); } if (fragment.mState > Fragment.INITIALIZING) { Bundle result = saveFragmentBasicState(fragment); @@ -913,7 +847,11 @@ final class FragmentManagerImpl extends FragmentManager { if (f.mContainerId != 0) { container = (ViewGroup)mActivity.findViewById(f.mContainerId); if (container == null && !f.mRestored) { - throwNoViewFound(f); + throwException(new IllegalArgumentException( + "No view found for id 0x" + + Integer.toHexString(f.mContainerId) + " (" + + f.getResources().getResourceName(f.mContainerId) + + ") for fragment " + f)); } } f.mContainer = container; @@ -1674,12 +1612,9 @@ final class FragmentManagerImpl extends FragmentManager { Fragment f = mActive.get(i); if (f != null) { if (f.mIndex < 0) { - String msg = "Failure saving state: active " + f - + " has cleared index: " + f.mIndex; - Slog.e(TAG, msg); - dump(" ", null, new PrintWriter(new LogWriter( - Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { }); - throw new IllegalStateException(msg); + throwException(new IllegalStateException( + "Failure saving state: active " + f + + " has cleared index: " + f.mIndex)); } haveFragments = true; @@ -1692,12 +1627,9 @@ final class FragmentManagerImpl extends FragmentManager { if (f.mTarget != null) { if (f.mTarget.mIndex < 0) { - String msg = "Failure saving state: " + f - + " has target not in fragment manager: " + f.mTarget; - Slog.e(TAG, msg); - dump(" ", null, new PrintWriter(new LogWriter( - Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { }); - throw new IllegalStateException(msg); + throwException(new IllegalStateException( + "Failure saving state: " + f + + " has target not in fragment manager: " + f.mTarget)); } if (fs.mSavedFragmentState == null) { fs.mSavedFragmentState = new Bundle(); @@ -1736,12 +1668,9 @@ final class FragmentManagerImpl extends FragmentManager { for (int i=0; i<N; i++) { added[i] = mAdded.get(i).mIndex; if (added[i] < 0) { - String msg = "Failure saving state: active " + mAdded.get(i) - + " has cleared index: " + added[i]; - Slog.e(TAG, msg); - dump(" ", null, new PrintWriter(new LogWriter( - Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { }); - throw new IllegalStateException(msg); + throwException(new IllegalStateException( + "Failure saving state: active " + mAdded.get(i) + + " has cleared index: " + added[i])); } if (DEBUG) Log.v(TAG, "saveAllState: adding fragment #" + i + ": " + mAdded.get(i)); @@ -1846,8 +1775,8 @@ final class FragmentManagerImpl extends FragmentManager { for (int i=0; i<fms.mAdded.length; i++) { Fragment f = mActive.get(fms.mAdded[i]); if (f == null) { - throw new IllegalStateException( - "No instantiated fragment for index #" + fms.mAdded[i]); + throwException(new IllegalStateException( + "No instantiated fragment for index #" + fms.mAdded[i])); } f.mAdded = true; if (DEBUG) Log.v(TAG, "restoreAllState: making added #" + i + ": " + f); @@ -1875,7 +1804,7 @@ final class FragmentManagerImpl extends FragmentManager { } public void attachActivity(Activity activity) { - if (mActivity != null) throw new IllegalStateException(); + if (mActivity != null) throw new IllegalStateException("Already attached"); mActivity = activity; } |