Skip to content

Commit f337a89

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "More view hierarchy, fragment debugging." into jb-mr1-dev
2 parents 427dccc + 4702a85 commit f337a89

File tree

11 files changed

+628
-585
lines changed

11 files changed

+628
-585
lines changed

api/17.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24500,7 +24500,6 @@ package android.view {
2450024500
field public static final int SYSTEM_UI_FLAG_VISIBLE = 0; // 0x0
2450124501
field public static final int SYSTEM_UI_LAYOUT_FLAGS = 1536; // 0x600
2450224502
field public static final int TEXT_ALIGNMENT_INHERIT = 0; // 0x0
24503-
field public static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = 131072; // 0x20000
2450424503
field public static final android.util.Property TRANSLATION_X;
2450524504
field public static final android.util.Property TRANSLATION_Y;
2450624505
field protected static final java.lang.String VIEW_LOG_TAG = "View";

api/current.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25029,16 +25029,15 @@ package android.view {
2502925029
field public static final int SYSTEM_UI_FLAG_VISIBLE = 0; // 0x0
2503025030
field public static final int SYSTEM_UI_LAYOUT_FLAGS = 1536; // 0x600
2503125031
field public static final int TEXT_ALIGNMENT_CENTER = 4; // 0x4
25032-
field protected static int TEXT_ALIGNMENT_DEFAULT;
25032+
field public static int TEXT_ALIGNMENT_DEFAULT;
2503325033
field public static final int TEXT_ALIGNMENT_GRAVITY = 1; // 0x1
2503425034
field public static final int TEXT_ALIGNMENT_INHERIT = 0; // 0x0
25035-
field public static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = 131072; // 0x20000
2503625035
field public static final int TEXT_ALIGNMENT_TEXT_END = 3; // 0x3
2503725036
field public static final int TEXT_ALIGNMENT_TEXT_START = 2; // 0x2
2503825037
field public static final int TEXT_ALIGNMENT_VIEW_END = 6; // 0x6
2503925038
field public static final int TEXT_ALIGNMENT_VIEW_START = 5; // 0x5
2504025039
field public static final int TEXT_DIRECTION_ANY_RTL = 2; // 0x2
25041-
field protected static int TEXT_DIRECTION_DEFAULT;
25040+
field public static int TEXT_DIRECTION_DEFAULT;
2504225041
field public static final int TEXT_DIRECTION_FIRST_STRONG = 1; // 0x1
2504325042
field public static final int TEXT_DIRECTION_INHERIT = 0; // 0x0
2504425043
field public static final int TEXT_DIRECTION_LOCALE = 5; // 0x5

core/java/android/app/Activity.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,6 +4733,29 @@ public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[]
47334733
mLoaderManager.dump(prefix + " ", fd, writer, args);
47344734
}
47354735
mFragments.dump(prefix, fd, writer, args);
4736+
writer.print(prefix); writer.println("View Hierarchy:");
4737+
dumpViewHierarchy(prefix + " ", writer, getWindow().getDecorView());
4738+
}
4739+
4740+
private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) {
4741+
writer.print(prefix);
4742+
if (view == null) {
4743+
writer.println("null");
4744+
return;
4745+
}
4746+
writer.println(view.toString());
4747+
if (!(view instanceof ViewGroup)) {
4748+
return;
4749+
}
4750+
ViewGroup grp = (ViewGroup)view;
4751+
final int N = grp.getChildCount();
4752+
if (N <= 0) {
4753+
return;
4754+
}
4755+
prefix = prefix + " ";
4756+
for (int i=0; i<N; i++) {
4757+
dumpViewHierarchy(prefix, writer, grp.getChildAt(i));
4758+
}
47364759
}
47374760

47384761
/**

core/java/android/app/FragmentManager.java

Lines changed: 36 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -428,92 +428,26 @@ public void run() {
428428
}
429429
};
430430

431-
private void logViewHierarchy(String prefix, View view) {
432-
StringBuilder builder = new StringBuilder(128);
433-
builder.append(prefix);
434-
DebugUtils.buildShortClassTag(view, builder);
435-
int id = view.getId();
436-
if (id != -1) {
437-
builder.append(" #");
438-
builder.append(Integer.toHexString(id));
439-
if (id != 0 && id != -1) {
440-
try {
441-
String pkgname;
442-
switch (id&0xff000000) {
443-
case 0x7f000000:
444-
pkgname="app";
445-
break;
446-
case 0x01000000:
447-
pkgname="android";
448-
break;
449-
default:
450-
pkgname = view.getResources().getResourcePackageName(id);
451-
break;
452-
}
453-
String typename = view.getResources().getResourceTypeName(id);
454-
String entryname = view.getResources().getResourceEntryName(id);
455-
builder.append(" (");
456-
builder.append(pkgname);
457-
builder.append(":");
458-
builder.append(typename);
459-
builder.append("/");
460-
builder.append(entryname);
461-
builder.append(")");
462-
} catch (Resources.NotFoundException e) {
463-
}
464-
}
465-
}
466-
Object tag = view.getTag();
467-
if (tag != null) {
468-
builder.append(" ");
469-
builder.append(tag);
470-
}
471-
builder.append("}");
472-
Log.e(TAG, builder.toString());
473-
474-
if (!(view instanceof ViewGroup)) {
475-
return;
476-
}
477-
ViewGroup grp = (ViewGroup)view;
478-
final int N = grp.getChildCount();
479-
if (N <= 0) {
480-
return;
481-
}
482-
prefix = prefix + " ";
483-
for (int i=0; i<N; i++) {
484-
logViewHierarchy(prefix, grp.getChildAt(i));
485-
}
486-
}
487-
488-
private void throwNoViewFound(Fragment f) {
489-
String msg = "No view found for id 0x"
490-
+ Integer.toHexString(f.mContainerId) + " ("
491-
+ f.getResources().getResourceName(f.mContainerId)
492-
+ ") for fragment " + f;
493-
Log.e(TAG, msg);
494-
Log.e(TAG, "Activity state:");
495-
if (f.getActivity() != null) {
431+
private void throwException(RuntimeException ex) {
432+
Log.e(TAG, ex.getMessage());
433+
LogWriter logw = new LogWriter(Log.ERROR, TAG);
434+
PrintWriter pw = new PrintWriter(logw);
435+
if (mActivity != null) {
436+
Log.e(TAG, "Activity state:");
496437
try {
497-
LogWriter logw = new LogWriter(Log.ERROR, TAG);
498-
PrintWriter pw = new PrintWriter(logw);
499-
f.getActivity().dump(" ", null, pw, new String[] { });
438+
mActivity.dump(" ", null, pw, new String[] { });
500439
} catch (Exception e) {
501440
Log.e(TAG, "Failed dumping state", e);
502441
}
503442
} else {
504-
Log.e(TAG, " NULL ACTIVITY!");
505-
}
506-
Log.e(TAG, "View hierarchy:");
507-
if (f.getActivity() != null) {
443+
Log.e(TAG, "Fragment manager state:");
508444
try {
509-
logViewHierarchy(" ", f.getActivity().getWindow().getDecorView());
445+
dump(" ", null, pw, new String[] { });
510446
} catch (Exception e) {
511-
Log.e(TAG, "Failed dumping view hierarchy", e);
447+
Log.e(TAG, "Failed dumping state", e);
512448
}
513-
} else {
514-
Log.e(TAG, " NULL ACTIVITY!");
515449
}
516-
throw new IllegalArgumentException(msg);
450+
throw ex;
517451
}
518452

519453
@Override
@@ -608,8 +542,8 @@ public void removeOnBackStackChangedListener(OnBackStackChangedListener listener
608542
@Override
609543
public void putFragment(Bundle bundle, String key, Fragment fragment) {
610544
if (fragment.mIndex < 0) {
611-
throw new IllegalStateException("Fragment " + fragment
612-
+ " is not currently in the FragmentManager");
545+
throwException(new IllegalStateException("Fragment " + fragment
546+
+ " is not currently in the FragmentManager"));
613547
}
614548
bundle.putInt(key, fragment.mIndex);
615549
}
@@ -621,22 +555,22 @@ public Fragment getFragment(Bundle bundle, String key) {
621555
return null;
622556
}
623557
if (index >= mActive.size()) {
624-
throw new IllegalStateException("Fragement no longer exists for key "
625-
+ key + ": index " + index);
558+
throwException(new IllegalStateException("Fragement no longer exists for key "
559+
+ key + ": index " + index));
626560
}
627561
Fragment f = mActive.get(index);
628562
if (f == null) {
629-
throw new IllegalStateException("Fragement no longer exists for key "
630-
+ key + ": index " + index);
563+
throwException(new IllegalStateException("Fragement no longer exists for key "
564+
+ key + ": index " + index));
631565
}
632566
return f;
633567
}
634568

635569
@Override
636570
public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) {
637571
if (fragment.mIndex < 0) {
638-
throw new IllegalStateException("Fragment " + fragment
639-
+ " is not currently in the FragmentManager");
572+
throwException(new IllegalStateException("Fragment " + fragment
573+
+ " is not currently in the FragmentManager"));
640574
}
641575
if (fragment.mState > Fragment.INITIALIZING) {
642576
Bundle result = saveFragmentBasicState(fragment);
@@ -913,7 +847,11 @@ void moveToState(Fragment f, int newState, int transit, int transitionStyle,
913847
if (f.mContainerId != 0) {
914848
container = (ViewGroup)mActivity.findViewById(f.mContainerId);
915849
if (container == null && !f.mRestored) {
916-
throwNoViewFound(f);
850+
throwException(new IllegalArgumentException(
851+
"No view found for id 0x"
852+
+ Integer.toHexString(f.mContainerId) + " ("
853+
+ f.getResources().getResourceName(f.mContainerId)
854+
+ ") for fragment " + f));
917855
}
918856
}
919857
f.mContainer = container;
@@ -1674,12 +1612,9 @@ Parcelable saveAllState() {
16741612
Fragment f = mActive.get(i);
16751613
if (f != null) {
16761614
if (f.mIndex < 0) {
1677-
String msg = "Failure saving state: active " + f
1678-
+ " has cleared index: " + f.mIndex;
1679-
Slog.e(TAG, msg);
1680-
dump(" ", null, new PrintWriter(new LogWriter(
1681-
Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { });
1682-
throw new IllegalStateException(msg);
1615+
throwException(new IllegalStateException(
1616+
"Failure saving state: active " + f
1617+
+ " has cleared index: " + f.mIndex));
16831618
}
16841619

16851620
haveFragments = true;
@@ -1692,12 +1627,9 @@ Parcelable saveAllState() {
16921627

16931628
if (f.mTarget != null) {
16941629
if (f.mTarget.mIndex < 0) {
1695-
String msg = "Failure saving state: " + f
1696-
+ " has target not in fragment manager: " + f.mTarget;
1697-
Slog.e(TAG, msg);
1698-
dump(" ", null, new PrintWriter(new LogWriter(
1699-
Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { });
1700-
throw new IllegalStateException(msg);
1630+
throwException(new IllegalStateException(
1631+
"Failure saving state: " + f
1632+
+ " has target not in fragment manager: " + f.mTarget));
17011633
}
17021634
if (fs.mSavedFragmentState == null) {
17031635
fs.mSavedFragmentState = new Bundle();
@@ -1736,12 +1668,9 @@ Parcelable saveAllState() {
17361668
for (int i=0; i<N; i++) {
17371669
added[i] = mAdded.get(i).mIndex;
17381670
if (added[i] < 0) {
1739-
String msg = "Failure saving state: active " + mAdded.get(i)
1740-
+ " has cleared index: " + added[i];
1741-
Slog.e(TAG, msg);
1742-
dump(" ", null, new PrintWriter(new LogWriter(
1743-
Log.ERROR, TAG, Log.LOG_ID_SYSTEM)), new String[] { });
1744-
throw new IllegalStateException(msg);
1671+
throwException(new IllegalStateException(
1672+
"Failure saving state: active " + mAdded.get(i)
1673+
+ " has cleared index: " + added[i]));
17451674
}
17461675
if (DEBUG) Log.v(TAG, "saveAllState: adding fragment #" + i
17471676
+ ": " + mAdded.get(i));
@@ -1846,8 +1775,8 @@ void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
18461775
for (int i=0; i<fms.mAdded.length; i++) {
18471776
Fragment f = mActive.get(fms.mAdded[i]);
18481777
if (f == null) {
1849-
throw new IllegalStateException(
1850-
"No instantiated fragment for index #" + fms.mAdded[i]);
1778+
throwException(new IllegalStateException(
1779+
"No instantiated fragment for index #" + fms.mAdded[i]));
18511780
}
18521781
f.mAdded = true;
18531782
if (DEBUG) Log.v(TAG, "restoreAllState: making added #" + i + ": " + f);
@@ -1875,7 +1804,7 @@ void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
18751804
}
18761805

18771806
public void attachActivity(Activity activity) {
1878-
if (mActivity != null) throw new IllegalStateException();
1807+
if (mActivity != null) throw new IllegalStateException("Already attached");
18791808
mActivity = activity;
18801809
}
18811810

core/java/android/view/HardwareRenderer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11011101
attachInfo.mIgnoreDirtyState = true;
11021102
attachInfo.mDrawingTime = SystemClock.uptimeMillis();
11031103

1104-
view.mPrivateFlags |= View.DRAWN;
1104+
view.mPrivateFlags |= View.PFLAG_DRAWN;
11051105

11061106
final int surfaceState = checkCurrent();
11071107
if (surfaceState != SURFACE_STATE_ERROR) {
@@ -1135,9 +1135,9 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
11351135
callbacks.onHardwarePreDraw(canvas);
11361136

11371137
try {
1138-
view.mRecreateDisplayList =
1139-
(view.mPrivateFlags & View.INVALIDATED) == View.INVALIDATED;
1140-
view.mPrivateFlags &= ~View.INVALIDATED;
1138+
view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED)
1139+
== View.PFLAG_INVALIDATED;
1140+
view.mPrivateFlags &= ~View.PFLAG_INVALIDATED;
11411141

11421142
long getDisplayListStartTime = 0;
11431143
if (mProfileEnabled) {

core/java/android/view/SurfaceView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public boolean gatherTransparentRegion(Region region) {
296296
}
297297

298298
boolean opaque = true;
299-
if ((mPrivateFlags & SKIP_DRAW) == 0) {
299+
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == 0) {
300300
// this view draws, remove it from the transparent region
301301
opaque = super.gatherTransparentRegion(region);
302302
} else if (region != null) {
@@ -320,7 +320,7 @@ public boolean gatherTransparentRegion(Region region) {
320320
public void draw(Canvas canvas) {
321321
if (mWindowType != WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
322322
// draw() is not called when SKIP_DRAW is set
323-
if ((mPrivateFlags & SKIP_DRAW) == 0) {
323+
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == 0) {
324324
// punch a whole in the view-hierarchy below us
325325
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
326326
}
@@ -332,7 +332,7 @@ public void draw(Canvas canvas) {
332332
protected void dispatchDraw(Canvas canvas) {
333333
if (mWindowType != WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
334334
// if SKIP_DRAW is cleared, draw() has already punched a hole
335-
if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) {
335+
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) {
336336
// punch a whole in the view-hierarchy below us
337337
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
338338
}

0 commit comments

Comments
 (0)