do not merge bug 3370834 Cherrypick from master CL 79417

Rely on the audio input source parameter for mixer configuration.

The generic APM implementation now passes the audio recording
 source as a configuration parameter, and uses the enum defined
 in mediarecorder.h. But the driver uses a string to define
 the "input source state". This change maps the input source
 to the string used by the driver.

Change-Id: I5fce44579a3cda01ed73f67fb8c3091ef05cce76
diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
index 585bb71..b6ec8ab 100644
--- a/libaudio/AudioHardware.cpp
+++ b/libaudio/AudioHardware.cpp
@@ -73,6 +73,11 @@
 
 // ----------------------------------------------------------------------------
 
+const char *AudioHardware::inputPathNameDefault = "Default";
+const char *AudioHardware::inputPathNameCamcorder = "Camcorder";
+const char *AudioHardware::inputPathNameVoiceRecognition = "Voice Recognition";
+const char *AudioHardware::inputPathNameVoiceCommunication = "Voice Communication";
+
 AudioHardware::AudioHardware() :
     mInit(false),
     mMicMute(false),
@@ -81,7 +86,7 @@
     mPcmOpenCnt(0),
     mMixerOpenCnt(0),
     mInCallAudioMode(false),
-    mInputSource("Default"),
+    mInputSource(AUDIO_SOURCE_DEFAULT),
     mBluetoothNrec(true),
     mSecRilLibHandle(NULL),
     mRilClient(0),
@@ -377,7 +382,7 @@
             LOGV("setMode() openPcmOut_l()");
             openPcmOut_l();
             openMixer_l();
-            setInputSource_l(String8("Default"));
+            setInputSource_l(AUDIO_SOURCE_DEFAULT);
             mInCallAudioMode = true;
         }
         if (mMode == AudioSystem::MODE_NORMAL && mInCallAudioMode) {
@@ -609,7 +614,7 @@
     snprintf(buffer, SIZE, "\tIn Call Audio Mode %s\n",
              (mInCallAudioMode) ? "ON" : "OFF");
     result.append(buffer);
-    snprintf(buffer, SIZE, "\tInput source %s\n", mInputSource.string());
+    snprintf(buffer, SIZE, "\tInput source %d\n", mInputSource);
     result.append(buffer);
     snprintf(buffer, SIZE, "\tmSecRilLibHandle: %p\n", mSecRilLibHandle);
     result.append(buffer);
@@ -885,11 +890,11 @@
     return spIn;
 }
 
-status_t AudioHardware::setInputSource_l(String8 source)
+status_t AudioHardware::setInputSource_l(audio_source source)
 {
-     LOGV("setInputSource_l(%s)", source.string());
+     LOGV("setInputSource_l(%d)", source);
      if (source != mInputSource) {
-         if ((source == "Default") || (mMode != AudioSystem::MODE_IN_CALL)) {
+         if ((source == AUDIO_SOURCE_DEFAULT) || (mMode != AudioSystem::MODE_IN_CALL)) {
              if (mMixer) {
                  TRACE_DRIVER_IN(DRV_MIXER_GET)
                  struct mixer_ctl *ctl= mixer_get_control(mMixer, "Input Source", 0);
@@ -897,9 +902,30 @@
                  if (ctl == NULL) {
                      return NO_INIT;
                  }
-                 LOGV("mixer_ctl_select, Input Source, (%s)", source.string());
+                 const char* sourceName;
+                 switch (source) {
+                     case AUDIO_SOURCE_DEFAULT: // intended fall-through
+                     case AUDIO_SOURCE_MIC:
+                         sourceName = inputPathNameDefault;
+                         break;
+                     case AUDIO_SOURCE_VOICE_COMMUNICATION:
+                         sourceName = inputPathNameVoiceCommunication;
+                         break;
+                     case AUDIO_SOURCE_CAMCORDER:
+                         sourceName = inputPathNameCamcorder;
+                         break;
+                     case AUDIO_SOURCE_VOICE_RECOGNITION:
+                         sourceName = inputPathNameVoiceRecognition;
+                         break;
+                     case AUDIO_SOURCE_VOICE_UPLINK:   // intended fall-through
+                     case AUDIO_SOURCE_VOICE_DOWNLINK: // intended fall-through
+                     case AUDIO_SOURCE_VOICE_CALL:     // intended fall-through
+                     default:
+                         return NO_INIT;
+                 }
+                 LOGV("mixer_ctl_select, Input Source, (%s)", sourceName);
                  TRACE_DRIVER_IN(DRV_MIXER_SEL)
-                 mixer_ctl_select(ctl, source.string());
+                 mixer_ctl_select(ctl, sourceName);
                  TRACE_DRIVER_OUT
              }
          }
@@ -1547,7 +1573,6 @@
     AudioParameter param = AudioParameter(keyValuePairs);
     status_t status = NO_ERROR;
     int value;
-    String8 source;
 
     LOGD("AudioStreamInALSA::setParameters() %s", keyValuePairs.string());
 
@@ -1556,14 +1581,14 @@
     {
         AutoMutex lock(mLock);
 
-        if (param.get(String8(INPUT_SOURCE_KEY), source) == NO_ERROR) {
+        if (param.getInt(String8(AudioParameter::keyInputSource), value) == NO_ERROR) {
             AutoMutex hwLock(mHardware->lock());
 
             mHardware->openMixer_l();
-            mHardware->setInputSource_l(source);
+            mHardware->setInputSource_l((audio_source)value);
             mHardware->closeMixer_l();
 
-            param.remove(String8(INPUT_SOURCE_KEY));
+            param.remove(String8(AudioParameter::keyInputSource));
         }
 
         if (param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR)
diff --git a/libaudio/AudioHardware.h b/libaudio/AudioHardware.h
index a2c47bd..37a9a6e 100644
--- a/libaudio/AudioHardware.h
+++ b/libaudio/AudioHardware.h
@@ -24,6 +24,7 @@
 #include <utils/SortedVector.h>
 
 #include <hardware_legacy/AudioHardwareBase.h>
+#include <media/mediarecorder.h>
 
 #include "secril-client.h"
 
@@ -66,7 +67,6 @@
 // Default audio input buffer size in bytes (8kHz mono)
 #define AUDIO_HW_IN_PERIOD_BYTES ((AUDIO_HW_IN_PERIOD_SZ*sizeof(int16_t))/8)
 
-#define INPUT_SOURCE_KEY "Input Source"
 
 class AudioHardware : public AudioHardwareBase
 {
@@ -74,6 +74,12 @@
     class AudioStreamInALSA;
 public:
 
+    // input path names used to translate from input sources to driver paths
+    static const char *inputPathNameDefault;
+    static const char *inputPathNameCamcorder;
+    static const char *inputPathNameVoiceRecognition;
+    static const char *inputPathNameVoiceCommunication;
+
     AudioHardware();
     virtual ~AudioHardware();
     virtual status_t initCheck();
@@ -111,7 +117,7 @@
 
             status_t setIncallPath_l(uint32_t device);
 
-            status_t setInputSource_l(String8 source);
+            status_t setInputSource_l(audio_source source);
 
     static uint32_t    getInputSampleRate(uint32_t sampleRate);
            sp <AudioStreamInALSA> getActiveInput_l();
@@ -142,7 +148,7 @@
     uint32_t        mMixerOpenCnt;
     bool            mInCallAudioMode;
 
-    String8         mInputSource;
+    audio_source    mInputSource;
     bool            mBluetoothNrec;
     void*           mSecRilLibHandle;
     HRilClient      mRilClient;
diff --git a/libaudio/AudioPolicyManager.cpp b/libaudio/AudioPolicyManager.cpp
index 93d70d8..c53d1e9 100644
--- a/libaudio/AudioPolicyManager.cpp
+++ b/libaudio/AudioPolicyManager.cpp
@@ -43,32 +43,4 @@
 }
 
 
-status_t AudioPolicyManager::startInput(audio_io_handle_t input)
-{
-    status_t status = AudioPolicyManagerBase::startInput(input);
-
-    if (status == NO_ERROR) {
-        AudioInputDescriptor *inputDesc = mInputs.valueFor(input);
-        String8 key = String8("Input Source");
-        String8 value;
-        switch(inputDesc->mInputSource) {
-        case AUDIO_SOURCE_VOICE_RECOGNITION:
-            value = String8("Voice Recognition");
-            break;
-        case AUDIO_SOURCE_CAMCORDER:
-            value = String8("Camcorder");
-            break;
-        case AUDIO_SOURCE_DEFAULT:
-        case AUDIO_SOURCE_MIC:
-            value = String8("Default");
-        default:
-            break;
-        }
-        AudioParameter param = AudioParameter();
-        param.add(key, value);
-        mpClientInterface->setParameters(input, param.toString());
-    }
-    return status;
-}
-
 }; // namespace android
diff --git a/libaudio/AudioPolicyManager.h b/libaudio/AudioPolicyManager.h
index ae283db..03141e5 100644
--- a/libaudio/AudioPolicyManager.h
+++ b/libaudio/AudioPolicyManager.h
@@ -34,7 +34,6 @@
 
         virtual ~AudioPolicyManager() {}
 
-        virtual status_t startInput(audio_io_handle_t input);
 protected:
         // true is current platform implements a back microphone
         virtual bool hasBackMicrophone() const { return false; }