Merge "location: dump LocationProvider internal state"
diff --git a/cmds/keystore/keystore_get.h b/cmds/keystore/keystore_get.h
index 0e7e1ae..8330f8e 100644
--- a/cmds/keystore/keystore_get.h
+++ b/cmds/keystore/keystore_get.h
@@ -19,7 +19,6 @@
 
 #include <stdio.h>
 #include <stdint.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -28,18 +27,21 @@
 
 #define KEYSTORE_MESSAGE_SIZE 65535
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* This function is provided for native components to get values from keystore.
  * Users are required to link against libcutils. The lengths of keys and values
  * are limited to KEYSTORE_MESSAGE_SIZE. This function returns the length of
  * the requested value or -1 if something goes wrong. */
-static int keystore_get(const char *key, char *value)
+static int keystore_get(const char *key, int length, char *value)
 {
-    int length = strlen(key);
     uint8_t bytes[2] = {length >> 8, length};
     uint8_t code = 'g';
     int sock;
 
-    if (length > KEYSTORE_MESSAGE_SIZE) {
+    if (length < 0 || length > KEYSTORE_MESSAGE_SIZE) {
         return -1;
     }
     sock = socket_local_client("keystore", ANDROID_SOCKET_NAMESPACE_RESERVED,
@@ -66,4 +68,8 @@
     return length;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index c951ce9..3e426f5 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -668,7 +668,7 @@
                 // The user changed the query, remember it.
                 mUserQuery = s == null ? "" : s.toString();
             }
-            updateVoiceButton(TextUtils.isEmpty(s));
+            updateVoiceButton(mSearchAutoComplete.isEmpty());
         }
 
         public void afterTextChanged(Editable s) {
@@ -691,13 +691,30 @@
     };
 
     /**
-     * Enable/Disable the cancel button based on edit text state (any text?)
+     * Enable/Disable the go button based on edit text state (any text?)
      */
     private void updateWidgetState() {
         // enable the button if we have one or more non-space characters
         boolean enabled = !mSearchAutoComplete.isEmpty();
-        mGoButton.setEnabled(enabled);
-        mGoButton.setFocusable(enabled);
+        if (isBrowserSearch()) {
+            // In the browser, we hide the search button when there is no text
+            if (enabled) {
+                mSearchAutoComplete.setBackgroundResource(
+                        com.android.internal.R.drawable.textfield_search);
+                mGoButton.setVisibility(View.VISIBLE);
+                // Just to be sure
+                mGoButton.setEnabled(true);
+                mGoButton.setFocusable(true);
+            } else {
+                mSearchAutoComplete.setBackgroundResource(
+                        com.android.internal.R.drawable.textfield_search_empty);
+                mGoButton.setVisibility(View.GONE);
+            }
+        } else {
+            // Elsewhere we just disable the button
+            mGoButton.setEnabled(enabled);
+            mGoButton.setFocusable(enabled);
+        }
     }
 
     /**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 65ae059..6eca68c 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3213,27 +3213,6 @@
         }
     }
 
-    private static class Metrics {
-        int mScrollX;
-        int mScrollY;
-        int mWidth;
-        int mHeight;
-        float mInvScale;
-    }
-
-    private Metrics getViewMetrics() {
-        Metrics metrics = new Metrics();
-        metrics.mScrollX = mScrollX;
-        metrics.mScrollY = computeVerticalScrollOffset();
-        metrics.mWidth = getWidth();
-        metrics.mHeight = getHeight() - getVisibleTitleHeight();
-        if (mFindIsUp) {
-            metrics.mHeight -= mFindHeight;
-        }
-        metrics.mInvScale = mInvActualScale;
-        return metrics;
-    }
-
     private void drawExtras(Canvas canvas, int extras) {
         // If mNativeClass is 0, we should not reach here, so we do not
         // need to check it again.
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 0f1b845..88bbafd 100644
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -527,6 +527,53 @@
     }

 }

 

+static bool Bitmap_sameAs(JNIEnv* env, jobject, const SkBitmap* bm0,

+                             const SkBitmap* bm1) {

+    if (bm0->width() != bm1->width() ||

+        bm0->height() != bm1->height() ||

+        bm0->config() != bm1->config()) {

+        return false;

+    }

+

+    SkAutoLockPixels alp0(*bm0);

+    SkAutoLockPixels alp1(*bm1);

+

+    // if we can't load the pixels, return false

+    if (NULL == bm0->getPixels() || NULL == bm1->getPixels()) {

+        return false;

+    }

+

+    if (bm0->config() == SkBitmap::kIndex8_Config) {

+        SkColorTable* ct0 = bm0->getColorTable();

+        SkColorTable* ct1 = bm1->getColorTable();

+        if (NULL == ct0 || NULL == ct1) {

+            return false;

+        }

+        if (ct0->count() != ct1->count()) {

+            return false;

+        }

+

+        SkAutoLockColors alc0(ct0);

+        SkAutoLockColors alc1(ct1);

+        const size_t size = ct0->count() * sizeof(SkPMColor);

+        if (memcmp(alc0.colors(), alc1.colors(), size) != 0) {

+            return false;

+        }

+    }

+

+    // now compare each scanline. We can't do the entire buffer at once,

+    // since we don't care about the pixel values that might extend beyond

+    // the width (since the scanline might be larger than the logical width)

+    const int h = bm0->height();

+    const size_t size = bm0->width() * bm0->bytesPerPixel();

+    for (int y = 0; y < h; y++) {

+        if (memcmp(bm0->getAddr(0, y), bm1->getAddr(0, y), size) != 0) {

+            return false;

+        }

+    }

+    return true;

+}

+

 static void Bitmap_prepareToDraw(JNIEnv* env, jobject, SkBitmap* bitmap) {

     bitmap->lockPixels();

     bitmap->unlockPixels();

@@ -567,7 +614,8 @@
                                             (void*)Bitmap_copyPixelsToBuffer },

     {   "nativeCopyPixelsFromBuffer", "(ILjava/nio/Buffer;)V",

                                             (void*)Bitmap_copyPixelsFromBuffer },

-    {   "nativePrepareToDraw",      "(I)V", (void*)Bitmap_prepareToDraw }

+    {   "nativeSameAs",             "(II)Z", (void*)Bitmap_sameAs },

+    {   "nativePrepareToDraw",      "(I)V", (void*)Bitmap_prepareToDraw },

 };

 

 #define kClassPathName  "android/graphics/Bitmap"

diff --git a/core/res/res/drawable-hdpi/textfield_search_empty_default.9.png b/core/res/res/drawable-hdpi/textfield_search_empty_default.9.png
new file mode 100644
index 0000000..c0b84da
--- /dev/null
+++ b/core/res/res/drawable-hdpi/textfield_search_empty_default.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/textfield_search_empty_pressed.9.png b/core/res/res/drawable-hdpi/textfield_search_empty_pressed.9.png
new file mode 100644
index 0000000..0a0fc6b
--- /dev/null
+++ b/core/res/res/drawable-hdpi/textfield_search_empty_pressed.9.png
Binary files differ
diff --git a/core/res/res/drawable-hdpi/textfield_search_empty_selected.9.png b/core/res/res/drawable-hdpi/textfield_search_empty_selected.9.png
new file mode 100644
index 0000000..04813c2
--- /dev/null
+++ b/core/res/res/drawable-hdpi/textfield_search_empty_selected.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/textfield_search_empty_default.9.png b/core/res/res/drawable-mdpi/textfield_search_empty_default.9.png
new file mode 100644
index 0000000..515117f
--- /dev/null
+++ b/core/res/res/drawable-mdpi/textfield_search_empty_default.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/textfield_search_empty_pressed.9.png b/core/res/res/drawable-mdpi/textfield_search_empty_pressed.9.png
new file mode 100644
index 0000000..a01f763
--- /dev/null
+++ b/core/res/res/drawable-mdpi/textfield_search_empty_pressed.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/textfield_search_empty_selected.9.png b/core/res/res/drawable-mdpi/textfield_search_empty_selected.9.png
new file mode 100644
index 0000000..611276f
--- /dev/null
+++ b/core/res/res/drawable-mdpi/textfield_search_empty_selected.9.png
Binary files differ
diff --git a/core/res/res/drawable/textfield_search_empty.xml b/core/res/res/drawable/textfield_search_empty.xml
new file mode 100644
index 0000000..55eec83
--- /dev/null
+++ b/core/res/res/drawable/textfield_search_empty.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+  
+          http://www.apache.org/licenses/LICENSE-2.0
+  
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:state_window_focused="false" android:state_enabled="true"
+        android:drawable="@drawable/textfield_search_empty_default" />
+
+    <item android:state_pressed="true"
+        android:drawable="@drawable/textfield_search_empty_pressed" />
+
+    <item android:state_enabled="true" android:state_focused="true"
+        android:drawable="@drawable/textfield_search_empty_selected" />
+
+    <item android:state_enabled="true"
+        android:drawable="@drawable/textfield_search_empty_default" />
+
+</selector>
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 5aa88b0..7ca3741 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -972,6 +972,19 @@
     }
 
     /**
+     *  Given another bitmap, return true if it has the same dimensions, config,
+     *  and pixel data as this bitmap. If any of those differ, return false.
+     *  If other is null, return false.
+     *
+     * @hide (just needed internally right now)
+     */
+    public boolean sameAs(Bitmap other) {
+        return this == other ||
+              (other != null &&
+               nativeSameAs(mNativeBitmap, other.mNativeBitmap));
+    }
+
+    /**
      * Rebuilds any caches associated with the bitmap that are used for
      * drawing it. In the case of purgeable bitmaps, this call will attempt to
      * ensure that the pixels have been decoded.
@@ -1042,6 +1055,7 @@
 
     private static native void nativePrepareToDraw(int nativeBitmap);
     private static native void nativeSetHasAlpha(int nBitmap, boolean hasAlpha);
+    private static native boolean nativeSameAs(int nb0, int nb1);
 
     /* package */ final int ni() {
         return mNativeBitmap;
diff --git a/packages/TtsService/src/android/tts/SynthProxy.java b/packages/TtsService/src/android/tts/SynthProxy.java
index 6255275..cd46c05 100755
--- a/packages/TtsService/src/android/tts/SynthProxy.java
+++ b/packages/TtsService/src/android/tts/SynthProxy.java
@@ -36,9 +36,9 @@
     // Such a huge filter gain is justified by how much energy in the low frequencies is "wasted" at
     // the output of the synthesis. The low shelving filter removes it, leaving room for
     // amplification.
-    private final static float PICO_FILTER_GAIN = 5.5f; // linear gain
-    private final static float PICO_FILTER_LOWSHELF_ATTENUATION = -18.0f; // in dB
-    private final static float PICO_FILTER_TRANSITION_FREQ = 1100.0f;     // in Hz
+    private final static float PICO_FILTER_GAIN = 4.0f; // linear gain
+    private final static float PICO_FILTER_LOWSHELF_ATTENUATION = -16.0f; // in dB
+    private final static float PICO_FILTER_TRANSITION_FREQ = 1000.0f;     // in Hz
     private final static float PICO_FILTER_SHELF_SLOPE = 1.0f;            // Q
 
     //
@@ -50,7 +50,7 @@
      */
     public SynthProxy(String nativeSoLib) {
         boolean applyFilter = nativeSoLib.toLowerCase().contains("pico");
-        Log.v(TtsService.SERVICE_TAG, "about to load "+ nativeSoLib + ", applyFilter="+applyFilter);
+        Log.v(TtsService.SERVICE_TAG, "About to load "+ nativeSoLib + ", applyFilter="+applyFilter);
         native_setup(new WeakReference<SynthProxy>(this), nativeSoLib);
         native_setLowShelf(applyFilter, PICO_FILTER_GAIN, PICO_FILTER_LOWSHELF_ATTENUATION,
                 PICO_FILTER_TRANSITION_FREQ, PICO_FILTER_SHELF_SLOPE);
diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java
index 71826ff..5f23a90 100644
--- a/services/java/com/android/server/UiModeManagerService.java
+++ b/services/java/com/android/server/UiModeManagerService.java
@@ -347,11 +347,13 @@
                 }
             }
             if (mKeyguardLock != null) {
+                long ident = Binder.clearCallingIdentity();
                 if (enabled) {
                     mKeyguardLock.disableKeyguard();
                 } else {
                     mKeyguardLock.reenableKeyguard();
                 }
+                Binder.restoreCallingIdentity(ident);
             }
         }
     }