Merge change 8130 into donut

* changes:
  Increase the volume of the AudioTrack instance used for the speech synthesis.
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 444f222..9432755 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -788,6 +788,11 @@
         final SearchManager searchManager = (SearchManager) mContext
                 .getSystemService(Context.SEARCH_SERVICE);
 
+        // can't start search without an associated activity (e.g a system dialog)
+        if (!searchManager.hasIdent()) {
+            return false;
+        }
+
         // associate search with owner activity if possible (otherwise it will default to
         // global search).
         final ComponentName appName = mOwnerActivity == null ? null
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index c98d966..0631ad5 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -1536,6 +1536,10 @@
         mService = ISearchManager.Stub.asInterface(
                 ServiceManager.getService(Context.SEARCH_SERVICE));
     }
+
+    /*package*/ boolean hasIdent() {
+        return mIdent != 0;
+    }
     
     /*package*/ void setIdent(int ident) {
         if (mIdent != 0) {
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index b0dbfcb..a5f298c 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -4513,6 +4513,9 @@
      * and {@link #FILL_IN_COMPONENT} to override the restriction where the
      * corresponding field will not be replaced if it is already set.
      *
+     * <p>Note: The component field will only be copied if {@link #FILL_IN_COMPONENT} is explicitly
+     * specified.
+     *
      * <p>For example, consider Intent A with {data="foo", categories="bar"}
      * and Intent B with {action="gotit", data-type="some/thing",
      * categories="one","two"}.
diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java
index 6e34cc8..2805bd5 100644
--- a/core/java/android/content/res/CompatibilityInfo.java
+++ b/core/java/android/content/res/CompatibilityInfo.java
@@ -342,8 +342,8 @@
     public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation,
             Rect outRect) {
         int width = dm.widthPixels;
-        int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density);
-        int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density);
+        int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density + 0.5f);
+        int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density + 0.5f);
         if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
             int xOffset = (width - portraitHeight) / 2 ;
             outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth);
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index bfab49d..38d99b3 100644
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -136,15 +136,19 @@
                 int defaultHeight;
                 switch (orientation) {
                     case Configuration.ORIENTATION_LANDSCAPE: {
-                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
-                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
+                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+                                0.5f);
+                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+                                0.5f);
                         break;
                     }
                     case Configuration.ORIENTATION_PORTRAIT:
                     case Configuration.ORIENTATION_SQUARE:
                     default: {
-                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density);
-                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density);
+                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+                                0.5f);
+                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+                                0.5f);
                         break;
                     }
                     case Configuration.ORIENTATION_UNDEFINED: {
@@ -172,8 +176,8 @@
             scaledDensity *= invertedRatio;
             xdpi *= invertedRatio;
             ydpi *= invertedRatio;
-            widthPixels *= invertedRatio;
-            heightPixels *= invertedRatio;
+            widthPixels = (int) (widthPixels * invertedRatio + 0.5f);
+            heightPixels = (int) (heightPixels * invertedRatio + 0.5f);
         }
     }
 
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 0178d63..83c30e1 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -19,6 +19,7 @@
 import android.graphics.*;
 import android.os.Parcelable;
 import android.os.Parcel;
+import android.util.DisplayMetrics;
 import android.util.Log;
 
 /**
@@ -131,6 +132,10 @@
     @SuppressWarnings("unused")
     private Canvas mCanvas;
 
+    // The display metrics used to provide the pseudo canvas size for applications
+    // running in compatibility mode. This is set to null for regular mode.
+    private DisplayMetrics mDisplayMetrics;
+
     /**
      * Exception thrown when a surface couldn't be created or resized
      */
@@ -167,7 +172,23 @@
      * {@hide}
      */
     public Surface() {
-        mCanvas = new Canvas();
+        mCanvas = new Canvas() {
+            @Override
+            public int getWidth() {
+                return mDisplayMetrics == null ? super.getWidth() : mDisplayMetrics.widthPixels;
+            }
+            @Override
+            public int getHeight() {
+                return mDisplayMetrics == null ? super.getHeight() : mDisplayMetrics.heightPixels;
+            }
+        };
+    }
+
+    /**
+     * Sets the display metrics used to provide canva's width/height in comaptibility mode.
+     */
+    void setCompatibleDisplayMetrics(DisplayMetrics metrics) {
+        mDisplayMetrics = metrics;
     }
     
     /**
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index aa701af..95bba97 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -17,6 +17,7 @@
 package android.view;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.content.res.CompatibilityInfo.Translator;
 import android.graphics.Canvas;
 import android.graphics.PixelFormat;
@@ -301,6 +302,11 @@
 
         float appScale = mTranslator == null ? 1.0f : mTranslator.applicationScale;
         
+        Resources res = getContext().getResources();
+        if (mTranslator != null || !res.getCompatibilityInfo().supportsScreen()) {
+            mSurface.setCompatibleDisplayMetrics(res.getDisplayMetrics());
+        }
+        
         int myWidth = mRequestedWidth;
         if (myWidth <= 0) myWidth = getWidth();
         int myHeight = mRequestedHeight;
@@ -309,8 +315,8 @@
         // Use original size if the app specified the size of the view,
         // and let the flinger to scale up.
         if (mRequestedWidth <= 0 && mTranslator != null) {
-            myWidth *= appScale;
-            myHeight *= appScale;
+            myWidth = (int) (myWidth * appScale + 0.5f);
+            myHeight = (int) (myHeight * appScale + 0.5f);
             mScaled = true;
         } else {
             mScaled = false;
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 301d604..2f92b32 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -42,6 +42,7 @@
 import android.widget.Scroller;
 import android.content.pm.PackageManager;
 import android.content.res.CompatibilityInfo;
+import android.content.res.Resources;
 import android.content.Context;
 import android.app.ActivityManagerNative;
 import android.Manifest;
@@ -386,10 +387,14 @@
                 mView = view;
                 mWindowAttributes.copyFrom(attrs);
                 attrs = mWindowAttributes;
-
-                CompatibilityInfo compatibilityInfo =
-                        mView.getContext().getResources().getCompatibilityInfo();
+                Resources resources = mView.getContext().getResources();
+                CompatibilityInfo compatibilityInfo = resources.getCompatibilityInfo();
                 mTranslator = compatibilityInfo.getTranslator(attrs);
+
+                if (mTranslator != null || !compatibilityInfo.supportsScreen()) {
+                    mSurface.setCompatibleDisplayMetrics(resources.getDisplayMetrics());
+                }
+
                 boolean restore = false;
                 if (attrs != null && mTranslator != null) {
                     restore = true;
@@ -907,7 +912,8 @@
             mHeight = frame.height();
 
             if (initialized) {
-                mGlCanvas.setViewport((int) (mWidth * appScale), (int) (mHeight * appScale));
+                mGlCanvas.setViewport((int) (mWidth * appScale + 0.5f),
+                        (int) (mHeight * appScale + 0.5f));
             }
 
             boolean focusChangedDueToTouchMode = ensureTouchModeLocally(
@@ -1237,7 +1243,7 @@
 
         if (fullRedrawNeeded) {
             mAttachInfo.mIgnoreDirtyState = true;
-            dirty.union(0, 0, (int) (mWidth * appScale), (int) (mHeight * appScale));
+            dirty.union(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f));
         }
 
         if (DEBUG_ORIENTATION || DEBUG_DRAW) {
@@ -1749,7 +1755,8 @@
                             if (mGlCanvas != null) {
                                 float appScale = mAttachInfo.mApplicationScale;
                                 mGlCanvas.setViewport(
-                                        (int) (mWidth * appScale), (int) (mHeight * appScale));
+                                        (int) (mWidth * appScale + 0.5f),
+                                        (int) (mHeight * appScale + 0.5f));
                             }
                         }
                     }
@@ -2394,8 +2401,8 @@
         }
         int relayoutResult = sWindowSession.relayout(
                 mWindow, params,
-                (int) (mView.mMeasuredWidth * appScale),
-                (int) (mView.mMeasuredHeight * appScale),
+                (int) (mView.mMeasuredWidth * appScale + 0.5f),
+                (int) (mView.mMeasuredHeight * appScale + 0.5f),
                 viewVisibility, insetsPending, mWinFrame,
                 mPendingContentInsets, mPendingVisibleInsets, mSurface);
         if (restore) {
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 6a26a31..c0be9e8 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -991,13 +991,13 @@
          * @hide
          */
         public void scale(float scale) {
-            x *= scale;
-            y *= scale;
+            x = (int) (x * scale + 0.5f);
+            y = (int) (y * scale + 0.5f);
             if (width > 0) {
-                width *= scale;
+                width = (int) (width * scale + 0.5f);
             }
             if (height > 0) {
-                height *= scale;
+                height = (int) (height * scale + 0.5f);
             }
         }
 
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index d8ed4f0..3fab692 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -2443,7 +2443,13 @@
         }
 
         if (ss.error != null) {
-            setError(ss.error);
+            final CharSequence error = ss.error;
+            // Display the error later, after the first layout pass
+            post(new Runnable() {
+                public void run() {
+                    setError(error);
+                }
+            });
         }
     }
 
@@ -3263,7 +3269,9 @@
             final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
                     null);
 
-            mPopup = new ErrorPopup(err, 200, 50);
+            final float scale = getResources().getDisplayMetrics().density;
+            mPopup = new ErrorPopup(err, (int) (200 * scale + 0.5f),
+                    (int) (50 * scale + 0.5f));
             mPopup.setFocusable(false);
             // The user is entering text, so the input method is needed.  We
             // don't want the popup to be displayed on top of it.
@@ -3317,11 +3325,12 @@
          * The "25" is the distance between the point and the right edge
          * of the background
          */
+        final float scale = getResources().getDisplayMetrics().density;
 
         final Drawables dr = mDrawables;
         return getWidth() - mPopup.getWidth()
                 - getPaddingRight()
-                - (dr != null ? dr.mDrawableSizeRight : 0) / 2 + 25;
+                - (dr != null ? dr.mDrawableSizeRight : 0) / 2 + (int) (25 * scale + 0.5f);
     }
 
     /**
diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java
index 50ab566..42a14ce 100644
--- a/graphics/java/android/graphics/Rect.java
+++ b/graphics/java/android/graphics/Rect.java
@@ -552,10 +552,10 @@
      */
     public void scale(float scale) {
         if (scale != 1.0f) {
-            left *= scale;
-            top *= scale;
-            right *= scale;
-            bottom*= scale;
+            left = (int) (left * scale + 0.5f);
+            top = (int) (top * scale + 0.5f);
+            right = (int) (right * scale + 0.5f);
+            bottom = (int) (bottom * scale + 0.5f);
         }
     }
 }