New command line tool 'idmap'

Introduce a new tool 'idmap' to handle generation and verification of
idmap files. The tool is modelled on 'dexopt', and is intended to be
used similarly, notably by 'installd'.
See cmds/idmap/idmap.cpp for further documentation on 'idmap'.

Note: this commit is interdependent on a commit in project build/ to add
'idmap' to PRODUCT_PACKAGES.

Note: the changes to androidfw are only stubs. The actual implementation
will be provided in Runtime resource overlay, iteration 2.

Change-Id: I7131b74ece1e46c8a9c0a31d103e686aa07da2bb
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Runtime resource overlay, iteration 2

Support any number of overlay packages. Support any target package.

UPDATED PACKAGE MATCHING
------------------------
In Runtime resource overlay, iteration 1, only a single overlay package
was considered. Package matching was based on file paths:
/vendor/overlay/system/framework-res.apk corresponded to
/system/framework-res.apk. Introduce a more flexible matching scheme
where any package is an overlay package if its manifest includes

    <overlay targetPackage="com.target.package"/>

For security reasons, an overlay package must fulfill certain criteria
to take effect: see below.

THE IDMAP TOOL AND IDMAP FILES
------------------------------
Idmap files are created by the 'idmap' binary; idmap files must be
present when loading packages. For the Android system, Zygote calls
'idmap' as part of the resource pre-loading. For application packages,
'idmap' is invoked via 'installd' during package installation (similar
to 'dexopt').

UPDATED FLOW
------------
The following is an outline of the start-up sequences for the Android
system and Android apps. Steps marked with '+' are introduced by this
commit.

Zygote initialization
   Initial AssetManager object created
+    idmap --scan creates idmaps for overlays targeting 'android', \
           stores list of overlays in /data/resource-cache/overlays.list
   AssetManager caches framework-res.apk
+  AssetManager caches overlay packages listed in overlays.list

Android boot
   New AssetManager's ResTable acquired
     AssetManager re-uses cached framework-res.apk
+    AssetManager re-uses cached 'android' overlays (if any)

App boot
   ActivityThread prepares AssetManager to load app.apk
+  ActivityThread prepares AssetManager to load app overlays (if any)
   New AssetManager's ResTable acquired as per Android boot

SECURITY
--------
Overlay packages are required to be pre-loaded (in /vendor/overlay).
These packages are trusted by definition. A future iteration of runtime
resource overlay may add support for downloaded overlays, which would
likely require target and overlay signatures match for the overlay to
be trusted.

LOOKUP PRIORITY
---------------
During resource lookup, packages are sequentially queried to provide a
best match, given the constraints of the current configuration. If any
package provide a better match than what has been found so far, it
replaces the previous match. The target package is always queried last.

When loading a package with more than one overlay, the order in which
the overlays are added become significant if several packages overlay
the same resource.

Had downloaded overlays been supported, the install time could have been
used to determine the load order. Regardless, for pre-installed
overlays, the install time is randomly determined by the order in which
the Package Manager locates the packages during initial boot. To support
a well-defined order, pre-installed overlay packages are expected to
define an additional 'priority' attribute in their <overlay> tags:

    <overlay targetPackage="com.target.package" priority="1234"/>

Pre-installed overlays are loaded in order of their priority attributes,
sorted in ascending order.

Assigning the same priority to several overlays targeting the same base
package leads to undefined behaviour. It is the responsibility of the
vendor to avoid this.

The following example shows the ResTable and PackageGroups after loading
an application and two overlays. The resource lookup framework will
query the packages in the order C, B, A.

        +------+------+-     -+------+------+
        | 0x01 |      |  ...  |      | 0x7f |
        +------+------+-     -+------+------+
            |                           |
        "android"                Target package A
                                        |
                       Pre-installed overlay B (priority 1)
                                        |
                       Pre-installed overlay C (priority 2)

Change-Id: If49c963149369b1957f7d2303b3dd27f669ed24e
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>

Conflicts:
	cmds/installd/commands.c
	cmds/installd/installd.c
	cmds/installd/installd.h

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
New Theme Engine [2/6] CM11 Themes

See frameworks/base themes commit for full summary.

[SUMMARY]
1. Modifies idmap binary to include target APK in filename. Needed so one theme apk can have multi targets.
2. Allows aapt to be called via installd. Needed to compile resources found in a theme apk's assets folder.

[IDMAP EXAMPLE]
OLD: vendor@overlay@overlay.apk@idmap
NEW: vendor@overlay@overlay.apk@system@app@target.apk@idmap

[CONTRIBUTORS]
Andrew Mast <andy@cyngn.com>
Clark Scheff <clark@cyngn.com>
Special thanks to Mårten Kongstad and the rest of the Sony team for their work in idmap.

Change-Id: I0cb15830109ac36780c015e61348c00ec08d24a1
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>

Conflicts:
	cmds/installd/commands.c
	cmds/installd/installd.c
	cmds/installd/installd.h

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
CM11 Themes: Store hash codes for target and overlay in idmap

Due to some system packages always having the same last modified
time stamp of 08/01/2008 we must use some other unique value to
determine that the contents of either the target or the overlay
have changed.  This unique value will be passed down from the java
layer and written to the idmap header.

This change requires the following patch from frameworks/base
http://review.cyanogenmod.org/62565

Change-Id: I0adcafaca96110268766d6e3349414364ecea4c3
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>

Conflicts:
	cmds/installd/installd.c
	cmds/installd/installd.h

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
CM11 Themes: Pipe stderr from aapt to logcat.

This will allow users to see why aapt failed when installing a
theme.

Change-Id: I74314daae9e844dce2f4c3eeb6c78a40b5ad6357
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
CM11 Themes: Common overlay for sharing resources. [2/2]

Change-Id: Ied21ede2f36ba16dd190bc1e6cec44fd8560ca90
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Themes: Fix -110 install error [1/2]

aapt was being called from PM with a ' ' at the end of the cmd. This would
cause installd to read unexpected parts of memory which sometimes
causes it to parse the command incorrectly.

Change-Id: Id9f1170db05b40f030d6ea5009bed38bc9fc3b5f
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Avoid calling idmap w/ trailing whitespace [2/2]

installd performs a buffer over-read if trailing ws is sent to it.
No observable effect found yet for idmap, but until installd is
fixed upstream, best to play it safe.

Change-Id: I002de7a9d177df16f91b47e7f87af59457c1f421
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>

Conflicts:
	cmds/installd/installd.c

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Move idmap to frameworks/base [1/2]

idmap depends on libandroidfw, so it should go in frameworks/base.
This follows AOSP which moved idmap to frameworks/base back in
February of 2014.

Change-Id: If86df906bddf987fd58e31f947ae78ddd0d2c666
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
frameworks/native: Fix build in ISO C++ 11 mode

Fix constructs that are considered new string literals in C++ 11 mode

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
binder: Fix ABI incompatibility between older and newer compilers

Parcel::writeString16's first parameter was a char16_t - defined to
uint16_t somewhere else.

With ISO C++11 compatible compilers, however, char16_t is a
compiler-defined-type that is not necessarily unsigned.

This causes the symbol to be different, breaking support for talking
to binary blobs built with pre-ISO C++11-compilers, such as the
Galaxy Nexus RIL.

Change-Id: Ibaa57fbd7d9fc4a95649d3b45d28d29963a9548b
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
frameworks/native: Fix build with ISO C++11 compilers

Fix macro definitions so they can't be confused with C++11 string
literals

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
surfaceflinger: Work around aliasing violations

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
surfaceflinger: Don't crash on missing functions in hwcomposers

Some hwcomposers -- most notably hwcomposer.default.so -- don't
implement blank() or eventControl().
Don't crash when trying to use them.

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
frameworks/native: Fix build with ISO C++11 compilers

Fix few more macro definitions so they can't be confused with
C++11 string literals

Change-Id: I8d18acd12341306436cd5037d05eaef1563c1bc8
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Fix some char16_t vs. uint16_t bits

Change-Id: Ie2392098fa6b25f3c0713a7774929e36d824d26f
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>