ANR caused by incorrect cleanup in BroadcastQueue.

Two broadcasts could be sent to the same app simultaneously:
one foreground, one background. For example, LOCALE_CHANGED
and PACKAGE_CHANGED are delievered to com.android.vending
at the same time.
1. AMS started new vending process to handle LOCALE_CHANGED.
   And set app.curReceiver = LOCALE_CHANGED.
2. Before LOCALE_CHANGED is handled by vending process,
   PACKAGE_CHANGED was delievered to vending process too.
   AMS set app.curReceiver = PACKAGE_CHANGED. Bad!
3. Vending process finished handling LOCALE_CHANGED.
   AMS clear app.curReceiver = NULL. Bad!
   And Vending process  killed itself without handling
   PACKAGE_CHANGED.
4. AMS known vending process has died, but didn't know that
   BgBroadcastQueue was still waiting for finish message
   for PACKAGE_CHANGED.
At last, BgBroadcastQueue reported ANR for PACKAGE_CHANGED.

This patch adds protection before clearing app.curReceiver,
only set to NULL if the finishing receiver = app.curReceiver
So handleAppDied would know that PACKAGE_CHANGED was not
finished yet, it will abort the broadcast and continue.

Change-Id: Ic4f31b35e21823d4a3c27712391ecbede213a494
Signed-off-by: Guobin Zhang <guobin.zhang@intel.com>

(cherry picked from commit 3eb195804271b36ce2a32172491c58b3f1c20202)
Fix Presentation window is removed on stack change

If an activity show a Presentation window and this activity is moved
to bottom or top, thus this Presentation window will be removed from
its display window list, and no chance to be added back into window
container; It will cause the incorrect state that Presentation window
is lost from secondary display window list(displayContent.mWindows),
but still exist in app token's window list(appWindowToken.allAppWindows);
Moreover, once this activity resume again, Presentation window is not
shown because it's lost.

In this way, don't remove non-target display app windows due to only
target(or called default) display windows are removed temporarily and
re-sorted then added back into window list later.

Change-Id: I8960ce191f6c662455cba5a0a5e6a1ff9ef03ae1
Signed-off-by: tingna_sung <tingna_sung@htc.com>

(cherry picked from commit 96625654ddc92d77cb997f60a444d4ce12f8f29f)
Sync focus stack frame and layer with focus app.

Update focus stack frame/layer when focus app is changed to avoid
focus stack/layer isn't updated synchronously with focus app, it's
due to performLayoutAndPlaceSurfacesLocked() is not necessarily
called on focus app change; it will cause sending mismatching
TAP_OUTSIDE_STACK message if there is effectual incoming pointer
event, hence may also result in focus stack is changed again,
therefore erroneous focus app is set by ActivityManager at final.

Change-Id: Ia0ec9a543be887b51a3b29b3e62fdd471c15edf2
Signed-off-by: tingna_sung <tingna_sung@htc.com>

(cherry picked from commit 261c239feb50bd102d8b9e54b22025017dbdbd7a)
Not include fullscreen opaque window on screenshot

Extend the fullscreen meaning by adding opaque drawn check on
screenshot application; if there is a fullscreen window but not
opaque, we will continue finding behind windows; otherwise ending up
including behind windows. It's able to help avoiding capturing BLACK
screenshot bitmap.

Change-Id: I1c7e8f513c366688ea8001c3d0c799f3522f0ffd
Signed-off-by: tingna_sung <tingna_sung@htc.com>

(cherry picked from commit 3170548c62abb6e2372d07a45589e954dc79925a)
Measure absolute value of pointer motion distance

If pointer is moving to the negative axis direction, pointer movement
distance will always less than pre-defined mMotionSlop, thus
TAP_OUTSIDE_STACK will have chance to be sent, will cause unnecessary
focus stack switch.

Change-Id: Ia4c066bebce250257c7361ef976907a0ca2c6461
Signed-off-by: tingna_sung <tingna_sung@htc.com>

(cherry picked from commit 66700c723b0125018795beea06bfab8af6f39f6e)
Start MountService before performBootDexOpt

This change is to start Mountservice before starting
performBootDexOpt, as in one case, in performBootDexOpt
when system upgrade happens, StorageManager will be started to
get the low threshold of DataDir. But, at this point, as
Mountservice is still not up, StorageManager will end up
having a null object of Mountservice.

Change-Id: I6dec474266faa5de67449c1bbe6ef30791e5ecaa

(cherry picked from commit b461f80a6b94ff9266c6b01f46946790b025b98e)
Add window to child window list with correct order

The original logic of comparing with mBaseLayer of two child windows
of the same parent was wrong, because the mBaseLayer is always the
same.

After adding two child windows with the same positive sublayer, the
one added later should have greater z-order. The order should be
consistent with WindowManagerService.addAttachedWindowToListLocked()

Change-Id: I789179aee61d141fad86bd24262fabfb1e517e66

(cherry picked from commit e7cd76d5ecdd21f0f86ae4be1d8a32be22635d3f)
Intercept Home button press to wake device

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

(cherry picked from commit 3ddf1931eba0b1d9e7025d902fba04129cd32d85)

Conflicts:
	policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
Frameworks: Option to enable/disable HOME button wake

Dependency commit:

Intercept Home button press to wake device
https://github.com/temasek/android_frameworks_base/commit/3ddf1931eba0b1d9e7025d902fba04129cd32d85

(cherry picked from commit 56a65db31a0048aa4f07fe6d3fecc5b6e0613a37)

Conflicts:
	core/java/android/provider/Settings.java
Fix the layout of the network speed indicatior

Conflicts:
	packages/SystemUI/res/layout/status_bar.xml

(cherry picked from commit 07b25a7099ddf7f34f18657be618d63f627215b1)
Revert "Add missing network indicator items"

This reverts commit c4393b91efa02b69f41b100c01eafb982e03134c.

(cherry picked from commit 287a63a6b9d9986842149a5a1e961147eac4d89b)
[1/2] TrafficMeter: added option for auto-hiding on inactivity

Together with inactivity threshold

Thanks to @C3C0 for the code

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

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

(cherry picked from commit 49f0ec234e58d5b834663310f2b5495475957562)
TrafficMeter: fix auto hiding when Bytes is set as the unit

(cherry picked from commit f51a67ff9d19c9a7dca4fd3fa1b14459ea2bfa78)
Recents: Port "Development shortcut" (2/2)

This patch includes the equivalent of our Development Shortcuts in
CM11 recents. Recents is very different now and this is mostly a rewrite.

The semantics changed a bit as well. The current code already has special
developer behavior when long-pressing the app icon and that is also where
the developer shortcuts are hooked. If the app icon is long-pressed and
developer shortcuts are active, a menu will be shown with the several available
options.

Fixes CML-61

Change-Id: I391a360b3dd88e179c2315503d18125f8d0b3792

(cherry picked from commit 552943ca153aec19ab8598f1fe4e419718744e51)
SystemServer: Move sensor init to a new thread.

Move Sensor init to a separate thread so that it doesn't block the
critical booting path.

Initializing Sensors in separate thread has been seen to improve boot
time on customer devices with low-tier / ult chipsets(less cpu cores)

Change-Id: I5c46a5805c04ffe551019b4683523e3bf70274a2

(cherry picked from commit 3e31f300bbc0152ee065725daa79ed937ea91e7c)
Disable config item to support SIM refresh for dual mode card

Set "config_sim_refresh_for_dual_mode_card" to false;
Resetting this config as majority of the targets don't
need it to be set.

Change-Id: I955fead91e4939172a478fba2b79ae11fecda82b
CRs-Fixed: 665741

(cherry picked from commit 99c2a065e3dfe67e5de0bbfe47601d1c2974c450)
Telephony: Add a config item to control fetching APN from OMH card

Change-Id: I5c14a6870ea0767cc14ff3addeeb0828cc704a32
CRs-Fixed: 748148
(cherry picked from commit 41990ea1599382b7edf69fa2de8bea180393fe41)

Conflicts:
	core/res/res/values/config.xml
CamcorderProfile: Add 4k DCI timelapse encoder constant

 4k encoder constant during timelapse is added
 for the 4k timelapse use case.

CRs-Fixed: 642013
Change-Id: I901fa362242477dad84130d23055815cdfee6167

(cherry picked from commit bc68e96f0511753c53046beaeb5c0af4b6d520fc)
security: prevent FDE after PFE

Full-Disk-Encryption (FDE) is not allowed
after Per-File-Encryption (PFE) is activated.

Change-Id: I17e6039f3b33450835fea6ee5e612c079868b71f

(cherry picked from commit 14527e0dba352ec497ea72f14d942c88a5358a27)
QuickBoot: enable poweroff charging under QuickBoot mode

Support poweroff charging by enable/disable qbcharger process under
QuickBoot mode.

Change-Id: I34ee10443564ba3f9ebc7239137958c80e8db6c9

(cherry picked from commit 0de7eca52a141d830d68cfb6acb64adef5f7e57b)