hal: Support the audio amplifier hook

* Original legacy HAL commit:
  Ib236598a5888b2af19bcfb81e285f644a0e84c0d
* Example: http://review.cyanogenmod.org/38221

Change-Id: Ic944a9f7059c78b79322dae9c787cdd8bb029cff
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index af1dfb5..4978a4f 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -56,6 +56,10 @@
 #include "sound/compress_params.h"
 #include "sound/asound.h"
 
+#ifdef USES_AUDIO_AMPLIFIER
+#include <audio_amplifier.h>
+#endif
+
 #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4
 /* ToDo: Check and update a proper value in msec */
 #define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 96
@@ -875,6 +879,13 @@
 
     enable_audio_route(adev, usecase);
 
+#ifdef USES_AUDIO_AMPLIFIER
+    /* Rely on amplifier_set_devices to distinguish between in/out devices */
+    amplifier_set_devices(in_snd_device);
+    amplifier_set_devices(out_snd_device);
+#endif
+
+
     /* Applicable only on the targets that has external modem.
      * Enable device command should be sent to modem only after
      * enabling voice call mixer controls
@@ -3086,6 +3097,10 @@
     pthread_mutex_lock(&adev->lock);
     if (adev->mode != mode) {
         ALOGD("%s mode %d\n", __func__, mode);
+#ifdef USES_AUDIO_AMPLIFIER
+        if (amplifier_set_mode(mode) != 0)
+            ALOGE("Failed setting amplifier mode");
+#endif
         adev->mode = mode;
     }
     pthread_mutex_unlock(&adev->lock);
@@ -3433,6 +3448,10 @@
     pthread_mutex_lock(&adev_init_lock);
 
     if ((--audio_device_ref_count) == 0) {
+#ifdef USES_AUDIO_AMPLIFIER
+        if (amplifier_close() != 0)
+            ALOGE("Amplifier close failed");
+#endif
         audio_extn_listen_deinit(adev);
         audio_route_free(adev->audio_route);
         free(adev->snd_dev_ref_cnt);
@@ -3583,6 +3602,11 @@
     if (k_enable_extended_precision)
         adev_verify_devices(adev);
 
+#ifdef USES_AUDIO_AMPLIFIER
+    if (amplifier_open() != 0)
+        ALOGE("Amplifier initialization failed");
+#endif
+
     audio_device_ref_count++;
 
     char value[PROPERTY_VALUE_MAX];