Fixed upgrading from forward-lock application to system application

Fixes the case when the app on system is newer than the
currently installed. Something that can happen e.g. after
a FOTA update.

Change-Id: I102e9cdd5693d5e66667c0c8989dc2643c72dd16
ANR caused by incorrect cleanup in BroadcastQueue.

Two broadcasts could be sent to the same app simultaneously:
one foreground, one background. For example, LOCALE_CHANGED
and PACKAGE_CHANGED are delievered to com.android.vending
at the same time.
1. AMS started new vending process to handle LOCALE_CHANGED.
   And set app.curReceiver = LOCALE_CHANGED.
2. Before LOCALE_CHANGED is handled by vending process,
   PACKAGE_CHANGED was delievered to vending process too.
   AMS set app.curReceiver = PACKAGE_CHANGED. Bad!
3. Vending process finished handling LOCALE_CHANGED.
   AMS clear app.curReceiver = NULL. Bad!
   And Vending process  killed itself without handling
   PACKAGE_CHANGED.
4. AMS known vending process has died, but didn't know that
   BgBroadcastQueue was still waiting for finish message
   for PACKAGE_CHANGED.
At last, BgBroadcastQueue reported ANR for PACKAGE_CHANGED.

This patch adds protection before clearing app.curReceiver,
only set to NULL if the finishing receiver = app.curReceiver
So handleAppDied would know that PACKAGE_CHANGED was not
finished yet, it will abort the broadcast and continue.

Change-Id: Ic4f31b35e21823d4a3c27712391ecbede213a494
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>
Clarify the documentation of SparseArray.indexOfValue.

Bug: https://code.google.com/p/android/issues/detail?id=53297
Change-Id: I28725a2d03d4c11948bfe4fb90d730c86bf41481
New ArrayMap class.

This is a new kind of key/value mapping that stores its data
as an array, so it doesn't need to create an extra Entry object
for every mapping placed in to it.  It is also optimized to reduce
memory overhead in other ways, by keeping the base object small,
being fairly aggressive about keeping the array data structures
small, etc.

There are some unit and performance tests dropped in to some
random places; they will need to be put somewhere else once I
decided what we are going to do with this for the next release
(for example if we make it public the unit tests should go in
to CTS).

Switch IntentResolver to using ArrayMap instead of HashMap.

Also get rid of a bunch of duplicate implementations of binarySearch,
and add an optimization to the various sparse arrays where you can
supply an explicit 0 capacity to prevent it from doing an initial
array allocation; use this new optimization in a few places where it
makes sense.

Change-Id: I01ef2764680f8ae49938e2a2ed40dc01606a056b

Conflicts:
	services/java/com/android/server/wm/WindowManagerService.java
Frameworks: apple can do...we can do as well

incredible apple engineers speeded up the overall UI and reduced per default slightly
the animation scales. Well we do as well and reduce it from 1 to 0.75...smooth, looks well
and does not break anything

Change-Id: Icbcc889e49c8d3ab24cf2b1c10bbe0e8bf7e7637
Additional functionality and performance for ArrayMap

Added equals() and hashCode() to ArrayMap to allow equals() tests
of maps with the same key/value pairs to return true.

Changed putAll() to handle the case of an empty map faster, just copying
the arrays instead of adding elements one by one.

Added to ArrayMapTests to test new equals() and copy constructor
functionality.

Issue #9299310 Optimize ArrayMap copy constructor

Change-Id: I1186a0eddd1fd53a0f380c2f3972fc1942cdf879
ArrayMap is great, so how about ArraySet!

Also a few little tweaks to the ArrayMap implementation.  Note that
these are fairly parallel implementations; I looked at what I could
abstract out as a base class, but there isn't really all that much without
making the resulting code more general and thus slower.  If we kept
the data structure for ArraySet the same as map, where the array has
two values per entry, then they could probably share a lot of code.
I couldn't really bring myself to do that at this point, though...

Change-Id: I9e0dd8baa8e1febcc1033ecef61623ad59ce4aae

Conflicts:
	core/java/android/util/ArrayMap.java
Update SparseArray docs to be more informative.

Change-Id: I5d8d17d46a69ccdcf6b29f93be3d44addd80ab61
Make ArrayMap public! :)

Also do some tweaking of the various container classes
to synchronize them with the support lib and make it
easier to copy code between the two.

And update activity/fragment to use ArrayMap.

Change-Id: I3cfe82392a17119dfc72c3d9961f64e1914f42be

Conflicts:
	core/java/android/app/AppOpsManager.java
	core/java/android/util/ArrayMap.java
Switch Bundle's implementation over to ArrayMap.

That was...  um...  easier than I thought it was going to be.

Change-Id: Id8f2211c1d5f8145e0bb009dca0f62a590f2b860
Fix crash.

Change-Id: I0b5d846d5a9e6b1c7c3756b653833c263634270b
Fix issue #9940105: IllegalArgumentException in ArrayMap

Try to deal with unmarshalling old parcels.  Turns out someone
was writing a parcel to disk storing a Bundle.  Naughty, naughty.
This helps us not completely keel over.

Change-Id: Id343da2690b7bab89f6c3cb6fad1b92f270dad03
Okay, I give in, add null key support to ArrayMap and ArraySet.

Change-Id: Iac5035f9c5884a9f9d5acb38132bb128d7a55249
Fix issue #10921903: CTS: android.os.cts.ParcelTest#testReadBundle...

...fails from KRS84 across all platforms

My fix for issue #10807048 was wrong, wrong, wrong.  The problem was
actually just a stupid mistake in ArrayMap.erase().  This makes it
all right.

Change-Id: I762f7a2d5100bceb86a091ab3d6368edc21b4266

Conflicts:
	core/java/android/os/Bundle.java
Mmmmmmm...  lovely, lovely ArrayMap.

And ArraySet, too.

Change-Id: I72ea28cbb2286b01b6e1be082f8e7ec17e99074e

Conflicts:
	core/java/android/app/ActivityThread.java
	core/java/android/app/ResourcesManager.java
Cache reflection lookups

This change also cleanups the code a little bit. Caching lookups
not only speed things up but it also avoids unnecessary allocations.

Change-Id: Ie3d1ae106d32b3b5f2c5d33b6318ed93cd9e27f9
Use the parameter type as part of the methods cache key

Change-Id: Ie204d16b62028fc1eb35cc7cb3244654e1360a37
Fix crash in app widgets
Bug #9983130

Change-Id: Ie2319c9e8f6e7591c03061224021973b94ae07cb
ArrayMap: Fix build error and bootloop

Change-Id: I92f0761cf58f2f3c63f54b4df3df2ebf8efcde74
Replace HashMap with ArrayMap to remove unnecessary allocations

This change also fixes a race condition. If multiple UI threads are used
in a single process, RelativeLayouts could end up using the same nodes
in different windows, causing mayhem and headaches.

Change-Id: I9ba4a0bf05d44e1a1e7a82443d40c500c657cd7a