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

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/////////////////////////////////////!
Author:                             /!
Yongyi Li <yongyi.li.cn@gmail.com>  /!
/////////////////////////////////////!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

Signed-off-by: pcarenza <pcarenza@gmail.com>

Conflicts:

	core/jni/Android.mk

Change-Id: Ic91414f5ca8b8ead5b3dd6eebdf9085cbcc9ef03

Conflicts:
	core/jni/Android.mk

Signed-off-by: pcarenza <pcarenza@gmail.com>
Signed-off-by: hany <hany.alsamman@gmail.com>
Frameworks: Add ADB Paranoid mode (1/2)

Signed-off-by: Arnav Gosain <nolinuxnoparty@gmail.com>

Conflicts:
	core/java/android/provider/Settings.java

Change-Id: I1f9c9e42dcd8cbacd7e7c4bc24c6bdf55db04fc3
Last App Toggle from Omnirom (1/2)

Change-Id: I5c66e0cc2126a9ade755577dc58fb6f9e0a12763
BatteryMeter: Make <15% text color less orange

ps2: use arrays and the existing level==>color code to affect
    the same change as the previous PS's java fix (that broke the text
    updating below 15%)

-Vanir

Change-Id: Ia2db9afcd424bc6a703ea0ff34b3d44dbcf88276
Multi-user support for phones

Allow multi-user support on devices that previously didn't have it without
hard-coding it on.

ps2: Give it the nuclear touch.
ps3: Correct initialization.

Change-Id: I376f3f51ee1d8843d0977384101f93e23e278c97
mediaeditor: Fix c++11 narrowing

Summary: Depends on D309 D310

Test Plan: verified

Reviewers: randall.rushing, jriordan001

Reviewed By: randall.rushing

Differential Revision: http://review.codefirex.com/D312

Change-Id: I34a0e0e0fc9879e6c4a12a1dd8375dd409042878
Signed-off-by: DHOMD <DHO@dho.im>
[1/2] base: add CPU info overlay

this shows
CPU temp (if available)
for every core governor + online + freq

PS3:
increased font size

PS4:
whitespace cleanup

PS5:
more of that :(

Change-Id: I8e2fd81edd8499eea2b1a6de8c042938387b33ef
systemui: turn off debugging

should be all of it

-VanirAOSP

Change-Id: Ia279a1be6968f67a4ad448cf51743f4c455af88a
allow showing rotation lock tile

Change-Id: I708e935dd490b998eea4fcce2378109a6904e53f
Improve the up/down arrows visibility

No idea why such a small image was made translucent.  Lets add some more
contrast and make these opaque.

-VanirAOSP

Change-Id: If57192bbe1c5527f4dba4ea8d511735ea021e640
updated progress bars from 4.3

slightly faster/smoother.. not overdone like the previous version

Change-Id: I9a97d3239734d3e9503c7cf4327bcb80ebfc5e94
Frameworks: Add network usage stats to status bar
Network stats: use number formating based on android code

Uses logic from Formatter.formatFileSize

Change-Id: I9008df0e90fbaf8d733cfd853dc1ef6160cf67f5
Signed-off-by: Dirk Rettschlag <dirk.rettschlag@gmail.com>
Don't show Netstats when there's no traffic

Change-Id: Ie90caabd52dcfb6889cf26da37d7c57974993ffb
Hide netstats on light out (this was annoying as fuck)

Signed-off-by: Arnav Gosain <nolinuxnoparty@gmail.com>
Frameworks: Add Music Tile (1/2)

Tap to play/pause. Longpress for next track

Author: kufikugel

Signed-off-by: Arnav Gosain <nolinuxnoparty@gmail.com>
Frameworks: Add missing permissions to kill apps
Facebook Sync Dirty Hack (Credit RomanB)
Hot reboot

Change-Id: Iebd56c590ac5ac8189dbffc64580f3a2aabb9016
Signed-off-by: Chester Kener <Cl3Kener@gmail.com>

Conflicts:
	services/java/com/android/server/power/ShutdownThread.java

Fix

Signed-off-by: Chester Kener <Cl3Kener@gmail.com>
Frameworks: Update missing google UI changes for 4.4

Change-Id: I5f608ee444ad86e7c1fc01004922d2086562fa61