frameworks/base/: Fix black wallpaper issue when home pressed.

In the specified usecase, there is a completely new set of
windows that appear on the screen during rotation. And the
existing code in the framework ignores the drawstate of the
hidden windows.

Wait till the drawState is ready for the hidden windows also.

CRs-Fixed: 521758

Change-Id: Ibd96502059c84210ad84ecb03aac5eca28f3c9fe
(cherry picked from commit 3384b25ae83a535e05a58a16941555b6ee7005f3)
(cherry picked from commit 2fa1eea7fd819b11ee6cc8f8f6921fdaeeabb4bf)
base: App crash when select suggestion's length more than specified.

App crashed by catch IndexOutOfBoundsException which raised
by check span range when select suggested string.The root
cause is that the editor will truncate the suggested string
which length is more than it specified, but it also set span
use the suggestion's original length.

Update the suggestion's real length after editor replace the
original string to suggested.

Change-Id: I2d765701934a9e68be172cb87a104590f3cdeceb
CRs-Fixed: 532211
Magnification: Fix screen freeze after activity resumes from rotation

mMagnifedViewport.onRotationChangedLocked() will call setShown(),
and then cancel a anime. As the anime should be only canceled in
a looper, if it is executed in the onRotationChangedLocked() of
DisplayMagnifier, a crash will be caused. Therefore when the
magnification is enabled, the activity will crash after rotation.

Move mMagnifedViewport.onRotationChangedLocked() from main thread
into the handler. When MESSAGE_NOTIFY_ROTATION_CHANGED is received,
execute it. As handler is created with a looper, the crash will be
fixed.

CRs-Fixed: 541799

Change-Id: I2a78f24f73d5a9b8693e557d18e2fb01fcaec8fa
frameworks/base: Fix the random UI corruption

On low memory device, when a view goes to background. Its HW layer cache
will be destroyed to release memory. There is a very rare case that the
hardware render is not valid when destroy the layer, so the layer is not
destroyed and reused when the view comes to foreground. But the GL
context has changed, so the view is not rendered correctly due to its
HW layer cache. To fix this issue, destroy the layer in a safelyRun. Make
sure the layer is destroyed correctly.

Change-Id: I1c714e1d53db7353d5169e874a7cd0f527c3f67b
CRs-Fixed: 623239
lowmemorykiller: Overwrite LMK parameters for low-tier devices

LMK parameters calculated by default algorithm were not optimal for
low-tier devices. Values mentioned here were well tested and
evaluated w.r.t memory and performance for such setups.

Change-Id: I40ed92d204aae6e758028ea1e9bd4ec7226dbe2b
hwui: Always enable the scissor while composing layer

Due to scissor optimization feature added in KK, scissor was disabled
all the time. Hence the undefined areas/region of textures are not
masking properly with GL_LINEAR filter mode.

Change-Id: Ifbbde2c67a4c01e45eda07ada709e066255fffcb
CRs-fixed: 645077
Fix a resource race bug in PathCache

When enabled defer rendering, it will do precache for DrawPathOp.
The paint used for creating PathTask in precache just get the address
of mFilteredPaint of OpenGLRenderer. So for the following defer
operation like DrawTextOp has possibility change the mFilteredPaint
by getPaint while another WorkerThread in PathCache is using the paint
which pointed to the same address of mFilteredPaint to generate bitmap.
As a result, it will generate a wrong bitmap for generateTexture in
PathCache. To fix it, do a copy of paint when creating PathTask.

CRs-Fixed: 664244

Change-Id: I5516f5b143458b88d3573d15b7ebb34f688800c7
Add reboot reason to detect device shutdown

This change will detect silent device shutdown

Change-Id: Ia3c13e372b02dd4d3ec4a99d1c1f7c4787977ac3
Fix the texture ID reuse issue in HWUI.

Issue: When the layer of previous frame is destroyed, it doesn't clear the
texture id in mBoundTextures[mTextureUnit], so in the next frame, if
glGenTexture returns same texture ID of the previous frame,
the new texture is not bound.

CRs-fixed: 671736

Change-Id: Ifc5fd2115fb1863b3c006ab14b0faabeaeb4eab4
Prevent killing of process during service bringup

ActivityManagerService sometimes kills the process whose service
is being brought up during bindService.
This happens when the process starts hitting some Pss threashold.
Specifically this is causing InCallUI process to be killed during
bind request from Phone app.

CRs-Fixed: 681329

Change-Id: Id548a22d7e7ce3aa0b0511763078f813fafd6e16
Fixing parcel leaks to avoid virtual memory leak

Client has to call recycle() on parcel object after its usage
otherwise native layer of binder won't clear the resources of
parcel which were allocated for IPC

Change-Id: Ib31ddcc92aa4ebd80bb66729922b9133692e9c9e
ActivityManagerService: Fix heavy games kill during incoming call

Force heavy apps penalisation only to large "cached" apps. Donot
include "previous" app in this category. This ensures large apps
are not killed during special incoming alerts like incall, sms.

Change-Id: I51b4a238415efad63ef36f7e0cd056823a72a47d
Fix visibility of multiple non-fullscreen activities.

Issue detail:
Assume X, Y are non-fullscreen activities.
 a.Home starts an activity X in task A in application stack.
 b.X starts an activity Y in <task A> or <new task B>
 c.Activity X will be invisible.

How to fix:
Because the function "isActivityOverHome" means an activity is able to see home.
But there may have many non-fullscreen activities between the top non-fullscreen activity and home.
If flag "behindFullscreen" is set, those middle activities will be invisible.
So it should only take care from who is adjacent to home.
Then check two flags frontOfTask(task root) and mOnTopOfHome for constraining the condition.

Change-Id: I60bcea304976414e44835a0a38675aae365e9e19
Make SurfaceView layers captured by screenshotApplications()

Since SurfaceView layers are located below application layers,
SurfaceView is not captured by screenshotApplications()
when the application is running in fullscreen.

Moreover, ws.isFullscreen(dw, dh) returns mostly true
on the devices which do not use the navigation bar.

Change-Id: Ia1036c79054950384a97504714929fd85c8147de
Signed-off-by: Sangkyu Lee <sk82.lee@lge.com>