Merge change 5190 into donut

* changes:
  Fix 1933269: startPreview failed.
diff --git a/api/current.xml b/api/current.xml
index 595a9f0..f5bcb5c 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -3485,17 +3485,6 @@
  visibility="public"
 >
 </field>
-<field name="donut_resource_pad29"
- type="int"
- transient="false"
- volatile="false"
- value="16843395"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="donut_resource_pad3"
  type="int"
  transient="false"
@@ -3672,6 +3661,17 @@
  visibility="public"
 >
 </field>
+<field name="dropDownHeight"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843395"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="dropDownHintAppearance"
  type="int"
  transient="false"
@@ -162150,6 +162150,17 @@
  visibility="public"
 >
 </method>
+<method name="getDropDownHeight"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getDropDownWidth"
  return="int"
  abstract="false"
@@ -162373,6 +162384,19 @@
 <parameter name="id" type="int">
 </parameter>
 </method>
+<method name="setDropDownHeight"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="height" type="int">
+</parameter>
+</method>
 <method name="setDropDownWidth"
  return="void"
  abstract="false"
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 5dd3ec4..70749d1 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -80,6 +80,7 @@
  * @attr ref android.R.styleable#AutoCompleteTextView_dropDownSelector
  * @attr ref android.R.styleable#AutoCompleteTextView_dropDownAnchor
  * @attr ref android.R.styleable#AutoCompleteTextView_dropDownWidth
+ * @attr ref android.R.styleable#AutoCompleteTextView_dropDownHeight
  */
 public class AutoCompleteTextView extends EditText implements Filter.FilterListener {
     static final boolean DEBUG = false;
@@ -101,6 +102,7 @@
     private int mDropDownAnchorId;
     private View mDropDownAnchorView;  // view is retrieved lazily from id once needed
     private int mDropDownWidth;
+    private int mDropDownHeight;
 
     private Drawable mDropDownListHighlight;
 
@@ -166,6 +168,8 @@
         // (for full screen width) or WRAP_CONTENT (to match the width of the anchored view).
         mDropDownWidth = a.getLayoutDimension(R.styleable.AutoCompleteTextView_dropDownWidth,
                 ViewGroup.LayoutParams.WRAP_CONTENT);
+        mDropDownHeight = a.getLayoutDimension(R.styleable.AutoCompleteTextView_dropDownHeight,
+                ViewGroup.LayoutParams.WRAP_CONTENT);
 
         mHintResource = a.getResourceId(R.styleable.AutoCompleteTextView_completionHintView,
                 R.layout.simple_dropdown_hint);
@@ -254,6 +258,34 @@
     public void setDropDownWidth(int width) {
         mDropDownWidth = width;
     }
+
+    /**
+     * <p>Returns the current height for the auto-complete drop down list. This can
+     * be a fixed height, or {@link ViewGroup.LayoutParams#FILL_PARENT} to fill
+     * the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the height
+     * of the drop down's content.</p>
+     *
+     * @return the height for the drop down list
+     *
+     * @attr ref android.R.styleable#AutoCompleteTextView_dropDownHeight
+     */
+    public int getDropDownHeight() {
+        return mDropDownHeight;
+    }
+
+    /**
+     * <p>Sets the current height for the auto-complete drop down list. This can
+     * be a fixed height, or {@link ViewGroup.LayoutParams#FILL_PARENT} to fill
+     * the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the height
+     * of the drop down's content.</p>
+     *
+     * @param height the height to use
+     *
+     * @attr ref android.R.styleable#AutoCompleteTextView_dropDownHeight
+     */
+    public void setDropDownHeight(int height) {
+        mDropDownHeight = height;
+    }
     
     /**
      * <p>Returns the id for the view that the auto-complete drop down list is anchored to.</p>
@@ -635,7 +667,7 @@
                     // event to prevent focus from moving.
                     clearListSelection();
                     mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
-                    mPopup.update();
+                    showDropDown();
                     return true;
                 } else {
                     // WARNING: Please read the comment where mListSelectionHidden
@@ -655,7 +687,7 @@
                     // by ensuring it has focus and getting its window out
                     // of touch mode.
                     mDropDownList.requestFocusFromTouch();
-                    mPopup.update();
+                    showDropDown();
 
                     switch (keyCode) {
                         // avoid passing the focus from the text view to the
@@ -1052,8 +1084,13 @@
      */
     public void showDropDown() {
         int height = buildDropDown();
+
+        int widthSpec = 0;
+        int heightSpec = 0;
+
+        boolean noInputMethod = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
+
         if (mPopup.isShowing()) {
-            int widthSpec;
             if (mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT) {
                 // The call to PopupWindow's update method below can accept -1 for any
                 // value you do not want to update.
@@ -1063,20 +1100,51 @@
             } else {
                 widthSpec = mDropDownWidth;
             }
+
+            if (mDropDownHeight == ViewGroup.LayoutParams.FILL_PARENT) {
+                // The call to PopupWindow's update method below can accept -1 for any
+                // value you do not want to update.
+                heightSpec = noInputMethod ? height : ViewGroup.LayoutParams.FILL_PARENT;
+                if (noInputMethod) {
+                    mPopup.setWindowLayoutMode(
+                            mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT ?
+                                    ViewGroup.LayoutParams.FILL_PARENT : 0, 0);
+                } else {
+                    mPopup.setWindowLayoutMode(
+                            mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT ?
+                                    ViewGroup.LayoutParams.FILL_PARENT : 0,
+                            ViewGroup.LayoutParams.FILL_PARENT);
+                }
+            } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
+                heightSpec = height;
+            } else {
+                heightSpec = mDropDownHeight;
+            }
+
             mPopup.update(getDropDownAnchorView(), mDropDownHorizontalOffset,
-                    mDropDownVerticalOffset, widthSpec, height);
+                    mDropDownVerticalOffset, widthSpec, heightSpec);
         } else {
             if (mDropDownWidth == ViewGroup.LayoutParams.FILL_PARENT) {
-                mPopup.setWindowLayoutMode(ViewGroup.LayoutParams.FILL_PARENT, 0);
+                widthSpec = ViewGroup.LayoutParams.FILL_PARENT;
             } else {
-                mPopup.setWindowLayoutMode(0, 0);
                 if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) {
                     mPopup.setWidth(getDropDownAnchorView().getWidth());
                 } else {
                     mPopup.setWidth(mDropDownWidth);
                 }
             }
-            mPopup.setHeight(height);
+
+            if (mDropDownHeight == ViewGroup.LayoutParams.FILL_PARENT) {
+                heightSpec = ViewGroup.LayoutParams.FILL_PARENT;
+            } else {
+                if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
+                    mPopup.setHeight(height);
+                } else {
+                    mPopup.setHeight(mDropDownHeight);
+                }
+            }
+
+            mPopup.setWindowLayoutMode(widthSpec, heightSpec);
             mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
             
             // use outside touchable to dismiss drop down when touching outside of it, so
@@ -1195,10 +1263,12 @@
         final int maxHeight = mPopup.getMaxAvailableHeight(
                 getDropDownAnchorView(), mDropDownVerticalOffset, ignoreBottomDecorations);
 
-        final int measuredHeight = mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,
-                0, ListView.NO_POSITION, maxHeight - otherHeights, 2) + otherHeights;
+        if (mDropDownAlwaysVisible) {
+            return maxHeight;
+        }
 
-        return mDropDownAlwaysVisible ? maxHeight : measuredHeight;
+        return mDropDownList.measureHeightOfChildren(MeasureSpec.UNSPECIFIED,
+                0, ListView.NO_POSITION, maxHeight - otherHeights, 2) + otherHeights;
     }
 
     private View getHintView(Context context) {
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index b188c31..bd6edfb 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -49,7 +49,7 @@
  */
 public class PopupWindow {
     /**
-     * Mode for {@link #setInputMethodMode(int): the requirements for the
+     * Mode for {@link #setInputMethodMode(int)}: the requirements for the
      * input method should be based on the focusability of the popup.  That is
      * if it is focusable than it needs to work with the input method, else
      * it doesn't.
@@ -57,16 +57,15 @@
     public static final int INPUT_METHOD_FROM_FOCUSABLE = 0;
     
     /**
-     * Mode for {@link #setInputMethodMode(int): this popup always needs to
+     * Mode for {@link #setInputMethodMode(int)}: this popup always needs to
      * work with an input method, regardless of whether it is focusable.  This
      * means that it will always be displayed so that the user can also operate
      * the input method while it is shown.
      */
-    
     public static final int INPUT_METHOD_NEEDED = 1;
     
     /**
-     * Mode for {@link #setInputMethodMode(int): this popup never needs to
+     * Mode for {@link #setInputMethodMode(int)}: this popup never needs to
      * work with an input method, regardless of whether it is focusable.  This
      * means that it will always be displayed to use as much space on the
      * screen as needed, regardless of whether this covers the input method.
@@ -1131,8 +1130,7 @@
             return;
         }
 
-        WindowManager.LayoutParams p = (WindowManager.LayoutParams)
-                mPopupView.getLayoutParams();
+        WindowManager.LayoutParams p = (WindowManager.LayoutParams) mPopupView.getLayoutParams();
 
         boolean update = force;
 
@@ -1219,8 +1217,7 @@
             registerForScrollChanged(anchor, xoff, yoff);
         }
 
-        WindowManager.LayoutParams p = (WindowManager.LayoutParams)
-                mPopupView.getLayoutParams();
+        WindowManager.LayoutParams p = (WindowManager.LayoutParams) mPopupView.getLayoutParams();
 
         if (updateDimension) {
             if (width == -1) {
diff --git a/core/res/res/layout/search_bar.xml b/core/res/res/layout/search_bar.xml
index 54ab6de..13e66aa 100644
--- a/core/res/res/layout/search_bar.xml
+++ b/core/res/res/layout/search_bar.xml
@@ -76,6 +76,7 @@
                 android:ellipsize="end"
                 android:inputType="text|textAutoComplete"
                 android:dropDownWidth="fill_parent"
+                android:dropDownHeight="fill_parent"
                 android:dropDownAnchor="@id/search_plate"
                 android:dropDownVerticalOffset="-9dip"
                 android:popupBackground="@android:drawable/search_dropdown_background"
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 23ab573..e978ef5 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1998,6 +1998,16 @@
             <!-- The dropdown should fit the width of its anchor. -->
             <enum name="wrap_content" value="-2" />
         </attr>
+        <!-- Specifies the basic width of the dropdown. Its value may
+             be a dimension (such as "12dip") for a constant width, fill_parent
+             to fill the width of the screen, or wrap_content to match the height of
+             the content of the drop down. -->
+        <attr name="dropDownHeight" format="dimension">
+            <!-- The dropdown should fill the width of the screen. -->
+            <enum name="fill_parent" value="-1" />
+            <!-- The dropdown should fit the width of its anchor. -->
+            <enum name="wrap_content" value="-2" />
+        </attr>
         <attr name="inputType" />
     </declare-styleable>
     <declare-styleable name="PopupWindow">
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index e5a58b1..4634b50 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1116,7 +1116,8 @@
   <public type="attr" name="allowBackup" />
   <public type="attr" name="glEsVersion" />
   <public type="attr" name="queryAfterZeroResults" />
-  
+  <public type="attr" name="dropDownHeight" />
+
   <public-padding type="attr" name="donut_resource_pad" end="0x0101029f" />
 
   <public-padding type="id" name="donut_resource_pad" end="0x01020040" />
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
index dbf937c..69e93a1 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/stress/MediaRecorderStressTest.java
@@ -18,6 +18,11 @@
 
 import com.android.mediaframeworktest.MediaFrameworkTest;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.Writer;
+
 import android.hardware.Camera;
 import android.media.MediaPlayer;
 import android.media.MediaRecorder;
@@ -47,6 +52,8 @@
     private static final long WAIT_TIME_PLAYBACK = 60000;  // 6 second
     private static final String OUTPUT_FILE = "/sdcard/temp";
     private static final String OUTPUT_FILE_EXT = ".3gp";
+    private static final String MEDIA_STRESS_OUTPUT =
+        "/sdcard/mediaStressOutput.txt";
     
     public MediaRecorderStressTest() {
         super("com.android.mediaframeworktest", MediaFrameworkTest.class);
@@ -62,8 +69,14 @@
     public void testStressCamera() throws Exception {
         SurfaceHolder mSurfaceHolder;             
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("Camera start preview stress:\n");
+        output.write("Total number of loops:" + 
+                NUMBER_OF_CAMERA_STRESS_LOOPS + "\n");
         try {        
             Log.v(TAG, "Start preview");
+            output.write("No of loop: ");
             for (int i = 0; i< NUMBER_OF_CAMERA_STRESS_LOOPS; i++){
                 mCamera = Camera.open();
                 mCamera.setPreviewDisplay(mSurfaceHolder);
@@ -71,10 +84,13 @@
                 Thread.sleep(WAIT_TIME_CAMERA_TEST);
                 mCamera.stopPreview();
                 mCamera.release();
+                output.write(" ," + i);
             }
         } catch (Exception e) {
                 Log.v(TAG, e.toString());
         }
+        output.write("\n\n");
+        output.close();
     }
     
     //Test case for stressing the camera preview.
@@ -83,7 +99,13 @@
         String filename;
         SurfaceHolder mSurfaceHolder;             
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        try {    
+        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("H263 video record- reset after prepare Stress test\n");
+        output.write("Total number of loops:" +
+                NUMBER_OF_RECORDER_STRESS_LOOPS + "\n");
+        try {
+            output.write("No of loop: ");
             Log.v(TAG, "Start preview");
             for (int i = 0; i < NUMBER_OF_RECORDER_STRESS_LOOPS; i++){
                 Log.v(TAG, "counter = " + i);
@@ -106,10 +128,13 @@
                 Thread.sleep(WAIT_TIME_RECORDER_TEST);  
                 mRecorder.reset();
                 mRecorder.release();
+                output.write(", " + i);
             }
         } catch (Exception e) {
                 Log.v(TAG, e.toString());
         }
+        output.write("\n\n");
+        output.close();
     }
     
     
@@ -119,8 +144,14 @@
         String filename;
         SurfaceHolder mSurfaceHolder;             
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
+        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("Camera and video recorder preview switching\n");
+        output.write("Total number of loops:"
+                + NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER + "\n");
         try {    
             Log.v(TAG, "Start preview");
+            output.write("No of loop: ");
             for (int i = 0; i < NUMBER_OF_SWTICHING_LOOPS_BW_CAMERA_AND_RECORDER; i++){
                 mCamera = Camera.open();
                 mCamera.setPreviewDisplay(mSurfaceHolder);
@@ -147,11 +178,14 @@
                 Log.v(TAG, "before release");
                 Thread.sleep(WAIT_TIME_CAMERA_TEST);  
                 mRecorder.release();
-                Log.v(TAG, "release video recorder");                
+                Log.v(TAG, "release video recorder");
+                output.write(", " + i);
             }
         } catch (Exception e) {
                 Log.v(TAG, e.toString());
         }
+        output.write("\n\n");
+        output.close();
     }
     
     //Stress test case for record a video and play right away.
@@ -160,7 +194,13 @@
         String filename;
         SurfaceHolder mSurfaceHolder;             
         mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
-        try {    
+        File stressOutFile = new File(MEDIA_STRESS_OUTPUT);
+        Writer output = new BufferedWriter(new FileWriter(stressOutFile, true));
+        output.write("Video record and play back stress test:\n");
+        output.write("Total number of loops:"
+                + NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS + "\n");
+        try {
+            output.write("No of loop: ");
             for (int i = 0; i < NUMBER_OF_RECORDERANDPLAY_STRESS_LOOPS; i++){
                 filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
                 Log.v(TAG, filename);
@@ -189,10 +229,13 @@
                 mp.start();
                 Thread.sleep(WAIT_TIME_PLAYBACK);
                 mp.release();
+                output.write(", " + i);
             }
         } catch (Exception e) {
                 Log.v(TAG, e.toString());
         }
+        output.write("\n\n");
+        output.close();
     }   
 }