LightsService: Turn light off after pulse

Turn the light off after a pulse instead of resetting the light
to the pulse color and leaving the light solid on.

Change-Id: I711e8f01c72cc1dd1c80908c74c17ad55d80c57e
Restore untrusted glStencilMask value on resume after functor

Fixes an issue where the stencil buffer is corrupted
(used in overdraw debugging, path clipping) when used in
conjunction with a HW accelerated WebView.

bug:15023700
bug:16465551

Change-Id: If201b503931380f7107a34e9a9a2f877a50f72b1
[ActivityManager] Ensure provider external access count will be released.

Sympton: Oom-adj of provider process will be always 0.

Root Cause: Exception happend in openContentUri
may not call removeContentProviderExternalUnchecked.

Flow:
application [MediaPlayer.setDataSource(Context context, Uri uri)]
    uri is invalid, IOException will be caught and below log will appear:
    "Couldn't open file on client side, trying server side"
    Continue to call setDataSource(String path, Map<String, String> headers)
 ->mediaserver [MediaPlayerService::Client::setDataSource]
    setDataSource(httpService, url, headers) calls openContentProviderFile
 ->system_server (ActivityManagerService) [openContentUri]
    Increase externalProcessNoHandleCount for media provider.
    Call [openFile] to media provider.
 ->android.process.media [check permission for openFile]
    enforceReadPermissionInner
 ->system_server [checkComponentPermission]
    Use mediaserver's uid to check READ_EXTERNAL_STORAGE
      -> not granted due to it is pure native process, not a known package.
    Throw security exception then the flow of openContentUri is broke.
    And externalProcessNoHandleCount is unable to decrease.

Application sample code:
 String invalidId = "54321";
 Uri externalUri = MediaStore.Files.getContentUri("external");
 Uri uri = Uri.withAppendedPath(externalUri, invalidId);
 mediaPlayer.setDataSource(mContext, uri);

Solution: Move removeContentProviderExternalUnchecked to finally block.

Change-Id: I75eec1f9631e9c6bb18449946d707d51ac21e8a7
[ActivityManager] Fix ServiceRecord leakage

Symptom:
The first step of cleaning up application services is
to clear the app state from services (which set sr.app
to null). Then it clean up the service connections.
In some scenario, the Service might be removed during
the connection cleanup (i.e. the Service is no longer
needed). In that case, the Service will be removed from
ServiceMap, but won't be removed from r.app.services
(line 1612) because the r.app is null.

Solution:
Remove the service connection first.

Change-Id: I644d73af58fe0e7c1c4a6c9779fe6b5d747b880d
[ActivityManager] Finish the failed-to-pause activity

Symptom:
In some scenario, the mPausingActivity may be replaced by other activity.
When previous activity paused, the completePausedLocked() won't be invoked
because it is no longer the mPausingActivity. If the activity is also
pending to finish, it would never be done because the activity kept in
PAUSING state. Since the activity's window also remain visible and is
above on Wallpaper, user would see it when back to home.

Solution:
Finish the failed-to-pause activity if the activity is pending to finish

A Real Case:
(1) Screen turn off
(2) The top activity T1 crashed
(3) When finish activity T1, the next top activity T2 will be scheduled
    to resume and pause (due to screen off).
(4) The activity T2 is also set to finishing due to T1 crashed.
(5) Before T2 paused and before paused timeout occurs, there has a new
    process started which brings up the next top activity T3 to resume
    and pause. So the pausing activity is now replaced.
(6) When activity T2 paused, it cannot completed the pause operation.
    T2 will remain in PAUSING and finishing state with its window visible.
    The process won't be killed because the oomadj stays at 1 (Visible).

Change-Id: Ib10fded891b21c774b26a93071c717fa50516e22
ContentProvider: Avoid duplicate initialization of AsyncTask

AsyncTask is being initialized by ActivityThread to ensure its static
handler initilization and ContentProvider need not duplicate the logic.

Change-Id: I48bc88bdba32b56114f09c04a75480e26508f704
[ActivityManager] Fix index out of bounds when updating next pss time.

Symptom:
System server crash.

Root Cause:
The value curProcState for array index is -1 if the process has not attached yet.

Solution:
Skip compute for process which is not attached or have invalid curProcState.

Change-Id: I71aaf45bb78d73097ebe9dfebf76b72f2d243232
[ActivityManager] Fix NullPointerException when dumping ContentProviderRecord.

Sympton: If there is external access without handles, dumpsys will met exception as:
  * ContentProviderRecord{45ed0fc8 u0 com.android.providers.media/.MediaProvider}
...
    externals=
Exception occurred while dumping:
java.lang.NullPointerException
	at com.android.server.am.ContentProviderRecord.dump(ContentProviderRecord.java:171)

Root Cause: External handles may be empty but there is "no handle" count.

Solution: Check null and print with handle, no handle count.

Change-Id: I0ee497096113e5685d491a0d4346f57d398495e6
Revert "ContentProvider: Avoid duplicate initialization of AsyncTask"

This change leads to soft reboots.
To reproduce:
  *) Take a screenshot
  *) Share it a few times
  *) The chooser dialog should appear but instead the system dies

E/AndroidRuntime( 4993): *** FATAL EXCEPTION IN SYSTEM PROCESS: PowerManagerService
E/AndroidRuntime( 4993): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
E/AndroidRuntime( 4993): 	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6027)
E/AndroidRuntime( 4993): 	at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:820)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.view.View.requestLayout(View.java:16455)
E/AndroidRuntime( 4993): 	at android.widget.AbsListView.requestLayout(AbsListView.java:1972)
E/AndroidRuntime( 4993): 	at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:814)
E/AndroidRuntime( 4993): 	at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6482)
E/AndroidRuntime( 4993): 	at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
E/AndroidRuntime( 4993): 	at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
E/AndroidRuntime( 4993): 	at com.android.internal.app.ResolverActivity$LoadIconTask.onPostExecute(ResolverActivity.java:756)
E/AndroidRuntime( 4993): 	at com.android.internal.app.ResolverActivity$LoadIconTask.onPostExecute(ResolverActivity.java:744)
E/AndroidRuntime( 4993): 	at android.os.AsyncTask.finish(AsyncTask.java:632)
E/AndroidRuntime( 4993): 	at android.os.AsyncTask.access$600(AsyncTask.java:177)
E/AndroidRuntime( 4993): 	at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
E/AndroidRuntime( 4993): 	at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 4993): 	at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 4993): 	at android.os.HandlerThread.run(HandlerThread.java:61)

This reverts commit d22a5b851abf2a06097db51368edfda7616fc34c.

Change-Id: Ibe9c1192ec73eb46e3359da991201f6088e3a78e
[HWUI] The IBO state should be reset after glDeleteBuffers.

Symptom:
Can't bind to correct IBO.

Root Cause:
If a buffer object that is currently bound is deleted by glDeleteBuffers, the binding reverts to 0.
This may cause bindIndicesBuffer doesn't work if mCurrentIndicesBuffer not reset to 0.

Solution:
Reset mCurrentIndicesBuffer to 0 after glDeleteBuffers.

Change-Id: Iecd3ded76d876fcadde89a8893bab5f75b1eb312
[HWUI] Infinite recursion in PathTessellator::recursiveQuadraticBezierVertices()

Symptom: In some cases like the distance between the calculating point is very
         small, the recursion may not terminate.
         If the calculated dx and dy are 0, d is 0 too. Then the termination
         condition(d*d < TH*TH*(dx*dx*sq + dy*dy*sq)) will never be met.
         Infinite recursion will cause stack-overflow.

Solution: We added one more threshold to terminate the recursion when d is very
          small (possibly 0).

Change-Id: I7d27a72811109766766f8f8cc5d8d88e75db7f60
[HWUI]: Bind wrong VBO when drawing text

Symptom:
We should not set mDrawn to true if we have no GL draw call.

Root Cause:
In some case, issueDrawCommand may executed without GL draw call.
It may miss the unbindMeshBuffer in the next issueDrawCommand and the status of VBO of FontRenderer will incorrect.

Solution:
Add condition to check if have draw call.

Change-Id: I9e96cd0334c515172b0ed6c25b101c81cf6d2e6f
Update SET_ACTIVITY_WATCHER protection to signature|system

Change-Id: Iabf8ad2fc4b298e96b494917a140e0e4ea4e26e2
Fix memory leak in nativeDecodeFileDescriptor

Fix memory leak in nativeDecodeFileDescriptor:
SkFILEStream::kCallerRetains_Ownership is used to keep
life cycle of file in Java,so fclose is not called when
destruct SkFILEStream because ownership not belong to
native here, while when file is closed in Java, close
is called instead of fclose,that means buffer allocated
by malloc in fseek, when create SkFrontBufferedStream
with this filestream, will not be freed, because this
buffer will only be freedin fclose.
To fix this issue: duplicate this fd, and use
SkFILEStream::kCallerPasses_Ownership for SkFILEStream,
means Java and native manage file life cycle separately.
CRs-Fixed: 718738

Change-Id: I1c664551ab8d381db2e1f948a2207bc6fb7a11f9