Merge "hidden api sameAs() to compare the pixels of 2 bitmaps for equality"
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp
index 7e81e90..00bd54e 100644
--- a/camera/libcameraservice/CameraService.cpp
+++ b/camera/libcameraservice/CameraService.cpp
@@ -1291,8 +1291,26 @@
     client->dataCallback(CAMERA_MSG_PREVIEW_FRAME, frame);
 }
 
+static const int kDumpLockRetries = 50;
+static const int kDumpLockSleep = 60000;
+
+static bool tryLock(Mutex& mutex)
+{
+    bool locked = false;
+    for (int i = 0; i < kDumpLockRetries; ++i) {
+        if (mutex.tryLock() == NO_ERROR) {
+            locked = true;
+            break;
+        }
+        usleep(kDumpLockSleep);
+    }
+    return locked;
+}
+
 status_t CameraService::dump(int fd, const Vector<String16>& args)
 {
+    static const char* kDeadlockedString = "CameraService may be deadlocked\n";
+
     const size_t SIZE = 256;
     char buffer[SIZE];
     String8 result;
@@ -1304,7 +1322,13 @@
         result.append(buffer);
         write(fd, result.string(), result.size());
     } else {
-        AutoMutex lock(&mServiceLock);
+        bool locked = tryLock(mServiceLock);
+        // failed to lock - CameraService is probably deadlocked
+        if (!locked) {
+            String8 result(kDeadlockedString);
+            write(fd, result.string(), result.size());
+        }
+
         if (mClient != 0) {
             sp<Client> currentClient = mClient.promote();
             sprintf(buffer, "Client (%p) PID: %d\n",
@@ -1317,6 +1341,8 @@
             result.append("No camera client yet.\n");
             write(fd, result.string(), result.size());
         }
+
+        if (locked) mServiceLock.unlock();
     }
     return NO_ERROR;
 }
diff --git a/cleanspec.mk b/cleanspec.mk
deleted file mode 100644
index 683e303..0000000
--- a/cleanspec.mk
+++ /dev/null
@@ -1 +0,0 @@
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/com/android/internal/os/IDropBoxService.java)
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/libs/audioflinger/AudioFlinger.cpp b/libs/audioflinger/AudioFlinger.cpp
index 2269352..8089389 100644
--- a/libs/audioflinger/AudioFlinger.cpp
+++ b/libs/audioflinger/AudioFlinger.cpp
@@ -3247,7 +3247,10 @@
                             if (mBytesRead < 0) {
                                 LOGE("Error reading audio input");
                                 if (mActiveTrack->mState == TrackBase::ACTIVE) {
-                                    sleep(1);
+                                    // Force input into standby so that it tries to
+                                    // recover at next read attempt
+                                    mInput->standby();
+                                    usleep(5000);
                                 }
                                 mRsmpInIndex = mFrameCount;
                                 framesOut = 0;
@@ -3429,7 +3432,10 @@
         if (mBytesRead < 0) {
             LOGE("RecordThread::getNextBuffer() Error reading audio input");
             if (mActiveTrack->mState == TrackBase::ACTIVE) {
-                sleep(1);
+                // Force input into standby so that it tries to
+                // recover at next read attempt
+                mInput->standby();
+                usleep(5000);
             }
             buffer->raw = 0;
             buffer->frameCount = 0;