Merge "Update GPS measurement HAL definition." into lmp-dev
diff --git a/include/hardware/bt_gatt_client.h b/include/hardware/bt_gatt_client.h
index c96789b..64c51ab 100644
--- a/include/hardware/bt_gatt_client.h
+++ b/include/hardware/bt_gatt_client.h
@@ -370,6 +370,10 @@
     /** Configure the MTU for a given connection */
     bt_status_t (*configure_mtu)(int conn_id, int mtu);
 
+    /** Request a connection parameter update */
+    bt_status_t (*conn_parameter_update)(const bt_bdaddr_t *bd_addr, int min_interval,
+                    int max_interval, int latency, int timeout);
+
     /** Sets the LE scan interval and window in units of N*0.625 msec */
     bt_status_t (*set_scan_parameters)(int scan_interval, int scan_window);
 
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h
index 882bade..af04181 100644
--- a/include/hardware/hwcomposer.h
+++ b/include/hardware/hwcomposer.h
@@ -619,12 +619,8 @@
          * setPowerMode(..., mode)
          * Sets the display screen's power state.
          *
-         * The expected functionality for the various modes is as follows:
-         * HWC_POWER_MODE_OFF    : Turn the display off.
-         * HWC_POWER_MODE_DOZE   : Turn on the display (if it was previously
-         *                         off) and put the display in a low power mode.
-         * HWC_POWER_MODE_NORMAL : Turn on the display (if it was previously
-         *                         off), and take it out of low power mode.
+         * Refer to the documentation of the HWC_POWER_MODE_* constants
+         * for information about each power mode.
          *
          * The functionality is similar to the blank() command in previous
          * versions of HWC, but with support for more power states.
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
index bd6e1e6..d24bc9d 100644
--- a/include/hardware/hwcomposer_defs.h
+++ b/include/hardware/hwcomposer_defs.h
@@ -201,9 +201,28 @@
 
 /* Display power modes */
 enum {
+    /* The display is turned off (blanked). */
     HWC_POWER_MODE_OFF      = 0,
+    /* The display is turned on and configured in a low power state
+     * that is suitable for presenting ambient information to the user,
+     * possibly with lower fidelity than normal but greater efficiency. */
     HWC_POWER_MODE_DOZE     = 1,
+    /* The display is turned on normally. */
     HWC_POWER_MODE_NORMAL   = 2,
+    /* The display is configured as in HWC_POWER_MODE_DOZE but may
+     * stop applying frame buffer updates from the graphics subsystem.
+     * This power mode is effectively a hint from the doze dream to
+     * tell the hardware that it is done drawing to the display for the
+     * time being and that the display should remain on in a low power
+     * state and continue showing its current contents indefinitely
+     * until the mode changes.
+     *
+     * This mode may also be used as a signal to enable hardware-based doze
+     * functionality.  In this case, the doze dream is effectively
+     * indicating that the hardware is free to take over the display
+     * and manage it autonomously to implement low power always-on display
+     * functionality. */
+    HWC_POWER_MODE_DOZE_SUSPEND  = 3,
 };
 
 /*****************************************************************************/
diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h
index 5ba5ef7..ec68b2b 100644
--- a/include/hardware/sensors.h
+++ b/include/hardware/sensors.h
@@ -577,6 +577,43 @@
 #define SENSOR_TYPE_WAKE_GESTURE                               (42)
 #define SENSOR_STRING_TYPE_WAKE_GESTURE                        "android.sensor.wake_gesture"
 
+/*
+ * SENSOR_TYPE_GLANCE_GESTURE
+ * reporting-mode: one-shot
+ * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
+ *
+ * A sensor enabling briefly turning the screen on to enable the user to
+ * glance content on screen based on a specific motion.  The device should
+ * turn the screen off after a few moments.
+ *
+ * When this sensor triggers, the device turns the screen on momentarily
+ * to allow the user to glance notifications or other content while the
+ * device remains locked in a non-interactive state (dozing). This behavior
+ * (briefly turning on the screen when this sensor triggers) might be deactivated
+ * by the user in the device settings. Changes in settings do not impact the
+ * behavior of the sensor: only whether the framework briefly turns the screen on
+ * when it triggers.
+ *
+ * The actual gesture to be detected is not specified, and can be chosen by
+ * the manufacturer of the device.
+ * This sensor must be low power, as it is likely to be activated 24/7.
+ * The only allowed value to return is 1.0.
+ */
+#define SENSOR_TYPE_GLANCE_GESTURE                             (43)
+#define SENSOR_STRING_TYPE_GLANCE_GESTURE                      "android.sensor.glance_gesture"
+
+/**
+ * SENSOR_TYPE_PICK_UP_GESTURE
+ * reporting-mode: one-shot
+ * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
+ *
+ * A sensor of this type triggers when the device is picked up regardless of wherever is was
+ * before (desk, pocket, bag). The only allowed return value is 1.0.
+ * This sensor de-activates itself immediately after it triggers.
+ */
+#define SENSOR_TYPE_PICK_UP_GESTURE                            (43)
+#define SENSOR_STRING_TYPE_PICK_UP_GESTURE                     "android.sensor.pick_up_gesture"
+
 /**
  * Values returned by the accelerometer in various locations in the universe.
  * all values are in SI units (m/s^2)
@@ -950,7 +987,6 @@
 } sensors_poll_device_1_t;
 
 
-
 /** convenience API for opening and closing a device */
 
 static inline int sensors_open(const struct hw_module_t* module,
diff --git a/include/hardware/tv_input.h b/include/hardware/tv_input.h
index e721caa..a94e4ea 100644
--- a/include/hardware/tv_input.h
+++ b/include/hardware/tv_input.h
@@ -63,14 +63,19 @@
 /*****************************************************************************/
 
 enum {
-    /* HDMI */
-    TV_INPUT_TYPE_HDMI = 1,
-
-    /* Built-in tuners. */
-    TV_INPUT_TYPE_BUILT_IN_TUNER = 2,
-
-    /* Passthrough */
-    TV_INPUT_TYPE_PASSTHROUGH = 3,
+    /* Generic hardware. */
+    TV_INPUT_TYPE_OTHER_HARDWARE = 1,
+    /* Tuner. (e.g. built-in terrestrial tuner) */
+    TV_INPUT_TYPE_TUNER = 2,
+    TV_INPUT_TYPE_COMPOSITE = 3,
+    TV_INPUT_TYPE_SVIDEO = 4,
+    TV_INPUT_TYPE_SCART = 5,
+    TV_INPUT_TYPE_COMPONENT = 6,
+    TV_INPUT_TYPE_VGA = 7,
+    TV_INPUT_TYPE_DVI = 8,
+    /* Physical HDMI port. (e.g. HDMI 1) */
+    TV_INPUT_TYPE_HDMI = 9,
+    TV_INPUT_TYPE_DISPLAY_PORT = 10,
 };
 typedef uint32_t tv_input_type_t;
 
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index 2af7897..89c498b 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -21,8 +21,9 @@
 LOCAL_SRC_FILES := \
 	audio_hw.c
 LOCAL_C_INCLUDES += \
-	external/tinyalsa/include
-LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa
+	external/tinyalsa/include \
+	$(call include-path-for, audio-utils)
+LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils
 LOCAL_MODULE_TAGS := optional
 LOCAL_CFLAGS := -Wno-unused-parameter
 
diff --git a/modules/usbaudio/audio_hw.c b/modules/usbaudio/audio_hw.c
index 8fbd528..05f0d2b 100644
--- a/modules/usbaudio/audio_hw.c
+++ b/modules/usbaudio/audio_hw.c
@@ -37,6 +37,8 @@
 
 #include <tinyalsa/asoundlib.h>
 
+#include <audio_utils/channels.h>
+
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 /* This is the default configuration to hand to The Framework on the initial
@@ -225,263 +227,6 @@
 }
 
 /*
- * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels
- * (where N < M).
- *   in_buff points to the buffer of PCM16 samples
- *   in_buff_channels Specifies the number of channels in the input buffer.
- *   out_buff points to the buffer to receive converted PCM16 samples.
- *   out_buff_channels Specifies the number of channels in the output buffer.
- *   num_in_bytes size of input buffer in BYTES
- * returns
- *   the number of BYTES of output data.
- * NOTE
- *   channels > N are filled with silence.
- *   This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t expand_channels_16(const int16_t* in_buff, int in_buff_chans,
-                                 int16_t* out_buff, int out_buff_chans,
-                                 size_t num_in_bytes)
-{
-    /*
-     * Move from back to front so that the conversion can be done in-place
-     * i.e. in_buff == out_buff
-     * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
-     */
-    size_t num_in_samples = num_in_bytes / sizeof(int16_t);
-
-    size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
-    short* dst_ptr = out_buff + num_out_samples - 1;
-    size_t src_index;
-    const short* src_ptr = in_buff + num_in_samples - 1;
-    int num_zero_chans = out_buff_chans - in_buff_chans;
-    for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
-        int dst_offset;
-        for (dst_offset = 0; dst_offset < num_zero_chans; dst_offset++) {
-            *dst_ptr-- = 0;
-        }
-        for (; dst_offset < out_buff_chans; dst_offset++) {
-            *dst_ptr-- = *src_ptr--;
-        }
-    }
-
-    /* return number of *bytes* generated */
-    return num_out_samples * sizeof(int16_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM16 samples to M-channel PCM16 channels
- * (where N > M).
- *   in_buff points to the buffer of PCM16 samples
- *   in_buff_channels Specifies the number of channels in the input buffer.
- *   out_buff points to the buffer to receive converted PCM16 samples.
- *   out_buff_channels Specifies the number of channels in the output buffer.
- *   num_in_bytes size of input buffer in BYTES
- * returns
- *   the number of BYTES of output data.
- * NOTE
- *   channels > N are thrown away.
- *   This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t contract_channels_16(const int16_t* in_buff, size_t in_buff_chans,
-                                   int16_t* out_buff, size_t out_buff_chans,
-                                   size_t num_in_bytes)
-{
-    /*
-     * Move from front to back so that the conversion can be done in-place
-     * i.e. in_buff == out_buff
-     * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
-     */
-    size_t num_in_samples = num_in_bytes / sizeof(int16_t);
-
-    size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
-    size_t num_skip_samples = in_buff_chans - out_buff_chans;
-
-    int16_t* dst_ptr = out_buff;
-    const int16_t* src_ptr = in_buff;
-    size_t src_index;
-    for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
-        size_t dst_offset;
-        for (dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) {
-            *dst_ptr++ = *src_ptr++;
-        }
-        src_ptr += num_skip_samples;
-    }
-
-    /* return number of *bytes* generated */
-    return num_out_samples * sizeof(int16_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM32 samples to M-channel PCM32 channels
- * (where N < M).
- *   in_buff points to the buffer of PCM32 samples
- *   in_buff_channels Specifies the number of channels in the input buffer.
- *   out_buff points to the buffer to receive converted PCM32 samples.
- *   out_buff_channels Specifies the number of channels in the output buffer.
- *   num_in_bytes size of input buffer in BYTES
- * returns
- *   the number of BYTES of output data.
- * NOTE
- *   channels > N are filled with silence.
- *   This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t expand_channels_32(const int32_t* in_buff, size_t in_buff_chans,
-                                 int32_t* out_buff, size_t out_buff_chans,
-                                 size_t num_in_bytes)
-{
-    /*
-     * Move from back to front so that the conversion can be done in-place
-     * i.e. in_buff == out_buff
-     * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
-     */
-    size_t num_in_samples = num_in_bytes / sizeof(int32_t);
-
-    size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
-    int32_t* dst_ptr = out_buff + num_out_samples - 1;
-    const int32_t* src_ptr = in_buff + num_in_samples - 1;
-    size_t num_zero_chans = out_buff_chans - in_buff_chans;
-    size_t src_index;
-    for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
-        size_t dst_offset;
-        for (dst_offset = 0; dst_offset < num_zero_chans; dst_offset++) {
-            *dst_ptr-- = 0;
-        }
-        for (; dst_offset < out_buff_chans; dst_offset++) {
-            *dst_ptr-- = *src_ptr--;
-        }
-    }
-
-    /* return number of *bytes* generated */
-    return num_out_samples * sizeof(int32_t);
-}
-
-/*
- * Convert a buffer of N-channel, interleaved PCM32 samples to M-channel PCM16 channels
- * (where N > M).
- *   in_buff points to the buffer of PCM32 samples
- *   in_buff_channels Specifies the number of channels in the input buffer.
- *   out_buff points to the buffer to receive converted PCM16 samples.
- *   out_buff_channels Specifies the number of channels in the output buffer.
- *   num_in_bytes size of input buffer in BYTES
- * returns
- *   the number of BYTES of output data.
- * NOTE
- *   channels > N are thrown away.
- *   This conversion is safe to do in-place (in_buff == out_buff)
- * We are doing this since we *always* present to The Framework as STEREO device, but need to
- * support 4-channel devices.
- * TODO Move this to a utilities module.
- */
-static size_t contract_channels_32(const int32_t* in_buff, size_t in_buff_chans,
-                                   int32_t* out_buff, size_t out_buff_chans,
-                                   size_t num_in_bytes)
-{
-    /*
-     * Move from front to back so that the conversion can be done in-place
-     * i.e. in_buff == out_buff
-     * NOTE: num_in_samples * out_buff_channels must be an even multiple of in_buff_chans
-     */
-    size_t num_in_samples = num_in_bytes / sizeof(int32_t);
-
-    size_t num_out_samples = (num_in_samples * out_buff_chans) / in_buff_chans;
-
-    size_t num_skip_samples = in_buff_chans - out_buff_chans;
-
-    int32_t* dst_ptr = out_buff;
-    const int32_t* src_ptr = in_buff;
-    size_t src_index;
-    for (src_index = 0; src_index < num_in_samples; src_index += in_buff_chans) {
-        size_t dst_offset;
-        for (dst_offset = 0; dst_offset < out_buff_chans; dst_offset++) {
-            *dst_ptr++ = *src_ptr++;
-        }
-        src_ptr += num_skip_samples;
-    }
-
-    /* return number of *bytes* generated */
-    return num_out_samples * sizeof(int32_t);
-}
-
-static size_t contract_channels(const void* in_buff, size_t in_buff_chans,
-                                void* out_buff, size_t out_buff_chans,
-                                unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
-    switch (sample_size_in_bytes) {
-    case 2:
-        return contract_channels_16((const int16_t*)in_buff, in_buff_chans,
-                                    (int16_t*)out_buff, out_buff_chans,
-                                    num_in_bytes);
-
-    /* TODO - do this conversion when we have a device to test it with */
-    case 3:
-        ALOGE("24-bit channel contraction not supported.");
-        return 0;
-
-    case 4:
-        return contract_channels_32((const int32_t*)in_buff, in_buff_chans,
-                                    (int32_t*)out_buff, out_buff_chans,
-                                    num_in_bytes);
-
-    default:
-        return 0;
-    }
-}
-
-static size_t expand_channels(const void* in_buff, size_t in_buff_chans,
-                                void* out_buff, size_t out_buff_chans,
-                                unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
-    switch (sample_size_in_bytes) {
-    case 2:
-        return expand_channels_16((const int16_t*)in_buff, in_buff_chans,
-                                  (int16_t*)out_buff, out_buff_chans,
-                                  num_in_bytes);
-
-    /* TODO - do this conversion when we have a device to test it with */
-    case 3:
-        ALOGE("24-bit channel expansion not supported.");
-        return 0;
-
-    case 4:
-        return expand_channels_32((const int32_t*)in_buff, in_buff_chans,
-                                  (int32_t*)out_buff, out_buff_chans,
-                                  num_in_bytes);
-
-    default:
-        return 0;
-    }
-}
-
-static size_t adjust_channels(const void* in_buff, size_t in_buff_chans,
-                              void* out_buff, size_t out_buff_chans,
-                              unsigned sample_size_in_bytes, size_t num_in_bytes)
-{
-    if (out_buff_chans > in_buff_chans) {
-        return expand_channels(in_buff, in_buff_chans, out_buff,  out_buff_chans,
-                               sample_size_in_bytes, num_in_bytes);
-    } else if (out_buff_chans < in_buff_chans) {
-        return contract_channels(in_buff, in_buff_chans, out_buff,  out_buff_chans,
-                                 sample_size_in_bytes, num_in_bytes);
-    } else if (in_buff != out_buff) {
-        memcpy(out_buff, in_buff, num_in_bytes);
-    }
-
-    return num_in_bytes;
-}
-
-/*
  * ALSA Utilities
  */
 /*TODO This table and the function that uses it should be moved to a utilities module (probably) */