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>
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>
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>
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>
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>
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
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
pm: Add persist property to enable lazy dexopt

 * Add "persist.sys.lazy.dexopt" property to enable lazy dexopt
   on userdebug builds.  As much as I enjoy these 20 minute
   dexopt sessions, I prefer instant gratification.

Change-Id: I568692f04d67c3c0a1a138fb724eda41e24b1235
Frameworks: Do not show privacy guard notification on lockscreen

Does not really makes sense to notify on lockscreen that the background app is
privacy guard protected. Notification in statusbar is more then enough.

Solve it with simply tagging the notification and check against the TAG

Change-Id: I908a7e6d35507e487ca799496616e391a469191d
Merge commit 'refs/changes/11/18911/1' of https://gerrit.slimroms.net/SlimRoms/frameworks_base into HEAD
Frameworks: : ADB_NOTIFY moved to Global

Change-Id: I3f32b1c241ed23409661ce7b45530fec4b082088
Systemui: Recents - do not add search widget on recents if widget is lost.

We have reports that sometimes under special circumstances the widget gets lost
and the view is added nevertheless

Ensure that if the widget loading fails that the id is set back to -1 to remove
the view.

Change-Id: I62f8dcea19817a243a001c80b6a4ab7b1e31a990
Frameworks AppOps: Enable MODE_IGNORED for OP_WAKE_LOCK

  *) Kitkat commit log highlights that the current
     implementation state is for auditing only
     https://android.googlesource.com/platform/frameworks/base/+/713df150b92a0a5eea877f99405e31eefbf93a09

  *) We go one step further and honour MODE_IGNORED
     when for OP_WAKE_LOCK.

Change-Id: I889227ca24a508a0d96bd43594c5179ba758ae3d
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
Framework/base: Relocating GC calls at the end of loop during zygote init

Relocating explicit GC calls at the end of the loop during the preloading
the resources and preloading clases, with this changes boottime improved.

Change-Id: I2e05ef68578eddca8cd435b5186e198ee7d71739
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
security: prevent FDE after PFE

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

Change-Id: I17e6039f3b33450835fea6ee5e612c079868b71f
AppOps: Add null pointer check for USERAGENT parameter.

Fix the Java exception which is caused by null pointer issue in
AndroidHttpClient.

Change-Id: If7e36298f94ca164b87e1b0604f49156bdfd4513
frameworks/base: No score update to 100 with wqe

When user explicitly selects an AP, the score of this AP will be
set to 100 and this has conflict with wqe. Disable this when wqe
is enabled

Change-Id: I57db8318a4421038d144bc41bd0ff5ae02d9edd3
AlarmMangerService: Fix the delay of ACTION_TIME_CHANGED for time-services

After boot completed, if low memory condition happens or some ordered
broadcasts have time out, it will cause delay for some receivers to
receive ordered broadcasts. Adding FLAG_RECEIVER_FOREGROUND into
time changed action will make TimeServiceBroadcastReceiver receive
ACTION_TIME_CHANGED in time.

CRs-Fixed: 630982
Change-Id: Id789d0b3c969af6b92f62612602ba119613382ab