\Theme Engine [3/8]
Bring new CyanogenMod Theme Engine to Deviant xone. This is a HUGE commits history (100+ commits),
it squashes all cm code about Theme Engine since old tmobile one. As well it inlcudes some changes
required as custom lockscreen wallpaper, keyguard app changes, wallpaper overscroll and transparent
navigation bar features. All commits inside, along with adaptations and fixes for our aosp base, are
listed in the commit message (as well as for new Theme Engine description, code-wise).

Infinite thanks to the CyanogenMod team for bringing us this new engine, kudos! And Thanks to AOSPA for the squashed commit path to follow

CM Credits:
Andrew Mast and Clark Sheff (as lead creators of new Theme Engine)
Roman Birg
Ricardo Cerqueira
Danny Baumann
Andy Prock
Kyrylo Mikos
Danesh M
All T-Mobile guys

PA Contributors:
@BigBrother1984
@beerbong
@linuxman94

------------------------------ HISTORY ------------------------------

[+]
Squashed commit of the theme engine support.

Updated 4.2 support for the old T-Mobile theme engine, as usual
needs the provider and switcher apps installed as well.

I'm finally dropping the 400+ commit history on this, since everybody
else keeps picking it up from CM as a single patch anyway... But
for the record, nothing of this would be possible without Josh, Ed,
and the rest of the TMo guys who wrote and maintained it until 2.2:

amit chabra <amit.chabra@t-mobile.com>
Amit Kohli <amit.kohli@t-mobile.com>
Chris Cogar <chriscogar@t-mobile.com>
Dirk Sigurdson <dirk.sigurdson@t-mobile.com>
Ed Carrigan <edward.carrigan@t-mobile.com>
Gaurav Sharma <gaurav.sharma3@t-mobile.com>
Hui Feng <hui.feng@t-mobile.com>
John Ritz <john.ritz1@t-mobile.com>
Josh Guilfoyle <josh.guilfoyle@t-mobile.com>
Mark Roberts <mark.roberts48@t-mobile.com>
Pankaj Kumar <Pankaj.kumar6@t-mobile.com>
Samuel Cheung <samuel.cheung@t-mobile.com>
Sergey Ten <sergey.ten6@t-mobile.com>

Change-Id: I7148d51be48f28a2dc4bdf9ec9018f04b268ffc4
Signed-off-by: mar5hal <errantzebra845@gmail.com>

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
	policy/src/com/android/internal/policy/impl/GlobalActions.java
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
	services/java/com/android/server/NotificationManagerService.java
	services/java/com/android/server/SystemServer.java
	services/java/com/android/server/am/ActivityManagerService.java
	services/java/com/android/server/pm/PackageManagerService.java
	services/java/com/android/server/wm/WindowManagerService.java

[+]
@hide API change from themes

Change-Id: Ia0798346d2e8e5a84e8456bb89b7d503a71a7afa

Conflicts:
	core/java/android/content/res/Resources.java

[+]
Framework: Remove orphaned Theme related code

Change-Id: I930d4cc75e655c5bc37532e6a1425d27bd1ee661

Conflicts:
	services/java/com/android/server/NotificationManagerService.java

[+]
framework: Allow specifying max wallpaper width

For some devices with very high-res screen (1920x1200), the wallpaper
width suggested by the launcher may be too large for the GPU and so
we need to limit it. (2048 for the above mentioned screen)

We don't need to limit the height since that's the height of the
screen.

Change-Id: I5b25bd931db0b2610e260921f28b92d8b0966aa6

Conflicts:
	core/res/res/values/config.xml

[+]
Check themes of current user, not user 0.

Change-Id: I5d685a04289b434a12e460b4fdacc43a41ff2be1
JIRA:CYAN-1303

[+]
Fix theme provider crashing for non-primary user.

PackageManagerService's context is for user 0, so if the theme provider
for other users was invoking the getInstalledThemePackages() method, the
themes provider crashed as it doesn't have the INTERACT_ACROSS_USERS
permission.
Fix that (and simplify code) by making getInstalledThemePackages()
return the installed themes for the current user, which was probably the
intent anyway.

Change-Id: I02002cee005b74128f3b2f7cc7a93b9b8514f1f3

[+]
AssetRedirectionService: Check for permissions before running dump()

Fix android.security.cts.ServicePermissionsTest failure

Change-Id: I9d629d19f3ff231db477d156c8bf557d4b8ee861

[+]
ThemeUtils: Retain the original package name in themed UI context

In order for themes to reflect on system elements, we're changing
their context, including the package name.

This breaks anything that tries to identify system elements,
most notably any users of the uiautomator. Trying to do
'UiSelector().packageName("android")' to find, for example,
a force-close dialog will fail.

Fixes com.android.cts.uiautomatortest.CtsUiAutomatorTest#testUiWatcher

Change-Id: Ic05c3024b20ac3772ed5597846fbfa4a184ebb0d

[+]
AssetRedirectionManager: Accept redirections only for whitelisted resource types

Change-Id: Idf1ea739a81719b6a196f0114c9fc3b7c7ff428c

[+]
platform: Fix the gid for the theme manager service

It was mismatched with fs_config, resulting in attribution of the
"-1" gid

Change-Id: Ia6d55af0b39f659da2965f9bc0bda0df5c775ba4

[+]
PackageManager: Let system-defined permissions take precedence over settings

If a permission was already present in the device's settings due to having
no prior system definition, and the system tried to take it over
(after a version upgrade, for example), it'd fail, since the saved
value would clobber the one previously read from the permissions XML.

This breaks system-behavior changes (gid grants, in particular) unless
the user performs a factory reset after upgrading, which isn't acceptable.

Change-Id: If2e44110f6db735ad29cdf1086e814bd1299e290

[+]
Fix certain setting writes being incorrectly skipped.

If a value that previously had a very long value (over the 500 char
threshold) is now set to null, isRedundantSetValue would incorrectly
return true even though the value was changed.

Change-Id: Ia5304743024ec01024be98aa51ed260d38caf93c

[+]
AssetAtlas: Fix NPE when there are no preloaded resources

[+]
PackageManager: Let com.tmobile.thememanager access privileged permissions

Needed for CHANGE_CONFIGURATION

Change-Id: If50b0926d77e15e18ef5e88d7efac1b7f209d6e4

[+]
ResourcesManager: Fix theme insertion at boot

This was lost during the 4.4 ActivityThread reshuffle, put it back

Change-Id: I96eadf691973e9a2daa099b55816fc103d129be7

[+]
SystemUI: Reinflate on theme change

Reflect the updated assets immediately once the config_changed
notification happens

Change-Id: I480a719fbdd45875277871af39ce65849918ec0a

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

[+]
PackageManager: Prevent themes from going into ASEC containers

Themes on ASEC cause all kinds of random timing/racey issues at boot
time, and more kinds of racey concurrency issues at uninstall/upgrade
time. Stop them from getting into containers at all.

Change-Id: If08e90c51137b22239831a4eca17ea00d5d87d93

[+]
SystemUI: Allow theming battery via theme chooser

Change-Id: Iebea2dab0ed89baa14c0f18a4c8f487cdb8313a6

[+]
Keyguard: allow keyguard to be dismissed via intent

Requires system permission "android.permission.CONTROL_KEYGUARD"

Change-Id: I9f8f5ca90a65b949d43fac33ce3e9e39ffdf9254
Signed-off-by: Roman Birg <roman@cyngn.com>

[+]
Keyguard: smooth background change.

Change-Id: Ia0e4d0000db72b5cdb6fede03791805e34fa311d

[+]
Frameworks: Lockscreen custom wallpaper (1/2)

kitkat now has code for a custom wallpaper image.

Using that code set a switch case to set the custom background between
  - Custom Wallpaper
  - Default background

This way allows the same overlay shadow thats set on the keyguard when
its the defualt way.

Change-Id: I98fde63ef9f3c0a5f334cd9a97b237a6f99c57f6

Conflicts:
	core/java/android/provider/Settings.java
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java

[+]
Lockscreen: Fix SystemUI crash on initial selection of Custom Background.

Change-Id: I8df4984f4b90d211baa888d380a95fc00a85d1ad

Conflicts:
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java

[+]
Wallpaper Overscroll and Transparent NavBar

Now possible to offset wallpaper windows by more than the size of the wallpaper
and add added a transparent mode to the NavigationBar

Change-Id: I2b0f1129a4cf73b8def35abb7072d0472a9cc972

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

------------------------------ NEW THEME ENGINE  ------------------------------

[+]
Remove T-mobile items not used by new theme engine

Change-Id: I1e9c14e63ec25fdff61cfd2b7b8a05b1e488e558

Conflicts:
	core/jni/AndroidRuntime.cpp
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

[+]
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

[+]
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

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

[+]
Runtime resource overlay, iteration 2, test cases

Add automated test cases for runtime resource overlay, iteration 2.

The test cases are a mixture of 'adb shell' commands and regular
instrumentation tests. The device is rebooted between tests to setup
different overlay scenarios for framework-res.apk.

To verify Runtime resoure overlay, iteration 2, run
    $ frameworks/base/core/tests/overlaytests/testrunner.py

For a list of supported options, run
    $ frameworks/base/core/tests/overlaytests/testrunner.py --help

Change-Id: I692aa1a7ad073efd116b24f9ec7f197dfd65dfef

[+]
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:
	cmds/bootanimation/BootAnimation.cpp
	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
	policy/src/com/android/internal/policy/impl/GlobalActions.java
	services/java/com/android/server/InputMethodManagerService.java
	services/java/com/android/server/SystemServer.java
	services/java/com/android/server/am/ActivityManagerService.java
	services/java/com/android/server/pm/PackageManagerService.java

[+]
Keyguard: more consistency with the new lockscreen wallpaper

* In the case when the screen was off and setCustomDrawable()
was being called, and the use wallpaper is null, then we could be
setting the color filter on a null drawable.

* Fix logic when old custom background was null and the new one is also
null (but could be the user one) and the func was being returned, thus not
clearing out the current media album art.

* Move resetting the shouldShowWallpaper() flag to the show() method
so it is not being called every time the screen is turned on.

* Fix user image not showing up on first boot if it exists

Change-Id: I567c2ec8920df627835defb822c2ea25be7b3cab
Signed-off-by: Roman Birg <roman@cyngn.com>

Conflicts:
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java

[+]
wallpaper: add missing @hides

Add missing @hides to setWallpaperOverscroll and setWallpaperOverscrollOffsets

Change-Id: I1cfe876272d7c0a94bef122567da30318eac9400

[+]
Lockscreen wallpaper for themes

Change-Id: If77b97301c5bfebd94b193fe9a54e676e678d3ed

[+]
Keyguard : Fix album art sticking after playback is stopped

newIsNull should be populated by what is currently being set and not by
what the user's custom background is, since otherwise you end up a in state
where the user has no custom background set, music stops, no album art via arg is provided and you simply return.

Change-Id: Ifaea1cae176faaba6b32a711071f3b75ccacdd63

[+]
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

[+]
revert camera icon disable when Settings.System.LOCKSCREEN_MODLOCK_ENABLED was set to 1

Change-Id: I0f6e318c5da7b526e24f8c0c73102e3d7d826a46

Conflicts:
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java

[+]
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

[+]
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

[+]
Fix segfault removing theme assets

Change-Id: I4827eb6e2b186547f1df6f9bbd048fb1e3a29890

[+]
Style previews [1/3]

Change-Id: Ifed0ef7829eb61492a39395e8140b99f01c5e6a3

[+]
CM11 Themes: Put overlays in their own group.

Overlays will now be added to their own group and the
target group will contain a pointer to the overlay
package to be used in getResource and getBagLocked.

Change-Id: Icc6c6eb791f04966e68dbc099eae8e7129546414

[+]
CM11 Themes: Remove type matching restriction

Change-Id: I5a8ac8ff1794350ff9dc03b378c704bfb97d0a9e

[+]
CM11 Themes: Allow forcing idmap (re)creation.

Change-Id: I9f5938e9b1052da83b7f2cd7b1ff6f1ed270db6b

idmap: Don't log spam "CREATING STRING CACHE"

Change-Id: Idce5aa5881c8e860eca9749cc85f748303c913c0

[+]
CM11 Themes: Use theme name for audible name.

Change-Id: Ib841cb80925b0f3f5ac770e00df04515849e9360

[+]
Allow icons in shared restables to be themed

Example
Google Drive's package  name: com.google.android.apps.docs
Google Drive's restable name: com.google.android.apps.docs.common

Before this patch we used resource table name to get the package info. For
app's like google drive this return a null package info and the icon would not be themed.

So instead of usnig the restable name, this patch creates a package name
in AssetManager that is set by getTopLevelResources.

Change-Id: Ic51b93f6c7ea0a32197682998c6d0aa36d774845

hide new AssetManager methods for themes

Change-Id: I9f5c6a432f9c2f3c1dd5bd9927c5e3fe3ddd1f93

[+]
CM11 Themes: Update lights out resources and extra nav buttons

The ImageViews that hold the lights out dots were not being
updated on a theme change as well as the KeyButtonView with
ID of R.id.one

Change-Id: Ieed5f5ba1d822fe47dad3ec934889bf70eb1a3ad

[+]
CM11 Themes: Adapt NavigationBarView changes to stock navbar

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>

[+]
WallpaperCropper: Fix crash when set .gif as wallpaper

It returns an equivalent scaled cropBounds as true
crop bounds, then it set the rounded rect by rounding
"out" the true crop rect, this make the rounded crop
rect may out range of the original bitmap, then an error
will happen.

We change to check the rounded crop rect, if it is out
the range of original bitmap, we set the original bitmap
bounds as rounded crop bounds.

CRs-Fixed: 622582

Change-Id: I215ef2a0165adaaadb05c62dee741a8ea6926144

[+]
wallpapercropper: OOM issue while opening *.bmp image

This change manages setting of large images as
wallpapers without encountering OOM.

CRs-fixed: 619815
Change-Id: I3a32ec4b42050b146076f0adf6b6e65afd6fae4e

[+]
frameworks: allow Keyguard package to be defined in overlay

This way, custom keyguards can have their own namespace.

Change-Id: Ia2dfa57652c6f3d3404963897fb2f20a265e5c76
Signed-off-by: Roman Birg <roman@cyngn.com>

Conflicts:
	core/java/com/android/internal/util/cm/LockscreenTargetUtils.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java

[+]
frameworks: move keyguard wallpaper to system  (1/2)

Change-Id: I0eb1b5578b705c2ade4c0772fa86e09478b9f73e
Signed-off-by: Roman Birg <roman@cyngn.com>

Conflicts:
	core/java/android/provider/Settings.java
	core/res/res/values/cm_strings.xml
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java

[+]
Return system theme when SecurityException is caught.

Isolated processes cannot access content resolvers so a SecurityException
will be thrown when calling getBootTheme.  This catches that
exception and returns sSystemTheme.

Change-Id: If4077adef4c657b80ba2c52a6610126dabe4ffdf

[+]
CM11 Themes: Common overlay for sharing resources. [1/2]

This patch will allow themes to contain common resources
which can be shared by all overlays.

Common resources will reside in assets/overlays/common and
can be referenced by other overlays.

Common resources will be referenced using the common package
name, i.e. To reference the common drawable some_drawable for
com.example.theme the theme designer would use
"@*common:drawable/some_drawable"

Change-Id: I395b6bd5eae91b00265a8e9221856ef7bf5d115a

[+]
CM11 Themes: Ensure customTheme is not null.

The configuration retrieved via getConfiguration() sometimes contains
a null customTheme which results in the theme returning to holo when
applying a component such as icons.  Icons will change but styles
and fonts would return to the default.

Change-Id: Iac0cb8eed5de8fdc9fe8efd697d968f26e801c08

[+]
CM11 Themes: Include alarms in mixnmatch.

Change-Id: I004f6b0149d71c8ed1a3952704f5a3521eca5add

[+]
CM11 Themes: Properly handle SystemUI theme package name.

Change-Id: Ia8915684e1620184dcc513c2c5039ea20aabbd04

[+]
Set themes to install internal only

Themes should not be moveable to sdcard. Before this patch the new
style themes installed with forward lock would fail.

Change-Id: Iea50f5526b1c2c56a825757eac5bf4bb01b4686d

[+]
rename the custom lockscreen state action

Change-Id: I4ffadda9392e8ca8765e5b8ca47994e3a9990792

[+]
Add wallpaper pickers to seperate package [1/2]

Currently wallpaper pickers were part of the various launchers
and we were relying on Trebuchet's to add code for including
wallpapers from themes.  If Trebuchet is removed then this
functionality is lost.  This package is already included in all
builds so making the picker available here removes the dependency
on a specific launcher.

Trebuchet still contains a picker which should probably be removed
and make use of this package instead.

Change-Id: Ie42ae0e01f951a8293d13d6c8a73fde0dea6682b

[+]
Reduce memory leaks by removing all views.

Change-Id: I1c7d3647ae0d40aa214108ea22e007e3cb3191b9

[+]
CM11 Themes: remove handleThemeConfigChanges

This was used by the T-Mobile theme chooser and is no longer
needed with the new chooser.

Change-Id: I035606ffe6cb3efc82a3a0ce79215509d8289503

[+]
WallpaperPicker: Destroy cropview to avoid leaks

If the cropview's TiledImageRenderer is rendering threads, the activity
context gets leaked. Avoid that by invoking its destroy in onDestroy() of activity.

Change-Id: I0804c903d14d3f3d13529f0fe90d12784d97e93f

[+]
CM11 Themes: Don't set sys.refresh_theme on icon update

Change-Id: I5ed49ad2aa93974c54434e092946c4be7699131d

[+]
CM11 Themes: Properly handle themeing apps on install

Previously when an app was installed or re-installed it would not
pick up the currently applied theme.

mOverlays was not being properly updated and therefore newly
installed or re-installed apps would not pick up the currently
applied theme.

Change-Id: I7ce5454af11fb44e9a73b30858d893050b2fba8a

[+]
CM11 Themes: Handle legacy themes in createIdmapsForPackageLI

Change-Id: Iff42bac7bf84b9c739831775c8deef86adbdc0ca

[+]
CM11 Themes: Fix how common resources are found

During the boot process, application info may not be fully
available and createPackageContext can throw a null pointer which
causes a theme's resource-cache to be cleared.  If this theme is
in /system/app or /system/priv-app the theme will still be installed
but applying it will result in styles not being applied.

Change-Id: I4094bdd923edc1d829024404a4ce1b72709bd4f1

[+]
Themes: Support launcher based icon packs [1/2]

Before this patch, icon packs written for Trebuchet/Nova/Apex could not be used
with the new theme engine as the formats were different. Particularly the icon package IDs are 7F,
the same ID as as regular apps. Furthermore the location of resources in these icon packs was different
from what the theme engine expects. This patch adds support for these icon packs by overriding
the pkg id.

AssetManager now can override package ids without requiring aapt to recompile the APK.
Note: XML references will still use the original id compiled with AAPT, so it is only useful for resources
which do not use xml drawables (such as icon packs).

PackageInfo now has a new member identify "legacy" (3rd party icon packs) written
for launcher's like Trebuchet, Nova, and Apex.

Change-Id: Icd12c097e156c9626df0772abeb50e00f7b61f64

[+]
Send broadcast when package is 'about' to be removed

If a theme package is removed and it is the currently applied
theme, some apps will crash because the theme resources are
no longer available, since they were cleaned up by the package
manager.  The themes provider will receive this broadcast and
take care of switching back to the default theme for components
that are using the package about to be removed.

Change-Id: I968c25e19eb17ec87e7ddcba5ac0fd81745cef20

[+]
CM11 Themes: Allow defining a custom default theme [1/3]

Change-Id: I6b794d6c9c27b2d6436bdf4fec51c84a7859c134

Conflicts:
	core/java/android/provider/Settings.java
	packages/SettingsProvider/res/values/defaults.xml
	packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

[+]
CM11 Themes: Reduce "unable to load asset" log spam

With the introduction of a "common" resource folder for themes,
we always try to attach the common resource table and if it does
not exist it won't be attached but we would see this log spam.

Change-Id: Ida4e815523fd71b34fe8f3b41cef3432e6e07b64

[+]
CM11 Themes: Get proper package name in attachThemeAssets

Change-Id: Ic77ff41519b22e3b20c4571785a1368cdf4d14d2

[+]
Cleanup themes that fail to install

Themes which fail to install due to aapt or idmap errors
would not be properly cleaned up. This caused subsequent installs
to give a INSTALL_FAILED_UID_CHANGED (-24) error.

This patch also adds install error codes specifically for themes.

Change-Id: Ie03b92ca0a7dec8c4a5e3725b717943d36abb349

[+]
Themes: Fix -110 install error [2/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: I85bf93045370478fd9baaf5db784c0cc3a4a03b9

[+]
CM11 Themes: Expose applyDefaultTheme to public service

Change-Id: I952870fb984d51d554e560566a8cadbe2c49cc6b

[+]
Avoid app install failures from malformed themes

When an app is installed we create idmaps between it and all the themes
that theme the app. If the theme is really badly written it could
potentially fail idmap generation, but we should not block the app
itself from being installed just because a bad theme is on the device.

Change-Id: I0e38fd373dfd294aac17fab1cf07ba49934a8859

[+]
CM11 Themes: Fix applyDefaultTheme implementation

Change-Id: I718be5db58166df48cca5578d6ad5088b91bc1e2

persist the changed position values in updateWallpaperOffsetLocked, even with a null mWallpaperTarget

Change-Id: I175773f6e0b3f91c1d983857028a89b959e4e9f2

[+]
Notify callbacks on "any" wallpaper change

Callbacks are not notified when the wallpaper is changed to
a live wallpaper.  This patch notifies callbacks of the change
regardless of the type of wallpaper be set.

Change-Id: Icbb7b825cd7e7096c90c5498b6fee0bc61a3de3b

[+]
CM11 Themes: Clear wallpaper mixnmatch entry on external change

If a wallpaper is applied from a theme and the wallpaper is changed
from an external source, the theme is still shown to have its
wallpaper applied.  This patch will clear this value out when a
wallpaper change is detected that is not from the ThemeService.

Change-Id: I3d32bb3c0ac96db3f940989bc7ad4eda5e4a71f7

Conflicts:
	services/java/com/android/server/ThemeService.java

[+]
Themes: Fix bad idmaps for system themes

For a system installed theme or a user who cleared his resource-cache,
there were empty idmaps for some packages.

[Details]
During startup PM could reach the theme package first before the target app was scanned in yet. This
would cause aapt to be skipped. Then when the target app is being installed in startup,
PM would try to create idmap pairs but it would fail since the resources from the theme
were not compiled for that target app.

Also cleaned up PM idmap/aapt creation a little bit more

Change-Id: I6a7dbd7c5d51a2d1336e3289c1e03bb3ed5d762e

[+]
Avoid calling idmap w/ trailing whitespace [1/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: I56c9b4bd956ca6f59935253c6d2c90c4dba0ae94

[+]
Themes: Map themed icon to app after upgrade

Before this patch, applying an icon theme and then upgrading an app would
cause the app to lose its themed icon.

Change-Id: Ia76a33d0fb731720aa735e9dd9596bc5d2e75d9f

[+]
CM11 Themes: load wp from apk if uri is null

When setting a default theme on first start, the provider may
not have processed the theme and the uri for the wp will be null.
If this happens try to load the wallpaper from the themes assets.

Change-Id: I883b9dd796920e66e4729e78d41cd8899916fa42

[+]
Themes: Add read/write permissions [1/2]

Change-Id: Id9710a7f6058454f563488288220744b02cc4850

Conflicts:
	core/res/res/values/cm_strings.xml

add a getter for the x and y offsets of the wallpaper window

Change-Id: I35294bcac664e85cc5d344b50b5c4335a60d3f37

[+]
CM11 Themes: Use sendBroadcastAsUser in ThemeService

Change-Id: I2a283318357ece9f6195a9bb825748b4549396af

[+]
SystemUI: Make wifi combo margin themable

Change-Id: Ie77b13cee84d5b472f878dba6388f3e168f5a249

[+]
Make KeyguardMultiUserAvatar fully themeable

Create the animation color for the username text based on the final
color.

Change-Id: I4b1beb70160e178264c32f3b33c6c0c7c51f70c5
Signed-off-by: Dirk Rettschlag <dirk.rettschlag@gmail.com>

[+]
CM11 Themes: Use package name from AndroidManifest

It is possible for an apk to have a different package
name for the resources than what is defined in the
AndroidManifest.xml of the apk.  Using the resource's
package name for the base package name causes themed
resources to not be properly loaded.

Instead of returning the resource package name we return
the apps package name from AssetManager.

A good example of this is Trebuchet.  The system sees
it as com.cyanogenmod.trebuchet but it's resources use
com.android.launcher3.

Change-Id: Id57e68b27b3c7509e3358a7fd12ae73a03dd6cdf

[+]
Revert "Reduce memory leaks by removing all views."

This reverts commit a61cab7.

[+]
This is causing BT icon to get caught up in "all views" removal. Backing this out until Clark can look into it.

Change-Id: Ied8f45f035492ee351e6b24fa0ae88c2abfbf9ea

[+]
Reduce memory leaks by removing all views.

Change-Id: I64b95981425840d101c8122421281976d0251bae

[+]
CM11 Themes: Delay setting default theme

Change-Id: I56c0ae7a8b6868a1e81b6c7a72c0dd4a079cd7ba

[+]
Revert "CM11 Themes: Delay setting default theme"

This reverts commit 293d7e8.

Change-Id: Ib36dd5f649b985238724dac06cbd0dca2eccb2cf

[+]
CM11 Themes: Add themeChange config change to manifest

Change-Id: Ia84c0089a79637906e4f75fa38a56e8ff3b21a2b

[+]
CM11 Themes: Don't kill setup wizards

Change-Id: Ib68dbf08b5b65f66e73f2f22882932ced0851093

[+]
Fix wallpapers not applying in full screen

Change-Id: I01f451d0b9a2236c2cdf0c7533e6f13ef03b7bf2

[+]
WallpaperCropper requires these permission.

Without these it just crashes lockscreen wallpaper.

Change-Id: I25c676244a919ed355e02664828ddd79dd327062

[+]
No need to hide flags in configChange

Change-Id: I36cda275f836d07e639419db8c856c7527307907

[+]
Revert "idmap: Don't log spam "CREATING STRING CACHE""

This reverts commit 8a8b3bc.

Change-Id: Ic461c90e9fd50b81051b2bc55bb6507f40144c36

[+]
idmap: reduce CREATING STRING CACHE verbosity

Change-Id: I7febe358b3b302427650edc1d00772fc9d2d547c

[+]
CM11 Themes: Big cleanup of cm dependencies and compatibility miscs

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>

[+]
CM11 Themes: Add theme support to Ringtone and Profile pickers activities

Patchset 3: Add support for theme RingtonePreference view. The dialog is
            automatically adjusted to the caller activity base theme.
Patchset 4: Don't break the android api

For Ringtones:

http://review.cyanogenmod.org/#/c/61393/

For Profiles:

Usage:

Intent intent = new Intent(ProfileManager.ACTION_PROFILE_PICKER);
intent.putExtra(ProfileManager.EXTRA_PROFILE_DIALOG_THEME, R.style.CustomDialogTheme); <<< Add your custom dialog theme here
startActivityForResult(intent, 0);

Style Usage:

Define an style that inherits from an android base theme

<style name="CustomDialogThemeDark" parent="@*android:style/Theme.Holo.Dialog.Alert">

or

<style name="CustomDialogThemeLight" parent="@*android:style/Theme.Holo.Light.Dialog.Alert">

or define your own dialog style

Change-Id: Icadbcf2c617c51177466989acdab9435066a47a0
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>

Conflicts:
	core/java/android/app/ProfileManager.java
	packages/SettingsProvider/src/com/android/providers/settings/ProfilePickerActivity.java

------------------------------ END ------------------------------

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Conflicts:
	cmds/bootanimation/BootAnimation.cpp
	core/java/android/app/ResourcesManager.java
	core/java/android/content/res/Resources.java
	core/java/android/provider/Settings.java
	core/java/com/android/internal/os/ZygoteConnection.java
	core/res/res/values/config.xml
	core/res/res/values/pa_strings.xml
	core/res/res/values/symbols.xml
	packages/Keyguard/src/com/android/keyguard/KeyguardMultiUserAvatar.java
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java
	packages/Keyguard/src/com/android/keyguard/KeyguardViewMediator.java
	packages/SettingsProvider/res/values/defaults.xml
	packages/SystemUI/res/values/colors.xml
	packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.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/NotificationManagerService.java
	services/java/com/android/server/SystemServer.java
	services/java/com/android/server/UiModeManagerService.java
	services/java/com/android/server/connectivity/Tethering.java
	services/java/com/android/server/wm/WindowManagerService.java

Conflicts:
	packages/SettingsProvider/res/values/defaults.xml
	packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java

Author: Carlo Savignano <stevewatersy@gmail.com>
Signed-off-by: mar5hal  <errantzebra845@gmail.com>

Conflicts:
	packages/SettingsProvider/res/values/defaults.xml
	packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java

Conflicts:
	core/res/AndroidManifest.xml
	core/res/res/values/candy_strings.xml
	packages/Keyguard/src/com/android/keyguard/KeyguardViewManager.java
	packages/SettingsProvider/res/values/defaults.xml
	packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
Fix resource leaks

Change-Id: I3a201cfd924e467d605351782bd06874c2af725e
Cleanup app->{theme1,theme2...} mapping on uninstall

Change-Id: I24b43e8817db1927d5b43fcf7ad3340269d046ea
Themes: Add '|' delimited list of components to broadcast

Change-Id: I742dcb0f502b6089dee584a92a3792016f2a9799
Themes: Handle apps using "original-package" tag

Before this patch the themes code assumed the pkgName from PackageInfo was equal to the
manifest value. This is not the case however for upgraded system apps that have gone
through a pkg-name change. For example, Trebuchet was "com.android.launcher3" and now
it is "com.cyanogenmod.trebuchet". If the device had wiped data then PM would use the new
pkg-name, but if the system apps were being upgraded then PM would use the old name which is
now different from the manifest name.

Change-Id: Ie7eb1b4e17899d1055535dc890d4f7a7bca9a98a
Make theme change broadcast a protected broadcast.

Change-Id: Ic24c840685d18d133dc73ff2637c041c4775f197
Themes: remove unused code

Change-Id: I5ee8de962c40ddc5fcfbbc0332a9e389223e716c
Themes: Delete icon resources during uninstall

Change-Id: Icf247642f9d246c8826f3394f873e4b434ad2b3f
WallpaperCropper: do not display null bitmaps

It is possible that themes can include a corrupted bitmap,
and the lockscreen will try and display a NULL image resulting in an
empty thumbnail and applying it will cause the app to crash.

Change-Id: Ie0770486a9d58050a5f296a219d844a39937421e
Signed-off-by: Roman Birg <roman@cyngn.com>
Themes: Update last postFinish call

* Previous patchset changed postFinish function signature.

Change-Id: Ibe07435e274054c7203504bc4b0877b4df006893
Themes: Keyguard: Fix NPE setting lockscreen wallpaper

After boot the view might not be laid out and so getWidth() and
getHeight() return 0 and will cause a NullPointerException in
createBitmap().

Bug AOSPA-448

Change-Id: Ibacf4199a69709dc34d21695732c2a5360533a23
Signed-off-by: Dirk Rettschlag <dirk.rettschlag@gmail.com>
TextView: Check also for mLayoutParams before calling checkForRelayout

Cherry-picked from OmniROM.

http://jira.omnirom.org/browse/OMNI-976

This was introduced with
https://github.com/omnirom/android_frameworks_base/commit/b3670c54e60387fde633fb91c649c5b896f8b962

Change-Id: I06c1926c5b8102b336d128d9b411f74a9eff3ded
Themes: uninstallThemeForAllApps shouldn't check if map is empty if it's null

Potential NPE introduced in ec2200878706735cdd2caf4d934d988296998e85

Change-Id: I6d1ec165957c2be63086a18af2236e46978e9c8a
fw: media: Handle NPE due to threading race

Change-Id: I6eab5bc3d687edfa6f0839e439b3314bed4fdcea
TextView: Prevent more NPEs

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Change-Id: If710bddace79d67a3c97c10ad591a4024c89e4ef
clean up some more
Revert "clean up some more"

This reverts commit 13148a2c9429d9ec1eb940701fd9fdfa5e5b4169.
CM11 Themes: Add support for composed icons [1/2]

If an icon pack includes background, mask, and/or foreground
images and an icon is not included for a given app, an icon
will be generated using the background, mask and foreground.

Icon packs can include the following items into their
appfilter.xml
    <!-- Set deafult scale factor for the icons -->
    <scale factor="1.0" />

    <!-- Set back image for composed icons -->
    <iconback img="iconback" />

    <!-- Set the mask image for composed icons
         Original icon will be masked off using this mask -->
    <iconmask img="iconmask" />

    <!-- Set foreground image for composed icons -->
    <iconupon img="iconupon" />

Note: Mutliple iconback images can be used as follows
    <iconback img1="iconback1" img2="iconback2" img3="iconback3" />

Change-Id: I0f5fd7de4f0eae485139cbcd282c1d1e1663952f
Themes: Don't set icons for iconpack that is applied.

Change-Id: I3cffade2c12ae1dbc1f75e43f1a74609ff0d7135
listview: ensure active views are filled prior than scrap views

The internal Recycler#fillActiveViews should be called prior to add any view
to the scrapViews queue, so it can be use safely without detaching views
because out of sync.

Change-Id: Ie119ad871a89e0a3fa1e07e955fcd5ca7b171f46
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>