Volumes in Settings/Sound is slow to start

There is a delay after pressing volume menu item
there is a delay until the Volume popup is shown.

The reason for this is that the initialization of
the different seekbars is slow and run in the main
thread. More specifically the call to get the
ringtone from the RingtoneManager is causing this
delay.

Moving the call to the ringtone manager to the
handler thread used to play ringtones to make
the launch of the volume dialog a bit snappier.

Change-Id: I76da0226592468debd542d67164b37b2b59897c7
Change SQL to improve performance.

To know the number of images, use "COUNT(*)" instead of "_id" in SQL.
Using "_id" gets all result set. and when getCount() is called, CursorWindow is filled.
But using "COUNT(*)" gets just 1by1 data.
So using "COUNT(*)" is more faster than now.
And this SQL is called everytime per a file during a file transfer in MTP
The better way is by using "EXIST".
But if using "EXIST", modify MediaProvider.call() method.
So i applied just a "COUNT(*)"

Change-Id: Ic5882af0fad2304f836b7b7043a4746359391609
Signed-off-by: muzbit.kim <muzbit.kim@lge.com>
Restore pre-KitKat permissions to external sd for all apps

Change-Id: Ib3ff52bcc47fd36e8f3fc5aefeaae4e56180e7c6
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.

Orig-Change-Id: I0e76441399f1ce74b83566edb8cf4f977dce58bf

Change-Id: I1884141d7d9c61601e2c8e07523a6e9aa6709afc
Signed-off-by: Pavan Kumar S <pavan.kumar.s@intel.com>
Signed-off-by: Jian Luo <jian.luo@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
Parallel shutdown

Decrease shutdown time by doing some shutdown tasks in parallel.

There are two threads executing during the shut down: the ShutdownThread
and a separate thread for the radio shutdown. However, the execution is
done in serial, as the ShutdownThread immediately joins on the radio
thread.

This commit will move the shutdown of the radio to the beginning of
shutdown and execute it in parallel to the shutdown of the rest of the
system.

The flow of the two threads during shutdown is now:

Radio Thread
  * Start shutdown of the radio
  * Wait for radio off or time out
  * Notify that the radio is done
ShutdownThread
  * Broadcast ACTION_SHUTDOWN as a parallel broadcast. (The receivers
    will get as much time to handle onReceive as it takes execute the
    rest of the tasks in the shut down flow. If they are not done in
    that time, we don't care.)
  * Shutdown ActivityManager
  * Shutdown MountService
  * Wait for MountService and radio to notify done
  * Vibrate
  * Low level shutdown

Change-Id: Ifdd8a9c75337fd9d00148a0d2b9917e10fa60634
Fix to memory leak leaving WallpaperCropActivity.

After running wallpaper cropper serveral times it crashes with
an OutOfMemotyException.

When leaving WallpaperCropActivity all textures are leaking until end
of process lifetime. This is due to a missing call to function
TiledImageView.destroy which in turn assures TiledImageRenderer
releases held resources.

Resolved by assuring WallpaperCropActivity calls TiledImageView.destroy
from WallpaperCropActivity.onDestroy. In case where onDestroy is not
called resources will be released anyway by process being brought down.

Change-Id: I016b1b9da5f4db8d2b14767edb59fe742415e074