Merge "Fix calls to captureScreen"
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c
index 7f84f98..577d31c 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.c
@@ -508,7 +508,7 @@
         if (!mkdir(anr_traces_dir, 0775)) {
             chown(anr_traces_dir, AID_SYSTEM, AID_SYSTEM);
             chmod(anr_traces_dir, 0775);
-            if (selinux_android_restorecon(anr_traces_dir) == -1) {
+            if (selinux_android_restorecon(anr_traces_dir, 0) == -1) {
                 fprintf(stderr, "restorecon failed for %s: %s\n", anr_traces_dir, strerror(errno));
             }
         } else if (errno != EEXIST) {
diff --git a/cmds/idmap/Android.mk b/cmds/idmap/Android.mk
deleted file mode 100644
index ffa83f2..0000000
--- a/cmds/idmap/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright (C) 2012 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.
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := idmap.cpp create.cpp scan.cpp inspect.cpp
-
-LOCAL_SHARED_LIBRARIES := liblog libutils libandroidfw
-
-LOCAL_MODULE := idmap
-
-LOCAL_C_INCLUDES := external/zlib
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_EXECUTABLE)
diff --git a/cmds/idmap/create.cpp b/cmds/idmap/create.cpp
deleted file mode 100644
index ae35f7b..0000000
--- a/cmds/idmap/create.cpp
+++ /dev/null
@@ -1,222 +0,0 @@
-#include "idmap.h"
-
-#include <UniquePtr.h>
-#include <androidfw/AssetManager.h>
-#include <androidfw/ResourceTypes.h>
-#include <androidfw/ZipFileRO.h>
-#include <utils/String8.h>
-
-#include <fcntl.h>
-#include <sys/stat.h>
-
-using namespace android;
-
-namespace {
-    int get_zip_entry_crc(const char *zip_path, const char *entry_name, uint32_t *crc)
-    {
-        UniquePtr<ZipFileRO> zip(ZipFileRO::open(zip_path));
-        if (zip.get() == NULL) {
-            return -1;
-        }
-        ZipEntryRO entry = zip->findEntryByName(entry_name);
-        if (entry == NULL) {
-            return -1;
-        }
-        if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)crc)) {
-            return -1;
-        }
-        zip->releaseEntry(entry);
-        return 0;
-    }
-
-    int open_idmap(const char *path)
-    {
-        int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644));
-        if (fd == -1) {
-            ALOGD("error: open %s: %s\n", path, strerror(errno));
-            goto fail;
-        }
-        if (fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
-            ALOGD("error: fchmod %s: %s\n", path, strerror(errno));
-            goto fail;
-        }
-        if (TEMP_FAILURE_RETRY(flock(fd, LOCK_EX | LOCK_NB)) != 0) {
-            ALOGD("error: flock %s: %s\n", path, strerror(errno));
-            goto fail;
-        }
-
-        return fd;
-fail:
-        if (fd != -1) {
-            close(fd);
-            unlink(path);
-        }
-        return -1;
-    }
-
-    int write_idmap(int fd, const uint32_t *data, size_t size)
-    {
-        if (lseek(fd, SEEK_SET, 0) < 0) {
-            return -1;
-        }
-        size_t bytesLeft = size;
-        while (bytesLeft > 0) {
-            ssize_t w = TEMP_FAILURE_RETRY(write(fd, data + size - bytesLeft, bytesLeft));
-            if (w < 0) {
-                fprintf(stderr, "error: write: %s\n", strerror(errno));
-                return -1;
-            }
-            bytesLeft -= w;
-        }
-        return 0;
-    }
-
-    bool is_idmap_stale_fd(const char *target_apk_path, const char *overlay_apk_path, int idmap_fd)
-    {
-        static const size_t N = ResTable::IDMAP_HEADER_SIZE_BYTES;
-        struct stat st;
-        if (fstat(idmap_fd, &st) == -1) {
-            return true;
-        }
-        if (st.st_size < N) {
-            // file is empty or corrupt
-            return true;
-        }
-
-        char buf[N];
-        ssize_t bytesLeft = N;
-        if (lseek(idmap_fd, SEEK_SET, 0) < 0) {
-            return true;
-        }
-        for (;;) {
-            ssize_t r = TEMP_FAILURE_RETRY(read(idmap_fd, buf + N - bytesLeft, bytesLeft));
-            if (r < 0) {
-                return true;
-            }
-            bytesLeft -= r;
-            if (bytesLeft == 0) {
-                break;
-            }
-            if (r == 0) {
-                // "shouldn't happen"
-                return true;
-            }
-        }
-
-        uint32_t cached_target_crc, cached_overlay_crc;
-        String8 cached_target_path, cached_overlay_path;
-        if (!ResTable::getIdmapInfo(buf, N, &cached_target_crc, &cached_overlay_crc,
-                    &cached_target_path, &cached_overlay_path)) {
-            return true;
-        }
-
-        if (cached_target_path != target_apk_path) {
-            return true;
-        }
-        if (cached_overlay_path != overlay_apk_path) {
-            return true;
-        }
-
-        uint32_t actual_target_crc, actual_overlay_crc;
-        if (get_zip_entry_crc(target_apk_path, AssetManager::RESOURCES_FILENAME,
-				&actual_target_crc) == -1) {
-            return true;
-        }
-        if (get_zip_entry_crc(overlay_apk_path, AssetManager::RESOURCES_FILENAME,
-				&actual_overlay_crc) == -1) {
-            return true;
-        }
-
-        return cached_target_crc != actual_target_crc || cached_overlay_crc != actual_overlay_crc;
-    }
-
-    bool is_idmap_stale_path(const char *target_apk_path, const char *overlay_apk_path,
-            const char *idmap_path)
-    {
-        struct stat st;
-        if (stat(idmap_path, &st) == -1) {
-            // non-existing idmap is always stale; on other errors, abort idmap generation
-            return errno == ENOENT;
-        }
-
-        int idmap_fd = TEMP_FAILURE_RETRY(open(idmap_path, O_RDONLY));
-        if (idmap_fd == -1) {
-            return false;
-        }
-        bool is_stale = is_idmap_stale_fd(target_apk_path, overlay_apk_path, idmap_fd);
-        close(idmap_fd);
-        return is_stale;
-    }
-
-    int create_idmap(const char *target_apk_path, const char *overlay_apk_path,
-            uint32_t **data, size_t *size)
-    {
-        uint32_t target_crc, overlay_crc;
-        if (get_zip_entry_crc(target_apk_path, AssetManager::RESOURCES_FILENAME,
-				&target_crc) == -1) {
-            return -1;
-        }
-        if (get_zip_entry_crc(overlay_apk_path, AssetManager::RESOURCES_FILENAME,
-				&overlay_crc) == -1) {
-            return -1;
-        }
-
-        AssetManager am;
-        bool b = am.createIdmap(target_apk_path, overlay_apk_path, target_crc, overlay_crc,
-                data, size);
-        return b ? 0 : -1;
-    }
-
-    int create_and_write_idmap(const char *target_apk_path, const char *overlay_apk_path,
-            int fd, bool check_if_stale)
-    {
-        if (check_if_stale) {
-            if (!is_idmap_stale_fd(target_apk_path, overlay_apk_path, fd)) {
-                // already up to date -- nothing to do
-                return 0;
-            }
-        }
-
-        uint32_t *data = NULL;
-        size_t size;
-
-        if (create_idmap(target_apk_path, overlay_apk_path, &data, &size) == -1) {
-            return -1;
-        }
-
-        if (write_idmap(fd, data, size) == -1) {
-            free(data);
-            return -1;
-        }
-
-        free(data);
-        return 0;
-    }
-}
-
-int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path,
-        const char *idmap_path)
-{
-    if (!is_idmap_stale_path(target_apk_path, overlay_apk_path, idmap_path)) {
-        // already up to date -- nothing to do
-        return EXIT_SUCCESS;
-    }
-
-    int fd = open_idmap(idmap_path);
-    if (fd == -1) {
-        return EXIT_FAILURE;
-    }
-
-    int r = create_and_write_idmap(target_apk_path, overlay_apk_path, fd, false);
-    close(fd);
-    if (r != 0) {
-        unlink(idmap_path);
-    }
-    return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, int fd)
-{
-    return create_and_write_idmap(target_apk_path, overlay_apk_path, fd, true) == 0 ?
-        EXIT_SUCCESS : EXIT_FAILURE;
-}
diff --git a/cmds/idmap/idmap.cpp b/cmds/idmap/idmap.cpp
deleted file mode 100644
index 46c0edc..0000000
--- a/cmds/idmap/idmap.cpp
+++ /dev/null
@@ -1,237 +0,0 @@
-#include "idmap.h"
-
-#include <private/android_filesystem_config.h> // for AID_SYSTEM
-
-#include <stdlib.h>
-#include <string.h>
-
-namespace {
-    const char *usage = "NAME\n\
-      idmap - create or display idmap files\n\
-\n\
-SYNOPSIS \n\
-      idmap --help \n\
-      idmap --fd target overlay fd \n\
-      idmap --path target overlay idmap \n\
-      idmap --scan dir-to-scan target-to-look-for target dir-to-hold-idmaps \n\
-      idmap --inspect idmap \n\
-\n\
-DESCRIPTION \n\
-      Idmap files play an integral part in the runtime resource overlay framework. An idmap \n\
-      file contains a mapping of resource identifiers between overlay package and its target \n\
-      package; this mapping is used during resource lookup. Idmap files also act as control \n\
-      files by their existence: if not present, the corresponding overlay package is ignored \n\
-      when the resource context is created. \n\
-\n\
-      Idmap files are stored in /data/resource-cache. For each pair (target package, overlay \n\
-      package), there exists exactly one idmap file, or none if the overlay should not be used. \n\
-\n\
-NOMENCLATURE \n\
-      target: the original, non-overlay, package. Each target package may be associated with \n\
-              any number of overlay packages. \n\
-\n\
-      overlay: an overlay package. Each overlay package is associated with exactly one target \n\
-               package, specified in the overlay's manifest using the <overlay target=\"...\"/> \n\
-               tag. \n\
-\n\
-OPTIONS \n\
-      --help: display this help \n\
-\n\
-      --fd: create idmap for target package 'target' (path to apk) and overlay package 'overlay' \n\
-            (path to apk); write results to file descriptor 'fd' (integer). This invocation \n\
-            version is intended to be used by a parent process with higher privileges to call \n\
-            idmap in a controlled way: the parent will open a suitable file descriptor, fork, \n\
-            drop its privileges and exec. This tool will continue execution without the extra \n\
-            privileges, but still have write access to a file it could not have opened on its \n\
-            own. \n\
-\n\
-      --path: create idmap for target package 'target' (path to apk) and overlay package \n\
-              'overlay' (path to apk); write results to 'idmap' (path). \n\
-\n\
-      --scan: non-recursively search directory 'dir-to-scan' (path) for overlay packages with \n\
-              target package 'target-to-look-for' (package name) present at 'target' (path to \n\
-              apk). For each overlay package found, create an idmap file in 'dir-to-hold-idmaps' \n\
-              (path). \n\
-\n\
-      --inspect: decode the binary format of 'idmap' (path) and display the contents in a \n\
-                 debug-friendly format. \n\
-\n\
-EXAMPLES \n\
-      Create an idmap file: \n\
-\n\
-      $ adb shell idmap --path /system/app/target.apk \\ \n\
-                               /vendor/overlay/overlay.apk \\ \n\
-                               /data/resource-cache/vendor@overlay@overlay.apk@idmap \n\
-\n\
-      Display an idmap file: \n\
-\n\
-      $ adb shell idmap --inspect /data/resource-cache/vendor@overlay@overlay.apk@idmap \n\
-      SECTION      ENTRY        VALUE      OFFSET    COMMENT \n\
-      IDMAP HEADER magic        0x706d6469 0x0 \n\
-                   base crc     0x484aa77f 0x1 \n\
-                   overlay crc  0x03c66fa5 0x2 \n\
-                   base path    .......... 0x03-0x42 /system/app/target.apk \n\
-                   overlay path .......... 0x43-0x82 /vendor/overlay/overlay.apk \n\
-      DATA HEADER  types count  0x00000003 0x83 \n\
-                   padding      0x00000000 0x84 \n\
-                   type offset  0x00000004 0x85      absolute offset 0x87, xml \n\
-                   type offset  0x00000007 0x86      absolute offset 0x8a, string \n\
-      DATA BLOCK   entry count  0x00000001 0x87 \n\
-                   entry offset 0x00000000 0x88 \n\
-                   entry        0x7f020000 0x89      xml/integer \n\
-      DATA BLOCK   entry count  0x00000002 0x8a \n\
-                   entry offset 0x00000000 0x8b \n\
-                   entry        0x7f030000 0x8c      string/str \n\
-                   entry        0x7f030001 0x8d      string/str2 \n\
-\n\
-      In this example, the overlay package provides three alternative resource values:\n\
-      xml/integer, string/str and string/str2.\n\
-\n\
-NOTES \n\
-      This tool and its expected invocation from installd is modelled on dexopt.";
-
-    bool verify_directory_readable(const char *path)
-    {
-        return access(path, R_OK | X_OK) == 0;
-    }
-
-    bool verify_directory_writable(const char *path)
-    {
-        return access(path, W_OK) == 0;
-    }
-
-    bool verify_file_readable(const char *path)
-    {
-        return access(path, R_OK) == 0;
-    }
-
-    bool verify_root_or_system()
-    {
-        uid_t uid = getuid();
-        gid_t gid = getgid();
-
-        return (uid == 0 && gid == 0) || (uid == AID_SYSTEM && gid == AID_SYSTEM);
-    }
-
-    int maybe_create_fd(const char *target_apk_path, const char *overlay_apk_path,
-            const char *idmap_str)
-    {
-        // anyone (not just root or system) may do --fd -- the file has
-        // already been opened by someone else on our behalf
-
-        char *endptr;
-        int idmap_fd = strtol(idmap_str, &endptr, 10);
-        if (*endptr != '\0') {
-            fprintf(stderr, "error: failed to parse file descriptor argument %s\n", idmap_str);
-            return -1;
-        }
-
-        if (!verify_file_readable(target_apk_path)) {
-            ALOGD("error: failed to read apk %s: %s\n", target_apk_path, strerror(errno));
-            return -1;
-        }
-
-        if (!verify_file_readable(overlay_apk_path)) {
-            ALOGD("error: failed to read apk %s: %s\n", overlay_apk_path, strerror(errno));
-            return -1;
-        }
-
-        return idmap_create_fd(target_apk_path, overlay_apk_path, idmap_fd);
-    }
-
-    int maybe_create_path(const char *target_apk_path, const char *overlay_apk_path,
-            const char *idmap_path)
-    {
-        if (!verify_root_or_system()) {
-            fprintf(stderr, "error: permission denied: not user root or user system\n");
-            return -1;
-        }
-
-        if (!verify_file_readable(target_apk_path)) {
-            ALOGD("error: failed to read apk %s: %s\n", target_apk_path, strerror(errno));
-            return -1;
-        }
-
-        if (!verify_file_readable(overlay_apk_path)) {
-            ALOGD("error: failed to read apk %s: %s\n", overlay_apk_path, strerror(errno));
-            return -1;
-        }
-
-        return idmap_create_path(target_apk_path, overlay_apk_path, idmap_path);
-    }
-
-    int maybe_scan(const char *overlay_dir, const char *target_package_name,
-            const char *target_apk_path, const char *idmap_dir)
-    {
-        if (!verify_root_or_system()) {
-            fprintf(stderr, "error: permission denied: not user root or user system\n");
-            return -1;
-        }
-
-        if (!verify_directory_readable(overlay_dir)) {
-            ALOGD("error: no read access to %s: %s\n", overlay_dir, strerror(errno));
-            return -1;
-        }
-
-        if (!verify_file_readable(target_apk_path)) {
-            ALOGD("error: failed to read apk %s: %s\n", target_apk_path, strerror(errno));
-            return -1;
-        }
-
-        if (!verify_directory_writable(idmap_dir)) {
-            ALOGD("error: no write access to %s: %s\n", idmap_dir, strerror(errno));
-            return -1;
-        }
-
-        return idmap_scan(overlay_dir, target_package_name, target_apk_path, idmap_dir);
-    }
-
-    int maybe_inspect(const char *idmap_path)
-    {
-        // anyone (not just root or system) may do --inspect
-        if (!verify_file_readable(idmap_path)) {
-            ALOGD("error: failed to read idmap %s: %s\n", idmap_path, strerror(errno));
-            return -1;
-        }
-        return idmap_inspect(idmap_path);
-    }
-}
-
-int main(int argc, char **argv)
-{
-#if 0
-    {
-        char buf[1024];
-        buf[0] = '\0';
-        for (int i = 0; i < argc; ++i) {
-            strncat(buf, argv[i], sizeof(buf) - 1);
-            strncat(buf, " ", sizeof(buf) - 1);
-        }
-        ALOGD("%s:%d: uid=%d gid=%d argv=%s\n", __FILE__, __LINE__, getuid(), getgid(), buf);
-    }
-#endif
-
-    if (argc == 2 && !strcmp(argv[1], "--help")) {
-        printf("%s\n", usage);
-        return 0;
-    }
-
-    if (argc == 5 && !strcmp(argv[1], "--fd")) {
-        return maybe_create_fd(argv[2], argv[3], argv[4]);
-    }
-
-    if (argc == 5 && !strcmp(argv[1], "--path")) {
-        return maybe_create_path(argv[2], argv[3], argv[4]);
-    }
-
-    if (argc == 6 && !strcmp(argv[1], "--scan")) {
-        return maybe_scan(argv[2], argv[3], argv[4], argv[5]);
-    }
-
-    if (argc == 3 && !strcmp(argv[1], "--inspect")) {
-        return maybe_inspect(argv[2]);
-    }
-
-    fprintf(stderr, "Usage: don't use this (cf dexopt usage).\n");
-    return EXIT_FAILURE;
-}
diff --git a/cmds/idmap/idmap.h b/cmds/idmap/idmap.h
deleted file mode 100644
index f507dd8..0000000
--- a/cmds/idmap/idmap.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef _IDMAP_H_
-#define _IDMAP_H_
-
-#define LOG_TAG "idmap"
-
-#include <utils/Log.h>
-
-#include <errno.h>
-#include <stdio.h>
-
-#ifndef TEMP_FAILURE_RETRY
-// Used to retry syscalls that can return EINTR.
-#define TEMP_FAILURE_RETRY(exp) ({         \
-    typeof (exp) _rc;                      \
-    do {                                   \
-        _rc = (exp);                       \
-    } while (_rc == -1 && errno == EINTR); \
-    _rc; })
-#endif
-
-int idmap_create_path(const char *target_apk_path, const char *overlay_apk_path,
-        const char *idmap_path);
-
-int idmap_create_fd(const char *target_apk_path, const char *overlay_apk_path, int fd);
-
-// Regarding target_package_name: the idmap_scan implementation should
-// be able to extract this from the manifest in target_apk_path,
-// simplifying the external API.
-int idmap_scan(const char *overlay_dir, const char *target_package_name,
-        const char *target_apk_path, const char *idmap_dir);
-
-int idmap_inspect(const char *idmap_path);
-
-#endif // _IDMAP_H_
diff --git a/cmds/idmap/inspect.cpp b/cmds/idmap/inspect.cpp
deleted file mode 100644
index a59f5d3..0000000
--- a/cmds/idmap/inspect.cpp
+++ /dev/null
@@ -1,291 +0,0 @@
-#include "idmap.h"
-
-#include <androidfw/AssetManager.h>
-#include <androidfw/ResourceTypes.h>
-#include <utils/String8.h>
-
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-
-using namespace android;
-
-#define NEXT(b, i, o) do { if (buf.next(&i, &o) < 0) { return -1; } } while (0)
-
-namespace {
-    static const uint32_t IDMAP_MAGIC = 0x706d6469;
-    static const size_t PATH_LENGTH = 256;
-    static const uint32_t IDMAP_HEADER_SIZE = (3 + 2 * (PATH_LENGTH / sizeof(uint32_t)));
-
-    void printe(const char *fmt, ...);
-
-    class IdmapBuffer {
-        private:
-            char *buf_;
-            size_t len_;
-            mutable size_t pos_;
-        public:
-            IdmapBuffer() : buf_((char *)MAP_FAILED), len_(0), pos_(0) {}
-
-            ~IdmapBuffer() {
-                if (buf_ != MAP_FAILED) {
-                    munmap(buf_, len_);
-                }
-            }
-
-            int init(const char *idmap_path)
-            {
-                struct stat st;
-                int fd;
-
-                if (stat(idmap_path, &st) < 0) {
-                    printe("failed to stat idmap '%s': %s\n", idmap_path, strerror(errno));
-                    return -1;
-                }
-                len_ = st.st_size;
-                if ((fd = TEMP_FAILURE_RETRY(open(idmap_path, O_RDONLY))) < 0) {
-                    printe("failed to open idmap '%s': %s\n", idmap_path, strerror(errno));
-                    return -1;
-                }
-                if ((buf_ = (char*)mmap(NULL, len_, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
-                    close(fd);
-                    printe("failed to mmap idmap: %s\n", strerror(errno));
-                    return -1;
-                }
-                close(fd);
-                return 0;
-            }
-
-            int next(uint32_t *i, uint32_t *offset) const
-            {
-                if (!buf_) {
-                    printe("failed to read next uint32_t: buffer not initialized\n");
-                    return -1;
-                }
-                if (pos_ + 4 > len_) {
-                    printe("failed to read next uint32_t: end of buffer reached at pos=0x%08x\n",
-                            pos_);
-                    return -1;
-                }
-                *offset = pos_ / sizeof(uint32_t);
-                char a = buf_[pos_++];
-                char b = buf_[pos_++];
-                char c = buf_[pos_++];
-                char d = buf_[pos_++];
-                *i = (d << 24) | (c << 16) | (b << 8) | a;
-                return 0;
-            }
-
-            int nextPath(char *b, uint32_t *offset_start, uint32_t *offset_end) const
-            {
-                if (!buf_) {
-                    printe("failed to read next path: buffer not initialized\n");
-                    return -1;
-                }
-                if (pos_ + PATH_LENGTH > len_) {
-                    printe("failed to read next path: end of buffer reached at pos=0x%08x\n", pos_);
-                    return -1;
-                }
-                memcpy(b, buf_ + pos_, PATH_LENGTH);
-                *offset_start = pos_ / sizeof(uint32_t);
-                pos_ += PATH_LENGTH;
-                *offset_end = pos_ / sizeof(uint32_t) - 1;
-                return 0;
-            }
-    };
-
-    void printe(const char *fmt, ...)
-    {
-        va_list ap;
-
-        va_start(ap, fmt);
-        fprintf(stderr, "error: ");
-        vfprintf(stderr, fmt, ap);
-        va_end(ap);
-    }
-
-    void print_header()
-    {
-        printf("SECTION      ENTRY        VALUE      OFFSET    COMMENT\n");
-    }
-
-    void print(const char *section, const char *subsection, uint32_t value, uint32_t offset,
-            const char *fmt, ...)
-    {
-        va_list ap;
-
-        va_start(ap, fmt);
-        printf("%-12s %-12s 0x%08x 0x%-4x    ", section, subsection, value, offset);
-        vprintf(fmt, ap);
-        printf("\n");
-        va_end(ap);
-    }
-
-    void print_path(const char *section, const char *subsection, uint32_t offset_start,
-            uint32_t offset_end, const char *fmt, ...)
-    {
-        va_list ap;
-
-        va_start(ap, fmt);
-        printf("%-12s %-12s .......... 0x%02x-0x%02x ", section, subsection, offset_start,
-                offset_end);
-        vprintf(fmt, ap);
-        printf("\n");
-        va_end(ap);
-    }
-
-    int resource_metadata(const AssetManager& am, uint32_t res_id,
-            String8 *package, String8 *type, String8 *name)
-    {
-        const ResTable& rt = am.getResources();
-        struct ResTable::resource_name data;
-        if (!rt.getResourceName(res_id, false, &data)) {
-            printe("failed to get resource name id=0x%08x\n", res_id);
-            return -1;
-        }
-        if (package) {
-            *package = String8(String16(data.package, data.packageLen));
-        }
-        if (type) {
-            *type = String8(String16(data.type, data.typeLen));
-        }
-        if (name) {
-            *name = String8(String16(data.name, data.nameLen));
-        }
-        return 0;
-    }
-
-    int package_id(const AssetManager& am)
-    {
-        return (am.getResources().getBasePackageId(0)) << 24;
-    }
-
-    int parse_idmap_header(const IdmapBuffer& buf, AssetManager& am)
-    {
-        uint32_t i, o, e;
-        char path[PATH_LENGTH];
-
-        NEXT(buf, i, o);
-        if (i != IDMAP_MAGIC) {
-            printe("not an idmap file: actual magic constant 0x%08x does not match expected magic "
-                    "constant 0x%08x\n", i, IDMAP_MAGIC);
-            return -1;
-        }
-        print_header();
-        print("IDMAP HEADER", "magic", i, o, "");
-
-        NEXT(buf, i, o);
-        print("", "base crc", i, o, "");
-
-        NEXT(buf, i, o);
-        print("", "overlay crc", i, o, "");
-
-        if (buf.nextPath(path, &o, &e) < 0) {
-            // printe done from IdmapBuffer::nextPath
-            return -1;
-        }
-        print_path("", "base path", o, e, "%s", path);
-        if (!am.addAssetPath(String8(path), NULL)) {
-            printe("failed to add '%s' as asset path\n", path);
-            return -1;
-        }
-
-        if (buf.nextPath(path, &o, &e) < 0) {
-            // printe done from IdmapBuffer::nextPath
-            return -1;
-        }
-        print_path("", "overlay path", o, e, "%s", path);
-
-        return 0;
-    }
-
-    int parse_data_header(const IdmapBuffer& buf, const AssetManager& am, Vector<uint32_t>& types)
-    {
-        uint32_t i, o;
-        const uint32_t numeric_package = package_id(am);
-
-        NEXT(buf, i, o);
-        print("DATA HEADER", "types count", i, o, "");
-        const uint32_t N = i;
-
-        for (uint32_t j = 0; j < N; ++j) {
-            NEXT(buf, i, o);
-            if (i == 0) {
-                print("", "padding", i, o, "");
-            } else {
-                String8 type;
-                const uint32_t numeric_type = (j + 1) << 16;
-                const uint32_t res_id = numeric_package | numeric_type;
-                if (resource_metadata(am, res_id, NULL, &type, NULL) < 0) {
-                    // printe done from resource_metadata
-                    return -1;
-                }
-                print("", "type offset", i, o, "absolute offset 0x%02x, %s",
-                        i + IDMAP_HEADER_SIZE, type.string());
-                types.add(numeric_type);
-            }
-        }
-
-        return 0;
-    }
-
-    int parse_data_block(const IdmapBuffer& buf, const AssetManager& am, size_t numeric_type)
-    {
-        uint32_t i, o, n, id_offset;
-        const uint32_t numeric_package = package_id(am);
-
-        NEXT(buf, i, o);
-        print("DATA BLOCK", "entry count", i, o, "");
-        n = i;
-
-        NEXT(buf, i, o);
-        print("", "entry offset", i, o, "");
-        id_offset = i;
-
-        for ( ; n > 0; --n) {
-            String8 type, name;
-
-            NEXT(buf, i, o);
-            if (i == 0) {
-                print("", "padding", i, o, "");
-            } else {
-                uint32_t res_id = numeric_package | numeric_type | id_offset;
-                if (resource_metadata(am, res_id, NULL, &type, &name) < 0) {
-                    // printe done from resource_metadata
-                    return -1;
-                }
-                print("", "entry", i, o, "%s/%s", type.string(), name.string());
-            }
-            ++id_offset;
-        }
-
-        return 0;
-    }
-}
-
-int idmap_inspect(const char *idmap_path)
-{
-    IdmapBuffer buf;
-    if (buf.init(idmap_path) < 0) {
-        // printe done from IdmapBuffer::init
-        return EXIT_FAILURE;
-    }
-    AssetManager am;
-    if (parse_idmap_header(buf, am) < 0) {
-        // printe done from parse_idmap_header
-        return EXIT_FAILURE;
-    }
-    Vector<uint32_t> types;
-    if (parse_data_header(buf, am, types) < 0) {
-        // printe done from parse_data_header
-        return EXIT_FAILURE;
-    }
-    const size_t N = types.size();
-    for (size_t i = 0; i < N; ++i) {
-        if (parse_data_block(buf, am, types.itemAt(i)) < 0) {
-            // printe done from parse_data_block
-            return EXIT_FAILURE;
-        }
-    }
-    return EXIT_SUCCESS;
-}
diff --git a/cmds/idmap/scan.cpp b/cmds/idmap/scan.cpp
deleted file mode 100644
index c5fc941..0000000
--- a/cmds/idmap/scan.cpp
+++ /dev/null
@@ -1,244 +0,0 @@
-#include "idmap.h"
-
-#include <UniquePtr.h>
-#include <androidfw/ResourceTypes.h>
-#include <androidfw/StreamingZipInflater.h>
-#include <androidfw/ZipFileRO.h>
-#include <private/android_filesystem_config.h> // for AID_SYSTEM
-#include <utils/SortedVector.h>
-#include <utils/String16.h>
-#include <utils/String8.h>
-
-#include <dirent.h>
-
-#define NO_OVERLAY_TAG (-1000)
-
-using namespace android;
-
-namespace {
-    struct Overlay {
-        Overlay() {}
-        Overlay(const String8& a, const String8& i, int p) :
-            apk_path(a), idmap_path(i), priority(p) {}
-
-        bool operator<(Overlay const& rhs) const
-        {
-            // Note: order is reversed by design
-            return rhs.priority < priority;
-        }
-
-        String8 apk_path;
-        String8 idmap_path;
-        int priority;
-    };
-
-    bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector)
-    {
-        FILE* fout = fopen(filename, "w");
-        if (fout == NULL) {
-            return false;
-        }
-
-        for (size_t i = 0; i < overlayVector.size(); ++i) {
-            const Overlay& overlay = overlayVector[i];
-            fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string());
-        }
-
-        fclose(fout);
-
-        // Make file world readable since Zygote (running as root) will read
-        // it when creating the initial AssetManger object
-        const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; // 0644
-        if (chmod(filename, mode) == -1) {
-            unlink(filename);
-            return false;
-        }
-
-        return true;
-    }
-
-    String8 flatten_path(const char *path)
-    {
-        String16 tmp(path);
-        tmp.replaceAll('/', '@');
-        return String8(tmp);
-    }
-
-    int mkdir_p(const String8& path, uid_t uid, gid_t gid)
-    {
-        static const mode_t mode =
-            S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH;
-        struct stat st;
-
-        if (stat(path.string(), &st) == 0) {
-            return 0;
-        }
-        if (mkdir_p(path.getPathDir(), uid, gid) < 0) {
-            return -1;
-        }
-        if (mkdir(path.string(), 0755) != 0) {
-            return -1;
-        }
-        if (chown(path.string(), uid, gid) == -1) {
-            return -1;
-        }
-        if (chmod(path.string(), mode) == -1) {
-            return -1;
-        }
-        return 0;
-    }
-
-    int parse_overlay_tag(const ResXMLTree& parser, const char *target_package_name)
-    {
-        const size_t N = parser.getAttributeCount();
-        String16 target;
-        int priority = -1;
-        for (size_t i = 0; i < N; ++i) {
-            size_t len;
-            String16 key(parser.getAttributeName(i, &len));
-            if (key == String16("targetPackage")) {
-                const uint16_t *p = parser.getAttributeStringValue(i, &len);
-                if (p) {
-                    target = String16(p, len);
-                }
-            } else if (key == String16("priority")) {
-                Res_value v;
-                if (parser.getAttributeValue(i, &v) == sizeof(Res_value)) {
-                    priority = v.data;
-                    if (priority < 0 || priority > 9999) {
-                        return -1;
-                    }
-                }
-            }
-        }
-        if (target == String16(target_package_name)) {
-            return priority;
-        }
-        return NO_OVERLAY_TAG;
-    }
-
-    int parse_manifest(const void *data, size_t size, const char *target_package_name)
-    {
-        ResXMLTree parser(data, size);
-        if (parser.getError() != NO_ERROR) {
-            ALOGD("%s failed to init xml parser, error=0x%08x\n", __FUNCTION__, parser.getError());
-            return -1;
-        }
-
-        ResXMLParser::event_code_t type;
-        do {
-            type = parser.next();
-            if (type == ResXMLParser::START_TAG) {
-                size_t len;
-                String16 tag(parser.getElementName(&len));
-                if (tag == String16("overlay")) {
-                    return parse_overlay_tag(parser, target_package_name);
-                }
-            }
-        } while (type != ResXMLParser::BAD_DOCUMENT && type != ResXMLParser::END_DOCUMENT);
-
-        return NO_OVERLAY_TAG;
-    }
-
-    int parse_apk(const char *path, const char *target_package_name)
-    {
-        UniquePtr<ZipFileRO> zip(ZipFileRO::open(path));
-        if (zip.get() == NULL) {
-            ALOGW("%s: failed to open zip %s\n", __FUNCTION__, path);
-            return -1;
-        }
-        ZipEntryRO entry;
-        if ((entry = zip->findEntryByName("AndroidManifest.xml")) == NULL) {
-            ALOGW("%s: failed to find entry AndroidManifest.xml\n", __FUNCTION__);
-            return -1;
-        }
-        size_t uncompLen = 0;
-        int method;
-        if (!zip->getEntryInfo(entry, &method, &uncompLen, NULL, NULL, NULL, NULL)) {
-            ALOGW("%s: failed to read entry info\n", __FUNCTION__);
-            return -1;
-        }
-        if (method != ZipFileRO::kCompressDeflated) {
-            ALOGW("%s: cannot handle zip compression method %d\n", __FUNCTION__, method);
-            return -1;
-        }
-        FileMap *dataMap = zip->createEntryFileMap(entry);
-        if (!dataMap) {
-            ALOGW("%s: failed to create FileMap\n", __FUNCTION__);
-            return -1;
-        }
-        char *buf = new char[uncompLen];
-        if (NULL == buf) {
-            ALOGW("%s: failed to allocate %d byte\n", __FUNCTION__, uncompLen);
-            dataMap->release();
-            return -1;
-        }
-        StreamingZipInflater inflater(dataMap, uncompLen);
-        if (inflater.read(buf, uncompLen) < 0) {
-            ALOGW("%s: failed to inflate %d byte\n", __FUNCTION__, uncompLen);
-            delete[] buf;
-            dataMap->release();
-            return -1;
-        }
-
-        int priority = parse_manifest(buf, uncompLen, target_package_name);
-        delete[] buf;
-        dataMap->release();
-        return priority;
-    }
-}
-
-int idmap_scan(const char *overlay_dir, const char *target_package_name,
-        const char *target_apk_path, const char *idmap_dir)
-{
-    String8 filename = String8(idmap_dir);
-    filename.appendPath("overlays.list");
-    if (unlink(filename.string()) != 0 && errno != ENOENT) {
-        return EXIT_FAILURE;
-    }
-
-    DIR *dir = opendir(overlay_dir);
-    if (dir == NULL) {
-        return EXIT_FAILURE;
-    }
-
-    SortedVector<Overlay> overlayVector;
-    struct dirent *dirent;
-    while ((dirent = readdir(dir)) != NULL) {
-        struct stat st;
-        char overlay_apk_path[PATH_MAX + 1];
-        snprintf(overlay_apk_path, PATH_MAX, "%s/%s", overlay_dir, dirent->d_name);
-        if (stat(overlay_apk_path, &st) < 0) {
-            continue;
-        }
-        if (!S_ISREG(st.st_mode)) {
-            continue;
-        }
-
-        int priority = parse_apk(overlay_apk_path, target_package_name);
-        if (priority < 0) {
-            continue;
-        }
-
-        String8 idmap_path(idmap_dir);
-        idmap_path.appendPath(flatten_path(overlay_apk_path + 1));
-        idmap_path.append("@idmap");
-
-        if (idmap_create_path(target_apk_path, overlay_apk_path, idmap_path.string()) != 0) {
-            ALOGE("error: failed to create idmap for target=%s overlay=%s idmap=%s\n",
-                    target_apk_path, overlay_apk_path, idmap_path.string());
-            continue;
-        }
-
-        Overlay overlay(String8(overlay_apk_path), idmap_path, priority);
-        overlayVector.add(overlay);
-    }
-
-    closedir(dir);
-
-    if (!writePackagesList(filename.string(), overlayVector)) {
-        return EXIT_FAILURE;
-    }
-
-    return EXIT_SUCCESS;
-}
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index e4f63e2..ef063e7 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -91,7 +91,7 @@
         return -1;
     }
 
-    if (selinux_android_setfilecon2(pkgdir, pkgname, seinfo, uid) < 0) {
+    if (selinux_android_setfilecon(pkgdir, pkgname, seinfo, uid) < 0) {
         ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
         unlink(libsymlink);
         unlink(pkgdir);
@@ -245,7 +245,7 @@
         return -1;
     }
 
-    if (selinux_android_setfilecon2(pkgdir, pkgname, seinfo, uid) < 0) {
+    if (selinux_android_setfilecon(pkgdir, pkgname, seinfo, uid) < 0) {
         ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
         unlink(libsymlink);
         unlink(pkgdir);
diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c
index 9c66f2d..549aaab 100644
--- a/cmds/installd/installd.c
+++ b/cmds/installd/installd.c
@@ -398,7 +398,7 @@
             goto fail;
         }
 
-        if (selinux_android_restorecon(android_media_dir.path)) {
+        if (selinux_android_restorecon(android_media_dir.path, 0)) {
             goto fail;
         }
 
diff --git a/include/gui/ISurfaceComposer.h b/include/gui/ISurfaceComposer.h
index 5c3c99c..35dcd4e 100644
--- a/include/gui/ISurfaceComposer.h
+++ b/include/gui/ISurfaceComposer.h
@@ -120,7 +120,8 @@
     virtual status_t captureScreen(const sp<IBinder>& display,
             const sp<IGraphicBufferProducer>& producer,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ) = 0;
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform) = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index e982bcd..350b987 100644
--- a/include/gui/SurfaceComposerClient.h
+++ b/include/gui/SurfaceComposerClient.h
@@ -164,7 +164,8 @@
             const sp<IBinder>& display,
             const sp<IGraphicBufferProducer>& producer,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ);
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform);
 
 private:
     mutable sp<CpuConsumer> mCpuConsumer;
@@ -177,12 +178,14 @@
     ~ScreenshotClient();
 
     // frees the previous screenshot and capture a new one
-    status_t update(const sp<IBinder>& display);
-    status_t update(const sp<IBinder>& display,
-            uint32_t reqWidth, uint32_t reqHeight);
+    status_t update(const sp<IBinder>& display, bool useIdentityTransform);
     status_t update(const sp<IBinder>& display,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ);
+            bool useIdentityTransform);
+    status_t update(const sp<IBinder>& display,
+            uint32_t reqWidth, uint32_t reqHeight,
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform);
 
     sp<CpuConsumer> getCpuConsumer() const;
 
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 3791ad5..870071d 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -35,6 +35,7 @@
 
 #include <private/binder/binder_module.h>
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -1382,6 +1383,7 @@
 void Parcel::ipcSetDataReference(const uint8_t* data, size_t dataSize,
     const binder_size_t* objects, size_t objectsCount, release_func relFunc, void* relCookie)
 {
+    binder_size_t minOffset = 0;
     freeDataNoInit();
     mError = NO_ERROR;
     mData = const_cast<uint8_t*>(data);
@@ -1394,6 +1396,16 @@
     mNextObjectHint = 0;
     mOwner = relFunc;
     mOwnerCookie = relCookie;
+    for (size_t i = 0; i < mObjectsSize; i++) {
+        binder_size_t offset = mObjects[i];
+        if (offset < minOffset) {
+            ALOGE("%s: bad object offset %"PRIu64" < %"PRIu64"\n",
+                  __func__, (uint64_t)offset, (uint64_t)minOffset);
+            mObjectsSize = 0;
+            break;
+        }
+        minOffset = offset + sizeof(flat_binder_object);
+    }
     scanForFds();
 }
 
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index aab0604..e96cc54 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -105,7 +105,8 @@
     virtual status_t captureScreen(const sp<IBinder>& display,
             const sp<IGraphicBufferProducer>& producer,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ)
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform)
     {
         Parcel data, reply;
         data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -115,6 +116,7 @@
         data.writeInt32(reqHeight);
         data.writeInt32(minLayerZ);
         data.writeInt32(maxLayerZ);
+        data.writeInt32(static_cast<int32_t>(useIdentityTransform));
         remote()->transact(BnSurfaceComposer::CAPTURE_SCREEN, data, &reply);
         return reply.readInt32();
     }
@@ -285,8 +287,11 @@
             uint32_t reqHeight = data.readInt32();
             uint32_t minLayerZ = data.readInt32();
             uint32_t maxLayerZ = data.readInt32();
+            bool useIdentityTransform = static_cast<bool>(data.readInt32());
+
             status_t res = captureScreen(display, producer,
-                    reqWidth, reqHeight, minLayerZ, maxLayerZ);
+                    reqWidth, reqHeight, minLayerZ, maxLayerZ,
+                    useIdentityTransform);
             reply->writeInt32(res);
             return NO_ERROR;
         }
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 2246f5f..5fe99e8 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -628,11 +628,11 @@
         const sp<IBinder>& display,
         const sp<IGraphicBufferProducer>& producer,
         uint32_t reqWidth, uint32_t reqHeight,
-        uint32_t minLayerZ, uint32_t maxLayerZ) {
+        uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) {
     sp<ISurfaceComposer> s(ComposerService::getComposerService());
     if (s == NULL) return NO_INIT;
     return s->captureScreen(display, producer,
-            reqWidth, reqHeight, minLayerZ, maxLayerZ);
+            reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
 }
 
 ScreenshotClient::ScreenshotClient()
@@ -655,7 +655,8 @@
 
 status_t ScreenshotClient::update(const sp<IBinder>& display,
         uint32_t reqWidth, uint32_t reqHeight,
-        uint32_t minLayerZ, uint32_t maxLayerZ) {
+        uint32_t minLayerZ, uint32_t maxLayerZ,
+        bool useIdentityTransform) {
     sp<ISurfaceComposer> s(ComposerService::getComposerService());
     if (s == NULL) return NO_INIT;
     sp<CpuConsumer> cpuConsumer = getCpuConsumer();
@@ -667,7 +668,7 @@
     }
 
     status_t err = s->captureScreen(display, mBufferQueue,
-            reqWidth, reqHeight, minLayerZ, maxLayerZ);
+            reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
 
     if (err == NO_ERROR) {
         err = mCpuConsumer->lockNextBuffer(&mBuffer);
@@ -678,13 +679,16 @@
     return err;
 }
 
-status_t ScreenshotClient::update(const sp<IBinder>& display) {
-    return ScreenshotClient::update(display, 0, 0, 0, -1UL);
+status_t ScreenshotClient::update(const sp<IBinder>& display,
+        bool useIdentityTransform) {
+    return ScreenshotClient::update(display, 0, 0, 0, -1UL,
+            useIdentityTransform);
 }
 
 status_t ScreenshotClient::update(const sp<IBinder>& display,
-        uint32_t reqWidth, uint32_t reqHeight) {
-    return ScreenshotClient::update(display, reqWidth, reqHeight, 0, -1UL);
+        uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) {
+    return ScreenshotClient::update(display, reqWidth, reqHeight, 0, -1UL,
+            useIdentityTransform);
 }
 
 void ScreenshotClient::release() {
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
index 95a8ef2..32bc5d9 100644
--- a/opengl/libagl/Android.mk
+++ b/opengl/libagl/Android.mk
@@ -29,17 +29,13 @@
 LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils liblog libpixelflinger libETC1 libui
 LOCAL_LDLIBS := -lpthread -ldl
 
-ifeq ($(TARGET_ARCH),arm)
-	LOCAL_SRC_FILES += fixed_asm.S iterators.S
-	LOCAL_CFLAGS += -fstrict-aliasing
-endif
+LOCAL_SRC_FILES_arm += fixed_asm.S iterators.S
+LOCAL_CFLAGS_arm += -fstrict-aliasing
 
-ifeq ($(TARGET_ARCH),mips)
-    LOCAL_SRC_FILES += arch-$(TARGET_ARCH)/fixed_asm.S
-    LOCAL_CFLAGS += -fstrict-aliasing
-    # The graphics code can generate division by zero
-    LOCAL_CFLAGS += -mno-check-zero-division
-endif
+LOCAL_SRC_FILES_mips += arch-mips/fixed_asm.S
+LOCAL_CFLAGS_mips += -fstrict-aliasing
+# The graphics code can generate division by zero
+LOCAL_CFLAGS_mips += -mno-check-zero-division
 
 # we need to access the private Bionic header <bionic_tls.h>
 LOCAL_C_INCLUDES += bionic/libc/private
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 02914a0..e528831 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -187,8 +187,13 @@
 
     LOG_ALWAYS_FATAL_IF(!hnd, "couldn't find an OpenGL ES implementation");
 
+#if defined(__LP64__)
+    cnx->libGles2 = load_wrapper("/system/lib64/libGLESv2.so");
+    cnx->libGles1 = load_wrapper("/system/lib64/libGLESv1_CM.so");
+#else
     cnx->libGles2 = load_wrapper("/system/lib/libGLESv2.so");
     cnx->libGles1 = load_wrapper("/system/lib/libGLESv1_CM.so");
+#endif
     LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
             "couldn't load system OpenGL ES wrapper libraries");
 
@@ -268,8 +273,13 @@
             String8 pattern;
             pattern.appendFormat("lib%s", kind);
             const char* const searchPaths[] = {
+#if defined(__LP64__)
+                    "/vendor/lib64/egl",
+                    "/system/lib64/egl"
+#else
                     "/vendor/lib/egl",
                     "/system/lib/egl"
+#endif
             };
 
             // first, we search for the exact name of the GLES userspace
@@ -310,7 +320,11 @@
             if (checkGlesEmulationStatus() == 0) {
                 ALOGD("Emulator without GPU support detected. "
                       "Fallback to software renderer.");
+#if defined(__LP64__)
+                result.setTo("/system/lib64/egl/libGLES_android.so");
+#else
                 result.setTo("/system/lib/egl/libGLES_android.so");
+#endif
                 return true;
             }
 
diff --git a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp
index 0cfd886..0b6bf58 100644
--- a/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp
+++ b/opengl/tools/glgen/stubs/egl/eglCreateWindowSurface.cpp
@@ -116,7 +116,7 @@
     if (producer == NULL)
         goto not_valid_surface;
 
-    window = new android::Surface(producer);
+    window = new android::Surface(producer, true);
 
     if (window == NULL)
         goto not_valid_surface;
diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java
index bad2137..d66200f 100644
--- a/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java
+++ b/opengl/tools/glgen/stubs/gles11/glGetActiveAttrib.java
@@ -16,6 +16,7 @@
 
     // C function void glGetActiveAttrib ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
 
+    /** @hide Method is broken, but used to be public (b/6006380) */
     public static native void glGetActiveAttrib(
         int program,
         int index,
diff --git a/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java
index 28aaa78..8c8d5a2 100644
--- a/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java
+++ b/opengl/tools/glgen/stubs/gles11/glGetActiveUniform.java
@@ -16,6 +16,7 @@
 
     // C function void glGetActiveUniform ( GLuint program, GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, char *name )
 
+    /** @hide Method is broken, but used to be public (b/6006380) */
     public static native void glGetActiveUniform(
         int program,
         int index,
diff --git a/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java
index 199d93a..afbaaca 100644
--- a/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java
+++ b/opengl/tools/glgen/stubs/gles11/glGetShaderSource.java
@@ -11,6 +11,7 @@
 
     // C function void glGetShaderSource ( GLuint shader, GLsizei bufsize, GLsizei *length, char *source )
 
+    /** @hide Method is broken, but used to be public (b/6006380) */
     public static native void glGetShaderSource(
         int shader,
         int bufsize,
diff --git a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp
index cc10336..4743038 100644
--- a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp
+++ b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp
@@ -182,7 +182,7 @@
             if (array) {
                 releasePointer(_env, array, buf, 0);
             }
-            buf = buf + offset;
+            buf = (char*)buf + offset;
         } else {
             jniThrowException(_env, "java/lang/IllegalArgumentException",
                               "Must use a native order direct Buffer");
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index e5ecf07..d7bbf5c 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -194,6 +194,8 @@
         eglSetSwapRectangleANDROID(dpy, surface,
                 b.left, b.top, b.width(), b.height());
     }
+#else
+    (void) dirty; // Eliminate unused parameter warning
 #endif
 
     mPageFlipCount++;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index fcc9d78..465d376 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -145,7 +145,7 @@
 // callbacks
 // ---------------------------------------------------------------------------
 
-void Layer::onLayerDisplayed(const sp<const DisplayDevice>& hw,
+void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */,
         HWComposer::HWCLayerInterface* layer) {
     if (layer) {
         layer->onDisplayed();
@@ -418,7 +418,7 @@
     layer.setBuffer(mActiveBuffer);
 }
 
-void Layer::setAcquireFence(const sp<const DisplayDevice>& hw,
+void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */,
         HWComposer::HWCLayerInterface& layer) {
     int fenceFd = -1;
 
@@ -442,14 +442,20 @@
 // ---------------------------------------------------------------------------
 
 void Layer::draw(const sp<const DisplayDevice>& hw, const Region& clip) const {
-    onDraw(hw, clip);
+    onDraw(hw, clip, false);
 }
 
-void Layer::draw(const sp<const DisplayDevice>& hw) {
-    onDraw( hw, Region(hw->bounds()) );
+void Layer::draw(const sp<const DisplayDevice>& hw,
+        bool useIdentityTransform) const {
+    onDraw(hw, Region(hw->bounds()), useIdentityTransform);
 }
 
-void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
+void Layer::draw(const sp<const DisplayDevice>& hw) const {
+    onDraw(hw, Region(hw->bounds()), false);
+}
+
+void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
+        bool useIdentityTransform) const
 {
     ATRACE_CALL();
 
@@ -540,16 +546,17 @@
     } else {
         engine.setupLayerBlackedOut();
     }
-    drawWithOpenGL(hw, clip);
+    drawWithOpenGL(hw, clip, useIdentityTransform);
     engine.disableTexturing();
 }
 
 
-void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
-        float red, float green, float blue, float alpha) const
+void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw,
+        const Region& /* clip */, float red, float green, float blue,
+        float alpha) const
 {
     RenderEngine& engine(mFlinger->getRenderEngine());
-    computeGeometry(hw, mMesh);
+    computeGeometry(hw, mMesh, false);
     engine.setupFillWithColor(red, green, blue, alpha);
     engine.drawMesh(mMesh);
 }
@@ -559,12 +566,12 @@
     clearWithOpenGL(hw, clip, 0,0,0,0);
 }
 
-void Layer::drawWithOpenGL(
-        const sp<const DisplayDevice>& hw, const Region& clip) const {
+void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw,
+        const Region& /* clip */, bool useIdentityTransform) const {
     const uint32_t fbHeight = hw->getHeight();
     const State& s(getDrawingState());
 
-    computeGeometry(hw, mMesh);
+    computeGeometry(hw, mMesh, useIdentityTransform);
 
     /*
      * NOTE: the way we compute the texture coordinates here produces
@@ -634,10 +641,12 @@
 // local state
 // ----------------------------------------------------------------------------
 
-void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh) const
+void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh,
+        bool useIdentityTransform) const
 {
     const Layer::State& s(getDrawingState());
-    const Transform tr(hw->getTransform() * s.transform);
+    const Transform tr(useIdentityTransform ?
+            hw->getTransform() : hw->getTransform() * s.transform);
     const uint32_t hw_h = hw->getHeight();
     Rect win(s.active.w, s.active.h);
     if (!s.active.crop.isEmpty()) {
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index ea65ded..9283eaa 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -135,7 +135,8 @@
     uint32_t getTransactionFlags(uint32_t flags);
     uint32_t setTransactionFlags(uint32_t flags);
 
-    void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh) const;
+    void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh,
+            bool useIdentityTransform) const;
     Rect computeBounds() const;
 
     sp<IBinder> getHandle();
@@ -182,7 +183,8 @@
     /*
      * onDraw - draws the surface.
      */
-    virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const;
+    virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
+            bool useIdentityTransform) const;
 
 public:
     // -----------------------------------------------------------------------
@@ -216,7 +218,8 @@
      * and calls onDraw().
      */
     void draw(const sp<const DisplayDevice>& hw, const Region& clip) const;
-    void draw(const sp<const DisplayDevice>& hw);
+    void draw(const sp<const DisplayDevice>& hw, bool useIdentityTransform) const;
+    void draw(const sp<const DisplayDevice>& hw) const;
 
     /*
      * doTransaction - process the transaction. This is a good place to figure
@@ -326,7 +329,8 @@
     // drawing
     void clearWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
             float r, float g, float b, float alpha) const;
-    void drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip) const;
+    void drawWithOpenGL(const sp<const DisplayDevice>& hw, const Region& clip,
+            bool useIdentityTransform) const;
 
 
     // -----------------------------------------------------------------------
diff --git a/services/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp
index 4e82bab..14aa328 100644
--- a/services/surfaceflinger/LayerDim.cpp
+++ b/services/surfaceflinger/LayerDim.cpp
@@ -39,12 +39,13 @@
 LayerDim::~LayerDim() {
 }
 
-void LayerDim::onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const
+void LayerDim::onDraw(const sp<const DisplayDevice>& hw,
+        const Region& /* clip */, bool useIdentityTransform) const
 {
     const State& s(getDrawingState());
     if (s.alpha>0) {
         Mesh mesh(Mesh::TRIANGLE_FAN, 4, 2);
-        computeGeometry(hw, mesh);
+        computeGeometry(hw, mesh, useIdentityTransform);
         RenderEngine& engine(mFlinger->getRenderEngine());
         engine.setupDimLayerBlending(s.alpha);
         engine.drawMesh(mesh);
diff --git a/services/surfaceflinger/LayerDim.h b/services/surfaceflinger/LayerDim.h
index 6561d7f..4de0ddc 100644
--- a/services/surfaceflinger/LayerDim.h
+++ b/services/surfaceflinger/LayerDim.h
@@ -34,7 +34,8 @@
         virtual ~LayerDim();
 
     virtual const char* getTypeId() const { return "LayerDim"; }
-    virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const;
+    virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
+            bool useIdentityTransform) const;
     virtual bool isOpaque() const         { return false; }
     virtual bool isSecure() const         { return false; }
     virtual bool isFixedSize() const      { return true; }
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 9f687e2..808fa1b 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -190,7 +190,7 @@
     eglTerminate(display);
 }
 
-void SurfaceFlinger::binderDied(const wp<IBinder>& who)
+void SurfaceFlinger::binderDied(const wp<IBinder>& /* who */)
 {
     // the window manager died on us. prepare its eulogy.
 
@@ -593,12 +593,12 @@
 }
 
 status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
-        nsecs_t reltime, uint32_t flags) {
+        nsecs_t reltime, uint32_t /* flags */) {
     return mEventQueue.postMessage(msg, reltime);
 }
 
 status_t SurfaceFlinger::postMessageSync(const sp<MessageBase>& msg,
-        nsecs_t reltime, uint32_t flags) {
+        nsecs_t reltime, uint32_t /* flags */) {
     status_t res = mEventQueue.postMessage(msg, reltime);
     if (res == NO_ERROR) {
         msg->wait();
@@ -1710,7 +1710,7 @@
     return status_t(index);
 }
 
-uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags) {
+uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t /* flags */) {
     return android_atomic_release_load(&mTransactionFlags);
 }
 
@@ -2220,8 +2220,8 @@
     return NO_ERROR;
 }
 
-void SurfaceFlinger::listLayersLocked(const Vector<String16>& args, size_t& index,
-        String8& result) const
+void SurfaceFlinger::listLayersLocked(const Vector<String16>& /* args */,
+        size_t& /* index */, String8& result) const
 {
     const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
     const size_t count = currentLayers.size();
@@ -2259,7 +2259,7 @@
 }
 
 void SurfaceFlinger::clearStatsLocked(const Vector<String16>& args, size_t& index,
-        String8& result)
+        String8& /* result */)
 {
     String8 name;
     if (index < args.size()) {
@@ -2664,7 +2664,7 @@
      * data and reply Parcel and forward them to the calling thread.
      */
     virtual status_t transact(uint32_t code,
-            const Parcel& data, Parcel* reply, uint32_t flags) {
+            const Parcel& data, Parcel* reply, uint32_t /* flags */) {
         this->code = code;
         this->data = &data;
         this->reply = reply;
@@ -2718,7 +2718,8 @@
 status_t SurfaceFlinger::captureScreen(const sp<IBinder>& display,
         const sp<IGraphicBufferProducer>& producer,
         uint32_t reqWidth, uint32_t reqHeight,
-        uint32_t minLayerZ, uint32_t maxLayerZ) {
+        uint32_t minLayerZ, uint32_t maxLayerZ,
+        bool useIdentityTransform) {
 
     if (CC_UNLIKELY(display == 0))
         return BAD_VALUE;
@@ -2744,16 +2745,19 @@
         sp<IGraphicBufferProducer> producer;
         uint32_t reqWidth, reqHeight;
         uint32_t minLayerZ,maxLayerZ;
+        bool useIdentityTransform;
         status_t result;
     public:
         MessageCaptureScreen(SurfaceFlinger* flinger,
                 const sp<IBinder>& display,
                 const sp<IGraphicBufferProducer>& producer,
                 uint32_t reqWidth, uint32_t reqHeight,
-                uint32_t minLayerZ, uint32_t maxLayerZ)
+                uint32_t minLayerZ, uint32_t maxLayerZ,
+                bool useIdentityTransform)
             : flinger(flinger), display(display), producer(producer),
               reqWidth(reqWidth), reqHeight(reqHeight),
               minLayerZ(minLayerZ), maxLayerZ(maxLayerZ),
+              useIdentityTransform(useIdentityTransform),
               result(PERMISSION_DENIED)
         {
         }
@@ -2763,8 +2767,9 @@
         virtual bool handler() {
             Mutex::Autolock _l(flinger->mStateLock);
             sp<const DisplayDevice> hw(flinger->getDisplayDevice(display));
-            result = flinger->captureScreenImplLocked(hw,
-                    producer, reqWidth, reqHeight, minLayerZ, maxLayerZ);
+            result = flinger->captureScreenImplLocked(hw, producer,
+                    reqWidth, reqHeight, minLayerZ, maxLayerZ,
+                    useIdentityTransform);
             static_cast<GraphicProducerWrapper*>(producer->asBinder().get())->exit(result);
             return true;
         }
@@ -2786,7 +2791,7 @@
     // which does the marshaling work forwards to our "fake remote" above.
     sp<MessageBase> msg = new MessageCaptureScreen(this,
             display, IGraphicBufferProducer::asInterface( wrapper ),
-            reqWidth, reqHeight, minLayerZ, maxLayerZ);
+            reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform);
 
     status_t res = postMessageAsync(msg);
     if (res == NO_ERROR) {
@@ -2800,7 +2805,7 @@
         const sp<const DisplayDevice>& hw,
         uint32_t reqWidth, uint32_t reqHeight,
         uint32_t minLayerZ, uint32_t maxLayerZ,
-        bool yswap)
+        bool yswap, bool useIdentityTransform)
 {
     ATRACE_CALL();
     RenderEngine& engine(getRenderEngine());
@@ -2829,7 +2834,7 @@
             if (state.z >= minLayerZ && state.z <= maxLayerZ) {
                 if (layer->isVisible()) {
                     if (filtering) layer->setFiltering(true);
-                    layer->draw(hw);
+                    layer->draw(hw, useIdentityTransform);
                     if (filtering) layer->setFiltering(false);
                 }
             }
@@ -2846,7 +2851,8 @@
         const sp<const DisplayDevice>& hw,
         const sp<IGraphicBufferProducer>& producer,
         uint32_t reqWidth, uint32_t reqHeight,
-        uint32_t minLayerZ, uint32_t maxLayerZ)
+        uint32_t minLayerZ, uint32_t maxLayerZ,
+        bool useIdentityTransform)
 {
     ATRACE_CALL();
 
@@ -2900,7 +2906,7 @@
                         // an EGLSurface and therefore we're not
                         // dependent on the context's EGLConfig.
                         renderScreenImplLocked(hw, reqWidth, reqHeight,
-                                minLayerZ, maxLayerZ, true);
+                                minLayerZ, maxLayerZ, true, useIdentityTransform);
 
                         // Create a sync point and wait on it, so we know the buffer is
                         // ready before we pass it along.  We can't trivially call glFlush(),
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 9db0ce1..9230467 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -203,7 +203,8 @@
     virtual status_t captureScreen(const sp<IBinder>& display,
             const sp<IGraphicBufferProducer>& producer,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ);
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform);
     // called when screen needs to turn off
     virtual void blank(const sp<IBinder>& display);
     // called when screen is turning back on
@@ -307,13 +308,14 @@
             const sp<const DisplayDevice>& hw,
             uint32_t reqWidth, uint32_t reqHeight,
             uint32_t minLayerZ, uint32_t maxLayerZ,
-            bool yswap);
+            bool yswap, bool useIdentityTransform);
 
     status_t captureScreenImplLocked(
             const sp<const DisplayDevice>& hw,
             const sp<IGraphicBufferProducer>& producer,
             uint32_t reqWidth, uint32_t reqHeight,
-            uint32_t minLayerZ, uint32_t maxLayerZ);
+            uint32_t minLayerZ, uint32_t maxLayerZ,
+            bool useIdentityTransform);
 
     /* ------------------------------------------------------------------------
      * EGL