diff options
author | Craig Mautner <cmautner@google.com> | 2012-10-23 14:27:49 -0700 |
---|---|---|
committer | Craig Mautner <cmautner@google.com> | 2012-10-23 15:34:29 -0700 |
commit | 6018aeec27914f138f36b00d8f00136a87562fd3 (patch) | |
tree | 0c8b276da84779587815f20d5ccd2b6a5c78c27e /core/java/android/view/WindowManagerGlobal.java | |
parent | 04c8d402fa824c548dc5de82c56e63eb5df02371 (diff) | |
download | frameworks_base-6018aeec27914f138f36b00d8f00136a87562fd3.zip frameworks_base-6018aeec27914f138f36b00d8f00136a87562fd3.tar.gz frameworks_base-6018aeec27914f138f36b00d8f00136a87562fd3.tar.bz2 |
Add throwing InvalidDisplayException from addView.
Throw an InvalidDisplayException to addView if the display being
added to has been removed. Handle this exception in Dialog.show()
by removing the view after it has been added and rethrow the
exception from there.
Add javadoc to ViewManager.addView and Presentation.show explaining
the new exception and how best to handle it.
Bug: 7368565 partially fixed. It remains for the Videos app to
handle Presentation.show throwing the InvalidDisplayException.
Change-Id: Ib4303c9b3f7bf7a0cfa95d19bd60a0c128658c48
Diffstat (limited to 'core/java/android/view/WindowManagerGlobal.java')
-rw-r--r-- | core/java/android/view/WindowManagerGlobal.java | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index 5cdc1ed..e8945aa 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -186,8 +186,8 @@ public final class WindowManagerGlobal { mSystemPropertyUpdater = new Runnable() { @Override public void run() { synchronized (mLock) { - for (ViewRootImpl root : mRoots) { - root.loadSystemProperties(); + for (ViewRootImpl viewRoot : mRoots) { + viewRoot.loadSystemProperties(); } } } @@ -242,7 +242,18 @@ public final class WindowManagerGlobal { } // do this last because it fires off messages to start doing things - root.setView(view, wparams, panelParentView); + try { + root.setView(view, wparams, panelParentView); + } catch (RuntimeException e) { + // BadTokenException or InvalidDisplayException, clean up. + synchronized (mLock) { + final int index = findViewLocked(view, false); + if (index >= 0) { + removeViewLocked(index, true); + } + } + throw e; + } } public void updateViewLayout(View view, ViewGroup.LayoutParams params) { @@ -360,20 +371,18 @@ public final class WindowManagerGlobal { } private int findViewLocked(View view, boolean required) { - synchronized (mLock) { - if (mViews != null) { - final int count = mViews.length; - for (int i = 0; i < count; i++) { - if (mViews[i] == view) { - return i; - } + if (mViews != null) { + final int count = mViews.length; + for (int i = 0; i < count; i++) { + if (mViews[i] == view) { + return i; } } - if (required) { - throw new IllegalArgumentException("View not attached to window manager"); - } - return -1; } + if (required) { + throw new IllegalArgumentException("View not attached to window manager"); + } + return -1; } public void startTrimMemory(int level) { |