Squash: Memory leaks, NPEs, races and optimizations for fw/base

This is a combination of 13 commits.

The first commit's message is:

Fix a programmatic smooth scroll bug

Bug: smoothScrollToPosition() stops at child view of which height is
higher than list view itself.

Signed-off-by: Yongyi Li <yongyi.li.cn@gmail.com>

This is the 2nd commit message:

Fix infinite recursive loop

There is an apparent recursive loop at IntProperty.java
in method set(Object, Integer)

This method unconditionally invokes itself. This would seem
to indicate an infinite recursive loop that will result in a stack overflow.

This was brought over from out original JB branch.  Somehow, this got
overlooked, and never made it into JB42.

This is the 3rd commit message:

Rework thumbnail handling

Since ids of media file are usually not continuous, the original file of thumbnail are
sparse. When there are big numbers files on ex\
ternal storage, the size of this file will be horrible.
Ex, when the id is 20000, then the .thumbnails/.thumbdata3-xx file will be 50000*10k = 488.28M.
Can refer http://stackoverflow.com/questions/12396715/android-huge-thumbdata4-file-in-dcim-folder
Because after 4.0, MediaProvider will scan any files, this will be a big problem. So I modify MiniThumbFile.java to avoid this.
According to the id, we now produce an index file. In this index file, one id will use BYTES_PER_MINTHUMB_INDEX(8) bytes in offset (i\
d+1)*BYTES_PER_MINTHUMB_INDEX. The data of these 8 bytes is the index of thumbnail file. The first BYTES_PER_MINTHUMB_INDEX bytes kee\
p next available index. And when you need insert a thumbnail, the index increase by 1. In this way, the block data in thumbnail file \
will be continuous. And thus unnecessary zero paddings will not be saved.

This is the 4th commit message:

frameworks/base: Fix for the race in Wallpaperservice

Wallpaperservice has a race among message handler of
DO_DETACH and service's onDestroy. In certain cases,
the engine kept track in mActiveEngines is removed by
message handler of DO_DETACH and service's onDestroy
doesn't get a entry in mActivieEngines and isn't able
to invoke detach. This keeps the broadcast receiver,
mReceiver active and is unregistered by the framework
and a corresponding leak is reported.

  Later, the message handler of DO_DETACH continues
and invokes detach on mEngine, which attempts to
unregister mReceiver and framework throws an exception
"Receiver not registered: android.service.wallpaper.
WallpaperService$Engine$1@40874580" and causes the
framework to reboot.

  In case of system_server, WindownManagerPolicy and
android.server.ServerThread contest for access of
shared members, mActiveEngines and mEgine. Fix is to
protect the critical section via synchronized block.

This is the 5th commit message:

Make EntropyMixer mix in output of Hardware RNG into Linux RNG.

On devices with Hardware RNG (HW RNG), this makes EntropyMixer
periodically (every three hours) read 512 bytes from HW RNG and mix
them into the Linux RNG.

This is done without increasing Linux RNG's entropy estimates to
avoid having to trust the quality of the HW RNG. This approach cannot
reduce the quality of the Linux RNG output, but may increase it.

This is the 6th commit message:

build core/jni with fstrict

This is the 7th commit message:

Reduce EntropyMixer seed size from 4096 to 512 bytes.

The suggested seed size from Linux drivers/char/random.c is 512 bytes
rather than the 4096 bytes currently used.

This is the 8th commit message:

frameworks/base/: Fix black wallpaper issue when home pressed.

In the specified usecase, there is a completely new set of
windows that appear on the screen during rotation. And the
existing code in the framework ignores the drawstate of the
hidden windows.

Wait till the drawState is ready for the hidden windows also.

CRs-Fixed: 521758

This is the 9th commit message:

Fix to NullPointerException when activity is relaunched

When ChooseTypeAndAccountActivity is relaunched and resumed
by ActivityManager a call is made to onActivityResult without
first triggering onResume. This leads to mAccounts object
still being null.

Fixed by properly setting mAccounts object if it is null prior
to use after function onCreate has been called.

This is the 10th commit message:

Remove possible leak when exception occurred.

nameUtf8 is not released after exception.
In addtion, Fix code going down after ThrowException.

This is the 11th commit message:

frameworks/base: Fix to remove exception in tonegenerator

- Framework reboot happens, if tonegenerator fails to create
  a track in audioflinger.
- The cause for framework reboot is, an exception thrown by
  tonegenerator if fails to init.
- Fix is to remove the exception and delete the tonegenerator
  instance.
CRs-fixed:466491

This is the 12th commit message:

framework: packageinstaller :fix logical error in size calculation

fix logical error in available size calculation.

This is the 13th commit message:

frameworks/base: move the traces file to avoid data loss

If an ANR comes just after the framework reboot, the traces for
the framework reboot will get over-written with the ANR traces.
So, We are missing the traces for the framework reboot which
makes debugging the framework reboot difficult.

This patch will rename this trace file for the framework reboot
once the ActivityManager collects the traces.

Patchset 2: Made commit message easier to read

Change-Id: Iee07b13ba02d8aab9cc43567aa5df131cc43c737

Conflicts:
	core/jni/Android.mk
fw/base: MOAR misc fixes & enhancements

Make ImageView drawable update more efficient in some cases.

When updating the view's drawable via setImageResource or setImageURI,
make sure to skip the layout pass if the old and new drawable have equal
sizes. This follows what is already done for setDrawable().

Fix a bootloop problem when /data/system/usagestats/usage-history.xml is empty.
This often occurs after an incomplete reboot/shutdown or battery pull.

ActivityManagerService: stay away from zombie content providers

When the lowmemorykiller kills a content provider in an unfortunate
moment, an innocent client app can become attached to a zombie provider
and be unconditionally killed moments after, when the dead provider is
being removed.
Prevent this race by addition of isAlive function to Process.java that
determines whether a process is still running and is not only a zombie,
add a check of the state of the provider process to getContentProviderImpl.

bootanim: Don't cache textures if they're expected to use a lot of VRAM

bootanimation cached all the textures generated until the animation
was completed.
For Hi-res animations with lots of frames (like the new CM9 anim on
xhdpi devices), this implied using large amounts of video RAM, more
than most devices actually have available, causing the animation to
stall (and in some cases, gralloc to lock up); so if an animation is
expected to use a lot of RAM (rough estimation based on frame size
and number of frames), disable cache entirely and generate the textures
on demand

bootanimation: performance enhancements

This patch implements two simple performance enhancements, which
might benefit devices. They are completely opt-in by setting
the following variables.

  * TARGET_BOOTANIMATION_PRELOAD: will preload the bootanimation
    zip to memory; this is handy on devices where the storage
    might be slow. By preloading it, we get quick access to the
    zip file, and the animation doesn't stutter.

  * TARGET_BOOTANIMATION_TEXTURE_CACHE: allows maintainers to
    force texture cache on/off.

Also fixes the sign warnings related to int / size_t comparison

bootanimation: fix usage of LOGW

bootanimation: allow using RGB565 instead of ARGB8888

RGB565 uses considerably less memory, and together with texture
cache, it allows us to offer a really smooth bootanimation on
not so powerful devices.

audio: libaudioeffect_jni GREF leak fix

- Excessive JNI global reference in AudioEffects.
- Global references created during native setup
  are not deleted.
- Global references are deleted in setup failure
  and during native release.

CRs-fixed: 413633
(cherry picked from commit f60e70097b84c4ef26eeb31024d52e5b1fc8aa64)
(cherry picked from commit 9c9279277ad10582ff3dcf5cad576d2d7f036569)

Call to equals() comparing different types (FindBugs)

Call to HashSet<PrintServiceInfo>.equals(ArrayList<PrintServiceInfo>).
The result of this comparison will always be false.

MiniThumbFile: Fix image/bitmap retrieval

Change I66005dd69b0a5c8f4353bd7a8225d163a654fd2d changed the insertion
and creation indexing mechanism, but the retrieval method was still
using the old sparse one. Fixit

Fixes android.provider.cts.MediaStore_Images_MediaTest#testInsertImageWithBitmap,
android.provider.cts.MediaStore_Images_MediaTest#testInsertImageWithImagePath,
android.provider.cts.MediaStore_Images_ThumbnailsTest#testQueryExternalMiniThumbnails,
and android.provider.cts.MediaStore_Video_ThumbnailsTest#testGetThumbnail

Memory leak in IInputMethodSessionWrapper executeMessage

In some cases the executeMessage is called with
mInputMethodSession == null. For the messages

DO_UPDATE_SELECTION, DO_APP_PRIVATE_COMMAND

memory is leaked. This commit recycles the args freeing
the allocated memory.

Fix resource leak: When call MediaMetadataRetriever.setDataSource or getFrameAtTime should ensure call release in finally to avoid resource leak
                   Patch set 2: Remove unnecessary white spaces

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: I3ccfc311546abe2b2b18262f76faba75e494075e

Conflicts:
	cmds/bootanimation/BootAnimation.cpp
	services/java/com/android/server/am/UsageStatsService.java
Merge in a lot of VANIR fixes and improvements

Thank you guys a lot you're awesome!

eb605813aae3058ef8d111722c5584a867de1df3 improve rotation handling
ed2e8f9ff28a329d4cdb56d49437db3495aa22a2 Forward compatibility fixes
6eb657f2882478f1f327f4ec8ebc945022d4f924 Forward compatibility fix
9ce50c5d886c3d012002699ded8f85380b02d3a6 Missing break in switch statement
5f48acfdd1b3dd0ba9ae41b3a10ac60de267f98c Prevent nullPointerException by updateBondedBluetoothDevices
d9d59b2e1c82f8683e559539501059850ba65f4c Fix to NullPointerException when activity is relaunched
dcd7f57582c39d1eab60408d54a80e1636711ede make WidgetView observer private
0f48310bdb6c8e8d4801c7cc7bdae27a63d6c223 Fix for NullPointerException in HTML5VideoViewProxy
98871cb5a3a1863bacf221589799e0d699265fc2 Selectively restore non-stupid parts of stuff we had before a patented nuclear decrapificating
1cdfaee436b9e38039e8c6a4e92fa6f026886029 build core/jni with fstrict
a7ea71d7b05432ecbcb2b50ba39796d6dabbdb4d services: make sure to recycle set args
6384e8636d55b59e7e6e3e3e6e55eaeeeb5c703a potential GraphRunner leak in camera effects
c2e8755decaf0f9b6b3e5ad4e499388385a2b873 Fix unresponsive home key after waking device with a long press
bed41b9bf1864b8c7e2c3e48dce3cf1cda46e198 Hide traffic on lights out
eb605813aae3058ef8d111722c5584a867de1df3 improve rotation handling
ed2e8f9ff28a329d4cdb56d49437db3495aa22a2 Forward compatibility fixes
6eb657f2882478f1f327f4ec8ebc945022d4f924 Forward compatibility fix
9ce50c5d886c3d012002699ded8f85380b02d3a6 Missing break in switch statement
5f48acfdd1b3dd0ba9ae41b3a10ac60de267f98c Prevent nullPointerException by updateBondedBluetoothDevices
d9d59b2e1c82f8683e559539501059850ba65f4c Fix to NullPointerException when activity is relaunched
dcd7f57582c39d1eab60408d54a80e1636711ede make WidgetView observer private
0f48310bdb6c8e8d4801c7cc7bdae27a63d6c223 Fix for NullPointerException in HTML5VideoViewProxy
98871cb5a3a1863bacf221589799e0d699265fc2 Selectively restore non-stupid parts of stuff we had before a patented nuclear decrapificating
1cdfaee436b9e38039e8c6a4e92fa6f026886029 build core/jni with fstrict
a7ea71d7b05432ecbcb2b50ba39796d6dabbdb4d services: make sure to recycle set args
6384e8636d55b59e7e6e3e3e6e55eaeeeb5c703a potential GraphRunner leak in camera effects
68dfb6b493863aba26074c862e44f3af10f2f61f DeviceKeyHandler squash
c2e8755decaf0f9b6b3e5ad4e499388385a2b873 Fix unresponsive home key after waking device with a long press
35bc0f31e5967b59c7c83a33238a22e611c077a0 PhoneWindowManager: Hardware key handling fixes and cleanup
838f7ebfabc91f4ab2065af46a40cc6c9167a5a5 Fix hardware home key behavior on wake-up
a73132ad1635267886d4969e410723ab18dbb846 Fix ordering of home keypress handling
f84f26bb91c387762cf3048dc2a85dbd59703027 statusbar: performance and fixups
cc104e3cccf3901da2b2040f77fe0f08706c2ed5 interrupter: Use LOCAL_LDLIBS rather than LOCAL_LDFLAGS
44dfffa26e14aee1a9d12c1edc211d40467a4124 Don't unnecessarily recycle things.
d24d56509fcbf88a3bba0177c3721ad253ccad34 Correcting NULL pointer when callerApp is not set
05a382390cde82461d8f53f63d0cb12ce7c55dbd l'oops: fix inputservice ANRs
fa7bd7f869cef7534ed8b6616c5874afbd4b72a5 don't register a content observer if the device is already provisioned
bf0b5c820243ffa101e9f43fa319570fd72d8d03 Privatize PhoneWindowManager
f53da810731f654fa712487f2f468c5b81b816a5 Reduce EntropyMixer seed size from 4096 to 512 bytes.
661b956d0f7ecc4347acbeb86fc585a9ae107110 Detach engines before destroying WallpaperService
1f734ecc9714c2e5ee56b6f17c9a35598dab5c0d frameworks: squash of leak & race fixes
97d08382cd97756c4497389baaed89575810a78e Make ActivityManagerService.systemReady thread safe
c5f90b9bd64a99ffc49fc96b1a066a675069899b Don't ANR when no windows are touchable.
95552ef44afb48052c97dd3b76eb020ff8319700 Avoid IndexOutOfBounds Exception in ActivityManagerService
13b6f23037905ad6cb8538490fcdd47e7bcc26cf Scroll: modified velocitytracker
3ea66792ae162eeafeecc50c858cbe4162248297 recycle TypedArray calls in F_B
4ae81b789e309bf14ae8b8851e5e2df51d12a98d privatize keybuttonview
148ec969b96ea67de9fa2d27b4f5c0298cd74d8c If frameworks wants ASCII casing, it should explicity ask for it.
0ccacb22858eb47946a8f4cda0f50d0dcb17bb65 onSavePassword dialog can leak when WebViewClassic is destroyed.
ac7d546dc6ff67d325a205599edb12bb9cd23bd8 Fix issue #10226007: Reset apps restores most of the changed settings...
63aa94ff65d5ce93c23502136e154fa10db516e2 base: App crash when select suggestion's length more than specified.
560ab7cb9c53739df53c1869350bf78312ffe9c2 Remove useless import statement
3851a0951ea20c64164f5fa9c08ab7476c7d7a45 aapt: set interlace handling for png_read_update_info
ea15b65b7eadd1f769a90f517244f7f45d0f1068 Memory leak: parseObbFile.footer
0d32d6d57709b329eeae965c4badd3df44d60946 GlobalAction dialog ref not set to null
60293f9c8fa23ea8d42ac4b9d74b78ca9a386c5a Follow convention for localizing DB and NET strings
6df4d75495677f8e8e86d8b17877d6d2acf7a8fa Restore previous ViewConfiguration constants

also fixed the traffic meter on lights out

and updated the phone windows manager to match cm their custom keys system

Change-Id: I205a2add9f226913b16d6e8f04335819dda05e29
Signed-off-by: anerik <anerikgames@gmail.com>

Conflicts:
	core/java/android/widget/ProgressBar.java
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java