Fix to avoid NullPointerException in RecentsPanelView

The content of mRecentTaskDescriptions is loaded in an AsyncTask
in RecentTasksLoader and mRecentTaskDescriptions can occasionally
be null. Added checks to avoid NullPointerException in RecentsPanelView.

Change-Id: I4bb9d39f4bfca948d836114e9792370c36863b45
Finish the window in onItemLongClick() to replace in onStop().

Event will send to new activity to replace "Choose an action" activity.
ANR is voided.

rootcause:
The ResolverActivity is finished in onStop() and causes window state is abnormal.

Change-Id: I926fa4a47ecd04f1f211b29f757dcee720b09dee
Author: Bing Deng <bingx.deng@intel.com>
Signed-off-by: Bing Deng <bingx.deng@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: 59540
Prevent SystemUI crash by limiting the number of popups on long click

Recent apps screen shows multiple popup windows by long click
for multiple items. Sometimes outdated popup windows left causes
SystemUI crash. By only having single popup window, SystemUI crash
can be avoided.

Bug: http://code.google.com/p/android/issues/detail?id=66376
Change-Id: Ifc2fbe797a2350ee9ce01092caf6087fab08d0ae

Conflicts:
	packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
Allow line-breaking after close punctuation

Improves the approximation of the Unicode line-breaking algorithm in
StaticLayout slightly.

Change-Id: I9f8a3eed1904bd8482bb5cee4fb7b00ee6667df1
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

Conflicts:
	services/java/com/android/server/power/ShutdownThread.java
Release SQLite page cache as much as it can

Call sqlite3_release_memory() until it returns 0

Change-Id: Id7a0942805c2c3ad5a7efe8bc3ecd8b7fffbf75b
fix wrong transparent computation when background is transparent

1. when a view is set to be WILL_NOT_DRAW, it would check if the background is
null or not, to change mPrivateFlags follow rules:
    a) background is null, add the flag PFLAG_SKIP_DRAW
    b) background is valid, remove PFLAG_SKIP_DRAW and add PFLAG_ONLY_DRAWS_BACKGROUND
so when flag has PFLAG_ONLY_DRAWS_BACKGROUND, it must exclude PFLAG_SKIP_DRAW.

For transparent region computation, the function gatherTransparentRegion check
"non-PFLAG_SKIP_DRAW" case firstly, but it's wrong for PFLAG_ONLY_DRAWS_BACKGROUND
case,since it always has no PFLAG_SKIP_DRAW, it will always match the "if" part and
never go to the "else if" part, and always be taken as a non-transparent region
without checking background properties, which is wrong behavior.

So check PFLAG_SKIP_DRAW and PFLAG_ONLY_DRAWS_BACKGROUND here at the same time to
get the correct transparent computation.

2. In applyDrawableToTransparentRegion, getTransparentRegion of Drawable returns null
sometimes if subclass not implemented, so add opacity check here to make sure get the
correct transparent region.

3. Visibility change can also influence transparent region computation, so request
layout here to make sure the correct result.

Change-Id: I0978e022add002b94541b14c149ec8990e728ac7
Signed-off-by: Shuo Gao <shuo.gao@intel.com>
Reviewed-on: http://android.intel.com:8080/130698
Reviewed-by: Yao, Yong <yong.yao@intel.com>
Tested-by: Chen, HuaqiangX <huaqiangx.chen@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: 120472
[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.

Change-Id: Ifecb2dd132a75334c821df2269b974db93f9a892
Author: Pavan Kumar S <pavan.kumar.s@intel.com>
Signed-off-by: Pavan Kumar S <pavan.kumar.s@intel.com>
Singed-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
Audio: Fix abnormal keytone playback during silent mode changing

Change-Id: I603dbf70615b25dfad846235b97be5eb2731617e
Origin-Change-Id: I29e8673bb8305d96d5adc0a7e82b9bb9bcb3e7de
Orig-Change-Id: I5240aa118d3eeb7c630b2e03abe5536c26e6a405
Orig-Change-Id: I70e634beaedf5a9220d7b36224bad7b5c0a164f3
Author: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: ezhao3X <ertaox.zhao@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: 19084
Fix 'input rotationevent' sometimes not working issue

Observers exist for both Settings.System.USER_ROTATION and
Settings.System.ACCELEROMETER_ROTATION config values, and
updateSettings() may get wrong rotation status if these two values are
set separately. Use "mLock" to protect this situation and make sure they
are set together.

Change-Id: Ic89e6f14b45ee839c518e135096ae18d27f0a809
Signed-off-by: Carton He <carton.he@marvell.com>
Fix leaking starting window issue

Currently monkey test can result in many "starting window" surface
layers leaked which occupies ION buffer and can cause other ION
allocation failures before reclaimSomeSurfaceMemoryLocked kicked in.

Force to remove those "starting window"s when they have not been on
screen for long time.

Bug: http://code.google.com/p/android/issues/detail?id=59885
Change-Id: Ib2f624632b598f26388395f47516f697b343e2cb
Signed-off-by: Carton He <carton.he@marvell.com>

Conflicts:
	services/java/com/android/server/wm/WindowManagerService.java
Remove unused local variable (pkg) in ResTable::getEntry method.

Change-Id: Ibb40cdd3dc3d4611078e2d3e94695a65aae7c412
Fix a bug in getInstalledAccessibilityServiceList()

Steps to reproduce:
1. Run Unit test, such as CTS test:
run cts -c com.android.cts.jank.ui.CtsHostJankUi -m testScrolling
2. Press Home key to go back home screen.
3. Enter Settings->Accessibility at the same time.
Then we can see the Settings force closed.

The UiAutomationService's ResolveInfo is null. AccessibilityManagerService
should not return its AccessibilityServiceInfo to client (such as Settings
app) in getInstalledAccessibilityServiceList() method.
getInstalledAccessibilityServiceList() should have removed the
AccessibilityServiceInfo that for UiAutomationService, but it incorrectly
removes UiAutomationService itself now.

Change-Id: I790d87c7d4bc069d63fe83026b1c8cff8af87ab9
Signed-off-by: hanpengx <pengfeix.han@intel.com>
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>
fix some CTS problems

Some CTS test cases which are to test a long-click availability on a
view fail if "long_press_timeout" would be changed. For instance, if
we would change "Touch & hold delay" setting to "medium" or "long",
the following test cases fail.
  - GestureDetectorTest#testOnTouchEvent
  - View_UsingViewsTest#testSetupListeners
  - AbsListViewTest#testGetContextMenuInfo
These test cases call TouchUtils.longClickView(). ThelongClickView()
uses ViewConfiguration.getLongPressTimeout() to get
"long_press_timeout". However the method will always return a
default value '500' if it would be called from non-main thread.
CTS test case runs on non-main thread. So longClickView() should
read the value from SettingProvider.

Change-Id: I19465678a1f6a10b93262263975d612b386856f9
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

Conflicts:
	core/java/com/android/internal/os/BatteryStatsImpl.java