audio: changes for new audio device enums

Modifications for new audio device enums:
- Separated input and output device fields as output and input device
values are now on 32 bits.
- changed audio device API version to 2.0

Also removed get_supported_devices() function not needed if audio_policy.conf
file is present.

Change-Id: Ieb32abfa3c3aac1fb9c16dc73350d5cc231e41a4
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 5159cb5..6527885 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -101,7 +101,8 @@
     struct audio_hw_device hw_device;
 
     pthread_mutex_t lock; /* see note below on mutex acquisition order */
-    unsigned int devices;
+    unsigned int out_device;
+    unsigned int in_device;
     bool standby;
     bool mic_mute;
     struct audio_route *ar;
@@ -183,10 +184,10 @@
     int speaker_on;
     int main_mic_on;
 
-    headphone_on = adev->devices & (AUDIO_DEVICE_OUT_WIRED_HEADSET |
+    headphone_on = adev->out_device & (AUDIO_DEVICE_OUT_WIRED_HEADSET |
                                     AUDIO_DEVICE_OUT_WIRED_HEADPHONE);
-    speaker_on = adev->devices & AUDIO_DEVICE_OUT_SPEAKER;
-    main_mic_on = adev->devices & AUDIO_DEVICE_IN_BUILTIN_MIC;
+    speaker_on = adev->out_device & AUDIO_DEVICE_OUT_SPEAKER;
+    main_mic_on = adev->in_device & AUDIO_DEVICE_IN_BUILTIN_MIC;
 
     reset_mixer_state(adev->ar);
 
@@ -264,7 +265,7 @@
      * (speaker/headphone) PCM or the BC SCO PCM open at
      * the same time.
      */
-    if (adev->devices & AUDIO_DEVICE_OUT_ALL_SCO) {
+    if (adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
         device = PCM_DEVICE_SCO;
         out->pcm_config = &pcm_config_sco;
     } else {
@@ -333,7 +334,7 @@
      * it greatly simplifies things to have only the main
      * mic PCM or the BC SCO PCM open at the same time.
      */
-    if (adev->devices & AUDIO_DEVICE_IN_ALL_SCO) {
+    if (adev->in_device & AUDIO_DEVICE_IN_ALL_SCO) {
         device = PCM_DEVICE_SCO;
         in->pcm_config = &pcm_config_sco;
     } else {
@@ -593,20 +594,19 @@
     pthread_mutex_lock(&adev->lock);
     if (ret >= 0) {
         val = atoi(value);
-        if (((adev->devices & AUDIO_DEVICE_OUT_ALL) != val) && (val != 0)) {
+        if ((adev->out_device != val) && (val != 0)) {
             /*
              * If SCO is turned on/off, we need to put audio into standby
              * because SCO uses a different PCM.
              */
             if ((val & AUDIO_DEVICE_OUT_ALL_SCO) ^
-                    (adev->devices & AUDIO_DEVICE_OUT_ALL_SCO)) {
+                    (adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO)) {
                 pthread_mutex_lock(&out->lock);
                 do_out_standby(out);
                 pthread_mutex_unlock(&out->lock);
             }
 
-            adev->devices &= ~AUDIO_DEVICE_OUT_ALL;
-            adev->devices |= val;
+            adev->out_device = val;
             select_devices(adev);
         }
     }
@@ -629,7 +629,7 @@
 
     pthread_mutex_lock(&adev->lock);
 
-    if (adev->screen_off && !adev->active_in && !(adev->devices & AUDIO_DEVICE_OUT_ALL_SCO))
+    if (adev->screen_off && !adev->active_in && !(adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO))
         period_count = OUT_LONG_PERIOD_COUNT;
     else
         period_count = OUT_SHORT_PERIOD_COUNT;
@@ -677,7 +677,7 @@
     }
     buffer_type = (adev->screen_off && !adev->active_in) ?
             OUT_BUFFER_TYPE_LONG : OUT_BUFFER_TYPE_SHORT;
-    sco_on = (adev->devices & AUDIO_DEVICE_OUT_ALL_SCO);
+    sco_on = (adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO);
     pthread_mutex_unlock(&adev->lock);
 
     /* detect changes in screen ON/OFF state and adapt buffer size
@@ -897,21 +897,20 @@
                             value, sizeof(value));
     pthread_mutex_lock(&adev->lock);
     if (ret >= 0) {
-        val = atoi(value);
-        if (((adev->devices & AUDIO_DEVICE_IN_ALL) != val) && (val != 0)) {
+        val = atoi(value) & ~AUDIO_DEVICE_BIT_IN;
+        if ((adev->in_device != val) && (val != 0)) {
             /*
              * If SCO is turned on/off, we need to put audio into standby
              * because SCO uses a different PCM.
              */
             if ((val & AUDIO_DEVICE_IN_ALL_SCO) ^
-                    (adev->devices & AUDIO_DEVICE_IN_ALL_SCO)) {
+                    (adev->in_device & AUDIO_DEVICE_IN_ALL_SCO)) {
                 pthread_mutex_lock(&in->lock);
                 do_in_standby(in);
                 pthread_mutex_unlock(&in->lock);
             }
 
-            adev->devices &= ~AUDIO_DEVICE_IN_ALL;
-            adev->devices |= val;
+            adev->in_device = val;
             select_devices(adev);
         }
     }
@@ -1254,22 +1253,6 @@
     return 0;
 }
 
-static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
-{
-    return (/* OUT */
-            AUDIO_DEVICE_OUT_SPEAKER |
-            AUDIO_DEVICE_OUT_WIRED_HEADSET |
-            AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
-            AUDIO_DEVICE_OUT_ALL_SCO |
-            AUDIO_DEVICE_OUT_DEFAULT |
-            /* IN */
-            AUDIO_DEVICE_IN_BUILTIN_MIC |
-            AUDIO_DEVICE_IN_WIRED_HEADSET |
-            AUDIO_DEVICE_IN_BACK_MIC |
-            AUDIO_DEVICE_IN_ALL_SCO |
-            AUDIO_DEVICE_IN_DEFAULT);
-}
-
 static int adev_open(const hw_module_t* module, const char* name,
                      hw_device_t** device)
 {
@@ -1284,11 +1267,10 @@
         return -ENOMEM;
 
     adev->hw_device.common.tag = HARDWARE_DEVICE_TAG;
-    adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_1_0;
+    adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
     adev->hw_device.common.module = (struct hw_module_t *) module;
     adev->hw_device.common.close = adev_close;
 
-    adev->hw_device.get_supported_devices = adev_get_supported_devices;
     adev->hw_device.init_check = adev_init_check;
     adev->hw_device.set_voice_volume = adev_set_voice_volume;
     adev->hw_device.set_master_volume = adev_set_master_volume;
@@ -1306,6 +1288,8 @@
 
     adev->ar = audio_route_init();
     adev->orientation = ORIENTATION_UNDEFINED;
+    adev->out_device = AUDIO_DEVICE_OUT_SPEAKER;
+    adev->in_device = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN;
 
     *device = &adev->hw_device.common;