Prevent AutoCompleteTextView from opening a popup when it shouldn't
Bug #5553515

The People app is forcing ACTV to show the IME which had the side effect
of showing the drop down popup. ACTV was unfortunately not ready to show
the drop down if the filtering resulted in no results. Doing so was putting
ACTV in a weird state that in turn caused a window to be leaked and really
bad behavior to occur in the lower graphics levels.

Change-Id: I2ff146d5ae4e4a28edf6ea17039c9f8fdb710e4f
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index f7a6b272..de11fe9 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -1031,7 +1031,9 @@
     public void ensureImeVisible(boolean visible) {
         mPopup.setInputMethodMode(visible
                 ? ListPopupWindow.INPUT_METHOD_NEEDED : ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
-        showDropDown();
+        if (mPopup.isDropDownAlwaysVisible() || (mFilter != null && enoughToFilter())) {
+            showDropDown();
+        }
     }
 
     /**
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java
index 4037a69..0a868fa 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TextActivity.java
@@ -21,6 +21,7 @@
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.os.Bundle;
+import android.text.TextPaint;
 import android.view.View;
 
 @SuppressWarnings({"UnusedDeclaration"})
@@ -39,6 +40,7 @@
         private final Paint mScaledPaint;
         private final Paint mSkewPaint;
         private final Paint mHugePaint;
+        private final TextPaint mEventPaint;
 
         CustomTextView(Context c) {
             super(c);
@@ -70,6 +72,11 @@
             mHugePaint.setAntiAlias(true);
             mHugePaint.setColor(0xff000000);
             mHugePaint.setTextSize(300f);
+
+            mEventPaint = new TextPaint();
+            mEventPaint.setFakeBoldText(true);
+            mEventPaint.setAntiAlias(true);
+            mEventPaint.setTextSize(14);
         }
 
         @Override
@@ -77,6 +84,8 @@
             super.onDraw(canvas);
             canvas.drawRGB(255, 255, 255);
 
+            canvas.drawText("Hello OpenGL renderer!", 300, 20, mEventPaint);
+            
             mMediumPaint.setStyle(Paint.Style.FILL_AND_STROKE);
             mMediumPaint.setStrokeWidth(2.0f);
             canvas.drawText("Hello OpenGL renderer!", 100, 20, mMediumPaint);