Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6018aeec authored by Craig Mautner's avatar Craig Mautner
Browse files

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
parent 04c8d402
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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);
+6 −1
Original line number Diff line number Diff line
@@ -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);
+10 −0
Original line number Diff line number Diff line
@@ -140,6 +140,16 @@ public class Presentation extends Dialog {
        super.onStop();
    }

    /**
     * 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.
+10 −0
Original line number Diff line number Diff line
@@ -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);
+8 −10
Original line number Diff line number Diff line
@@ -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);
    }
Loading