audio policy: fix merging error for commit 112b0af8.

Wrong patch set was merged from partner gerrit.

Change-Id: I850d61b1cc8682e0a82ee64bc8cb022b7512de1c
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
index 32cb600..34149bd 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
@@ -71,7 +71,6 @@
     virtual void toAudioPort(struct audio_port *port) const;
 
     virtual void importAudioPort(const sp<AudioPort> port);
-    void clearCapabilities() { mProfiles.clearProfiles(); }
 
     void addAudioProfile(const sp<AudioProfile> &profile) { mProfiles.add(profile); }
 
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioProfile.h b/services/audiopolicy/common/managerdefinitions/include/AudioProfile.h
index 9780dc6..404e27d 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioProfile.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioProfile.h
@@ -258,7 +258,6 @@
         if (dynamicFormatProfile == 0) {
             return;
         }
-        clearProfiles();
         for (size_t i = 0; i < formats.size(); i++) {
             sp<AudioProfile> profile = new AudioProfile(formats[i],
                                                         dynamicFormatProfile->getChannels(),
@@ -270,6 +269,33 @@
         }
     }
 
+    void clearProfiles()
+    {
+        for (size_t i = size(); i != 0; ) {
+            sp<AudioProfile> profile = itemAt(--i);
+            if (profile->isDynamicFormat() && profile->hasValidFormat()) {
+                removeAt(i);
+                continue;
+            }
+            profile->clear();
+        }
+    }
+
+    void dump(int fd, int spaces) const
+    {
+        const size_t SIZE = 256;
+        char buffer[SIZE];
+
+        snprintf(buffer, SIZE, "%*s- Profiles:\n", spaces, "");
+        write(fd, buffer, strlen(buffer));
+        for (size_t i = 0; i < size(); i++) {
+            snprintf(buffer, SIZE, "%*sProfile %zu:", spaces + 4, "", i);
+            write(fd, buffer, strlen(buffer));
+            itemAt(i)->dump(fd, spaces + 8);
+        }
+    }
+
+private:
     void setSampleRatesFor(const SampleRateVector &sampleRates, audio_format_t format)
     {
         for (size_t i = 0; i < size(); i++) {
@@ -308,33 +334,6 @@
         }
     }
 
-    void clearProfiles()
-    {
-        for (size_t i = size(); i != 0; ) {
-            sp<AudioProfile> profile = itemAt(--i);
-            if (profile->isDynamicFormat() && profile->hasValidFormat()) {
-                removeAt(i);
-                continue;
-            }
-            profile->clear();
-        }
-    }
-
-    void dump(int fd, int spaces) const
-    {
-        const size_t SIZE = 256;
-        char buffer[SIZE];
-
-        snprintf(buffer, SIZE, "%*s- Profiles:\n", spaces, "");
-        write(fd, buffer, strlen(buffer));
-        for (size_t i = 0; i < size(); i++) {
-            snprintf(buffer, SIZE, "%*sProfile %zu:", spaces + 4, "", i);
-            write(fd, buffer, strlen(buffer));
-            itemAt(i)->dump(fd, spaces + 8);
-        }
-    }
-
-private:
     sp<AudioProfile> getProfileFor(audio_format_t format) const
     {
         for (size_t i = 0; i < size(); i++) {
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 2aed7b1..f853274 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -3465,7 +3465,7 @@
 
     if (audio_device_is_digital(device)) {
         // erase all current sample rates, formats and channel masks
-        devDesc->clearCapabilities();
+        devDesc->clearAudioProfiles();
     }
 
     if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
@@ -3710,7 +3710,7 @@
 
     if (audio_device_is_digital(device)) {
         // erase all current sample rates, formats and channel masks
-        devDesc->clearCapabilities();
+        devDesc->clearAudioProfiles();
     }
 
     if (state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
@@ -5129,8 +5129,10 @@
     }
     const FormatVector &supportedFormats = profiles.getSupportedFormats();
 
-    for(size_t formatIndex = 0; formatIndex < supportedFormats.size(); formatIndex++) {
+    for (size_t formatIndex = 0; formatIndex < supportedFormats.size(); formatIndex++) {
         audio_format_t format = supportedFormats[formatIndex];
+        ChannelsVector channelMasks;
+        SampleRateVector samplingRates;
         AudioParameter requestedParameters;
         requestedParameters.addInt(String8(AUDIO_PARAMETER_STREAM_FORMAT), format);
 
@@ -5141,7 +5143,7 @@
             ALOGV("%s: supported sampling rates %s", __FUNCTION__, reply.string());
             value = strpbrk((char *)reply.string(), "=");
             if (value != NULL) {
-                profiles.setSampleRatesFor(samplingRatesFromString(value + 1), format);
+                samplingRates = samplingRatesFromString(value + 1);
             }
         }
         if (profiles.hasDynamicChannelsFor(format)) {
@@ -5151,9 +5153,10 @@
             ALOGV("%s: supported channel masks %s", __FUNCTION__, reply.string());
             value = strpbrk((char *)reply.string(), "=");
             if (value != NULL) {
-                profiles.setChannelsFor(channelMasksFromString(value + 1), format);
+                channelMasks = channelMasksFromString(value + 1);
             }
         }
+        profiles.addProfileFromHal(new AudioProfile(format, channelMasks, samplingRates));
     }
 }