audio policy: strengthen dynamic audio profile intialization

Add some robustness to getParameters() reply parsing
in AudioPolicyManager::updateAudioProfiles().
Some audio HALs may respond with more than just the parameters requested.

Change-Id: Id9327604f521f9fb5636ff93cb6a7c3c23c86778
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index ad2ad69..941757a 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -5183,12 +5183,13 @@
         reply = mpClientInterface->getParameters(ioHandle,
                                                  String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS));
         ALOGV("%s: supported formats %s", __FUNCTION__, reply.string());
-        value = strpbrk((char *)reply.string(), "=");
-        if (value == NULL) {
+        AudioParameter repliedParameters(reply);
+        if (repliedParameters.get(
+                String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS), reply) != NO_ERROR) {
             ALOGE("%s: failed to retrieve format, bailing out", __FUNCTION__);
             return;
         }
-        profiles.setFormats(formatsFromString(value + 1));
+        profiles.setFormats(formatsFromString(reply.string()));
     }
     const FormatVector &supportedFormats = profiles.getSupportedFormats();
 
@@ -5204,9 +5205,10 @@
                                                      requestedParameters.toString() + ";" +
                                                      AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES);
             ALOGV("%s: supported sampling rates %s", __FUNCTION__, reply.string());
-            value = strpbrk((char *)reply.string(), "=");
-            if (value != NULL) {
-                samplingRates = samplingRatesFromString(value + 1);
+            AudioParameter repliedParameters(reply);
+            if (repliedParameters.get(
+                    String8(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES), reply) == NO_ERROR) {
+                samplingRates = samplingRatesFromString(reply.string());
             }
         }
         if (profiles.hasDynamicChannelsFor(format)) {
@@ -5214,9 +5216,10 @@
                                                      requestedParameters.toString() + ";" +
                                                      AUDIO_PARAMETER_STREAM_SUP_CHANNELS);
             ALOGV("%s: supported channel masks %s", __FUNCTION__, reply.string());
-            value = strpbrk((char *)reply.string(), "=");
-            if (value != NULL) {
-                channelMasks = channelMasksFromString(value + 1);
+            AudioParameter repliedParameters(reply);
+            if (repliedParameters.get(
+                    String8(AUDIO_PARAMETER_STREAM_SUP_CHANNELS), reply) == NO_ERROR) {
+                channelMasks = channelMasksFromString(reply.string());
             }
         }
         profiles.addProfileFromHal(new AudioProfile(format, channelMasks, samplingRates));