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 95f8e177434bd1fe3c2d6908d4326c0e33a44ab6)

(cherry picked from commit 200e62948f783378d4466633357a8dec977baee1)
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 fd782d839e22e948baa630a4aa2527737668c2ef)

(cherry picked from commit fd9b658b141726e05e7e1faa5b3cd3d4c8ae1b64)
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 9a2e6dbe296610f7113b70f49aac788b19197200)

(cherry picked from commit 87e397c1e50346ffa95d673f3ccde4d287232a4b)
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 8db56961feacefb92f1ec7fbb05f6067a53a7332)

(cherry picked from commit c93041b26d0afe2b2a49ff51567038dadf0087f4)
Scale down the wallpaper image if it is larger than the surface frame

Let the wallpaper can fit the screen if the wallpaper is larger.

Change-Id: Ie4116dc0386c7b390a6a71608b09645cd08ffe78

(cherry picked from commit b5168e01b688431757b0c17a1fc9c712ad5f3cb1)
[ActivityManager] Improve task order of getRunningTasks.

Symptom:
During switching task in same stack, the first result
of getRunningTasks will be the behind stack's top task.
e.g.
 App Task X is starting task Y, the first entry may be home.

Root Cause:
TaskRecord's lastActiveTime is updated when pausing
or resuming. When X task launch a new task Y, Y is
on the top of task history, before X complete pause,
Y's lastActiveTime will be 0 because it is a new task.
Then when comparing the front task with other stack,
other stack will be regarded as the newer one.

Solution:
If the stack is focused stack, give the top task with the last time.

Change-Id: I0adc07608e03d333e0120a0dbc52a0fbbbb12f34

(cherry picked from commit c6a859126416f62d010c1d552086c167bd5c8d83)
Remove the window whose client process has died or become zombie

Window Manager Service would fail to report window-resized to the
process which has become zombie. This would cause the window to
freeze screen continuously. In this case, we assume the process has
died and remove its window to recycle resources and to prevent it from
freezing the screen.

Change-Id: Ic7384731bf9a1fa8b9602d4f1dbee7492db126c5

Conflicts:
	services/java/com/android/server/wm/WindowManagerService.java

(cherry picked from commit 19bab687f81e15be2b45e32d16d6dee282fbe8fb)
core/res: resolve merge cruft

related to: https://github.com/AOSPA-legacy/android_frameworks_base/commit/359efbc589a3656866f4c2517a666428b7e6aa71

Change-Id: Ic992a9ef286d40ee26c6ae9db2428eb6c00d010f