Merge "Bump axis limit"
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 34a5353..8911570 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -625,6 +625,10 @@
     property_get("dalvik.vm.dex2oat-flags", dex2oat_flags, "");
     ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags);
 
+    char profiler_prop[PROPERTY_VALUE_MAX];
+    bool profiler = property_get("dalvik.vm.profiler", profiler_prop, "0")
+                    && (profiler_prop[0] == '1');
+
     static const char* DEX2OAT_BIN = "/system/bin/dex2oat";
     static const int MAX_INT_LEN = 12;      // '-'+10dig+'\0' -OR- 0x+8dig
     static const unsigned int MAX_INSTRUCTION_SET_LEN = 32;
@@ -647,9 +651,17 @@
     sprintf(oat_fd_arg, "--oat-fd=%d", oat_fd);
     sprintf(oat_location_arg, "--oat-location=%s", output_file_name);
     sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
-    if (strcmp(pkgname, "*") != 0) {
-        snprintf(profile_file_arg, sizeof(profile_file_arg), "--profile-file=%s/%s",
+
+    if (profiler && (strcmp(pkgname, "*") != 0)) {
+        char profile_file[PKG_PATH_MAX];
+        snprintf(profile_file, sizeof(profile_file), "%s/%s",
                  DALVIK_CACHE_PREFIX "profiles", pkgname);
+        struct stat st;
+        if (stat(profile_file, &st) == -1) {
+            strcpy(profile_file_arg, "--no-profile-file");
+        } else {
+            sprintf(profile_file_arg, "--profile-file=%s", profile_file);
+        }
     } else {
         strcpy(profile_file_arg, "--no-profile-file");
     }
diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c
index 064ee32..f714836 100644
--- a/cmds/installd/installd.c
+++ b/cmds/installd/installd.c
@@ -489,6 +489,11 @@
         goto fail;
     }
 
+    if (ensure_config_user_dirs(0) == -1) {
+        ALOGE("Failed to setup misc for user 0");
+        goto fail;
+    }
+
     if (version == 2) {
         ALOGD("Upgrading to /data/misc/user directories");
 
@@ -517,12 +522,31 @@
             closedir(dir);
         }
 
-        version = 3;
-    }
+        // Just rename keychain files into user/0; they should already have the right permissions
+        char misc_dir[PATH_MAX];
+        char keychain_added_dir[PATH_MAX];
+        char keychain_removed_dir[PATH_MAX];
+        char config_added_dir[PATH_MAX];
+        char config_removed_dir[PATH_MAX];
 
-    if (ensure_config_user_dirs(0) == -1) {
-        ALOGE("Failed to setup misc for user 0");
-        goto fail;
+        snprintf(misc_dir, PATH_MAX, "%s/misc", android_data_dir.path);
+        snprintf(keychain_added_dir, PATH_MAX, "%s/keychain/cacerts-added", misc_dir);
+        snprintf(keychain_removed_dir, PATH_MAX, "%s/keychain/cacerts-removed", misc_dir);
+        snprintf(config_added_dir, PATH_MAX, "%s/user/0/cacerts-added", misc_dir);
+        snprintf(config_removed_dir, PATH_MAX, "%s/user/0/cacerts-removed", misc_dir);
+
+        if (access(keychain_added_dir, F_OK) == 0) {
+            if (rename(keychain_added_dir, config_added_dir) != 0) {
+                goto fail;
+            }
+        }
+        if (access(keychain_removed_dir, F_OK) == 0) {
+            if (rename(keychain_removed_dir, config_removed_dir) != 0) {
+                goto fail;
+            }
+        }
+
+        version = 3;
     }
 
     // Persist layout version if changed
diff --git a/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp
index f3f26ac..36e3c06 100644
--- a/libs/gui/BufferQueueConsumer.cpp
+++ b/libs/gui/BufferQueueConsumer.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
+
 #define LOG_TAG "BufferQueueConsumer"
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
 //#define LOG_NDEBUG 0
@@ -104,14 +106,16 @@
                 // This buffer is set to display in the near future, or
                 // desiredPresent is garbage. Either way we don't want to drop
                 // the previous buffer just to get this on the screen sooner.
-                BQ_LOGV("acquireBuffer: nodrop desire=%lld expect=%lld "
-                        "(%lld) now=%lld", desiredPresent, expectedPresent,
+                BQ_LOGV("acquireBuffer: nodrop desire=%" PRId64 " expect=%"
+                        PRId64 " (%" PRId64 ") now=%" PRId64,
+                        desiredPresent, expectedPresent,
                         desiredPresent - expectedPresent,
                         systemTime(CLOCK_MONOTONIC));
                 break;
             }
 
-            BQ_LOGV("acquireBuffer: drop desire=%lld expect=%lld size=%d",
+            BQ_LOGV("acquireBuffer: drop desire=%" PRId64 " expect=%" PRId64
+                    " size=%zu",
                     desiredPresent, expectedPresent, mCore->mQueue.size());
             if (mCore->stillTracking(front)) {
                 // Front buffer is still in mSlots, so mark the slot as free
@@ -125,15 +129,16 @@
         nsecs_t desiredPresent = front->mTimestamp;
         if (desiredPresent > expectedPresent &&
                 desiredPresent < expectedPresent + MAX_REASONABLE_NSEC) {
-            BQ_LOGV("acquireBuffer: defer desire=%lld expect=%lld "
-                    "(%lld) now=%lld", desiredPresent, expectedPresent,
+            BQ_LOGV("acquireBuffer: defer desire=%" PRId64 " expect=%" PRId64
+                    " (%" PRId64 ") now=%" PRId64,
+                    desiredPresent, expectedPresent,
                     desiredPresent - expectedPresent,
                     systemTime(CLOCK_MONOTONIC));
             return PRESENT_LATER;
         }
 
-        BQ_LOGV("acquireBuffer: accept desire=%lld expect=%lld "
-                "(%lld) now=%lld", desiredPresent, expectedPresent,
+        BQ_LOGV("acquireBuffer: accept desire=%" PRId64 " expect=%" PRId64 " "
+                "(%" PRId64 ") now=%" PRId64, desiredPresent, expectedPresent,
                 desiredPresent - expectedPresent,
                 systemTime(CLOCK_MONOTONIC));
     }
@@ -142,7 +147,7 @@
     *outBuffer = *front;
     ATRACE_BUFFER_INDEX(slot);
 
-    BQ_LOGV("acquireBuffer: acquiring { slot=%d/%llu buffer=%p }",
+    BQ_LOGV("acquireBuffer: acquiring { slot=%d/%" PRIu64 " buffer=%p }",
             slot, front->mFrameNumber, front->mGraphicBuffer->handle);
     // If the front buffer is still being tracked, update its slot state
     if (mCore->stillTracking(front)) {
diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp
index 593b6f1..40e6884 100644
--- a/libs/gui/BufferQueueCore.cpp
+++ b/libs/gui/BufferQueueCore.cpp
@@ -173,7 +173,8 @@
     const int minBufferCount = mUseAsyncBuffer ? 2 : 1;
     if (count < minBufferCount || count > BufferQueueDefs::NUM_BUFFER_SLOTS) {
         BQ_LOGV("setDefaultMaxBufferCount: invalid count %d, should be in "
-                "[%d, %d]", minBufferCount, BufferQueueDefs::NUM_BUFFER_SLOTS);
+                "[%d, %d]",
+                count, minBufferCount, BufferQueueDefs::NUM_BUFFER_SLOTS);
         return BAD_VALUE;
     }
 
@@ -212,8 +213,8 @@
 bool BufferQueueCore::stillTracking(const BufferItem* item) const {
     const BufferSlot& slot = mSlots[item->mSlot];
 
-    BQ_LOGV("stillTracking: item { slot=%d/%llu buffer=%p } "
-            "slot { slot=%d/%llu buffer=%p }",
+    BQ_LOGV("stillTracking: item { slot=%d/%" PRIu64 " buffer=%p } "
+            "slot { slot=%d/%" PRIu64 " buffer=%p }",
             item->mSlot, item->mFrameNumber,
             (item->mGraphicBuffer.get() ? item->mGraphicBuffer->handle : 0),
             item->mSlot, slot.mFrameNumber,
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index f536a59..7017ddf 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
+
 #define LOG_TAG "BufferQueueProducer"
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
 //#define LOG_NDEBUG 0
@@ -209,9 +211,10 @@
         // our slots are empty but we have many buffers in the queue. This can
         // cause us to run out of memory if we outrun the consumer. Wait here if
         // it looks like we have too many buffers queued up.
-        bool tooManyBuffers = mCore->mQueue.size() > maxBufferCount;
+        bool tooManyBuffers = mCore->mQueue.size()
+                            > static_cast<size_t>(maxBufferCount);
         if (tooManyBuffers) {
-            BQ_LOGV("%s: queue size is %d, waiting", caller,
+            BQ_LOGV("%s: queue size is %zu, waiting", caller,
                     mCore->mQueue.size());
         }
 
@@ -367,7 +370,8 @@
         eglDestroySyncKHR(eglDisplay, eglFence);
     }
 
-    BQ_LOGV("dequeueBuffer: returning slot=%d/%llu buf=%p flags=%#x", *outSlot,
+    BQ_LOGV("dequeueBuffer: returning slot=%d/%" PRIu64 " buf=%p flags=%#x",
+            *outSlot,
             mSlots[*outSlot].mFrameNumber,
             mSlots[*outSlot].mGraphicBuffer->handle, returnFlags);
 
@@ -560,8 +564,8 @@
             return BAD_VALUE;
         }
 
-        BQ_LOGV("queueBuffer: slot=%d/%llu time=%llu crop=[%d,%d,%d,%d] "
-                "transform=%#x scale=%s",
+        BQ_LOGV("queueBuffer: slot=%d/%" PRIu64 " time=%" PRIu64
+                " crop=[%d,%d,%d,%d] transform=%#x scale=%s",
                 slot, mCore->mFrameCounter + 1, timestamp,
                 crop.left, crop.top, crop.right, crop.bottom,
                 transform, BufferItem::scalingModeName(scalingMode));
diff --git a/libs/gui/Sensor.cpp b/libs/gui/Sensor.cpp
index 70180f8..f161aeb 100644
--- a/libs/gui/Sensor.cpp
+++ b/libs/gui/Sensor.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/limits.h>
@@ -67,7 +68,8 @@
         if (hwSensor->maxDelay > INT_MAX) {
             // Max delay is declared as a 64 bit integer for 64 bit architectures. But it should
             // always fit in a 32 bit integer, log error and cap it to INT_MAX.
-            ALOGE("Sensor maxDelay overflow error %s %lld", mName.string(), hwSensor->maxDelay);
+            ALOGE("Sensor maxDelay overflow error %s %" PRId64, mName.string(),
+                  static_cast<int64_t>(hwSensor->maxDelay));
             mMaxDelay = INT_MAX;
         } else {
             mMaxDelay = (int32_t) hwSensor->maxDelay;
diff --git a/libs/gui/StreamSplitter.cpp b/libs/gui/StreamSplitter.cpp
index 83e08fb..771b263 100644
--- a/libs/gui/StreamSplitter.cpp
+++ b/libs/gui/StreamSplitter.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <inttypes.h>
+
 #define LOG_TAG "StreamSplitter"
 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
 //#define LOG_NDEBUG 0
@@ -63,7 +65,7 @@
     }
 
     if (mBuffers.size() > 0) {
-        ALOGE("%d buffers still being tracked", mBuffers.size());
+        ALOGE("%zu buffers still being tracked", mBuffers.size());
     }
 }
 
@@ -126,7 +128,7 @@
     LOG_ALWAYS_FATAL_IF(status != NO_ERROR,
             "acquiring buffer from input failed (%d)", status);
 
-    ALOGV("acquired buffer %#llx from input",
+    ALOGV("acquired buffer %#" PRIx64 " from input",
             bufferItem.mGraphicBuffer->getId());
 
     status = mInput->detachBuffer(bufferItem.mBuf);
@@ -176,7 +178,7 @@
                     "queueing buffer to output failed (%d)", status);
         }
 
-        ALOGV("queued buffer %#llx to output %p",
+        ALOGV("queued buffer %#" PRIx64 " to output %p",
                 bufferItem.mGraphicBuffer->getId(), output->get());
     }
 }
@@ -199,7 +201,8 @@
                 "detaching buffer from output failed (%d)", status);
     }
 
-    ALOGV("detached buffer %#llx from output %p", buffer->getId(), from.get());
+    ALOGV("detached buffer %#" PRIx64 " from output %p",
+          buffer->getId(), from.get());
 
     const sp<BufferTracker>& tracker = mBuffers.editValueFor(buffer->getId());
 
@@ -209,7 +212,7 @@
 
     // Check to see if this is the last outstanding reference to this buffer
     size_t releaseCount = tracker->incrementReleaseCountLocked();
-    ALOGV("buffer %#llx reference count %d (of %d)", buffer->getId(),
+    ALOGV("buffer %#" PRIx64 " reference count %zu (of %zu)", buffer->getId(),
             releaseCount, mOutputs.size());
     if (releaseCount < mOutputs.size()) {
         return;
@@ -233,7 +236,7 @@
     LOG_ALWAYS_FATAL_IF(status != NO_ERROR,
             "releasing buffer to input failed (%d)", status);
 
-    ALOGV("released buffer %#llx to input", buffer->getId());
+    ALOGV("released buffer %#" PRIx64 " to input", buffer->getId());
 
     // We no longer need to track the buffer once it has been returned to the
     // input
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 5bad2e6..21fd443 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -22,6 +22,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <math.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -312,7 +313,7 @@
     }
 
     if (pointerCount > MAX_POINTERS || pointerCount < 1) {
-        ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %zu.",
+        ALOGE("channel '%s' publisher ~ Invalid number of pointers provided: %"PRIu32".",
                 mChannel->getName().string(), pointerCount);
         return BAD_VALUE;
     }