Fix build
handle negative temperature

When the battery temperature drops to below zero, BatteryLevelInit()
fails to show negative temperature. Because the type is unsigned
and the size of bit field is 10 bits.
So to handle negative temperature, change the type of battery temperature
from "char" to "short". And extend the size of temperature bit field
from 10 to 11 bits, which first bit is used for the sign bit.

Before:
31             24                    14                 0
+---------------+---------------------+-----------------+
| Battery Level | Battery temperature | Battery Voltage |
+---------------+---------------------+-----------------+

After:
31           25                      14                 0
+-------------+-----------------------+-----------------+
|Battery Level|  Battery temperature  | Battery Voltage |
+-------------+-----------------------+-----------------+

Bits 31..25: battery level percentage (7 bits unsigned)
Bits 24..14: battery temperature (11 bits signed)
    First bit is used for the sign and others for the temperature
Bits 13..0: battery voltage in 0.001 volt units (14 bits unsigned)

Becuase of changing the format, let the BatteryStatsImpl.VERSION field
increment.

Bug: 8009514
Change-Id: Iaa12f4d3f14e6cf4d73bc1a23d81c60f9677a499
Merge branch 'jb43' of github.com:ModdedPA/android_frameworks_base into jb43
Fix a variety of small publicly-reported bugs.

Possible NULL dereference in cmds/bootanimation/BootAnimation.cpp.
https://code.google.com/p/android/issues/detail?id=61556

Missing fclose in core/jni/android_os_Debug.cpp.
https://code.google.com/p/android/issues/detail?id=61546

Bad loop guards in core/jni/android_util_Process.cpp.
https://code.google.com/p/android/issues/detail?id=61557

Assignment to wrong variable in libs/androidfw/AssetManager.cpp.
https://code.google.com/p/android/issues/detail?id=61560

Missing delete[]s in libs/androidfw/ObbFile.cpp.
https://code.google.com/p/android/issues/detail?id=61549

Leaks on error in tools/aapt/Images.cpp.
https://code.google.com/p/android/issues/detail?id=61552

Two missing fclose calls in tools/aapt/Resource.cpp.
https://code.google.com/p/android/issues/detail?id=61553

Missing fclose in tools/aidl/aidl.cpp.
https://code.google.com/p/android/issues/detail?id=61554

Change-Id: I5820f3824e72d07a9acb776cf0af3e7443f5694a
Squash of 30 commits fixing bugs, deadlocks, memory leaks etc (Thanks to Team Gummy and BytecodeME)

Fixed a leaked partial wakelock in AbstractThreadedSyncAdapter.
This fix ensures that onFinished() is always called in a syncClient
even if the application lacks the READ_SYNC_SETTINGS permission.
Fix error when cpufreq is loaded at runtime
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
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.
remove leak WaitResult List in startActivityMayWait
Signed-off-by: Young-ho Cha <ganadist@gmail.com>
Avoid unnecessary FindClass("java/lang/String").
Use previously retrieved global reference instead.
Check for NULL after creating the global reference.
Fix deadlock of WebViewCoreThread
There was a deadlock in destroy process.
Investigation showed that WebViewCoreThread is waiting some
callbacks but in this case WebViewCoreThread can not resume
itself not to call notify method.
Flow:
1. CallbackProxy.sendMessageToUiThreadSync
2. WebViewClassic.destroy()
3. CallbackProxy.blockMessages()
4. CallbackProxy.handleMessage is called via MainThread
5. The WebViewCoreThread deadlock is occured.
The cases we have to call notify method are followings.
OVERRIDE_URL
CREATE_WINDOW
SAVE_PASSWORD
NOTIFY
OPEN_FILE_CHOOSER
JS_ALERT
JS_CONFIRM
JS_PROMPT
JS_UNLOAD
JS_TIMEOUT
FastScroller: Fix to use appropriate index
Fix FastScroller to use appropriate index to determine the
the position of a section while calculating the y coordinates
of thumb. In case of last section, use totalItemCount to determine
next section position.
Prevent MediaScanner infinite loop with invalid path
including double slash  "/storage/sdcard0/xx//xxx/xxxx"
Consider mScrollX when drawing the checkMarkDrawable
When mScrollX has a very large value the checkmark will not show,
unless it is considered when setting the bounds of the drawable.
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.
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 DataInputStream leaks
Fix fixes
-In viewstateserializer, try to close before throwing or returning, and throw early if inputstream is null
-other stuff
build core/jni with fstrict
Conflicts:
	core/jni/Android.mk
Javacrash java.lang.NullPointerException in com.android.browser.
Provide a WebView interface in WebSettings, for BrowserSettings need to access it.
Author: Yijun Zhu <yijunx.zhu@intel.com>
Signed-off-by: Yijun Zhu <yijunx.zhu@intel.com>
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 34962
NPE in SearchManager.triggerSearch
mAssociatedPackage field is never initialized and cause NPE.
Fix WebView.loadData ignores encoding on Android 3.x and after
In WebView.loadData encoding parameter was ignored (expect if the value was 'base64').
Now, charset encoding is used to display the data.
The following call should display well.
webView.loadData("éàçèù", "text/plain", "utf-8") will display 'éàçèù' where it display garbage in version > 3.x.
webview.loadData("aGVsb68=", "text/plain", "base64") will still display 'hello'.
webview.loadData("6eDn6Pk=", "text/plain", "utf-8,base64") will show 'éàçèù' where it display garbage in the current version.
webview.loadDataWithBaseURL(url, "éàçèù", "text/plain", "utf-8", null) will still display 'éàçèù' if (url is null or different of "data:").
webView.loadDataWithBaseURL("data:", "éàçèù", "text/plain", "utf-8", null) will display 'éàçèù' where it display garbage in version > 3.x
This assure downward compatibility with the change made in 3.x
This fix a bug that appears in the 3.x android version.
Fix issues:
19747 http://code.google.com/p/android/issues/detail?id=19747
19306 http://code.google.com/p/android/issues/detail?id=19306
17163 http://code.google.com/p/android/issues/detail?id=17163
Sources:
- http://en.wikipedia.org/wiki/Data_URI_scheme
- http://tools.ietf.org/html/rfc2397
Amends:
rebased to 4.3
remove + string concat
remove "or base64" from the url encoded case
integrate jb remastering
integrate new comments style
Signed-off-by: Guillaume Châtelet <guillaume.chatelet@orange.com>
Memory leak: parseObbFile.footer
Signed-off-by: You Kim <you.kim72@gmail.com>
Fix NullException in QwertyKeyListener.KeyDown
Extending null protection for view to "c == i" case in addition to
"c == Character.toUpperCase(i)" case that helped to fix some force closures.
Seems as typo in original implementation.
Signed-off-by: Dmitry Tsyganyuk <fdt017@motorola.com>
Avoid IndexOutOfBounds Exception in ActivityManagerService
1. finishActivityLocked() doesn't give guaranty to remove only
   one ActivityRecord from the history stack.
2. Unfortunaly if our topRunningActivity is top of the stack,
   then there is potential IndexOutOfBounds Exception in
   ActivityManagerService.
To avoid it, we can just traverse to the top of the history stack.
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.
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.
allow customized memory cache size for webkit
ps2: add missing ;
todo: test and set this in vendor make files when an optimized amount is found
frameworks/base: Fix memory leak in BitmapRegionDecoder
When un-supported image is passed to bitmap decoder, mStream object
of SkMemoryStream class is leaking its resources. This is getting
called frequently when gallery app is trying to render unsupported
thumbnails in album view
fix null pointer exception in enqueuing
Scroll: modified velocitytracker
Velocitytracker and overscroll are called on every touch event to
calculate if there is a scrolling/fling. Move this and the recycling
to static voids so they are pre-optimized at compile time rather than
after evoking the method call during runtime (JIT) to increase responsiveness.
-Vanir
frameworks: squash of leak & race fixes
commit 5c837244a550308a6b8fadf95275d50f6bf3b202
Author: Daniel 2 Olofsson <daniel2.olofsson@sonymobile.com>
Date:   Mon Jun 10 14:49:14 2013 +0200
    Fixed race condition in Spinner.DialogPopup on null reference.
    NullPointerException is triggered when DialogPopup is
    dismissed due to object mPopup being null when not showing.
    Race condition is triggered when dialog is dismissed before
    touch event to dismiss dialog has been processed properly.
    Fixed by adding a null check prior to accessing mPopup object.
commit 4950d85c29bed35c0874858d094d5a0f628f1e54
Author: Pawel Augustyn <pawel.augustyn@sonymobile.com>
Date:   Mon Jul 16 11:23:54 2012 +0200
    Fix for native leaks in YuvToJpegEncoder.cpp
    Objects allocated by Get<object>ArrayElements function,
    should be released. Add a fix to release this objects
    in error cases.
commit 463ac945502552ab0c06ae00c987d3c400161fe3
Author: Michal Szynkaruk <michal.szynkaruk@sonymobile.com>
Date:   Wed Jun 26 11:28:36 2013 +0200
    Fix for MemoryLeak in InputMethodService
    Problem: when onConfigrationChanged is called many times,
    mInsetsComputer is added many times to the list.
    Solution: check before if specific listener is already
    in the arraylist.
commit 5167ab57b2a1dbee38a5303e4b490a04b9dff950
Author: Pavan Kumar S <pavan.kumar.s@intel.com>
Date:   Fri Aug 3 12:03:01 2012 +0530
    [BatteryStatsImpl] Avoid memory corruption due to Parcel Recycling
    While processing batterystatsfile, in present code there is a race where a parcel
    might be recycled while it is being written to disk in another thread.
    The write process is done in 2 steps:
    - write into a Parcel (memory block)
    - then write this Parcel to disk using Journaled API.
    The Journaled API ensures robustness against file-system issues due to power cut.
    The writing is done in batch using a thread running commitPendingDataToDisk().
    This function writes the parcel to disk but this parcel is a global variable
    initialized by writeLocked(). If the writing takes too long time and two write
    threads are launched, the parcel is freed by the second writeLocked() call;
    which could cause the memory corruption.
    Hence, change global Parcel variable by a Parcel parameter to commitPendingDataToDisk()
    and only this function will be allowed to recycle the parcel.
    Signed-off-by: Pavan Kumar S <pavan.kumar.s@intel.com>
    Author: Pavan Kumar S <pavan.kumar.s@intel.com>
    Signed-off-by: Shuo Gao <shuo.gao@intel.com>
    Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
    Signed-off-by: Jack Ren <jack.ren@intel.com>
    Author-tracking-BZ: 47466 19426
commit ab625310c19573caf5cdcf4c6ef573bbfbc8a26b
Author: Vairavan Srinivasan <vairav@codeaurora.org>
Date:   Mon Jun 6 13:42:54 2011 -0700
    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.
    Conflicts:
    	core/java/android/service/wallpaper/WallpaperService.java
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.
Fix for NullPointerException in HTML5VideoViewProxy
There is a missing null check of mHTML5VideoView.
services: make sure to recycle set args
2 minor leaks found here in the screen magnification service
potential GraphRunner leak in camera effects
if the camera FCs while recording effects.. *poof* a tiny leak is born.
so.. we close mRunner onDestroy.

Change-Id: Iffd349f1b3fe53b05f90c5bd3e45b3cd72074a47

Conflicts:
	core/java/android/service/wallpaper/WallpaperService.java
	media/mca/samples/CameraEffectsRecordingSample/java/android/media/filterfw/samples/CameraEffectsRecordingSample.java
Fix for the below commit
Merge branch 'jb43' of https://github.com/ModdedPA/android_frameworks_base into jb43

Conflicts:
	core/java/android/provider/Settings.java
Merge branch 'jb43' into multiwindow

Conflicts:
	core/java/android/provider/Settings.java
	policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java