Skip to content

Commit 6757572

Browse files
Craig MautnerAndroid (Google) Code Review
authored andcommitted
Merge "Add throwing InvalidDisplayException from addView." into jb-mr1-dev
2 parents c63aa96 + 6018aee commit 6757572

File tree

7 files changed

+78
-26
lines changed

7 files changed

+78
-26
lines changed

api/17.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7094,7 +7094,7 @@ package android.content.res {
70947094
method public int getIndexCount();
70957095
method public int getInt(int, int);
70967096
method public int getInteger(int, int);
7097-
method public deprecated int getLayoutDimension(int, java.lang.String);
7097+
method public int getLayoutDimension(int, java.lang.String);
70987098
method public int getLayoutDimension(int, int);
70997099
method public java.lang.String getNonResourceString(int);
71007100
method public java.lang.String getPositionDescription();
@@ -8263,6 +8263,7 @@ package android.graphics {
82638263
method public int getScaledWidth(int);
82648264
method public final int getWidth();
82658265
method public final boolean hasAlpha();
8266+
method public final boolean hasMipMap();
82668267
method public final boolean isMutable();
82678268
method public final boolean isPremultiplied();
82688269
method public final boolean isRecycled();
@@ -8271,6 +8272,7 @@ package android.graphics {
82718272
method public boolean sameAs(android.graphics.Bitmap);
82728273
method public void setDensity(int);
82738274
method public void setHasAlpha(boolean);
8275+
method public final void setHasMipMap(boolean);
82748276
method public void setPixel(int, int, int);
82758277
method public void setPixels(int[], int, int, int, int, int, int);
82768278
method public void writeToParcel(android.os.Parcel, int);
@@ -25975,6 +25977,11 @@ package android.view {
2597525977
ctor public WindowManager.BadTokenException(java.lang.String);
2597625978
}
2597725979

25980+
public static class WindowManager.InvalidDisplayException extends java.lang.RuntimeException {
25981+
ctor public WindowManager.InvalidDisplayException();
25982+
ctor public WindowManager.InvalidDisplayException(java.lang.String);
25983+
}
25984+
2597825985
public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable {
2597925986
ctor public WindowManager.LayoutParams();
2598025987
ctor public WindowManager.LayoutParams(int);

api/current.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16151,7 +16151,7 @@ package android.os {
1615116151

1615216152
public class Looper {
1615316153
method public void dump(android.util.Printer, java.lang.String);
16154-
method public static synchronized android.os.Looper getMainLooper();
16154+
method public static android.os.Looper getMainLooper();
1615516155
method public java.lang.Thread getThread();
1615616156
method public static void loop();
1615716157
method public static android.os.Looper myLooper();
@@ -25977,6 +25977,11 @@ package android.view {
2597725977
ctor public WindowManager.BadTokenException(java.lang.String);
2597825978
}
2597925979

25980+
public static class WindowManager.InvalidDisplayException extends java.lang.RuntimeException {
25981+
ctor public WindowManager.InvalidDisplayException();
25982+
ctor public WindowManager.InvalidDisplayException(java.lang.String);
25983+
}
25984+
2598025985
public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable {
2598125986
ctor public WindowManager.LayoutParams();
2598225987
ctor public WindowManager.LayoutParams(int);

core/java/android/app/Presentation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ protected void onStop() {
140140
super.onStop();
141141
}
142142

143+
/**
144+
* Inherited from {@link Dialog#show}. Will throw
145+
* {@link android.view.WindowManager.InvalidDisplayException} if the specified secondary
146+
* {@link Display} can't be found.
147+
*/
148+
@Override
149+
public void show() {
150+
super.show();
151+
}
152+
143153
/**
144154
* Called by the system when the {@link Display} to which the presentation
145155
* is attached has been removed.

core/java/android/view/ViewManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
*/
2222
public interface ViewManager
2323
{
24+
/**
25+
* Assign the passed LayoutParams to the passed View and add the view to the window.
26+
* <p>Throws {@link android.view.WindowManager.BadTokenException} for certain programming
27+
* errors, such as adding a second view to a window without removing the first view.
28+
* <p>Throws {@link android.view.WindowManager.InvalidDisplayException} if the window is on a
29+
* secondary {@link Display} and the specified display can't be found
30+
* (see {@link android.app.Presentation}).
31+
* @param view The view to be added to this window.
32+
* @param params The LayoutParams to assign to view.
33+
*/
2434
public void addView(View view, ViewGroup.LayoutParams params);
2535
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
2636
public void removeView(View view);

core/java/android/view/ViewRootImpl.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
556556
mPendingVisibleInsets.set(0, 0, 0, 0);
557557
if (DEBUG_LAYOUT) Log.v(TAG, "Added window " + mWindow);
558558
if (res < WindowManagerGlobal.ADD_OKAY) {
559-
mView = null;
560559
mAttachInfo.mRootView = null;
561560
mAdded = false;
562561
mFallbackEventHandler.setView(null);
@@ -592,6 +591,10 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
592591
throw new WindowManager.BadTokenException(
593592
"Unable to add window " + mWindow +
594593
" -- permission denied for this window type");
594+
case WindowManagerGlobal.ADD_INVALID_DISPLAY:
595+
throw new WindowManager.InvalidDisplayException(
596+
"Unable to add window " + mWindow +
597+
" -- the specified display can not be found");
595598
}
596599
throw new RuntimeException(
597600
"Unable to add window -- unknown error code " + res);
@@ -808,27 +811,21 @@ void handleScreenStateChange(boolean on) {
808811
}
809812
}
810813

811-
/**
812-
* {@inheritDoc}
813-
*/
814+
@Override
814815
public void requestFitSystemWindows() {
815816
checkThread();
816817
mFitSystemWindowsRequested = true;
817818
scheduleTraversals();
818819
}
819820

820-
/**
821-
* {@inheritDoc}
822-
*/
821+
@Override
823822
public void requestLayout() {
824823
checkThread();
825824
mLayoutRequested = true;
826825
scheduleTraversals();
827826
}
828827

829-
/**
830-
* {@inheritDoc}
831-
*/
828+
@Override
832829
public boolean isLayoutRequested() {
833830
return mLayoutRequested;
834831
}
@@ -848,6 +845,7 @@ void invalidateWorld(View view) {
848845
}
849846
}
850847

848+
@Override
851849
public void invalidateChild(View child, Rect dirty) {
852850
invalidateChildInParent(null, dirty);
853851
}

core/java/android/view/WindowManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ public BadTokenException(String name) {
6161
}
6262
}
6363

64+
/**
65+
* Exception that is thrown when calling {@link #addView} to a secondary display that cannot
66+
* be found. See {@link android.app.Presentation} for more information on secondary displays.
67+
*/
68+
public static class InvalidDisplayException extends RuntimeException {
69+
public InvalidDisplayException() {
70+
}
71+
72+
public InvalidDisplayException(String name) {
73+
super(name);
74+
}
75+
}
76+
6477
/**
6578
* Returns the {@link Display} upon which this {@link WindowManager} instance
6679
* will create new windows.

core/java/android/view/WindowManagerGlobal.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public void addView(View view, ViewGroup.LayoutParams params,
186186
mSystemPropertyUpdater = new Runnable() {
187187
@Override public void run() {
188188
synchronized (mLock) {
189-
for (ViewRootImpl root : mRoots) {
190-
root.loadSystemProperties();
189+
for (ViewRootImpl viewRoot : mRoots) {
190+
viewRoot.loadSystemProperties();
191191
}
192192
}
193193
}
@@ -242,7 +242,18 @@ public void addView(View view, ViewGroup.LayoutParams params,
242242
}
243243

244244
// do this last because it fires off messages to start doing things
245-
root.setView(view, wparams, panelParentView);
245+
try {
246+
root.setView(view, wparams, panelParentView);
247+
} catch (RuntimeException e) {
248+
// BadTokenException or InvalidDisplayException, clean up.
249+
synchronized (mLock) {
250+
final int index = findViewLocked(view, false);
251+
if (index >= 0) {
252+
removeViewLocked(index, true);
253+
}
254+
}
255+
throw e;
256+
}
246257
}
247258

248259
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
@@ -360,20 +371,18 @@ private static void removeItem(Object[] dst, Object[] src, int index) {
360371
}
361372

362373
private int findViewLocked(View view, boolean required) {
363-
synchronized (mLock) {
364-
if (mViews != null) {
365-
final int count = mViews.length;
366-
for (int i = 0; i < count; i++) {
367-
if (mViews[i] == view) {
368-
return i;
369-
}
374+
if (mViews != null) {
375+
final int count = mViews.length;
376+
for (int i = 0; i < count; i++) {
377+
if (mViews[i] == view) {
378+
return i;
370379
}
371380
}
372-
if (required) {
373-
throw new IllegalArgumentException("View not attached to window manager");
374-
}
375-
return -1;
376381
}
382+
if (required) {
383+
throw new IllegalArgumentException("View not attached to window manager");
384+
}
385+
return -1;
377386
}
378387

379388
public void startTrimMemory(int level) {

0 commit comments

Comments
 (0)