summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Mautner <cmautner@google.com>2012-10-23 14:27:49 -0700
committerCraig Mautner <cmautner@google.com>2012-10-23 15:34:29 -0700
commit6018aeec27914f138f36b00d8f00136a87562fd3 (patch)
tree0c8b276da84779587815f20d5ccd2b6a5c78c27e
parent04c8d402fa824c548dc5de82c56e63eb5df02371 (diff)
downloadframeworks_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
-rw-r--r--api/17.txt9
-rw-r--r--api/current.txt7
-rw-r--r--core/java/android/app/Presentation.java10
-rw-r--r--core/java/android/view/ViewManager.java10
-rw-r--r--core/java/android/view/ViewRootImpl.java18
-rw-r--r--core/java/android/view/WindowManager.java13
-rw-r--r--core/java/android/view/WindowManagerGlobal.java37
7 files changed, 78 insertions, 26 deletions
diff --git a/api/17.txt b/api/17.txt
index 84c2a93..31ed755 100644
--- a/api/17.txt
+++ b/api/17.txt
@@ -7094,7 +7094,7 @@ package android.content.res {
method public int getIndexCount();
method public int getInt(int, int);
method public int getInteger(int, int);
- method public deprecated int getLayoutDimension(int, java.lang.String);
+ method public int getLayoutDimension(int, java.lang.String);
method public int getLayoutDimension(int, int);
method public java.lang.String getNonResourceString(int);
method public java.lang.String getPositionDescription();
@@ -8263,6 +8263,7 @@ package android.graphics {
method public int getScaledWidth(int);
method public final int getWidth();
method public final boolean hasAlpha();
+ method public final boolean hasMipMap();
method public final boolean isMutable();
method public final boolean isPremultiplied();
method public final boolean isRecycled();
@@ -8271,6 +8272,7 @@ package android.graphics {
method public boolean sameAs(android.graphics.Bitmap);
method public void setDensity(int);
method public void setHasAlpha(boolean);
+ method public final void setHasMipMap(boolean);
method public void setPixel(int, int, int);
method public void setPixels(int[], int, int, int, int, int, int);
method public void writeToParcel(android.os.Parcel, int);
@@ -25975,6 +25977,11 @@ package android.view {
ctor public WindowManager.BadTokenException(java.lang.String);
}
+ public static class WindowManager.InvalidDisplayException extends java.lang.RuntimeException {
+ ctor public WindowManager.InvalidDisplayException();
+ ctor public WindowManager.InvalidDisplayException(java.lang.String);
+ }
+
public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable {
ctor public WindowManager.LayoutParams();
ctor public WindowManager.LayoutParams(int);
diff --git a/api/current.txt b/api/current.txt
index 5462aee..31ed755 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -16151,7 +16151,7 @@ package android.os {
public class Looper {
method public void dump(android.util.Printer, java.lang.String);
- method public static synchronized android.os.Looper getMainLooper();
+ method public static android.os.Looper getMainLooper();
method public java.lang.Thread getThread();
method public static void loop();
method public static android.os.Looper myLooper();
@@ -25977,6 +25977,11 @@ package android.view {
ctor public WindowManager.BadTokenException(java.lang.String);
}
+ public static class WindowManager.InvalidDisplayException extends java.lang.RuntimeException {
+ ctor public WindowManager.InvalidDisplayException();
+ ctor public WindowManager.InvalidDisplayException(java.lang.String);
+ }
+
public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable {
ctor public WindowManager.LayoutParams();
ctor public WindowManager.LayoutParams(int);
diff --git a/core/java/android/app/Presentation.java b/core/java/android/app/Presentation.java
index b5e5244..20b27c5 100644
--- a/core/java/android/app/Presentation.java
+++ b/core/java/android/app/Presentation.java
@@ -141,6 +141,16 @@ public class Presentation extends Dialog {
}
/**
+ * Inherited from {@link Dialog#show}. Will throw
+ * {@link android.view.WindowManager.InvalidDisplayException} if the specified secondary
+ * {@link Display} can't be found.
+ */
+ @Override
+ public void show() {
+ super.show();
+ }
+
+ /**
* Called by the system when the {@link Display} to which the presentation
* is attached has been removed.
*
diff --git a/core/java/android/view/ViewManager.java b/core/java/android/view/ViewManager.java
index 7f318c1..ab6856f 100644
--- a/core/java/android/view/ViewManager.java
+++ b/core/java/android/view/ViewManager.java
@@ -21,6 +21,16 @@ package android.view;
*/
public interface ViewManager
{
+ /**
+ * Assign the passed LayoutParams to the passed View and add the view to the window.
+ * <p>Throws {@link android.view.WindowManager.BadTokenException} for certain programming
+ * errors, such as adding a second view to a window without removing the first view.
+ * <p>Throws {@link android.view.WindowManager.InvalidDisplayException} if the window is on a
+ * secondary {@link Display} and the specified display can't be found
+ * (see {@link android.app.Presentation}).
+ * @param view The view to be added to this window.
+ * @param params The LayoutParams to assign to view.
+ */
public void addView(View view, ViewGroup.LayoutParams params);
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
public void removeView(View view);
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index ded4cfc..aa54a29 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -558,7 +558,6 @@ public final class ViewRootImpl implements ViewParent,
mPendingVisibleInsets.set(0, 0, 0, 0);
if (DEBUG_LAYOUT) Log.v(TAG, "Added window " + mWindow);
if (res < WindowManagerGlobal.ADD_OKAY) {
- mView = null;
mAttachInfo.mRootView = null;
mAdded = false;
mFallbackEventHandler.setView(null);
@@ -594,6 +593,10 @@ public final class ViewRootImpl implements ViewParent,
throw new WindowManager.BadTokenException(
"Unable to add window " + mWindow +
" -- permission denied for this window type");
+ case WindowManagerGlobal.ADD_INVALID_DISPLAY:
+ throw new WindowManager.InvalidDisplayException(
+ "Unable to add window " + mWindow +
+ " -- the specified display can not be found");
}
throw new RuntimeException(
"Unable to add window -- unknown error code " + res);
@@ -810,27 +813,21 @@ public final class ViewRootImpl implements ViewParent,
}
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void requestFitSystemWindows() {
checkThread();
mFitSystemWindowsRequested = true;
scheduleTraversals();
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void requestLayout() {
checkThread();
mLayoutRequested = true;
scheduleTraversals();
}
- /**
- * {@inheritDoc}
- */
+ @Override
public boolean isLayoutRequested() {
return mLayoutRequested;
}
@@ -850,6 +847,7 @@ public final class ViewRootImpl implements ViewParent,
}
}
+ @Override
public void invalidateChild(View child, Rect dirty) {
invalidateChildInParent(null, dirty);
}
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 4c97414..01923e2 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -62,6 +62,19 @@ public interface WindowManager extends ViewManager {
}
/**
+ * Exception that is thrown when calling {@link #addView} to a secondary display that cannot
+ * be found. See {@link android.app.Presentation} for more information on secondary displays.
+ */
+ public static class InvalidDisplayException extends RuntimeException {
+ public InvalidDisplayException() {
+ }
+
+ public InvalidDisplayException(String name) {
+ super(name);
+ }
+ }
+
+ /**
* Returns the {@link Display} upon which this {@link WindowManager} instance
* will create new windows.
* <p>
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) {