Merge "Updates WebAddress to ignore the colon after the host component of a URL if no port is specified"
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/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index cbcef4e..0e796dc 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -946,7 +946,8 @@
         MASK_UI_MODE_TYPE = 0x0f,
         UI_MODE_TYPE_ANY = 0x00,
         UI_MODE_TYPE_NORMAL = 0x01,
-        UI_MODE_TYPE_CAR = 0x02,
+        UI_MODE_TYPE_DESK = 0x02,
+        UI_MODE_TYPE_CAR = 0x03,
 
         // uiMode bits for the night switch.
         MASK_UI_MODE_NIGHT = 0x30,
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;
diff --git a/libs/audioflinger/AudioPolicyManagerBase.cpp b/libs/audioflinger/AudioPolicyManagerBase.cpp
index 7b866c7..cfcc3ea 100644
--- a/libs/audioflinger/AudioPolicyManagerBase.cpp
+++ b/libs/audioflinger/AudioPolicyManagerBase.cpp
@@ -1290,7 +1290,7 @@
                 a2dpOutputDesc->changeRefCount((AudioSystem::stream_type)i,-refCount);
             }
         }
-        // do not change newDevice is it was already set before this call by a previous call to
+        // do not change newDevice if it was already set before this call by a previous call to
         // getNewDevice() or checkOutputForStrategy() for a strategy with higher priority
         if (newDevice == 0 && hwOutputDesc->isUsedByStrategy(strategy)) {
             newDevice = getDeviceForStrategy(strategy, false);
@@ -1466,6 +1466,12 @@
 
     case STRATEGY_MEDIA: {
         uint32_t device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
+        if (device2 == 0) {
+            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE;
+        }
+        if (device2 == 0) {
+            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
+        }
 #ifdef WITH_A2DP
         if (mA2dpOutput != 0) {
             if (strategy == STRATEGY_SONIFICATION && !a2dpUsedForSonification()) {
@@ -1483,12 +1489,6 @@
         }
 #endif
         if (device2 == 0) {
-            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADPHONE;
-        }
-        if (device2 == 0) {
-            device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
-        }
-        if (device2 == 0) {
             device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
         }
 
diff --git a/libs/ui/EventHub.cpp b/libs/ui/EventHub.cpp
index 57192a5..d45eaf0 100644
--- a/libs/ui/EventHub.cpp
+++ b/libs/ui/EventHub.cpp
@@ -176,7 +176,7 @@
     if (device == NULL) return -1;
     
     if (sw >= 0 && sw <= SW_MAX) {
-        uint8_t sw_bitmask[(SW_MAX+1)/8];
+        uint8_t sw_bitmask[(SW_MAX+7)/8];
         memset(sw_bitmask, 0, sizeof(sw_bitmask));
         if (ioctl(mFDs[id_to_index(device->id)].fd,
                    EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
@@ -200,7 +200,7 @@
     if (device == NULL) return -1;
     
     if (code >= 0 && code <= KEY_MAX) {
-        uint8_t key_bitmask[(KEY_MAX+1)/8];
+        uint8_t key_bitmask[(KEY_MAX+7)/8];
         memset(key_bitmask, 0, sizeof(key_bitmask));
         if (ioctl(mFDs[id_to_index(device->id)].fd,
                    EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
@@ -225,7 +225,7 @@
     Vector<int32_t> scanCodes;
     device->layoutMap->findScancodes(code, &scanCodes);
     
-    uint8_t key_bitmask[(KEY_MAX+1)/8];
+    uint8_t key_bitmask[(KEY_MAX+7)/8];
     memset(key_bitmask, 0, sizeof(key_bitmask));
     if (ioctl(mFDs[id_to_index(device->id)].fd,
                EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
@@ -608,12 +608,12 @@
     // consider up through the function keys; we don't want to include
     // ones after that (play cd etc) so we don't mistakenly consider a
     // controller to be a keyboard.
-    uint8_t key_bitmask[(KEY_PLAYCD+1)/8];
+    uint8_t key_bitmask[(KEY_MAX+7)/8];
     memset(key_bitmask, 0, sizeof(key_bitmask));
     LOGV("Getting keys...");
     if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) {
         //LOGI("MAP\n");
-        //for (int i=0; i<((KEY_MAX+1)/8); i++) {
+        //for (int i=0; i<((KEY_MAX+7)/8); i++) {
         //    LOGI("%d: 0x%02x\n", i, key_bitmask[i]);
         //}
         for (int i=0; i<((BTN_MISC+7)/8); i++) {
@@ -636,7 +636,7 @@
     
     // See if this is a trackball.
     if (test_bit(BTN_MOUSE, key_bitmask)) {
-        uint8_t rel_bitmask[(REL_MAX+1)/8];
+        uint8_t rel_bitmask[(REL_MAX+7)/8];
         memset(rel_bitmask, 0, sizeof(rel_bitmask));
         LOGV("Getting relative controllers...");
         if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0)
@@ -647,7 +647,7 @@
         }
     }
     
-    uint8_t abs_bitmask[(ABS_MAX+1)/8];
+    uint8_t abs_bitmask[(ABS_MAX+7)/8];
     memset(abs_bitmask, 0, sizeof(abs_bitmask));
     LOGV("Getting absolute controllers...");
     ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask);
@@ -666,7 +666,7 @@
 
 #ifdef EV_SW
     // figure out the switches this device reports
-    uint8_t sw_bitmask[(SW_MAX+1)/8];
+    uint8_t sw_bitmask[(SW_MAX+7)/8];
     memset(sw_bitmask, 0, sizeof(sw_bitmask));
     if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask) >= 0) {
         for (int i=0; i<EV_SW; i++) {
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 6da11b5..38d8412 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -1850,7 +1850,7 @@
         if (Res_GETPACKAGE(resID)+1 == 0) {
             LOGW("No package identifier when getting name for resource number 0x%08x", resID);
         } else {
-            LOGV("Resources don't contain package for resource number 0x%08x", resID);
+            LOGW("No known package when getting name for resource number 0x%08x", resID);
         }
         return false;
     }
@@ -1898,9 +1898,9 @@
 
     if (p < 0) {
         if (Res_GETPACKAGE(resID)+1 == 0) {
-            LOGW("No package identifier when getting name for resource number 0x%08x", resID);
+            LOGW("No package identifier when getting value for resource number 0x%08x", resID);
         } else {
-            LOGV("Resources don't contain package for resource number 0x%08x", resID);
+            LOGW("No known package when getting value for resource number 0x%08x", resID);
         }
         return BAD_INDEX;
     }
@@ -1921,7 +1921,7 @@
     const PackageGroup* const grp = mPackageGroups[p];
     if (grp == NULL) {
         LOGW("Bad identifier when getting value for resource number 0x%08x", resID);
-        return false;
+        return BAD_INDEX;
     }
     size_t ip = grp->packages.size();
     while (ip > 0) {
@@ -2003,7 +2003,7 @@
         return bestPackage->header->index;
     }
 
-    return BAD_INDEX;
+    return BAD_VALUE;
 }
 
 ssize_t ResTable::resolveReference(Res_value* value, ssize_t blockIndex,
@@ -2018,6 +2018,9 @@
         uint32_t newFlags = 0;
         const ssize_t newIndex = getResource(value->data, value, true, &newFlags,
                 outConfig);
+        if (newIndex == BAD_INDEX) {
+            return BAD_INDEX;
+        }
         TABLE_THEME(LOGI("Resolving reference %p: newIndex=%d, type=0x%x, data=%p\n",
              (void*)lastRef, (int)newIndex, (int)value->dataType, (void*)value->data));
         //printf("Getting reference 0x%08x: newIndex=%d\n", value->data, newIndex);