Merge "Gralloc: add a HWComposer usage bit"
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index 75c5773..2d7f39d 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -43,18 +43,38 @@
 
 /**************************************/
 
+/**
+ *  standard audio parameters that the HAL may need to handle
+ */
+
+/**
+ *  audio device parameters
+ */
+
 /* BT SCO Noise Reduction + Echo Cancellation parameters */
 #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
 #define AUDIO_PARAMETER_VALUE_ON "on"
 #define AUDIO_PARAMETER_VALUE_OFF "off"
 
-/* standard audio parameters that the HAL may need to handle */
+/* TTY mode selection */
+#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
+#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
+#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
+#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
+#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
+
+/**
+ *  audio stream parameters
+ */
+
 #define AUDIO_PARAMETER_STREAM_ROUTING "routing"
 #define AUDIO_PARAMETER_STREAM_FORMAT "format"
 #define AUDIO_PARAMETER_STREAM_CHANNELS "channels"
 #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count"
 #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source"
 
+/**************************************/
+
 /* common audio stream parameters and operations */
 struct audio_stream {
 
diff --git a/include/hardware/qemu_pipe.h b/include/hardware/qemu_pipe.h
index 570af70..000c99e 100644
--- a/include/hardware/qemu_pipe.h
+++ b/include/hardware/qemu_pipe.h
@@ -20,11 +20,10 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/mman.h>
-#include <hardware/qemud.h>
-#include <hardware/qemu_pipe.h>
 #include <pthread.h>  /* for pthread_once() */
 #include <stdlib.h>
 #include <stdio.h>
+#include <errno.h>
 
 #ifndef D
 #  define  D(...)   do{}while(0)
diff --git a/include/hardware/qemud.h b/include/hardware/qemud.h
index 874a32f..5c39f9c 100644
--- a/include/hardware/qemud.h
+++ b/include/hardware/qemud.h
@@ -18,10 +18,12 @@
 #define ANDROID_INCLUDE_HARDWARE_QEMUD_H
 
 #include <cutils/sockets.h>
+#include "qemu_pipe.h"
 
 /* the following is helper code that is used by the QEMU-specific
  * hardware HAL modules to communicate with the emulator program
- * through the 'qemud' multiplexing daemon.
+ * through the 'qemud' multiplexing daemon, or through the qemud
+ * pipe.
  *
  * see the documentation comments for details in
  * development/emulator/qemud/qemud.c
@@ -64,30 +66,37 @@
     int  fd;
     int  namelen = strlen(name);
     char answer[2];
+    char pipe_name[256];
 
-    /* connect to qemud control socket */
-    fd = socket_local_client( "qemud",
-                              ANDROID_SOCKET_NAMESPACE_RESERVED,
-                              SOCK_STREAM );
+    /* First, try to connect to the pipe. */
+    snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", name);
+    fd = qemu_pipe_open(pipe_name);
     if (fd < 0) {
-        D("no qemud control socket: %s", strerror(errno));
-        return -1;
-    }
+        D("QEMUD pipe is not available for %s: %s", name, strerror(errno));
+        /* If pipe is not available, connect to qemud control socket */
+        fd = socket_local_client( "qemud",
+                                  ANDROID_SOCKET_NAMESPACE_RESERVED,
+                                  SOCK_STREAM );
+        if (fd < 0) {
+            D("no qemud control socket: %s", strerror(errno));
+            return -1;
+        }
 
-    /* send service name to connect */
-    if (qemud_fd_write(fd, name, namelen) != namelen) {
-        D("can't send service name to qemud: %s",
-           strerror(errno));
-        close(fd);
-        return -1;
-    }
+        /* send service name to connect */
+        if (qemud_fd_write(fd, name, namelen) != namelen) {
+            D("can't send service name to qemud: %s",
+               strerror(errno));
+            close(fd);
+            return -1;
+        }
 
-    /* read answer from daemon */
-    if (qemud_fd_read(fd, answer, 2) != 2 ||
-        answer[0] != 'O' || answer[1] != 'K') {
-        D("cant' connect to %s service through qemud", name);
-        close(fd);
-        return -1;
+        /* read answer from daemon */
+        if (qemud_fd_read(fd, answer, 2) != 2 ||
+            answer[0] != 'O' || answer[1] != 'K') {
+            D("cant' connect to %s service through qemud", name);
+            close(fd);
+            return -1;
+        }
     }
     return fd;
 }