From c1fdd2aa3276f2a3cc9c4dd9c5c6e1bbb2bd537f Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Wed, 21 Jun 2017 10:25:05 -0700 Subject: [PATCH] ListPopupWindow: Wrap new bounds checking in targetSdk check. While a negative height is pretty silly, crashing apps on the new version of android makes them sad. Test: Existing CTS passes. Bug: 62434804 Change-Id: I5fc3fc50fb6ccfa9e96f38ded4fb8e338f263f09 --- core/java/android/widget/ListPopupWindow.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java index 2e8faeec6f132..0d676153b2888 100644 --- a/core/java/android/widget/ListPopupWindow.java +++ b/core/java/android/widget/ListPopupWindow.java @@ -25,6 +25,7 @@ import android.content.res.TypedArray; import android.database.DataSetObserver; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Handler; import android.util.AttributeSet; import android.util.Log; @@ -532,8 +533,14 @@ public class ListPopupWindow implements ShowableListMenu { public void setHeight(int height) { if (height < 0 && ViewGroup.LayoutParams.WRAP_CONTENT != height && ViewGroup.LayoutParams.MATCH_PARENT != height) { - throw new IllegalArgumentException( - "Invalid height. Must be a positive value, MATCH_PARENT, or WRAP_CONTENT."); + if (mContext.getApplicationInfo().targetSdkVersion + < Build.VERSION_CODES.O) { + Log.e(TAG, "Negative value " + height + " passed to ListPopupWindow#setHeight" + + " produces undefined results"); + } else { + throw new IllegalArgumentException( + "Invalid height. Must be a positive value, MATCH_PARENT, or WRAP_CONTENT."); + } } mDropDownHeight = height; }