Solve three memory leaks related to PatchCache

A Patch can be fairly large, holding bitmap data, but
is also frequently leaked which adds to the severity.
The feature is used in many important processes such
as Home, SystemUI and Chrome.

The following leaks are solved:

1. The Patch itself was not always freed.
PatchCache::removeDeferred() can mark patches to be
cared for by PatchCache::clearGarbage(). But
mCache.remove() would only destroy the container
and the pointer, not the Patch object itself.

2. The vertices stored in the Patch at Patch::createMesh()
would always leak. The empty/default destructor in Patch
would not properly destroy "vertices" since it's just a
pointer.

3. A BufferBlock that's added to the mFreeBlocks
in PatchCache could leak. The leak happened when a
patch later needed the entire free block, because the
object was removed from the list but never deleted
in PatchCache::setupMesh().

Change-Id: I41e60824479230b67426fc546d3dbff294c8891f
Signed-off-by: houst0nn <houstonn@gmail.com>
Do not launch floating window when on default launcher

We only do this when user is on the default launcher 
because if the user was on a non-default launcher,
he/she must have been there for some purpose and we 
do not want to throw him/her back to the default 
launcher incase he/she exits the app with HOME button.
Fix thumbnail bug

When there was no thumbnail for a given image, the getThumbNail() convenience
method could return a previously-returned thumbnail instead of null.

b/15771860
https://code.google.com/p/android/issues/detail?id=40714

Change-Id: Ibd18e048145bf347469f800afdf436247ea6b693
Signed-off-by: houst0nn <houstonn@gmail.com>
Fixed VM memory leak in AudioSystem JNI interface

The function android_media_AudioSystem_error_callback from AudioSystem
JNI interface is using FindClass function but does not delete the
reference created by VM in this function.
By doing this call, VM will add a local reference in IndirectRefTable
and it's the caller's job to delete this reference.
By not doing this, everytime this callback is called, a new reference is
added and never deleted.
The effect is crashing the VM running system_server:

E/dalvikvm( 3071): JNI ERROR (app bug): local reference table overflow (max=512)
W/dalvikvm( 3071): JNI local reference table (0x732da288) dump:
W/dalvikvm( 3071):   Last 10 entries (of 512):
W/dalvikvm( 3071):       511: 0x42a90008 java.lang.Class<android.os.Parcel>
W/dalvikvm( 3071):       510: 0x4381fd90 android.view.KeyEvent
W/dalvikvm( 3071):       509: 0x439b9808 android.view.KeyEvent
W/dalvikvm( 3071):       508: 0x42d2fe18 java.lang.Class<com.android.server.input.InputManagerService>
W/dalvikvm( 3071):       507: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):       506: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):       505: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):       504: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):       503: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):       502: 0x42ad4298 java.lang.Class<android.media.AudioSystem>
W/dalvikvm( 3071):   Summary:
W/dalvikvm( 3071):       510 of java.lang.Class (3 unique instances)
W/dalvikvm( 3071):         2 of android.view.KeyEvent (2 unique instances)
E/dalvikvm( 3071): Failed adding to JNI local ref table (has 512 entries)
...
E/dalvikvm( 3071): VM aborting

In this case, PID 3071 is system server.

Change-Id: I0c113eb72256984854d59a3ccef11a8d23f96e79
Signed-off-by: Robert Chiras <robert.chiras@intel.com>
Signed-off-by: houst0nn <houstonn@gmail.com>
Automatic Translation Import

Change-Id: I1a255c84ce5c94069735b48bb4345f0508a45be4
HOVER: Don't treat touch outside event as true if is animating

- It needs to wait animation to be finished to start listen for touch outside
  and runs hide timer.

Signed-off-by: Carlo Savignano <stevewatersy@gmail.com>
Themes: Update LoadedApk resources.

Instead of creating a new LoadedApk when resources are not up to
date, we use the existing LoadedApk but recreate mResources.

Change-Id: Ic1ad810863d03c2cedc751c9e84dd7c954daf3d7
IndexOutOfBoundsException observed rarely in ProcessStats

Sometime IndexOutOfBoundsException is observed in ProcessStats
while allocating longs array. This could be due to synchronization.
This fix will return if array index is >= size.

Change-Id: I1df34152c95f2ff61829da07f750e79a6f1efab3
CRs-fixed: 626638
Signed-off-by: houst0nn <houstonn@gmail.com>
Fixing parcel leaks to avoid virtual memory leak

Client has to call recycle() on parcel object after its usage
otherwise native layer of binder won't clear the resources of
parcel which were allocated for IPC

Change-Id: Ib31ddcc92aa4ebd80bb66729922b9133692e9c9e
Signed-off-by: houst0nn <houstonn@gmail.com>
Merge "Automatic Translation Import" into kitkat
Merge "Solve three memory leaks related to PatchCache" into kitkat
Merge "Fixed VM memory leak in AudioSystem JNI interface" into kitkat
Merge "Fix thumbnail bug" into kitkat
Merge "Themes: Update LoadedApk resources." into kitkat
Merge "Fixing parcel leaks to avoid virtual memory leak" into kitkat
Merge "Do not launch floating window when on default launcher" into kitkat
Themes: Modify config to support app specific themes [1/4]

Summary of Changes
1. The configuration now supports each app to have their own theme.
Each theme can include icons, styles (ie overlays) and font.

2. The theme config is serialized into a json string and stored
in secure settings.  This entry consolidates what was previously 3 separate
keys (style, icon, font) into a single field.

3. 'CustomTheme' was renamed to 'ThemeConfiguration'.

Note: This commit is for the configuration. Additional work needs to be done to
the framework and UI to support app specific themes.

Credit to @BigBrother1984 for the original cherry pick

Change-Id: I8ac7e83f7cfa60567166bed699d1cb17c547e20d
Themes: Support theming navbar separately from SystemUI

This allows using a different theme for the navbar than the theme
applied to the rest of SystemUI.  This will not affect theming until
we have the front end in place that allows users to change this.

Credit to @BigBrother1984 for the original cherry pick

Change-Id: I753623696cdc017fc66dc5e85079fe80e5f626f9
Add getThemedResourcesForApplicationAsUser()

Credit to @BigBrother1984 for the original cherry pick

Change-Id: I90b7cb441e4056f59b7260ffa55e31eba644e25a
Themes: Allow specifying a theme when creating a Context

A Context normally loads the resources associated with the given
package that this context is for.  This patch allows us to specify
a theme we want attached to a given context's resources.

Credit to @BigBrother1984 for the original cherry pick

Change-Id: Idfb53aba307f58be6e2ed6d404b8a76c31199fc8