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
	core/java/android/content/Context.java
	core/java/com/android/internal/os/ZygoteConnection.java
	core/res/AndroidManifest.xml
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
	policy/src/com/android/internal/policy/impl/GlobalActions.java
	services/java/com/android/server/InputMethodManagerService.java
	services/java/com/android/server/SystemServer.java
	tools/aapt/Images.cpp
FWB: Fixes for the themes commit

Change-Id: Idfd5749b1e3605a1a75d4d04ff69b1ab7d74f1e3
Signed-off-by: Lokesh Chamane <lokesh.c703@gmail.com>

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
SysUI: Don't recreate controllers.

The various controllers, such as mLocationController, get recreated
every time the status bar is recreated due to a theme change.  We
should only need to create these if they are null, otherwise use
the controller as is.  Also, each of these controlers registers
themselves as a broadcast receiver and are never unregistered before
recreating them.

Change-Id: I6215aae5a82b7ced8f0f25cf592a804d38825260

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
New theme engine: Remove duplicates and null entries
New theme engine: Missed code bit
Update Tentacles QS tile png
CM11 Themes: Take into account ALL res/xml dirs

Only res/xml was being searched for redirection XML files, which
causes themes that use xml-v14, xml-v19, etc to be overlooked and
resources not being mapped.

Change-Id: I8ccad5770250150a95ec3b89be56f8d01025b126
CM11 Themes: Use 32bit hash to decide if idmap should be created

Using the last modified time of the package to determine if an idmap
should be created is not always valid for system packages.  We have
observed some packages having a time stamp of 08/01/2008 even if the
package has changed.  This causes system packages, such as
frameworks-res.apk to not be properly mapped if IDs changed in this
package.

This patch will generate a 32 bit hash code based on the file's
MD5 sum.  This hash code is then provided to idmap for writing these
values into the idmap header for future comparison.

This patch requires the following change found in frameworks/native
http://review.cyanogenmod.org/62566

Change-Id: Ie9e0273aef96217f06b08774623dd5f1b290a3da
Lockscreen wallpaper for themes

Change-Id: If77b97301c5bfebd94b193fe9a54e676e678d3ed
Revert "Implement "real" KitKat color scheme."

This reverts commit ae104bcea61d7e0468a76fc45f34f47bc3a2e103.

Conflicts:
	core/res/res/values/colors.xml
Revert " Implement "real" KitKat color scheme.  pt2 (forgotten values)"

This reverts commit d1de1f1ba59da4ac72d1a2bb5de11932da5b7918.
Revert "Lockscreen wallpaper for themes"

This reverts commit 88521787023b351420a6f060de8394f837bf7a0d.
Tentacles qs tile: Revamp pngs
Cleanup theme assets when done with them

Before this patch if phone was left on long enough it would reboot
when a theme was applied due to files being left open.

Change-Id: I4c242249fcf6e8097789c3dd6690104296485784
Wipe all the ass(ets)

Change-Id: I75735144b97173e6b60cf47b673740a165fcc185
fb: fix qs battery tile on normal icon due of left over
I forgot to commit a change so on icon and icon percentage there
was still a margin set. Remove the magin to fix it

Change-Id: If8848835d2371b44d3dc414a9f30af03f222a895
Themes: Fix handling of overlay packages in AssetManager

The new theme engine did not handle the fact that a legacy
theme contained one package ID that was being used for both
framework and 3rd party apps.  This caused some issues with
styles not bein properly loaded from legacy themes.  Missing
action bars in some apps was the most noticable side effect
of this problem.  This patch takes this into account without
affecting themes using the new format.

Change-Id: I89b3dbf71db925726b949511a7e34a0d2949deab
FWBase: Audio Themes Support [1/3]

Change-Id: I698acc3e7843dcb38ba545219a21e9bee0b2fbe6
Signed-off-by: STELIX <ssspinni@gmail.com>

Conflicts:
	core/java/android/provider/Settings.java
	media/java/android/media/AudioService.java
Revert "FWBase: Audio Themes Support [1/3]"

This reverts commit b1e12d9f9e2648f11f5106132a376940835e4a95.
Revert "Themes: Fix handling of overlay packages in AssetManager"

This reverts commit 284c178deca22c7dc91a5a148dab13e06c7e89b9.