frameworks/base: Fix race conditions on resume/suspend using power key

The wakelock PowerManagerService.Display sometimes cannot be released
after two quick power key pressings like a double click during phone
sleep (the target will resume then supposedly suspend shortly).

The second key event disturbs display power state on resume, as a
result display resources won't get released on suspend, which is fixed
in this change.

CRs-Fixed: 566059
Change-Id: I633fd377ab235f203ebfb649a74449a2385740c4
audio: Fix for LPCM surround sound recording

 - Format WAVE was defined as 10, which is getting
 over-ridden by format THREE_GPP2 (which holds value 10),
 because of which Media recorder failed for LPCM SSR.
 - Fix this by defining format WAVE to 11.

Change-Id: I4db84441b70b28da3579e2ff430b42b2711f9404
video: Add support for extended media listener

Added changes to handle additional message types for
dash playback.

Change-Id: Id07828866de8cae44137f26c1e74417aaa45704f
audio: Fix for volume level mismatch for AVRCP headset

-The volume level sent to AVRCP module from AudioService
 is incorrect.
-The volume level need to scale down for AVRCP module.
-Divide volume level by 10 to match AVRCP module volume
 levels.

Change-Id: Ieb8146797d0b552311b1a4782c45aea1be73e492
CRs-Fixed: 561649
Wifi: Fix for connection failure between third client and GC.

When third device sends a connection request to the group client, the
existing connection is terminating and also the ongoing connection not
successful.Currently as there is  no use case where third device is
connecting to GC,and the existing onnection getting terminated.This
is addressed by ignoring the new connection request from third client
to GC and the existing connection is intact.
CRs-Fixed: 467049

Change-Id: I784c38b9a4ca0c60b188b9697e3b4af4d09053cc
base: Fix for wifi tethering crash

Pass network info along with CMD_UPSTREAM_CHANGED
Added a NULL check for Network info in CMD_UPSTREAM_CHANGED

CRs-fixed: 562910
Change-Id: I98bd37205255d9d4025cfb95b0688c68bce3c9bd
Show PIN on Peer device on receiving PIN display request.

P2P provision discovery would request the peer to display a PIN.
The PIN is displayed handling the request, the PIN need to be
entered on keypad of requested peer device to achieve the
connection.

Change-Id: I8b6487681d78eb10c558983a08dec1ac8a8eee65
CRs-fixed: 382608
wifi: Fix for connection between GO and p2p device

When GO sends an invitation request to the p2p device without
persistent profile, GO gets an invitation result=8 which means
unknown group, when GO receives invitation result 8, its tries
to remove persistent profile of the client but it will not be able
find the profile so it does continue with sending the invitation
so the connection fails. To address this, ignore if there are no
persistent profiles found for the client and continue with sending
the Invitation request to the client to make connection succesful
connection. As GO has single profile saved unlike client which
saves multiple profiles of GO.

CRs-Fixed: 511282
Change-Id: I78f54d4bb2f0d603bc2170ec2c3ef55a91050236
p2p:Fix for discovery failure until STA is connected to AP.

The station when connecting to AP (wifi state is either
connecting or obtaining ip address) shall stop the already
issued p2p_find on the DHCP start and start the same after
the DHCP handshake. p2p service manager shall return a failure
for any p2p_find operation during these period resulting in a
discover failure.
Address this by deferring the p2p_find issued during this period
(set mDiscoveryPostponed to true) rather than returning a failure.

Change-Id: I40b2017bf126fd0d543ada8853223402cda63e9d
CRs-Fixed: 532138
framework:Thread synchronization for UI update

Issue : Framework reboot was observed due to out of sync between
        two threads which inturn causes Null pointer exception
        while updating airplanemode.
Fix : Handled Null pointer exception and the crash is not observed.
CRs-Fixed: 570122

Change-Id: I2e969f6e7726ffcf8648b366ebb54cb2b0afc292
P2P: Fix for GO inviting a p2p device.

A p2p device on an invitation request from the peer invokes
p2p_peer command to know if the peer is a p2p device / GO.
Due to the cached entries there would be a possibility of
not getting the updated information, ending up in the wrong
negotiation with the invited peer. Thus do not rely on
p2p_peer command, rather assume that the peer is a GO on an
invitation request, provided there is no persistent network
configured.

CRs-Fixed: 486437
Change-Id: Ifaeb6a8c5f9cddd7df96622056541e22aad74314
ActivityManager: Donot take launcher screenshot.

Currently ActivityManger takes screenshot for all activities
on an activity switch, for maintaining the screenshots in recent
app list. This can be skipped for launcher, as launcher is not
present in the recent app list.

Change-Id: I22f7cda2c63483ab50e0df4428151503892b7d9b
ActivityTrigger:  New class to invoke when activity starts/resumes

Change-Id: I46fa419e7b97953ba5581ee03127f0e3f93e48f0
(cherry picked from commit 71a57d30370584488a246a904750e7bdad5ba9a0)
(cherry picked from commit 5d2abff8e4d399e6bd320ea11bf672ad3b3be980)
(cherry picked from commit ffd89bcf976985acf0392c0dd667f8b5241d77ac)

frameworks/base: update perflock path name in Activity Trigger

Update the perflock path name and add
backup path for backward compatibility

Change-Id: I3d2c6f6fe1b3c63ec02827d06d5af667266db8d5
(cherry picked from commit 4db57e5021c4091352f40f6e4399b0b929f63151)
(cherry picked from commit b9fc7b99697a1b2f891dc642ff27c8a4194ca79d)
(cherry picked from commit 5910b639f0dea078049e31718e00bede2eb2ec00)

frameworks/base: update library path name in Activity Trigger

Change path from /system/lib to /vendor/lib
since it is no longer needed.

Change-Id: I5fa7a367b21d4128c92ab7190944c176a1f4dae6
(cherry picked from commit 7abea046455c1c8fc99126ae6cf9a6d4823ca50f)
(cherry picked from commit 5aadc3f081bef5b26b13e0bb4955354e3be0bcd7)
(cherry picked from commit 133db12892589a21865a900c3709073ed86eaf8a)
Remove opaque check in preparing dirty region

Since preserve swap is enabled, we need to clear the color buffer
when the scissor rect is prepared for a new process. This prevents
garbage being present from the previous process in the color buffer.

CRs-Fixed: 549755

Change-Id: Icd12ae388077b8c9ed329c37314e896500078543
(cherry picked from commit 48b6a9767317e08a24e189c9cbee21043543682a)
(cherry picked from commit 777610a5ddf19cebcad30b7e9a481e9dfe38b74c)
Update the layer's alpha value upon composition of the layer

Fixes: This patch makes sure that the layer's alpha value is
up-to-date and does not reflect the previous view's alpha value.
It fixes the square block on marquee fading edge when text view
is applied transparency.

CRs-Fixed: 562000

Change-Id: I397308b739f5f4fe4b630cf594825f401c97e0e3
Fix stencil buffer bug.

Stencil test is enabled by setStencilFromClip(), but not disabled
in some use case, which causes some of the pixels are discarded by
mistake in draws followed. Disable stencil test when there is no
dirty clip.

CRs-Fixed: 539456

Change-Id: I318fb47212e49e2da89bcbfd161a1689ef91b02f
ifeq QCOM: video: Add support for extended media listener

Bulid fails with error: 'MEDIA_QOE' was not declared in
this scope on other targets
Change-Id: Ic83be8f1acc4188b81fb903911023b39c614775b
Frameworks: QS performance profiles tile

Patchset 2: Fix not null comparation
Patchset 3: xxhdpi drawables
Patchset 4: Fix xxhdpi drawables (thx blunden)
            Rebased
Patchset 5: Add suggestions
            Sync on boot the system property with the setting
Patchset 6: Rebased

Conflicts:
	core/java/com/android/internal/util/cm/QSUtils.java
	core/res/res/values-cs/cm_strings.xml
	core/res/res/values-el/cm_strings.xml
	core/res/res/values-hu/cm_strings.xml
	core/res/res/values/cm_strings.xml
	core/res/res/values/config.xml
	core/res/res/values/symbols.xml
	packages/SystemUI/res/drawable-hdpi/ic_qs_perf_profile.png
	packages/SystemUI/res/drawable-hdpi/ic_qs_perf_profile_bal.png
	packages/SystemUI/res/drawable-hdpi/ic_qs_perf_profile_perf.png
	packages/SystemUI/res/drawable-hdpi/ic_qs_perf_profile_pwrsv.png
	packages/SystemUI/res/drawable-mdpi/ic_qs_perf_profile.png
	packages/SystemUI/res/drawable-mdpi/ic_qs_perf_profile_bal.png
	packages/SystemUI/res/drawable-mdpi/ic_qs_perf_profile_perf.png
	packages/SystemUI/res/drawable-mdpi/ic_qs_perf_profile_pwrsv.png
	packages/SystemUI/res/drawable-xhdpi/ic_qs_perf_profile.png
	packages/SystemUI/res/drawable-xhdpi/ic_qs_perf_profile_bal.png
	packages/SystemUI/res/drawable-xhdpi/ic_qs_perf_profile_perf.png
	packages/SystemUI/res/drawable-xhdpi/ic_qs_perf_profile_pwrsv.png
	packages/SystemUI/res/drawable-xxhdpi/ic_qs_perf_profile.png
	packages/SystemUI/res/drawable-xxhdpi/ic_qs_perf_profile_bal.png
	packages/SystemUI/res/drawable-xxhdpi/ic_qs_perf_profile_perf.png
	packages/SystemUI/res/drawable-xxhdpi/ic_qs_perf_profile_pwrsv.png
	packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsController.java
	services/java/com/android/server/SystemServer.java

Change-Id: Ib32d3734b63f88a3473e0ab10d8edf30dae9ceb6
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
[1/2] Forward port power connect/disconnect notification support

Original commit info:

    [1/2] Power connect/disconnect notification support

    part 1/2: frameworks/base PowerUI and Settings
    http://review.cyanogenmod.org/#/c/35241/

    part 2/2: packages/apps/Settings Sound settings
    http://review.cyanogenmod.org/#/c/35242/

    Change-Id: I36a6b9f924d2cd52191a8e83a744745b37c5b068

Change-Id: Ib865e1c296cb8e1d957b2a48616c88ceaba5c008