audio_server: Unify audio_patch creation

Provide PatchBuilder helper class instead of fiddling with
struct audio_patch directly.

Rename 'getAudioPortConfig' methods of AudioFlinger helper
classes into 'toAudioPortConfig' to match classes
of AudioPolicyManager.

Factor out common code in AudioPolicyManager that was
adding audio patches. For that, AudioOutputDescriptor now inherits
from AudioSessionInfoProvider, and the latter has been extended
with 'setPatchHandle' method.

Test: switch to/from Bluetooth on phone calls and media playback,
      use camcorder
Change-Id: Idd99645dc6943ed078c4d94d0197fead7831ab4d
diff --git a/services/audioflinger/PatchPanel.cpp b/services/audioflinger/PatchPanel.cpp
index eaf1120..be3286f 100644
--- a/services/audioflinger/PatchPanel.cpp
+++ b/services/audioflinger/PatchPanel.cpp
@@ -26,6 +26,7 @@
 #include "AudioFlinger.h"
 #include "ServiceUtilities.h"
 #include <media/AudioParameter.h>
+#include <media/PatchBuilder.h>
 
 // ----------------------------------------------------------------------------
 
@@ -373,15 +374,10 @@
 status_t AudioFlinger::PatchPanel::Patch::createConnections(PatchPanel *panel)
 {
     // create patch from source device to record thread input
-    struct audio_patch subPatch;
-    subPatch.num_sources = 1;
-    subPatch.sources[0] = mAudioPatch.sources[0];
-    subPatch.num_sinks = 1;
-
-    mRecord.thread()->getAudioPortConfig(&subPatch.sinks[0]);
-    subPatch.sinks[0].ext.mix.usecase.source = AUDIO_SOURCE_MIC;
-
-    status_t status = panel->createAudioPatch(&subPatch, mRecord.handlePtr());
+    status_t status = panel->createAudioPatch(
+            PatchBuilder().addSource(mAudioPatch.sources[0]).
+                addSink(mRecord.thread(), { .source = AUDIO_SOURCE_MIC }).patch(),
+            mRecord.handlePtr());
     if (status != NO_ERROR) {
         *mRecord.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
         return status;
@@ -389,9 +385,9 @@
 
     // create patch from playback thread output to sink device
     if (mAudioPatch.num_sinks != 0) {
-        mPlayback.thread()->getAudioPortConfig(&subPatch.sources[0]);
-        subPatch.sinks[0] = mAudioPatch.sinks[0];
-        status = panel->createAudioPatch(&subPatch, mPlayback.handlePtr());
+        status = panel->createAudioPatch(
+                PatchBuilder().addSource(mPlayback.thread()).addSink(mAudioPatch.sinks[0]).patch(),
+                mPlayback.handlePtr());
         if (status != NO_ERROR) {
             *mPlayback.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
             return status;