blob: dbdbf37277325bc8b4d62e5b8134c1c692f450e0 [file] [log] [blame]
Jackeagle0cc335a2018-10-19 00:06:49 -04001From 7e9375da9c53bebe4e7390044b7c8cbd4d1f9d88 Mon Sep 17 00:00:00 2001
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +02002From: Pierre-Hugues Husson <phh@phh.me>
3Date: Tue, 24 Apr 2018 00:14:28 +0200
Jackeagle0cc335a2018-10-19 00:06:49 -04004Subject: [PATCH 2/5] FIH devices: Fix "Earpiece" audio output
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +02005
6On some FIH devices (confirmed on Razer, and probably on Aquos SS2),
7Earpiece is not listed in attachedDevices, and devicePort's profile
8mentions it is AUDIO_CHANNEL_IN_MONO, instead of AUDIO_CHANNEL_OUT_MONO.
9
10Detect such cases (output device, but got only AUDIO_CHANNEL_IN_MONO),
11and fix both channelMasks and attachedDevices
12
13Change-Id: I4a88ba6d34d0fcd346eeea2ca903772f0271040a
14---
Jon West013ef582018-08-21 20:45:26 -040015 .../common/managerdefinitions/src/Serializer.cpp | 25 +++++++++++++++++++---
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020016 1 file changed, 22 insertions(+), 3 deletions(-)
17
18diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
Jon West013ef582018-08-21 20:45:26 -040019index a253113..380e2f8 100644
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020020--- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
21+++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
22@@ -191,16 +191,25 @@ const char AudioProfileTraits::Attributes::name[] = "name";
23 const char AudioProfileTraits::Attributes::samplingRates[] = "samplingRates";
24 const char AudioProfileTraits::Attributes::format[] = "format";
25 const char AudioProfileTraits::Attributes::channelMasks[] = "channelMasks";
26+static bool fixedEarpieceChannels = false;
27
28 status_t AudioProfileTraits::deserialize(_xmlDoc */*doc*/, const _xmlNode *root, PtrElement &profile,
29- PtrSerializingCtx /*serializingContext*/)
30+ PtrSerializingCtx serializingContext)
31 {
32+ bool isOutput = serializingContext != nullptr;
33 string samplingRates = getXmlAttribute(root, Attributes::samplingRates);
34 string format = getXmlAttribute(root, Attributes::format);
35 string channels = getXmlAttribute(root, Attributes::channelMasks);
36+ ChannelTraits::Collection channelsMask = channelMasksFromString(channels, ",");
37+
38+ //Some Foxconn devices have wrong earpiece channel mask, leading to no channel mask
39+ if(channelsMask.size() == 1 && channelsMask[0] == AUDIO_CHANNEL_IN_MONO && isOutput) {
40+ fixedEarpieceChannels = true;
41+ channelsMask = channelMasksFromString("AUDIO_CHANNEL_OUT_MONO", ",");
42+ }
43
44 profile = new Element(formatFromString(format, gDynamicFormat),
45- channelMasksFromString(channels, ","),
46+ channelsMask,
47 samplingRatesFromString(samplingRates, ","));
48
49 profile->setDynamicFormat(profile->getFormat() == gDynamicFormat);
Jon West1fd60302018-08-11 19:14:03 -040050@@ -326,7 +335,10 @@ status_t DevicePortTraits::deserialize(_xmlDoc *doc, const _xmlNode *root, PtrEl
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020051 }
52
53 AudioProfileTraits::Collection profiles;
54- deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
55+ if(audio_is_output_devices(type))
56+ deserializeCollection<AudioProfileTraits>(doc, root, profiles, (PtrSerializingCtx)1);
57+ else
58+ deserializeCollection<AudioProfileTraits>(doc, root, profiles, NULL);
59 if (profiles.isEmpty()) {
60 sp <AudioProfile> dynamicProfile = new AudioProfile(gDynamicFormat,
61 ChannelsVector(), SampleRateVector());
Jon West1fd60302018-08-11 19:14:03 -040062@@ -491,6 +503,13 @@ status_t ModuleTraits::deserialize(xmlDocPtr doc, const xmlNode *root, PtrElemen
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020063 }
64 children = children->next;
65 }
66+ if(fixedEarpieceChannels) {
67+ sp<DeviceDescriptor> device =
68+ module->getDeclaredDevices().getDeviceFromTagName(String8("Earpiece"));
69+ if(device != 0)
70+ ctx->addAvailableDevice(device);
71+ fixedEarpieceChannels = false;
72+ }
73 return NO_ERROR;
74 }
75
76--
Jon West013ef582018-08-21 20:45:26 -0400772.7.4
Pierre-Hugues Hussonc642be22018-07-07 23:43:53 +020078