New Theme Engine [1/6]

[Summary]
Took the T-mobile theme engine, replaced redirection mechanism with a modified Sony idmap and then extended the feature set.

The new theme engine allows the following:
1. Simple creation of themes by compiling on the device
2. System level icon packs.
3. Font packs
4. Swappable boot animations
5. Lockscreen wallpaper
6. Alarms
7  Of course all the things the previous engine could do including skins, ringtones and
notifications. There is also legacy support for old themes.

[Theme Format]
For the time being themes are APKs with all theme elements in the assets folder. Since these resources
are compiled at runtime there is no reason we can't change it to a zip but creating an APK is well
understood by themers.

The directory structure looks like this:

AndroidManifest.xml
src/
res/
assets/
  boot-animation/
  fonts/
  icons/
    res/ (note: same dir structure as res/ in trebuchet icon packs)
  wallpapers/
  ringtones/
  notifications/
  alarms/
  overlays/
      [target-pkg-name1]
          res/
           drawable/
           drawable-hdpi/
           ...
           layouts/
           xml/
      [target-pkg-name2]
          res/

Where [target-pkg-name] is the package of the app you are trying to overlay. For example, to overlay
facebook's app you would make a directory under overlay called "com.facebook.katana". For frameworks
resources use the target name "android".

Under each target pkg is a res/ folder which follows the same format as a typical APK's res/. During
install time AAPT will actually compiling these res/ folders individually.

There are also non-overlay folders like boot-animation, wallpaper, fonts etc.

A theme APK is identified by meta-value data in AndroidManifest.xml. Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.me.andytheme2"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-feature android:name="org.cyanogenmod.theme" />
    <meta-data android:name="org.cyanogenmod.theme.name" android:value="My Blue Theme"/>
    <meta-data android:name="org.cyanogenmod.theme.author" android:value="John Doe" />
</manifest>

By using meta-data we do not require special new tools.

[Changes to PackageManagerService]
During install time PackageManagerService will scan meta-data values in the manifest. If it finds
a meta-data name of "org.cyanogenmod.theme.name" then it will assume the APK is a theme and mark it as such.

Then PM will find all overlays from the theme. For each overlay target it will generate a resource table
and an idmap via Installd. Aapt will also run to compile 9patch and xml files. The new restable, idmap, and compiled resources
are stored under /data/resource-cache

[Changes to aapt]
Aapt has been extended to read zip entries and accept file descriptors to work with installd.

[Changes to frameworks/core]
Most of what TMO has done already here for runtime theme changes is kept so most changes
are simply plumbing to make Sony's overlays work at runtime. Additionally changes were made
to TMO classes to support mix n match better.

[Changes to libandroidfw]
Sony's idmap concept is one overlay apk -> one target apk, but themes support multiple target apks. So
most of the changes here are for support this. Also we support runtime overlay changes so functionality
had to be added to add/remove to the resource table during a configuration change.

[Security]
We run aapt in reduced priveledges via Installd. At the moment however a theme can overlay any resource. This
includes strings and layouts so any malicous theme could cause serious crashes to the device.

[See Also]
frameworks/native
external/skia
build
vendor/tmobile/providers/ThemeManager
vendor/tmobile/libs/com.tmobile.themes

[Contributors]
Andrew Mast <andy@cyngn.com>
Clark Scheff <clark@cyngn.com>
Special thanks to the T-Mobile theme team. This would not be possible without their efforts.
Special thanks to Mårten Kongstad and the rest of the Sony team for their work in idmap.

Change-Id: I812a3757bdb56c429b5870ff922485439ae00f8d

Conflicts:
	core/java/android/app/ContextImpl.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	services/java/com/android/server/SystemServer.java