Merge in upstream changes

From :https://github.com/phhusson/treble_patches

Change-Id: I785ed4d854f28f661b1b48530dc10a5adf076e74
diff --git a/patches/platform_frameworks_av/0001-FIH-devices-Fix-Earpiece-audio-output.patch b/patches/platform_frameworks_av/0001-FIH-devices-Fix-Earpiece-audio-output.patch
index 0cf64b4..c5ad3b8 100644
--- a/patches/platform_frameworks_av/0001-FIH-devices-Fix-Earpiece-audio-output.patch
+++ b/patches/platform_frameworks_av/0001-FIH-devices-Fix-Earpiece-audio-output.patch
@@ -1,7 +1,7 @@
 From 71286a6af35eeebf33171848285c9e6dc0da1366 Mon Sep 17 00:00:00 2001
 From: Pierre-Hugues Husson <phh@phh.me>
 Date: Tue, 24 Apr 2018 00:14:28 +0200
-Subject: [PATCH 1/2] FIH devices: Fix "Earpiece" audio output
+Subject: [PATCH 1/4] FIH devices: Fix "Earpiece" audio output
 
 On some FIH devices (confirmed on Razer, and probably on Aquos SS2),
 Earpiece is not listed in attachedDevices, and devicePort's profile
@@ -12,11 +12,11 @@
 
 Change-Id: I4a88ba6d34d0fcd346eeea2ca903772f0271040a
 ---
- .../managerdefinitions/src/Serializer.cpp     | 25 ++++++++++++++++---
+ .../common/managerdefinitions/src/Serializer.cpp   | 25 +++++++++++++++++++---
  1 file changed, 22 insertions(+), 3 deletions(-)
 
 diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
-index a2531131d..380e2f82b 100644
+index a253113..380e2f8 100644
 --- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
 +++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
 @@ -191,16 +191,25 @@ const char AudioProfileTraits::Attributes::name[] = "name";
@@ -74,5 +74,5 @@
  }
  
 -- 
-2.17.1
+2.7.4
 
diff --git a/patches/platform_frameworks_av/0002-Fix-WiFi-Display-on-Huawei-devices-EMUI-8.0.patch b/patches/platform_frameworks_av/0002-Fix-WiFi-Display-on-Huawei-devices-EMUI-8.0.patch
index 3b0f416..ddae3c7 100644
--- a/patches/platform_frameworks_av/0002-Fix-WiFi-Display-on-Huawei-devices-EMUI-8.0.patch
+++ b/patches/platform_frameworks_av/0002-Fix-WiFi-Display-on-Huawei-devices-EMUI-8.0.patch
@@ -1,7 +1,7 @@
 From 3e6bf2b4bd5cc97399e8bfe0dace8f4b2c6f69cc Mon Sep 17 00:00:00 2001
 From: Alexander Pohl <pohl199885@gmail.com>
 Date: Fri, 15 Jun 2018 19:58:07 +0200
-Subject: [PATCH 2/2] Fix WiFi-Display on Huawei devices (EMUI 8.0)
+Subject: [PATCH 2/4] Fix WiFi-Display on Huawei devices (EMUI 8.0)
 
 Huaweis media stack doesn't handle intra-refresh-mode, so skip the error instead.
 
@@ -11,7 +11,7 @@
  1 file changed, 2 insertions(+), 3 deletions(-)
 
 diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
-index 7f39d109f..ed54fb58a 100644
+index 7f39d10..ed54fb5 100644
 --- a/media/libstagefright/ACodec.cpp
 +++ b/media/libstagefright/ACodec.cpp
 @@ -4279,9 +4279,8 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) {
@@ -27,5 +27,5 @@
      }
  
 -- 
-2.17.1
+2.7.4
 
diff --git a/patches/platform_frameworks_av/0003-Kirin-Remove-lock-to-prevent-self-lock.patch b/patches/platform_frameworks_av/0003-Kirin-Remove-lock-to-prevent-self-lock.patch
new file mode 100644
index 0000000..4320ceb
--- /dev/null
+++ b/patches/platform_frameworks_av/0003-Kirin-Remove-lock-to-prevent-self-lock.patch
@@ -0,0 +1,34 @@
+From 3ff17862deda0303940be62e8f6cbb4eed06e292 Mon Sep 17 00:00:00 2001
+From: Pierre-Hugues Husson <phh@phh.me>
+Date: Sun, 19 Aug 2018 22:59:06 +0200
+Subject: [PATCH 3/4] ::Kirin:: Remove lock to prevent self-lock
+
+With Huawei Camera HAL, we get the following call order:
+cameraserver CameraService::enumerateProviders (*)
+=> HAL ICameraProvider::getVendorTags
+=> HAL ICameraProviderCallback::cameraDeviceStatusChange
+=> cameraserver CameraService::addState
+=> cameraserver CameraService::updateCameraNumAndIds (*)
+
+The two functions marked with (*) take mServiceLock
+Hence the safe-lock
+---
+ services/camera/libcameraservice/CameraService.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
+index c41de82..edbafbc 100644
+--- a/services/camera/libcameraservice/CameraService.cpp
++++ b/services/camera/libcameraservice/CameraService.cpp
+@@ -218,7 +218,7 @@ void CameraService::onNewProviderRegistered() {
+ }
+ 
+ void CameraService::updateCameraNumAndIds() {
+-    Mutex::Autolock l(mServiceLock);
++    //Mutex::Autolock l(mServiceLock);
+     mNumberOfCameras = mCameraProviderManager->getCameraCount();
+     mNormalDeviceIds =
+             mCameraProviderManager->getAPI1CompatibleCameraDeviceIds();
+-- 
+2.7.4
+
diff --git a/patches/platform_frameworks_av/0004-We-might-not-have-a-mFlashlight-at-this-state-but-th.patch b/patches/platform_frameworks_av/0004-We-might-not-have-a-mFlashlight-at-this-state-but-th.patch
new file mode 100644
index 0000000..7426512
--- /dev/null
+++ b/patches/platform_frameworks_av/0004-We-might-not-have-a-mFlashlight-at-this-state-but-th.patch
@@ -0,0 +1,26 @@
+From ec657f31e92f4a58791a39025632f0350a7750db Mon Sep 17 00:00:00 2001
+From: Pierre-Hugues Husson <phh@phh.me>
+Date: Sun, 19 Aug 2018 23:05:26 +0200
+Subject: [PATCH 4/4] We might not have a mFlashlight at this state, but that's
+ ok
+
+---
+ services/camera/libcameraservice/CameraService.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
+index edbafbc..222cfe4 100644
+--- a/services/camera/libcameraservice/CameraService.cpp
++++ b/services/camera/libcameraservice/CameraService.cpp
+@@ -243,7 +243,7 @@ void CameraService::addStates(const String8 id) {
+                                                                 conflicting));
+     }
+ 
+-    if (mFlashlight->hasFlashUnit(id)) {
++    if (mFlashlight != nullptr && mFlashlight->hasFlashUnit(id)) {
+         Mutex::Autolock al(mTorchStatusMutex);
+         mTorchStatusMap.add(id, TorchModeStatus::AVAILABLE_OFF);
+     }
+-- 
+2.7.4
+