New patches, AOSP v22
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
new file mode 100644
index 0000000..1cf9498
--- /dev/null
+++ b/patches/platform_frameworks_av/0001-FIH-devices-Fix-Earpiece-audio-output.patch
@@ -0,0 +1,78 @@
+From 25e8b3145db1134d114f54ab8b3f4bff9bb5a062 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
+
+On some FIH devices (confirmed on Razer, and probably on Aquos SS2),
+Earpiece is not listed in attachedDevices, and devicePort's profile
+mentions it is AUDIO_CHANNEL_IN_MONO, instead of AUDIO_CHANNEL_OUT_MONO.
+
+Detect such cases (output device, but got only AUDIO_CHANNEL_IN_MONO),
+and fix both channelMasks and attachedDevices
+
+Change-Id: I4a88ba6d34d0fcd346eeea2ca903772f0271040a
+---
+ .../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 a224004..f58d7e5 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";
+ const char AudioProfileTraits::Attributes::samplingRates[] = "samplingRates";
+ const char AudioProfileTraits::Attributes::format[] = "format";
+ const char AudioProfileTraits::Attributes::channelMasks[] = "channelMasks";
++static bool fixedEarpieceChannels = false;
+
+ status_t AudioProfileTraits::deserialize(_xmlDoc */*doc*/, const _xmlNode *root, PtrElement &profile,
+- PtrSerializingCtx /*serializingContext*/)
++ PtrSerializingCtx serializingContext)
+ {
++ bool isOutput = serializingContext != nullptr;
+ string samplingRates = getXmlAttribute(root, Attributes::samplingRates);
+ string format = getXmlAttribute(root, Attributes::format);
+ string channels = getXmlAttribute(root, Attributes::channelMasks);
++ ChannelTraits::Collection channelsMask = channelMasksFromString(channels, ",");
++
++ //Some Foxconn devices have wrong earpiece channel mask, leading to no channel mask
++ if(channelsMask.size() == 1 && channelsMask[0] == AUDIO_CHANNEL_IN_MONO && isOutput) {
++ fixedEarpieceChannels = true;
++ channelsMask = channelMasksFromString("AUDIO_CHANNEL_OUT_MONO", ",");
++ }
+
+ profile = new Element(formatFromString(format, gDynamicFormat),
+- channelMasksFromString(channels, ","),
++ channelsMask,
+ samplingRatesFromString(samplingRates, ","));
+
+ profile->setDynamicFormat(profile->getFormat() == gDynamicFormat);
+@@ -316,7 +325,10 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl
+ }
+
+ AudioProfileTraits::Collection profiles;
+- deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
++ if(audio_is_output_devices(type))
++ deserializeCollection<AudioProfileTraits>(doc, root, profiles, (PtrSerializingCtx)1);
++ else
++ deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
+ if (profiles.isEmpty()) {
+ sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat,
+ ChannelsVector(), SampleRateVector());
+@@ -481,6 +493,13 @@ status_t ModuleTraits::deserialize(xmlDocPtr doc, const xmlNode *root, PtrElemen
+ }
+ children = children->next;
+ }
++ if(fixedEarpieceChannels) {
++ sp<DeviceDescriptor> device =
++ module->getDeclaredDevices().getDeviceFromTagName(String8("Earpiece"));
++ if(device != 0)
++ ctx->addAvailableDevice(device);
++ fixedEarpieceChannels = false;
++ }
+ return NO_ERROR;
+ }
+
+--
+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
new file mode 100644
index 0000000..c5987fa
--- /dev/null
+++ b/patches/platform_frameworks_av/0002-Fix-WiFi-Display-on-Huawei-devices-EMUI-8.0.patch
@@ -0,0 +1,31 @@
+From e31fc7df0316ea378dbb737c4699ee6441b0f068 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)
+
+Huaweis media stack doesn't handle intra-refresh-mode, so skip the error instead.
+
+Thanks to Chris Vandomelen for pointing that out.
+---
+ media/libstagefright/ACodec.cpp | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
+index a2eb9a8..e5eefcb 100644
+--- a/media/libstagefright/ACodec.cpp
++++ b/media/libstagefright/ACodec.cpp
+@@ -4244,9 +4244,8 @@ status_t ACodec::setupAVCEncoderParameters(const sp<AMessage> &msg) {
+ if (msg->findInt32("intra-refresh-mode", &intraRefreshMode)) {
+ err = setCyclicIntraMacroblockRefresh(msg, intraRefreshMode);
+ if (err != OK) {
+- ALOGE("Setting intra macroblock refresh mode (%d) failed: 0x%x",
+- err, intraRefreshMode);
+- return err;
++ ALOGE("setupAVCEncoderParameters(): set intra-refresh-mode failed, ignoring..");
++ //return err;
+ }
+ }
+
+--
+2.7.4
+