Merge "Make parameter blocks read/writable even for SET_PARAMETER/SET_CONFIG requests." into honeycomb
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index bd5ec79..72b0023 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -135,6 +135,7 @@
     // Used to determine whether onFocusChanged was called as a result of
     // calling remove().
     private boolean mInsideRemove;
+    private boolean mInPassword;
 
     // Types used with setType.  Keep in sync with CachedInput.h
     private static final int NORMAL_TEXT_FIELD = 0;
@@ -784,22 +785,11 @@
         mInsideRemove = false;
     }
 
-    /**
-     * Move the caret/selection into view.
-     */
-    /* package */ void bringIntoView() {
-        bringPointIntoView(Selection.getSelectionEnd(getText()));
-    }
-
     @Override
     public boolean bringPointIntoView(int offset) {
-        if (mWebView == null) return false;
-        if (mWebView.nativeFocusCandidateIsPassword()) {
+        if (mInPassword) {
             return getLayout() != null && super.bringPointIntoView(offset);
         }
-        // For non password text input, tell webkit to move the caret/selection
-        // on screen, since webkit draws them.
-        mWebView.revealSelection();
         return true;
     }
 
@@ -914,6 +904,7 @@
      * @param   inPassword  True if the textfield is a password field.
      */
     /* package */ void setInPassword(boolean inPassword) {
+        mInPassword = inPassword;
         if (inPassword) {
             setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.
                 TYPE_TEXT_VARIATION_WEB_PASSWORD);
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index ebf3305..9e09c28 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -4268,7 +4268,7 @@
         Rect vBox = contentToViewRect(bounds);
         mWebTextView.setRect(vBox.left, vBox.top, vBox.width(), vBox.height());
         if (!Rect.intersects(bounds, visibleRect)) {
-            mWebTextView.bringIntoView();
+            revealSelection();
         }
         String text = nativeFocusCandidateText();
         int nodePointer = nativeFocusCandidatePointer();
@@ -7274,7 +7274,6 @@
                     // this is sent after finishing resize in WebViewCore. Make
                     // sure the text edit box is still on the  screen.
                     if (inEditingMode() && nativeCursorIsTextInput()) {
-                        mWebTextView.bringIntoView();
                         rebuildWebTextView();
                     }
                     break;
diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h
index 5170a2c..18fd90e 100644
--- a/include/media/stagefright/MetaData.h
+++ b/include/media/stagefright/MetaData.h
@@ -30,8 +30,10 @@
 // The following keys map to int32_t data unless indicated otherwise.
 enum {
     kKeyMIMEType          = 'mime',  // cstring
-    kKeyWidth             = 'widt',  // int32_t
-    kKeyHeight            = 'heig',  // int32_t
+    kKeyWidth             = 'widt',  // int32_t, image pixel
+    kKeyHeight            = 'heig',  // int32_t, image pixel
+    kKeyDisplayWidth      = 'dWid',  // int32_t, display/presentation
+    kKeyDisplayHeight     = 'dHgt',  // int32_t, display/presentation
 
     // a rectangle, if absent assumed to be (0, 0, width - 1, height - 1)
     kKeyCropRect          = 'crop',
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index 3f0036a..999e4ea 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -167,6 +167,10 @@
         float v2 = fmax(0.0f, stepY - 0.5f) / bitmapHeight;
 
         if (stepY > 0.0f) {
+            if (i == mYCount - 1 && mYDivs[i] == bitmapHeight) {
+                y2 = bottom - top;
+                v2 = 1.0f;
+            }
             generateRow(vertex, y1, y2, v1, v2, stretchX, right - left,
                     bitmapWidth, quadCount);
         }
@@ -177,8 +181,10 @@
         previousStepY = stepY;
     }
 
-    generateRow(vertex, y1, bottom - top, v1, 1.0f, stretchX, right - left,
-            bitmapWidth, quadCount);
+    if (previousStepY != bitmapHeight) {
+        generateRow(vertex, y1, bottom - top, v1, 1.0f, stretchX, right - left,
+                bitmapWidth, quadCount);
+    }
 
     if (verticesCount > 0) {
         Caches::getInstance().bindMeshBuffer(meshBuffer);
@@ -216,6 +222,10 @@
         float u2 = fmax(0.0f, stepX - 0.5f) / bitmapWidth;
 
         if (stepX > 0.0f) {
+            if (i == mXCount - 1 && mXDivs[i] == bitmapWidth) {
+                x2 = bitmapWidth;
+                u2 = 1.0f;
+            }
             generateQuad(vertex, x1, y1, x2, y2, u1, v1, u2, v2, quadCount);
         }
 
@@ -225,7 +235,9 @@
         previousStepX = stepX;
     }
 
-    generateQuad(vertex, x1, y1, width, y2, u1, v1, 1.0f, v2, quadCount);
+    if (previousStepX != bitmapWidth) {
+        generateQuad(vertex, x1, y1, width, y2, u1, v1, 1.0f, v2, quadCount);
+    }
 }
 
 void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index 4693ec5c..8908e67 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -96,18 +96,19 @@
 
     virtual bool threadLoop() {
         sMutex.lock();
-        mFd = open("/dev/mtp_usb", O_RDWR);
-        printf("open returned %d\n", mFd);
-        if (mFd < 0) {
-            LOGE("could not open MTP driver\n");
-            sMutex.unlock();
-            return false;
-        }
-
-        mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
-        mServer->addStorage(mStoragePath, mReserveSpace);
 
         while (!mDone) {
+            mFd = open("/dev/mtp_usb", O_RDWR);
+            printf("open returned %d\n", mFd);
+            if (mFd < 0) {
+                LOGE("could not open MTP driver\n");
+                sMutex.unlock();
+                return false;
+            }
+
+            mServer = new MtpServer(mFd, mDatabase, AID_MEDIA_RW, 0664, 0775);
+            mServer->addStorage(mStoragePath, mReserveSpace);
+
             sMutex.unlock();
 
             LOGD("MtpThread mServer->run");
@@ -115,12 +116,12 @@
             sleep(1);
 
             sMutex.lock();
-        }
 
-        close(mFd);
-        mFd = -1;
-        delete mServer;
-        mServer = NULL;
+            close(mFd);
+            mFd = -1;
+            delete mServer;
+            mServer = NULL;
+        }
 
         JNIEnv* env = AndroidRuntime::getJNIEnv();
         env->SetIntField(mJavaServer, field_context, 0);
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 49d05ed..58c4a2e 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -165,6 +165,8 @@
       mTimeSource(NULL),
       mVideoRendererIsPreview(false),
       mAudioPlayer(NULL),
+      mDisplayWidth(0),
+      mDisplayHeight(0),
       mFlags(0),
       mExtractorFlags(0),
       mVideoBuffer(NULL),
@@ -329,6 +331,18 @@
         if (!haveVideo && !strncasecmp(mime, "video/", 6)) {
             setVideoSource(extractor->getTrack(i));
             haveVideo = true;
+
+            // Set the presentation/display size
+            int32_t displayWidth, displayHeight;
+            bool success = meta->findInt32(kKeyDisplayWidth, &displayWidth);
+            if (success) {
+                success = meta->findInt32(kKeyDisplayHeight, &displayHeight);
+            }
+            if (success) {
+                mDisplayWidth = displayWidth;
+                mDisplayHeight = displayHeight;
+            }
+
         } else if (!haveAudio && !strncasecmp(mime, "audio/", 6)) {
             setAudioSource(extractor->getTrack(i));
             haveAudio = true;
@@ -370,6 +384,8 @@
 
 void AwesomePlayer::reset_l() {
     LOGI("reset_l");
+    mDisplayWidth = 0;
+    mDisplayHeight = 0;
 
     if (mDecryptHandle != NULL) {
             mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
@@ -862,6 +878,12 @@
 
     int32_t usableWidth = cropRight - cropLeft + 1;
     int32_t usableHeight = cropBottom - cropTop + 1;
+    if (mDisplayWidth != 0) {
+        usableWidth = mDisplayWidth;
+    }
+    if (mDisplayHeight != 0) {
+        usableHeight = mDisplayHeight;
+    }
 
     int32_t rotationDegrees;
     if (!mVideoTrack->getFormat()->findInt32(
diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp
index bafa243..e6e98aa 100644
--- a/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/MPEG4Extractor.cpp
@@ -1040,8 +1040,23 @@
             // have a 4 byte header (0x00 0x00 0x00 0x01) after conversion,
             // and thus will grow by 2 bytes per fragment.
             mLastTrack->meta->setInt32(kKeyMaxInputSize, max_size + 10 * 2);
-
             *offset += chunk_size;
+
+            // Calculate average frame rate.
+            const char *mime;
+            CHECK(mLastTrack->meta->findCString(kKeyMIMEType, &mime));
+            if (!strncasecmp("video/", mime, 6)) {
+                size_t nSamples = mLastTrack->sampleTable->countSamples();
+                int64_t durationUs;
+                if (mLastTrack->meta->findInt64(kKeyDuration, &durationUs)) {
+                    if (durationUs > 0) {
+                        int32_t frameRate = (nSamples * 1000000LL +
+                                    (durationUs >> 1)) / durationUs;
+                        mLastTrack->meta->setInt32(kKeyFrameRate, frameRate);
+                    }
+                }
+            }
+
             break;
         }
 
@@ -1321,10 +1336,12 @@
         mLastTrack->meta->setInt32(kKeyRotation, rotationDegrees);
     }
 
-#if 0
+    // Handle presentation display size, which could be different
+    // from the image size indicated by kKeyWidth and kKeyHeight.
     uint32_t width = U32_AT(&buffer[dynSize + 52]);
     uint32_t height = U32_AT(&buffer[dynSize + 56]);
-#endif
+    mLastTrack->meta->setInt32(kKeyDisplayWidth, width >> 16);
+    mLastTrack->meta->setInt32(kKeyDisplayHeight, height >> 16);
 
     return OK;
 }
diff --git a/media/libstagefright/include/AwesomePlayer.h b/media/libstagefright/include/AwesomePlayer.h
index fe008569..41ef181 100644
--- a/media/libstagefright/include/AwesomePlayer.h
+++ b/media/libstagefright/include/AwesomePlayer.h
@@ -150,6 +150,9 @@
     AudioPlayer *mAudioPlayer;
     int64_t mDurationUs;
 
+    int32_t mDisplayWidth;
+    int32_t mDisplayHeight;
+
     uint32_t mFlags;
     uint32_t mExtractorFlags;
     uint32_t mSinceLastDropped;