Merge "hardware: camera_common: add module open legacy device API"
diff --git a/include/hardware/activity_recognition.h b/include/hardware/activity_recognition.h
index 6ae90b7..8f99459 100644
--- a/include/hardware/activity_recognition.h
+++ b/include/hardware/activity_recognition.h
@@ -39,24 +39,39 @@
 #define ACTIVITY_RECOGNITION_HARDWARE_INTERFACE "activity_recognition_hw_if"
 
 /*
- * Define constants for various activity types. Multiple activities may be active at the same time
- * and sometimes none of these activities may be active.
+ * Define types for various activities. Multiple activities may be active at the same time and
+ * sometimes none of these activities may be active.
+ *
+ * Each activity has a corresponding type. Only activities that are defined here should use
+ * android.activity_recognition.* prefix. OEM defined activities should not use this prefix.
+ * Activity type of OEM-defined activities should start with the reverse domain name of the entity
+ * defining the activity.
+ *
+ * When android introduces a new activity type that can potentially replace an OEM-defined activity
+ * type, the OEM must use the official activity type on versions of the HAL that support this new
+ * official activity type.
+ *
+ * Example (made up): Suppose Google's Glass team wants to detect nodding activity.
+ *  - Such an activity is not officially supported in android L
+ *  - Glass devices launching on L can implement a custom activity with
+ *    type = "com.google.glass.nodding"
+ *  - In M android release, if android decides to define ACITIVITY_TYPE_NODDING, those types
+ *    should replace the Glass-team-specific types in all future launches.
+ *  - When launching glass on the M release, Google should now use the official activity type
+ *  - This way, other applications can use this activity.
  */
 
-/* Reserved. get_supported_activities_list() should not return this activity. */
-#define ACTIVITY_RESERVED          (0)
+#define ACTIVITY_TYPE_IN_VEHICLE       "android.activity_recognition.in_vehicle"
 
-#define ACTIVITY_IN_VEHICLE        (1)
+#define ACTIVITY_TYPE_ON_BICYCLE       "android.activity_recognition.on_bicycle"
 
-#define ACTIVITY_ON_BICYCLE        (2)
+#define ACTIVITY_TYPE_WALKING          "android.activity_recognition.walking"
 
-#define ACTIVITY_WALKING           (3)
+#define ACTIVITY_TYPE_RUNNING          "android.activity_recognition.running"
 
-#define ACTIVITY_RUNNING           (4)
+#define ACTIVITY_TYPE_STILL            "android.activity_recognition.still"
 
-#define ACTIVITY_STILL             (5)
-
-#define ACTIVITY_TILTING           (6)
+#define ACTIVITY_TYPE_TILTING          "android.activity_recognition.tilting"
 
 /* Values for activity_event.event_types. */
 enum {
@@ -69,19 +84,19 @@
      * return a flush_complete_event to indicate that the FIFO is empty.
      *
      * A flush complete event should have the following parameters set.
-     * activity_event_t.event_type = ACTIVITY_EVENT_TYPE_FLUSH_COMPLETE
-     * activity_event_t.activity = ACTIVITY_RESERVED
+     * activity_event_t.event_type = ACTIVITY_EVENT_FLUSH_COMPLETE
+     * activity_event_t.activity = 0
      * activity_event_t.timestamp = 0
      * activity_event_t.reserved = 0
      * See (*flush)() for more details.
      */
-    ACTIVITY_EVENT_TYPE_FLUSH_COMPLETE = 0,
+    ACTIVITY_EVENT_FLUSH_COMPLETE = 0,
 
     /* Signifies entering an activity. */
-    ACTIVITY_EVENT_TYPE_ENTER = 1,
+    ACTIVITY_EVENT_ENTER = 1,
 
     /* Signifies exiting an activity. */
-    ACTIVITY_EVENT_TYPE_EXIT  = 2
+    ACTIVITY_EVENT_EXIT  = 2
 };
 
 /*
@@ -89,10 +104,13 @@
  * or ended. Eg event: (event_type="enter", activity="ON_FOOT", timestamp)
  */
 typedef struct activity_event {
-    /* One of the ACTIVITY_EVENT_TYPE_* constants defined above. */
+    /* One of the ACTIVITY_EVENT_* constants defined above. */
     uint32_t event_type;
 
-    /* One of ACTIVITY_* constants defined above. */
+    /*
+     * Index of the activity in the list returned by get_supported_activities_list. If this event
+     * is a flush complete event, this should be set to zero.
+     */
     uint32_t activity;
 
     /* Time at which the transition/event has occurred in nanoseconds using elapsedRealTimeNano. */
@@ -112,12 +130,14 @@
     hw_module_t common;
 
     /*
-     * List of all activities supported by this module. Each activity is represented as an integer.
-     * Each value in the list is one of the ACTIVITY_* constants defined above. Return
-     * value is the size of this list.
+     * List of all activities supported by this module including OEM defined activities. Each
+     * activity is represented using a string defined above. Each string should be null terminated.
+     * The index of the activity in this array is used as a "handle" for enabling/disabling and
+     * event delivery.
+     * Return value is the size of this list.
      */
     int (*get_supported_activities_list)(struct activity_recognition_module* module,
-            int** activity_list);
+            char const* const* *activity_list);
 } activity_recognition_module_t;
 
 struct activity_recognition_device;
@@ -159,26 +179,27 @@
      * independently of the other. The HAL implementation needs to keep track of which pairs are
      * currently active and needs to detect only those pairs.
      *
-     * activity   - The specific activity that needs to be detected.
+     * activity_handle - Index of the specific activity that needs to be detected in the list
+     *                   returned by get_supported_activities_list.
      * event_type - Specific transition of the activity that needs to be detected.
      * max_batch_report_latency_ns - a transition can be delayed by at most
      *                               “max_batch_report_latency” nanoseconds.
      * Return 0 on success, negative errno code otherwise.
      */
     int (*enable_activity_event)(const struct activity_recognition_device* dev,
-            uint32_t activity, uint32_t event_type, int64_t max_batch_report_latency_ns);
+            uint32_t activity_handle, uint32_t event_type, int64_t max_batch_report_latency_ns);
 
     /*
      * Disables detection of a specific (activity, event_type) pair.
      */
     int (*disable_activity_event)(const struct activity_recognition_device* dev,
-            uint32_t activity, uint32_t event_type);
+            uint32_t activity_handle, uint32_t event_type);
 
     /*
      * Flush all the batch FIFOs. Report all the activities that were stored in the FIFO so far as
      * if max_batch_report_latency had expired. This shouldn't change the latency in any way. Add
      * a flush_complete_event to indicate the end of the FIFO after all events are delivered.
-     * See ACTIVITY_EVENT_TYPE_FLUSH_COMPLETE for more details.
+     * See ACTIVITY_EVENT_FLUSH_COMPLETE for more details.
      * Return 0 on success, negative errno code otherwise.
      */
     int (*flush)(const struct activity_recognition_device* dev);
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index d0648b7..6558dda 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -97,6 +97,9 @@
 /* A2DP sink address set by framework */
 #define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
 
+/* A2DP source address set by framework */
+#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
+
 /* Screen state */
 #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
 
diff --git a/include/hardware/bluetooth.h b/include/hardware/bluetooth.h
index c00a8f7..19c3410 100644
--- a/include/hardware/bluetooth.h
+++ b/include/hardware/bluetooth.h
@@ -17,6 +17,7 @@
 #ifndef ANDROID_INCLUDE_BLUETOOTH_H
 #define ANDROID_INCLUDE_BLUETOOTH_H
 
+#include <stdbool.h>
 #include <stdint.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
@@ -37,7 +38,9 @@
 /* Bluetooth profile interface IDs */
 
 #define BT_PROFILE_HANDSFREE_ID "handsfree"
+#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
 #define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
+#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
 #define BT_PROFILE_HEALTH_ID "health"
 #define BT_PROFILE_SOCKETS_ID "socket"
 #define BT_PROFILE_HIDHOST_ID "hidhost"
@@ -45,6 +48,7 @@
 
 #define BT_PROFILE_GATT_ID "gatt"
 #define BT_PROFILE_AV_RC_ID "avrcp"
+#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
 
 /** Bluetooth Address */
 typedef struct {
@@ -126,6 +130,16 @@
    int manufacturer;
 } bt_remote_version_t;
 
+typedef struct
+{
+    uint8_t local_privacy_enabled;
+    uint8_t max_adv_instance;
+    uint8_t rpa_offload_supported;
+    uint8_t max_irk_list_size;
+    uint8_t max_adv_filter_supported;
+    uint8_t scan_result_storage_size;
+}bt_local_le_features_t;
+
 /* Bluetooth Adapter and Remote Device property types */
 typedef enum {
     /* Properties common to both adapter and remote device */
@@ -208,6 +222,13 @@
 
     BT_PROPERTY_REMOTE_VERSION_INFO,
 
+    /**
+     * Description - Local LE features
+     * Access mode - GET.
+     * Data type   - bt_local_le_features_t.
+     */
+    BT_PROPERTY_LOCAL_LE_FEATURES,
+
     BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
 } bt_property_type_t;
 
@@ -219,6 +240,7 @@
     void *val;
 } bt_property_t;
 
+
 /** Bluetooth Device Type */
 typedef enum {
     BT_DEVICE_DEVTYPE_BREDR = 0x1,
@@ -342,6 +364,24 @@
     le_test_mode_callback le_test_mode_cb;
 } bt_callbacks_t;
 
+typedef void (*alarm_cb)(void *data);
+typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
+typedef int (*acquire_wake_lock_callout)(const char *lock_name);
+typedef int (*release_wake_lock_callout)(const char *lock_name);
+
+/** The set of functions required by bluedroid to set wake alarms and
+  * grab wake locks. This struct is passed into the stack through the
+  * |set_os_callouts| function on |bt_interface_t|.
+  */
+typedef struct {
+  /* set to sizeof(bt_os_callouts_t) */
+  size_t size;
+
+  set_wake_alarm_callout set_wake_alarm;
+  acquire_wake_lock_callout acquire_wake_lock;
+  release_wake_lock_callout release_wake_lock;
+} bt_os_callouts_t;
+
 /** NOTE: By default, no profiles are initialized at the time of init/enable.
  *  Whenever the application invokes the 'init' API of a profile, then one of
  *  the following shall occur:
@@ -453,6 +493,11 @@
 
     /* enable or disable bluetooth HCI snoop log */
     int (*config_hci_snoop_log)(uint8_t enable);
+
+    /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
+      * This should be called immediately after a successful |init|.
+      */
+    int (*set_os_callouts)(bt_os_callouts_t *callouts);
 } bt_interface_t;
 
 /** TODO: Need to add APIs for Service Discovery, Service authorization and
diff --git a/include/hardware/bt_av.h b/include/hardware/bt_av.h
index 2ec00c3..5252a17 100644
--- a/include/hardware/bt_av.h
+++ b/include/hardware/bt_av.h
@@ -47,12 +47,23 @@
 typedef void (* btav_audio_state_callback)(btav_audio_state_t state, 
                                                bt_bdaddr_t *bd_addr);
 
+/** Callback for audio configuration change.
+ *  Used only for the A2DP sink interface.
+ *  state will have one of the values from btav_audio_state_t
+ *  sample_rate: sample rate in Hz
+ *  channel_count: number of channels (1 for mono, 2 for stereo)
+ */
+typedef void (* btav_audio_config_callback)(bt_bdaddr_t *bd_addr,
+                                                uint32_t sample_rate,
+                                                uint8_t channel_count);
+
 /** BT-AV callback structure. */
 typedef struct {
     /** set to sizeof(btav_callbacks_t) */
     size_t      size;
     btav_connection_state_callback  connection_state_cb;
     btav_audio_state_callback audio_state_cb;
+    btav_audio_config_callback audio_config_cb;
 } btav_callbacks_t;
 
 /** 
@@ -65,7 +76,9 @@
  *    android_audio_hw library and the Bluetooth stack.
  * 
  */
-/** Represents the standard BT-AV interface. */
+/** Represents the standard BT-AV interface.
+ *  Used for both the A2DP source and sink interfaces.
+ */
 typedef struct {
 
     /** set to sizeof(btav_interface_t) */
diff --git a/include/hardware/bt_hf_client.h b/include/hardware/bt_hf_client.h
new file mode 100644
index 0000000..8acf1b2
--- /dev/null
+++ b/include/hardware/bt_hf_client.h
@@ -0,0 +1,363 @@
+/*
+ * Copyright (C) 2012-2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_INCLUDE_BT_HF_CLIENT_H
+#define ANDROID_INCLUDE_BT_HF_CLIENT_H
+
+__BEGIN_DECLS
+
+typedef enum {
+    BTHF_CLIENT_CONNECTION_STATE_DISCONNECTED = 0,
+    BTHF_CLIENT_CONNECTION_STATE_CONNECTING,
+    BTHF_CLIENT_CONNECTION_STATE_CONNECTED,
+    BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED,
+    BTHF_CLIENT_CONNECTION_STATE_DISCONNECTING
+} bthf_client_connection_state_t;
+
+typedef enum {
+    BTHF_CLIENT_AUDIO_STATE_DISCONNECTED = 0,
+    BTHF_CLIENT_AUDIO_STATE_CONNECTING,
+    BTHF_CLIENT_AUDIO_STATE_CONNECTED,
+    BTHF_CLIENT_AUDIO_STATE_CONNECTED_MSBC,
+} bthf_client_audio_state_t;
+
+typedef enum {
+    BTHF_CLIENT_VR_STATE_STOPPED = 0,
+    BTHF_CLIENT_VR_STATE_STARTED
+} bthf_client_vr_state_t;
+
+typedef enum {
+    BTHF_CLIENT_VOLUME_TYPE_SPK = 0,
+    BTHF_CLIENT_VOLUME_TYPE_MIC
+} bthf_client_volume_type_t;
+
+typedef enum
+{
+    BTHF_CLIENT_NETWORK_STATE_NOT_AVAILABLE = 0,
+    BTHF_CLIENT_NETWORK_STATE_AVAILABLE
+} bthf_client_network_state_t;
+
+typedef enum
+{
+    BTHF_CLIENT_SERVICE_TYPE_HOME = 0,
+    BTHF_CLIENT_SERVICE_TYPE_ROAMING
+} bthf_client_service_type_t;
+
+typedef enum {
+    BTHF_CLIENT_CALL_STATE_ACTIVE = 0,
+    BTHF_CLIENT_CALL_STATE_HELD,
+    BTHF_CLIENT_CALL_STATE_DIALING,
+    BTHF_CLIENT_CALL_STATE_ALERTING,
+    BTHF_CLIENT_CALL_STATE_INCOMING,
+    BTHF_CLIENT_CALL_STATE_WAITING,
+    BTHF_CLIENT_CALL_STATE_HELD_BY_RESP_HOLD,
+} bthf_client_call_state_t;
+
+typedef enum {
+    BTHF_CLIENT_CALL_NO_CALLS_IN_PROGRESS = 0,
+    BTHF_CLIENT_CALL_CALLS_IN_PROGRESS
+} bthf_client_call_t;
+
+typedef enum {
+    BTHF_CLIENT_CALLSETUP_NONE = 0,
+    BTHF_CLIENT_CALLSETUP_INCOMING,
+    BTHF_CLIENT_CALLSETUP_OUTGOING,
+    BTHF_CLIENT_CALLSETUP_ALERTING
+
+} bthf_client_callsetup_t;
+
+typedef enum {
+    BTHF_CLIENT_CALLHELD_NONE = 0,
+    BTHF_CLIENT_CALLHELD_HOLD_AND_ACTIVE,
+    BTHF_CLIENT_CALLHELD_HOLD,
+} bthf_client_callheld_t;
+
+typedef enum {
+    BTHF_CLIENT_RESP_AND_HOLD_HELD = 0,
+    BTRH_CLIENT_RESP_AND_HOLD_ACCEPT,
+    BTRH_CLIENT_RESP_AND_HOLD_REJECT,
+} bthf_client_resp_and_hold_t;
+
+typedef enum {
+    BTHF_CLIENT_CALL_DIRECTION_OUTGOING = 0,
+    BTHF_CLIENT_CALL_DIRECTION_INCOMING
+} bthf_client_call_direction_t;
+
+typedef enum {
+    BTHF_CLIENT_CALL_MPTY_TYPE_SINGLE = 0,
+    BTHF_CLIENT_CALL_MPTY_TYPE_MULTI
+} bthf_client_call_mpty_type_t;
+
+typedef enum {
+    BTHF_CLIENT_CMD_COMPLETE_OK = 0,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_CARRIER,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_BUSY,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_NO_ANSWER,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_DELAYED,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_BLACKLISTED,
+    BTHF_CLIENT_CMD_COMPLETE_ERROR_CME
+} bthf_client_cmd_complete_t;
+
+typedef enum {
+    BTHF_CLIENT_CALL_ACTION_CHLD_0 = 0,
+    BTHF_CLIENT_CALL_ACTION_CHLD_1,
+    BTHF_CLIENT_CALL_ACTION_CHLD_2,
+    BTHF_CLIENT_CALL_ACTION_CHLD_3,
+    BTHF_CLIENT_CALL_ACTION_CHLD_4,
+    BTHF_CLIENT_CALL_ACTION_CHLD_1x,
+    BTHF_CLIENT_CALL_ACTION_CHLD_2x,
+    BTHF_CLIENT_CALL_ACTION_ATA,
+    BTHF_CLIENT_CALL_ACTION_CHUP,
+    BTHF_CLIENT_CALL_ACTION_BTRH_0,
+    BTHF_CLIENT_CALL_ACTION_BTRH_1,
+    BTHF_CLIENT_CALL_ACTION_BTRH_2,
+} bthf_client_call_action_t;
+
+typedef enum {
+    BTHF_CLIENT_SERVICE_UNKNOWN = 0,
+    BTHF_CLIENT_SERVICE_VOICE,
+    BTHF_CLIENT_SERVICE_FAX
+} bthf_client_subscriber_service_type_t;
+
+typedef enum {
+    BTHF_CLIENT_IN_BAND_RINGTONE_NOT_PROVIDED = 0,
+    BTHF_CLIENT_IN_BAND_RINGTONE_PROVIDED,
+} bthf_client_in_band_ring_state_t;
+
+/* Peer features masks */
+#define BTHF_CLIENT_PEER_FEAT_3WAY   0x00000001  /* Three-way calling */
+#define BTHF_CLIENT_PEER_FEAT_ECNR   0x00000002  /* Echo cancellation and/or noise reduction */
+#define BTHF_CLIENT_PEER_FEAT_VREC   0x00000004  /* Voice recognition */
+#define BTHF_CLIENT_PEER_FEAT_INBAND 0x00000008  /* In-band ring tone */
+#define BTHF_CLIENT_PEER_FEAT_VTAG   0x00000010  /* Attach a phone number to a voice tag */
+#define BTHF_CLIENT_PEER_FEAT_REJECT 0x00000020  /* Ability to reject incoming call */
+#define BTHF_CLIENT_PEER_FEAT_ECS    0x00000040  /* Enhanced Call Status */
+#define BTHF_CLIENT_PEER_FEAT_ECC    0x00000080  /* Enhanced Call Control */
+#define BTHF_CLIENT_PEER_FEAT_EXTERR 0x00000100  /* Extended error codes */
+#define BTHF_CLIENT_PEER_FEAT_CODEC  0x00000200  /* Codec Negotiation */
+
+/* Peer call handling features masks */
+#define BTHF_CLIENT_CHLD_FEAT_REL           0x00000001  /* 0  Release waiting call or held calls */
+#define BTHF_CLIENT_CHLD_FEAT_REL_ACC       0x00000002  /* 1  Release active calls and accept other
+                                                              (waiting or held) cal */
+#define BTHF_CLIENT_CHLD_FEAT_REL_X         0x00000004  /* 1x Release specified active call only */
+#define BTHF_CLIENT_CHLD_FEAT_HOLD_ACC      0x00000008  /* 2  Active calls on hold and accept other
+                                                              (waiting or held) call */
+#define BTHF_CLIENT_CHLD_FEAT_PRIV_X        0x00000010  /* 2x Request private mode with specified
+                                                              call (put the rest on hold) */
+#define BTHF_CLIENT_CHLD_FEAT_MERGE         0x00000020  /* 3  Add held call to multiparty */
+#define BTHF_CLIENT_CHLD_FEAT_MERGE_DETACH  0x00000040  /* 4  Connect two calls and leave
+                                                              (disconnect from) multiparty */
+
+/** Callback for connection state change.
+ *  state will have one of the values from BtHfConnectionState
+ *  peer/chld_features are valid only for BTHF_CLIENT_CONNECTION_STATE_SLC_CONNECTED state
+ */
+typedef void (* bthf_client_connection_state_callback)(bthf_client_connection_state_t state,
+                                                       unsigned int peer_feat,
+                                                       unsigned int chld_feat,
+                                                       bt_bdaddr_t *bd_addr);
+
+/** Callback for audio connection state change.
+ *  state will have one of the values from BtHfAudioState
+ */
+typedef void (* bthf_client_audio_state_callback)(bthf_client_audio_state_t state,
+                                                  bt_bdaddr_t *bd_addr);
+
+/** Callback for VR connection state change.
+ *  state will have one of the values from BtHfVRState
+ */
+typedef void (* bthf_client_vr_cmd_callback)(bthf_client_vr_state_t state);
+
+/** Callback for network state change
+ */
+typedef void (* bthf_client_network_state_callback) (bthf_client_network_state_t state);
+
+/** Callback for network roaming status change
+ */
+typedef void (* bthf_client_network_roaming_callback) (bthf_client_service_type_t type);
+
+/** Callback for signal strength indication
+ */
+typedef void (* bthf_client_network_signal_callback) (int signal_strength);
+
+/** Callback for battery level indication
+ */
+typedef void (* bthf_client_battery_level_callback) (int battery_level);
+
+/** Callback for current operator name
+ */
+typedef void (* bthf_client_current_operator_callback) (const char *name);
+
+/** Callback for call indicator
+ */
+typedef void (* bthf_client_call_callback) (bthf_client_call_t call);
+
+/** Callback for callsetup indicator
+ */
+typedef void (* bthf_client_callsetup_callback) (bthf_client_callsetup_t callsetup);
+
+/** Callback for callheld indicator
+ */
+typedef void (* bthf_client_callheld_callback) (bthf_client_callheld_t callheld);
+
+/** Callback for response and hold
+ */
+typedef void (* bthf_client_resp_and_hold_callback) (bthf_client_resp_and_hold_t resp_and_hold);
+
+/** Callback for Calling Line Identification notification
+ *  Will be called only when there is an incoming call and number is provided.
+ */
+typedef void (* bthf_client_clip_callback) (const char *number);
+
+/**
+ * Callback for Call Waiting notification
+ */
+typedef void (* bthf_client_call_waiting_callback) (const char *number);
+
+/**
+ *  Callback for listing current calls. Can be called multiple time.
+ *  If number is unknown NULL is passed.
+ */
+typedef void (*bthf_client_current_calls) (int index, bthf_client_call_direction_t dir,
+                                           bthf_client_call_state_t state,
+                                           bthf_client_call_mpty_type_t mpty,
+                                           const char *number);
+
+/** Callback for audio volume change
+ */
+typedef void (*bthf_client_volume_change_callback) (bthf_client_volume_type_t type, int volume);
+
+/** Callback for command complete event
+ *  cme is valid only for BTHF_CLIENT_CMD_COMPLETE_ERROR_CME type
+ */
+typedef void (*bthf_client_cmd_complete_callback) (bthf_client_cmd_complete_t type, int cme);
+
+/** Callback for subscriber information
+ */
+typedef void (* bthf_client_subscriber_info_callback) (const char *name,
+                                                       bthf_client_subscriber_service_type_t type);
+
+/** Callback for in-band ring tone settings
+ */
+typedef void (* bthf_client_in_band_ring_tone_callback) (bthf_client_in_band_ring_state_t state);
+
+/**
+ * Callback for requested number from AG
+ */
+typedef void (* bthf_client_last_voice_tag_number_callback) (const char *number);
+
+/**
+ * Callback for sending ring indication to app
+ */
+typedef void (* bthf_client_ring_indication_callback) (void);
+
+/** BT-HF callback structure. */
+typedef struct {
+    /** set to sizeof(BtHfClientCallbacks) */
+    size_t      size;
+    bthf_client_connection_state_callback  connection_state_cb;
+    bthf_client_audio_state_callback       audio_state_cb;
+    bthf_client_vr_cmd_callback            vr_cmd_cb;
+    bthf_client_network_state_callback     network_state_cb;
+    bthf_client_network_roaming_callback   network_roaming_cb;
+    bthf_client_network_signal_callback    network_signal_cb;
+    bthf_client_battery_level_callback     battery_level_cb;
+    bthf_client_current_operator_callback  current_operator_cb;
+    bthf_client_call_callback              call_cb;
+    bthf_client_callsetup_callback         callsetup_cb;
+    bthf_client_callheld_callback          callheld_cb;
+    bthf_client_resp_and_hold_callback     resp_and_hold_cb;
+    bthf_client_clip_callback              clip_cb;
+    bthf_client_call_waiting_callback      call_waiting_cb;
+    bthf_client_current_calls              current_calls_cb;
+    bthf_client_volume_change_callback     volume_change_cb;
+    bthf_client_cmd_complete_callback      cmd_complete_cb;
+    bthf_client_subscriber_info_callback   subscriber_info_cb;
+    bthf_client_in_band_ring_tone_callback in_band_ring_tone_cb;
+    bthf_client_last_voice_tag_number_callback last_voice_tag_number_callback;
+    bthf_client_ring_indication_callback   ring_indication_cb;
+} bthf_client_callbacks_t;
+
+/** Represents the standard BT-HF interface. */
+typedef struct {
+
+    /** set to sizeof(BtHfClientInterface) */
+    size_t size;
+    /**
+     * Register the BtHf callbacks
+     */
+    bt_status_t (*init)(bthf_client_callbacks_t* callbacks);
+
+    /** connect to audio gateway */
+    bt_status_t (*connect)(bt_bdaddr_t *bd_addr);
+
+    /** disconnect from audio gateway */
+    bt_status_t (*disconnect)(bt_bdaddr_t *bd_addr);
+
+    /** create an audio connection */
+    bt_status_t (*connect_audio)(bt_bdaddr_t *bd_addr);
+
+    /** close the audio connection */
+    bt_status_t (*disconnect_audio)(bt_bdaddr_t *bd_addr);
+
+    /** start voice recognition */
+    bt_status_t (*start_voice_recognition)(void);
+
+    /** stop voice recognition */
+    bt_status_t (*stop_voice_recognition)(void);
+
+    /** volume control */
+    bt_status_t (*volume_control) (bthf_client_volume_type_t type, int volume);
+
+    /** place a call with number a number
+     * if number is NULL last called number is called (aka re-dial)*/
+    bt_status_t (*dial) (const char *number);
+
+    /** place a call with number specified by location (speed dial) */
+    bt_status_t (*dial_memory) (int location);
+
+    /** perform specified call related action
+     * idx is limited only for enhanced call control related action
+     */
+    bt_status_t (*handle_call_action) (bthf_client_call_action_t action, int idx);
+
+    /** query list of current calls */
+    bt_status_t (*query_current_calls) (void);
+
+    /** query name of current selected operator */
+    bt_status_t (*query_current_operator_name) (void);
+
+    /** Retrieve subscriber information */
+    bt_status_t (*retrieve_subscriber_info) (void);
+
+    /** Send DTMF code*/
+    bt_status_t (*send_dtmf) (char code);
+
+    /** Request a phone number from AG corresponding to last voice tag recorded */
+    bt_status_t (*request_last_voice_tag_number) (void);
+
+    /** Closes the interface. */
+    void (*cleanup)(void);
+
+    /** Send AT Command. */
+    bt_status_t (*send_at_cmd) (int cmd, int val1, int val2, const char *arg);
+} bthf_client_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_HF_CLIENT_H */
diff --git a/include/hardware/bt_rc.h b/include/hardware/bt_rc.h
index d455543..c565c48 100644
--- a/include/hardware/bt_rc.h
+++ b/include/hardware/bt_rc.h
@@ -171,7 +171,7 @@
 /** Callback for passthrough commands */
 typedef void (* btrc_passthrough_cmd_callback) (int id, int key_state);
 
-/** BT-RC callback structure. */
+/** BT-RC Target callback structure. */
 typedef struct {
     /** set to sizeof(BtRcCallbacks) */
     size_t      size;
@@ -189,7 +189,7 @@
     btrc_passthrough_cmd_callback               passthrough_cmd_cb;
 } btrc_callbacks_t;
 
-/** Represents the standard BT-RC interface. */
+/** Represents the standard BT-RC AVRCP Target interface. */
 typedef struct {
 
     /** set to sizeof(BtRcInterface) */
@@ -261,6 +261,36 @@
     void  (*cleanup)( void );
 } btrc_interface_t;
 
+
+typedef void (* btrc_passthrough_rsp_callback) (int id, int key_state);
+
+typedef void (* btrc_connection_state_callback) (bool state, bt_bdaddr_t *bd_addr);
+
+/** BT-RC Controller callback structure. */
+typedef struct {
+    /** set to sizeof(BtRcCallbacks) */
+    size_t      size;
+    btrc_passthrough_rsp_callback               passthrough_rsp_cb;
+    btrc_connection_state_callback              connection_state_cb;
+} btrc_ctrl_callbacks_t;
+
+/** Represents the standard BT-RC AVRCP Controller interface. */
+typedef struct {
+
+    /** set to sizeof(BtRcInterface) */
+    size_t          size;
+    /**
+     * Register the BtRc callbacks
+     */
+    bt_status_t (*init)( btrc_ctrl_callbacks_t* callbacks );
+
+    /** send pass through command to target */
+    bt_status_t (*send_pass_through_cmd) ( bt_bdaddr_t *bd_addr, uint8_t key_code, uint8_t key_state );
+
+    /** Closes the interface. */
+    void  (*cleanup)( void );
+} btrc_ctrl_interface_t;
+
 __END_DECLS
 
 #endif /* ANDROID_INCLUDE_BT_RC_H */
diff --git a/include/hardware/fingerprint.h b/include/hardware/fingerprint.h
index 7f6fa28..91ba45b 100644
--- a/include/hardware/fingerprint.h
+++ b/include/hardware/fingerprint.h
@@ -22,18 +22,28 @@
 
 typedef enum fingerprint_msg_type {
     FINGERPRINT_ERROR = -1,
-    FINGERPRINT_SCANNED = 1,
-    FINGERPRINT_TEMPLATE_ENROLLING = 2,
+    FINGERPRINT_ACQUIRED = 1,
+    FINGERPRINT_PROCESSED = 2,
+    FINGERPRINT_TEMPLATE_ENROLLING = 3,
     FINGERPRINT_TEMPLATE_REMOVED = 4
 } fingerprint_msg_type_t;
 
 typedef enum fingerprint_error {
     FINGERPRINT_ERROR_HW_UNAVAILABLE = 1,
-    FINGERPRINT_ERROR_BAD_CAPTURE = 2,
+    FINGERPRINT_ERROR_UNABLE_TO_PROCESS = 2,
     FINGERPRINT_ERROR_TIMEOUT = 3,
     FINGERPRINT_ERROR_NO_SPACE = 4  /* No space available to store a template */
 } fingerprint_error_t;
 
+typedef enum fingerprint_scan_info {
+    FINGERPRINT_SCAN_GOOD = 0,
+    FINGERPRINT_SCAN_PARTIAL = 1,
+    FINGERPRINT_SCAN_INSUFFICIENT = 2,
+    FINGERPRINT_SCAN_IMAGER_DIRTY = 4,
+    FINGERPRINT_SCAN_TOO_SLOW = 8,
+    FINGERPRINT_SCAN_TOO_FAST = 16
+} fingerprint_scan_info_t;
+
 typedef struct fingerprint_enroll {
     uint32_t id;
     /* samples_remaining goes from N (no data collected, but N scans needed)
@@ -61,9 +71,13 @@
     uint32_t id;
 } fingerprint_removed_t;
 
-typedef struct fingerprint_scanned {
+typedef struct fingerprint_acquired {
+    fingerprint_scan_info_t scan_info; /* information about the image */
+} fingerprint_acquired_t;
+
+typedef struct fingerprint_processed {
     uint32_t id; /* 0 is a special id and means no match */
-} fingerprint_scanned_t;
+} fingerprint_processed_t;
 
 typedef struct fingerprint_msg {
     fingerprint_msg_type_t type;
@@ -72,7 +86,8 @@
         fingerprint_error_t error;
         fingerprint_enroll_t enroll;
         fingerprint_removed_t removed;
-        fingerprint_scanned_t scan;
+        fingerprint_acquired_t acquired;
+        fingerprint_processed_t processed;
     } data;
 } fingerprint_msg_t;
 
@@ -82,10 +97,10 @@
 /* Synchronous operation */
 typedef struct fingerprint_device {
     /**
-     * Common methods of the fingerprint device.  This *must* be the first member of
-     * fingerprint_device as users of this structure will cast a hw_device_t to
-     * fingerprint_device pointer in contexts where it's known the hw_device_t references a
-     * fingerprint_device.
+     * Common methods of the fingerprint device. This *must* be the first member
+     * of fingerprint_device as users of this structure will cast a hw_device_t
+     * to fingerprint_device pointer in contexts where it's known
+     * the hw_device_t references a fingerprint_device.
      */
     struct hw_device_t common;
 
@@ -152,10 +167,10 @@
 
 typedef struct fingerprint_module {
     /**
-     * Common methods of the fingerprint module.  This *must* be the first member of
-     * fingerprint_module as users of this structure will cast a hw_module_t to
-     * fingerprint_module pointer in contexts where it's known the hw_module_t references a
-     * fingerprint_module.
+     * Common methods of the fingerprint module. This *must* be the first member
+     * of fingerprint_module as users of this structure will cast a hw_module_t
+     * to fingerprint_module pointer in contexts where it's known
+     * the hw_module_t references a fingerprint_module.
      */
     struct hw_module_t common;
 } fingerprint_module_t;
diff --git a/include/hardware/gps.h b/include/hardware/gps.h
index 4167793..7244738 100644
--- a/include/hardware/gps.h
+++ b/include/hardware/gps.h
@@ -21,6 +21,7 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <pthread.h>
+#include <sys/socket.h>
 
 #include <hardware/hardware.h>
 
@@ -135,6 +136,12 @@
 #define AGPS_SETID_TYPE_IMSI    1
 #define AGPS_SETID_TYPE_MSISDN  2
 
+typedef uint16_t ApnIpType;
+#define APN_IP_INVALID          0
+#define APN_IP_IPV4             1
+#define APN_IP_IPV6             2
+#define APN_IP_IPV4V6           3
+
 /**
  * String length constants
  */
@@ -481,13 +488,45 @@
 
 /** Represents the status of AGPS. */
 typedef struct {
-    /** set to sizeof(AGpsStatus) */
+    /** set to sizeof(AGpsStatus_v1) */
+    size_t          size;
+
+    AGpsType        type;
+    AGpsStatusValue status;
+} AGpsStatus_v1;
+
+/** Represents the status of AGPS augmented with a IPv4 address field. */
+typedef struct {
+    /** set to sizeof(AGpsStatus_v2) */
     size_t          size;
 
     AGpsType        type;
     AGpsStatusValue status;
     uint32_t        ipaddr;
-} AGpsStatus;
+} AGpsStatus_v2;
+
+/* Represents the status of AGPS augmented to support IPv4 and IPv6. */
+typedef struct {
+    /** set to sizeof(AGpsStatus_v3) */
+    size_t                  size;
+
+    AGpsType                type;
+    AGpsStatusValue         status;
+
+    /**
+     * Must be set to a valid IPv4 address if the field 'addr' contains an IPv4
+     * address, or set to INADDR_NONE otherwise.
+     */
+    uint32_t                ipaddr;
+
+    /**
+     * Must contain the IPv4 (AF_INET) or IPv6 (AF_INET6) address to report.
+     * Any other value of addr.ss_family will be rejected.
+     * */
+    struct sockaddr_storage addr;
+} AGpsStatus_v3;
+
+typedef AGpsStatus_v3     AGpsStatus;
 
 /** Callback with AGPS status information.
  *  Can only be called from a thread created by create_thread_cb.
@@ -503,7 +542,7 @@
 
 /** Extended interface for AGPS support. */
 typedef struct {
-    /** set to sizeof(AGpsInterface) */
+    /** set to sizeof(AGpsInterface_v1) */
     size_t          size;
 
     /**
@@ -528,7 +567,50 @@
      * Sets the hostname and port for the AGPS server.
      */
     int  (*set_server)( AGpsType type, const char* hostname, int port );
-} AGpsInterface;
+} AGpsInterface_v1;
+
+/**
+ * Extended interface for AGPS support, it is augmented to enable to pass
+ * extra APN data.
+ */
+typedef struct {
+    /** set to sizeof(AGpsInterface_v2) */
+    size_t size;
+
+    /**
+     * Opens the AGPS interface and provides the callback routines to the
+     * implementation of this interface.
+     */
+    void (*init)(AGpsCallbacks* callbacks);
+    /**
+     * Deprecated.
+     * If the HAL supports AGpsInterface_v2 this API will not be used, see
+     * data_conn_open_with_apn_ip_type for more information.
+     */
+    int (*data_conn_open)(const char* apn);
+    /**
+     * Notifies that the AGPS data connection has been closed.
+     */
+    int (*data_conn_closed)();
+    /**
+     * Notifies that a data connection is not available for AGPS.
+     */
+    int (*data_conn_failed)();
+    /**
+     * Sets the hostname and port for the AGPS server.
+     */
+    int (*set_server)(AGpsType type, const char* hostname, int port);
+
+    /**
+     * Notifies that a data connection is available and sets the name of the
+     * APN, and its IP type, to be used for SUPL connections.
+     */
+    int (*data_conn_open_with_apn_ip_type)(
+            const char* apn,
+            ApnIpType apnIpType);
+} AGpsInterface_v2;
+
+typedef AGpsInterface_v2    AGpsInterface;
 
 /** Error codes associated with certificate operations */
 #define AGPS_CERTIFICATE_OPERATION_SUCCESS               0
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h
index 049edea..f647ab3 100644
--- a/include/hardware/hwcomposer.h
+++ b/include/hardware/hwcomposer.h
@@ -297,10 +297,19 @@
         };
     };
 
-    /* Allow for expansion w/o breaking binary compatibility.
-     * Pad layer to 96 bytes, assuming 32-bit pointers.
+#ifdef __LP64__
+    /*
+     * For 64-bit mode, this struct is 120 bytes (and 8-byte aligned), and needs
+     * to be padded as such to maintain binary compatibility.
      */
-    int32_t reserved[24 - 19];
+    uint8_t reserved[120 - 96];
+#else
+    /*
+     * For 32-bit mode, this struct is 96 bytes, and needs to be padded as such
+     * to maintain binary compatibility.
+     */
+    uint8_t reserved[96 - 76];
+#endif
 
 } hwc_layer_1_t;
 
@@ -586,18 +595,53 @@
     int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
             int event, int enabled);
 
-    /*
-     * blank(..., blank)
-     * Blanks or unblanks a display's screen.
-     *
-     * Turns the screen off when blank is nonzero, on when blank is zero.
-     * Multiple sequential calls with the same blank value must be supported.
-     * The screen state transition must be be complete when the function
-     * returns.
-     *
-     * returns 0 on success, negative on error.
-     */
-    int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
+    union {
+        /*
+         * For HWC 1.3 and earlier, the blank() interface is used.
+         *
+         * blank(..., blank)
+         * Blanks or unblanks a display's screen.
+         *
+         * Turns the screen off when blank is nonzero, on when blank is zero.
+         * Multiple sequential calls with the same blank value must be
+         * supported.
+         * The screen state transition must be be complete when the function
+         * returns.
+         *
+         * returns 0 on success, negative on error.
+         */
+        int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
+
+        /*
+         * For HWC 1.4 and above, setPowerMode() will be used in place of
+         * blank().
+         *
+         * 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.
+         *
+         * The functionality is similar to the blank() command in previous
+         * versions of HWC, but with support for more power states.
+         *
+         * The display driver is expected to retain and restore the low power
+         * state of the display while entering and exiting from suspend.
+         *
+         * Multiple sequential calls with the same mode value must be supported.
+         *
+         * The screen state transition must be be complete when the function
+         * returns.
+         *
+         * returns 0 on success, negative on error.
+         */
+        int (*setPowerMode)(struct hwc_composer_device_1* dev, int disp,
+                int mode);
+    };
 
     /*
      * Used to retrieve information about the h/w composer
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
index 242e3f6..bd6e1e6 100644
--- a/include/hardware/hwcomposer_defs.h
+++ b/include/hardware/hwcomposer_defs.h
@@ -199,6 +199,13 @@
     HWC_DISPLAY_VIRTUAL_BIT     = 1 << HWC_DISPLAY_VIRTUAL,
 };
 
+/* Display power modes */
+enum {
+    HWC_POWER_MODE_OFF      = 0,
+    HWC_POWER_MODE_DOZE     = 1,
+    HWC_POWER_MODE_NORMAL   = 2,
+};
+
 /*****************************************************************************/
 
 __END_DECLS
diff --git a/include/hardware/sensors.h b/include/hardware/sensors.h
index 9327c41..5ba5ef7 100644
--- a/include/hardware/sensors.h
+++ b/include/hardware/sensors.h
@@ -100,10 +100,25 @@
     /*
      * Whether this sensor wakes up the AP from suspend mode when data is available.
      */
-    SENSOR_FLAG_WAKE_UP = 1U << 0
+    SENSOR_FLAG_WAKE_UP = 1U << 0,
+    /*
+     * Reporting modes for various sensors. Each sensor will have exactly one of these modes set.
+     * The least significant 2nd, 3rd and 4th bits are used to represent four possible reporting
+     * modes.
+     */
+    SENSOR_FLAG_CONTINUOUS_MODE        = 0,    // 0000
+    SENSOR_FLAG_ON_CHANGE_MODE         = 0x2,  // 0010
+    SENSOR_FLAG_ONE_SHOT_MODE          = 0x4,  // 0100
+    SENSOR_FLAG_SPECIAL_REPORTING_MODE = 0x6   // 0110
 };
 
 /*
+ * Mask and shift for reporting mode sensor flags defined above.
+ */
+#define REPORTING_MODE_MASK              (0xE)
+#define REPORTING_MODE_SHIFT             (1)
+
+/*
  * Sensor type
  *
  * Each sensor has a type which defines what this sensor measures and how
@@ -158,7 +173,7 @@
 
 /*
  * SENSOR_TYPE_META_DATA
- * trigger-mode: n/a
+ * reporting-mode: n/a
  * wake-up sensor: n/a
  *
  * NO SENSOR OF THAT TYPE MUST BE RETURNED (*get_sensors_list)()
@@ -191,7 +206,7 @@
 
 /*
  * SENSOR_TYPE_ACCELEROMETER
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  All values are in SI units (m/s^2) and measure the acceleration of the
@@ -203,7 +218,7 @@
 
 /*
  * SENSOR_TYPE_GEOMAGNETIC_FIELD
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  All values are in micro-Tesla (uT) and measure the geomagnetic
@@ -216,7 +231,7 @@
 
 /*
  * SENSOR_TYPE_ORIENTATION
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  * All values are angles in degrees.
@@ -229,7 +244,7 @@
 
 /*
  * SENSOR_TYPE_GYROSCOPE
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  All values are in radians/second and measure the rate of rotation
@@ -240,7 +255,7 @@
 
 /*
  * SENSOR_TYPE_LIGHT
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: no
  *
  * The light sensor value is returned in SI lux units.
@@ -250,7 +265,7 @@
 
 /*
  * SENSOR_TYPE_PRESSURE
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  * The pressure sensor return the athmospheric pressure in hectopascal (hPa)
@@ -264,7 +279,7 @@
 
 /*
  * SENSOR_TYPE_PROXIMITY
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
  *
  * The value corresponds to the distance to the nearest object in centimeters.
@@ -274,7 +289,7 @@
 
 /*
  * SENSOR_TYPE_GRAVITY
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  * A gravity output indicates the direction of and magnitude of gravity in
@@ -285,7 +300,7 @@
 
 /*
  * SENSOR_TYPE_LINEAR_ACCELERATION
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  * Indicates the linear acceleration of the device in device coordinates,
@@ -297,7 +312,7 @@
 
 /*
  * SENSOR_TYPE_ROTATION_VECTOR
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  * The rotation vector symbolizes the orientation of the device relative to the
@@ -308,7 +323,7 @@
 
 /*
  * SENSOR_TYPE_RELATIVE_HUMIDITY
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: no
  *
  * A relative humidity sensor measures relative ambient air humidity and
@@ -319,7 +334,7 @@
 
 /*
  * SENSOR_TYPE_AMBIENT_TEMPERATURE
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: no
  *
  * The ambient (room) temperature in degree Celsius.
@@ -329,7 +344,7 @@
 
 /*
  * SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  Similar to SENSOR_TYPE_MAGNETIC_FIELD, but the hard iron calibration is
@@ -340,7 +355,7 @@
 
 /*
  * SENSOR_TYPE_GAME_ROTATION_VECTOR
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  Similar to SENSOR_TYPE_ROTATION_VECTOR, but not using the geomagnetic
@@ -351,7 +366,7 @@
 
 /*
  * SENSOR_TYPE_GYROSCOPE_UNCALIBRATED
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  All values are in radians/second and measure the rate of rotation
@@ -362,7 +377,7 @@
 
 /*
  * SENSOR_TYPE_SIGNIFICANT_MOTION
- * trigger-mode: one-shot
+ * reporting-mode: one-shot
  * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
  *
  * A sensor of this type triggers an event each time significant motion
@@ -375,7 +390,7 @@
 
 /*
  * SENSOR_TYPE_STEP_DETECTOR
- * trigger-mode: special
+ * reporting-mode: special
  * wake-up sensor: no
  *
  * A sensor of this type triggers an event each time a step is taken
@@ -389,7 +404,7 @@
 
 /*
  * SENSOR_TYPE_STEP_COUNTER
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: no
  *
  * A sensor of this type returns the number of steps taken by the user since
@@ -402,7 +417,7 @@
 
 /*
  * SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR
- * trigger-mode: continuous
+ * reporting-mode: continuous
  * wake-up sensor: no
  *
  *  Similar to SENSOR_TYPE_ROTATION_VECTOR, but using a magnetometer instead
@@ -413,13 +428,20 @@
 
 /*
  * SENSOR_TYPE_HEART_RATE
- * trigger-mode: on-change
+ * reporting-mode: on-change
  * wake-up sensor: no
  *
- *  A sensor of this type returns the current heart rate if activated.
- *  The value is returned as a float which represents the heart rate in beats
- *  per minute (BPM).
- *  When the sensor cannot measure the heart rate, the returned value must be 0.
+ *  A sensor of this type returns the current heart rate.
+ *  The events contain the current heart rate in beats per minute (BPM) and the
+ *  status of the sensor during the measurement. See heart_rate_event_t for more
+ *  details.
+ *
+ *  Because this sensor is on-change, events must be generated when and only
+ *  when heart_rate.bpm or heart_rate.status have changed since the last
+ *  event. The event should be generated no faster than every period_ns passed
+ *  to setDelay() or to batch(). See the definition of the on-change reporting
+ *  mode for more information.
+ *
  *  sensor_t.requiredPermission must be set to SENSOR_PERMISSION_BODY_SENSORS.
  */
 #define SENSOR_TYPE_HEART_RATE                      (21)
@@ -509,16 +531,17 @@
 
 /*
  * SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
- * trigger-mode: special (setDelay has no impact)
+ * reporting-mode: special (setDelay has no impact)
  * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
  *
  * A sensor of this type generates an event each time a tilt event is detected. A tilt event
  * should be generated if the direction of the 2-seconds window average gravity changed by at least
- * 35 degrees since the activation of the sensor.
- *     initial_estimated_gravity = average of accelerometer measurements over the first
- *                                 1 second after activation.
+ * 35 degrees since the activation or the last trigger of the sensor.
+ *     reference_estimated_gravity = average of accelerometer measurements over the first
+ *                                 1 second after activation or the estimated gravity at the last
+ *                                 trigger.
  *     current_estimated_gravity = average of accelerometer measurements over the last 2 seconds.
- *     trigger when angle (initial_estimated_gravity, current_estimated_gravity) > 35 degrees
+ *     trigger when angle (reference_estimated_gravity, current_estimated_gravity) > 35 degrees
  *
  * Large accelerations without a change in phone orientation should not trigger a tilt event.
  * For example, a sharp turn or strong acceleration while driving a car should not trigger a tilt
@@ -535,7 +558,7 @@
 
 /*
  * SENSOR_TYPE_WAKE_GESTURE
- * trigger-mode: one-shot
+ * reporting-mode: one-shot
  * wake-up sensor: yes (set SENSOR_FLAG_WAKE_UP flag)
  *
  * A sensor enabling waking up the device based on a device specific motion.
@@ -567,17 +590,15 @@
 /** Minimum magnetic field on Earth's surface */
 #define MAGNETIC_FIELD_EARTH_MIN    (30.0f)
 
-
 /**
- * status of orientation sensor
+ * Possible values of the status field of sensor events.
  */
-
+#define SENSOR_STATUS_NO_CONTACT        -1
 #define SENSOR_STATUS_UNRELIABLE        0
 #define SENSOR_STATUS_ACCURACY_LOW      1
 #define SENSOR_STATUS_ACCURACY_MEDIUM   2
 #define SENSOR_STATUS_ACCURACY_HIGH     3
 
-
 /**
  * sensor event data
  */
@@ -627,6 +648,17 @@
 } meta_data_event_t;
 
 /**
+ * Heart rate event data
+ */
+typedef struct {
+  // Heart rate in beats per minute.
+  // Set to 0 when status is SENSOR_STATUS_UNRELIABLE or ..._NO_CONTACT
+  float bpm;
+  // Status of the sensor for this reading. Set to one SENSOR_STATUS_...
+  int8_t status;
+} heart_rate_event_t;
+
+/**
  * Union of the various types of sensor data
  * that can be returned.
  */
@@ -683,8 +715,8 @@
             /* uncalibrated magnetometer values are in micro-Teslas */
             uncalibrated_event_t uncalibrated_magnetic;
 
-            /* heart rate in bpm */
-            float           heart_rate;
+            /* heart rate data containing value in bpm and status */
+            heart_rate_event_t heart_rate;
 
             /* this is a special event. see SENSOR_TYPE_META_DATA above.
              * sensors_meta_data_event_t events are all reported with a type of
@@ -764,7 +796,7 @@
     /* rough estimate of this sensor's power consumption in mA */
     float           power;
 
-    /* this value depends on the trigger mode:
+    /* this value depends on the reporting mode:
      *
      *   continuous: minimum sample period allowed in microseconds
      *   on-change : 0
@@ -810,9 +842,12 @@
      * lower frequencies are requested through batch()/setDelay() the events will be generated
      * at this frequency instead. It can be used by the framework or applications to estimate
      * when the batch FIFO may be full.
-     * NOTE: period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
-     *     continuous: maximum sampling period allowed in microseconds.
-     *     on-change, one-shot, special : -1
+     *
+     * NOTE: 1) period_ns is in nanoseconds where as maxDelay/minDelay are in microseconds.
+     *              continuous: maximum sampling period allowed in microseconds.
+     *              on-change, one-shot, special : 0
+     *   2) maxDelay should always fit within a 32 bit signed integer. It is declared as 64 bit
+     *      on 64 bit architectures only for binary compatibility reasons.
      * Availability: SENSORS_DEVICE_API_VERSION_1_3
      */
     #ifdef __LP64__
@@ -821,7 +856,10 @@
        int32_t maxDelay;
     #endif
 
-    /* Flags for sensor. See SENSOR_FLAG_* above. */
+    /* Flags for sensor. See SENSOR_FLAG_* above. Only the least significant 32 bits are used here.
+     * It is declared as 64 bit on 64 bit architectures only for binary compatibility reasons.
+     * Availability: SENSORS_DEVICE_API_VERSION_1_3
+     */
     #ifdef __LP64__
        uint64_t flags;
     #else
@@ -901,7 +939,9 @@
     /*
      * Flush adds a META_DATA_FLUSH_COMPLETE event (sensors_event_meta_data_t)
      * to the end of the "batch mode" FIFO for the specified sensor and flushes
-     * the FIFO.
+     * the FIFO. If the FIFO is empty or if the sensor doesn't support batching (FIFO size zero),
+     * it should return SUCCESS along with a trivial META_DATA_FLUSH_COMPLETE event added to the
+     * event stream. This applies to all sensors other than ONE_SHOT sensors.
      */
     int (*flush)(struct sensors_poll_device_1* dev, int handle);
 
diff --git a/include/hardware/sound_trigger.h b/include/hardware/sound_trigger.h
new file mode 100644
index 0000000..fc3ac47
--- /dev/null
+++ b/include/hardware/sound_trigger.h
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <system/audio.h>
+#include <system/sound_trigger.h>
+#include <hardware/hardware.h>
+
+#ifndef ANDROID_SOUND_TRIGGER_HAL_H
+#define ANDROID_SOUND_TRIGGER_HAL_H
+
+
+__BEGIN_DECLS
+
+/**
+ * The id of this module
+ */
+#define SOUND_TRIGGER_HARDWARE_MODULE_ID "sound_trigger"
+
+/**
+ * Name of the audio devices to open
+ */
+#define SOUND_TRIGGER_HARDWARE_INTERFACE "sound_trigger_hw_if"
+
+#define SOUND_TRIGGER_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
+#define SOUND_TRIGGER_MODULE_API_VERSION_CURRENT SOUND_TRIGGER_MODULE_API_VERSION_1_0
+
+
+#define SOUND_TRIGGER_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
+#define SOUND_TRIGGER_DEVICE_API_VERSION_CURRENT SOUND_TRIGGER_DEVICE_API_VERSION_1_0
+
+/**
+ * List of known sound trigger HAL modules. This is the base name of the sound_trigger HAL
+ * library composed of the "sound_trigger." prefix, one of the base names below and
+ * a suffix specific to the device.
+ * e.g: sondtrigger.primary.goldfish.so or sound_trigger.primary.default.so
+ */
+
+#define SOUND_TRIGGER_HARDWARE_MODULE_ID_PRIMARY "primary"
+
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+struct sound_trigger_module {
+    struct hw_module_t common;
+};
+
+typedef void (*recognition_callback_t)(struct sound_trigger_recognition_event *event, void *cookie);
+typedef void (*sound_model_callback_t)(struct sound_trigger_model_event *event, void *cookie);
+
+struct sound_trigger_hw_device {
+    struct hw_device_t common;
+
+    /*
+     * Retrieve implementation properties.
+     */
+    int (*get_properties)(const struct sound_trigger_hw_device *dev,
+                          struct sound_trigger_properties *properties);
+
+    /*
+     * Load a sound model. Once loaded, recognition of this model can be started and stopped.
+     * Only one active recognition per model at a time. The SoundTrigger service will handle
+     * concurrent recognition requests by different users/applications on the same model.
+     * The implementation returns a unique handle used by other functions (unload_sound_model(),
+     * start_recognition(), etc...
+     */
+    int (*load_sound_model)(const struct sound_trigger_hw_device *dev,
+                            struct sound_trigger_sound_model *sound_model,
+                            sound_model_callback_t callback,
+                            void *cookie,
+                            sound_model_handle_t *handle);
+
+    /*
+     * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
+     * implementation limitations.
+     */
+    int (*unload_sound_model)(const struct sound_trigger_hw_device *dev,
+                              sound_model_handle_t handle);
+
+    /* Start recognition on a given model. Only one recognition active at a time per model.
+     * Once recognition succeeds of fails, the callback is called.
+     * TODO: group recognition configuration parameters into one struct and add key phrase options.
+     */
+    int (*start_recognition)(const struct sound_trigger_hw_device *dev,
+                             sound_model_handle_t sound_model_handle,
+                             audio_io_handle_t capture_handle,
+                             audio_devices_t capture_device,
+                             recognition_callback_t callback,
+                             void *cookie,
+                             unsigned int data_size,
+                             char *data);
+
+    /* Stop recognition on a given model.
+     * The implementation does not have to call the callback when stopped via this method.
+     */
+    int (*stop_recognition)(const struct sound_trigger_hw_device *dev,
+                           sound_model_handle_t sound_model_handle);
+};
+
+typedef struct sound_trigger_hw_device sound_trigger_hw_device_t;
+
+/** convenience API for opening and closing a supported device */
+
+static inline int sound_trigger_hw_device_open(const struct hw_module_t* module,
+                                       struct sound_trigger_hw_device** device)
+{
+    return module->methods->open(module, SOUND_TRIGGER_HARDWARE_INTERFACE,
+                                 (struct hw_device_t**)device);
+}
+
+static inline int sound_trigger_hw_device_close(struct sound_trigger_hw_device* device)
+{
+    return device->common.close(&device->common);
+}
+
+__END_DECLS
+
+#endif  // ANDROID_SOUND_TRIGGER_HAL_H
diff --git a/modules/camera/Camera.cpp b/modules/camera/Camera.cpp
index 1f22e00..de3ae78 100644
--- a/modules/camera/Camera.cpp
+++ b/modules/camera/Camera.cpp
@@ -473,14 +473,14 @@
     ATRACE_CALL();
     android::Mutex::Autolock al(mDeviceLock);
 
-    fdprintf(fd, "Camera ID: %d (Busy: %d)\n", mId, mBusy);
+    dprintf(fd, "Camera ID: %d (Busy: %d)\n", mId, mBusy);
 
     // TODO: dump all settings
-    fdprintf(fd, "Most Recent Settings: (%p)\n", mSettings);
+    dprintf(fd, "Most Recent Settings: (%p)\n", mSettings);
 
-    fdprintf(fd, "Number of streams: %d\n", mNumStreams);
+    dprintf(fd, "Number of streams: %d\n", mNumStreams);
     for (int i = 0; i < mNumStreams; i++) {
-        fdprintf(fd, "Stream %d/%d:\n", i, mNumStreams);
+        dprintf(fd, "Stream %d/%d:\n", i, mNumStreams);
         mStreams[i]->dump(fd);
     }
 }
diff --git a/modules/camera/Stream.cpp b/modules/camera/Stream.cpp
index b846a71..2db3ed2 100644
--- a/modules/camera/Stream.cpp
+++ b/modules/camera/Stream.cpp
@@ -225,18 +225,18 @@
 {
     android::Mutex::Autolock al(mLock);
 
-    fdprintf(fd, "Stream ID: %d (%p)\n", mId, mStream);
-    fdprintf(fd, "Stream Type: %s (%d)\n", typeToString(mType), mType);
-    fdprintf(fd, "Width: %"PRIu32" Height: %"PRIu32"\n", mWidth, mHeight);
-    fdprintf(fd, "Stream Format: %s (%d)", formatToString(mFormat), mFormat);
+    dprintf(fd, "Stream ID: %d (%p)\n", mId, mStream);
+    dprintf(fd, "Stream Type: %s (%d)\n", typeToString(mType), mType);
+    dprintf(fd, "Width: %"PRIu32" Height: %"PRIu32"\n", mWidth, mHeight);
+    dprintf(fd, "Stream Format: %s (%d)", formatToString(mFormat), mFormat);
     // ToDo: prettyprint usage mask flags
-    fdprintf(fd, "Gralloc Usage Mask: %#"PRIx32"\n", mUsage);
-    fdprintf(fd, "Max Buffer Count: %"PRIu32"\n", mMaxBuffers);
-    fdprintf(fd, "Buffers Registered: %s\n", mRegistered ? "true" : "false");
-    fdprintf(fd, "Number of Buffers: %"PRIu32"\n", mNumBuffers);
+    dprintf(fd, "Gralloc Usage Mask: %#"PRIx32"\n", mUsage);
+    dprintf(fd, "Max Buffer Count: %"PRIu32"\n", mMaxBuffers);
+    dprintf(fd, "Buffers Registered: %s\n", mRegistered ? "true" : "false");
+    dprintf(fd, "Number of Buffers: %"PRIu32"\n", mNumBuffers);
     for (uint32_t i = 0; i < mNumBuffers; i++) {
-        fdprintf(fd, "Buffer %"PRIu32"/%"PRIu32": %p\n", i, mNumBuffers,
-                                                                mBuffers[i]);
+        dprintf(fd, "Buffer %"PRIu32"/%"PRIu32": %p\n", i, mNumBuffers,
+                mBuffers[i]);
     }
 }
 
diff --git a/modules/sensors/multihal.cpp b/modules/sensors/multihal.cpp
index 5fd500a..76ec161 100644
--- a/modules/sensors/multihal.cpp
+++ b/modules/sensors/multihal.cpp
@@ -299,10 +299,11 @@
 int sensors_poll_context_t::poll(sensors_event_t *data, int maxReads) {
     ALOGV("poll");
     int empties = 0;
-    int queueCount = (int)this->queues.size();
+    int queueCount = 0;
     int eventsRead = 0;
 
     pthread_mutex_lock(&queue_mutex);
+    queueCount = (int)this->queues.size();
     while (eventsRead == 0) {
         while (empties < queueCount && eventsRead < maxReads) {
             SensorEventQueue* queue = this->queues.at(this->nextReadIndex);
@@ -311,7 +312,13 @@
                 empties++;
             } else {
                 empties = 0;
-                this->copy_event_remap_handle(&data[eventsRead++], event, nextReadIndex);
+                this->copy_event_remap_handle(&data[eventsRead], event, nextReadIndex);
+                if (data[eventsRead].sensor == -1) {
+                    // Bad handle, do not pass corrupted event upstream !
+                    ALOGW("Dropping bad local handle event packet on the floor");
+                } else {
+                    eventsRead++;
+                }
                 queue->dequeue();
             }
             this->nextReadIndex = (this->nextReadIndex + 1) % queueCount;
diff --git a/modules/soundtrigger/Android.mk b/modules/soundtrigger/Android.mk
new file mode 100644
index 0000000..325980c
--- /dev/null
+++ b/modules/soundtrigger/Android.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+# Stub sound_trigger HAL module, used for tests
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := sound_trigger.stub.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := sound_trigger_hw.c
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/soundtrigger/sound_trigger_hw.c b/modules/soundtrigger/sound_trigger_hw.c
new file mode 100644
index 0000000..8347d02
--- /dev/null
+++ b/modules/soundtrigger/sound_trigger_hw.c
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "sound_trigger_hw_default"
+/*#define LOG_NDEBUG 0*/
+
+#include <errno.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <cutils/log.h>
+
+#include <hardware/hardware.h>
+#include <system/sound_trigger.h>
+#include <hardware/sound_trigger.h>
+
+static const struct sound_trigger_properties hw_properties = {
+        "The Android Open Source Project", // implementor
+        "Sound Trigger stub HAL", // description
+        1, // version
+        { 0xed7a7d60, 0xc65e, 0x11e3, 0x9be4, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // uuid
+        1, // max_sound_models
+        1, // max_key_phrases
+        1, // max_users
+        RECOGNITION_MODE_VOICE_TRIGGER, // recognition_modes
+        false, // capture_transition
+        0, // max_buffer_ms
+        false, // concurrent_capture
+        0 // power_consumption_mw
+};
+
+struct stub_sound_trigger_device {
+    struct sound_trigger_hw_device device;
+    sound_model_handle_t model_handle;
+    recognition_callback_t recognition_callback;
+    void *recognition_cookie;
+    sound_model_callback_t sound_model_callback;
+    void *sound_model_cookie;
+    pthread_t callback_thread;
+    pthread_mutex_t lock;
+    pthread_cond_t  cond;
+
+};
+
+
+static void *callback_thread_loop(void *context)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)context;
+    ALOGI("%s", __func__);
+
+    prctl(PR_SET_NAME, (unsigned long)"sound trigger callback", 0, 0, 0);
+
+    pthread_mutex_lock(&stdev->lock);
+    if (stdev->recognition_callback == NULL) {
+        goto exit;
+    }
+    struct timespec ts;
+    clock_gettime(CLOCK_REALTIME, &ts);
+    ts.tv_sec += 3;
+    ALOGI("%s wait 3 sec", __func__);
+    int rc = pthread_cond_timedwait(&stdev->cond, &stdev->lock, &ts);
+    if (rc == ETIMEDOUT && stdev->recognition_callback != NULL) {
+        char *data = (char *)calloc(1, sizeof(struct sound_trigger_phrase_recognition_event) + 1);
+        struct sound_trigger_phrase_recognition_event *event =
+                (struct sound_trigger_phrase_recognition_event *)data;
+        event->common.status = RECOGNITION_STATUS_SUCCESS;
+        event->common.type = SOUND_MODEL_TYPE_KEYPHRASE;
+        event->common.model = stdev->model_handle;
+        event->key_phrase_in_capture = false;
+        event->num_phrases = 1;
+        event->phrase_extras[0].recognition_modes = RECOGNITION_MODE_VOICE_TRIGGER;
+        event->phrase_extras[0].num_users = 1;
+        event->phrase_extras[0].confidence_levels[0] = 100;
+        event->common.data_offset = sizeof(struct sound_trigger_phrase_recognition_event);
+        event->common.data_size = 1;
+        data[event->common.data_offset] = 8;
+        ALOGI("%s send callback model %d", __func__, stdev->model_handle);
+        stdev->recognition_callback(&event->common, stdev->recognition_cookie);
+        free(data);
+    } else {
+        ALOGI("%s abort recognition model %d", __func__, stdev->model_handle);
+    }
+    stdev->recognition_callback = NULL;
+
+exit:
+    pthread_mutex_unlock(&stdev->lock);
+
+    return NULL;
+}
+
+static int stdev_get_properties(const struct sound_trigger_hw_device *dev,
+                                struct sound_trigger_properties *properties)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)dev;
+
+    ALOGI("%s", __func__);
+    if (properties == NULL)
+        return -EINVAL;
+    memcpy(properties, &hw_properties, sizeof(struct sound_trigger_properties));
+    return 0;
+}
+
+static int stdev_load_sound_model(const struct sound_trigger_hw_device *dev,
+                                  struct sound_trigger_sound_model *sound_model,
+                                  sound_model_callback_t callback,
+                                  void *cookie,
+                                  sound_model_handle_t *handle)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)dev;
+    int status = 0;
+
+    ALOGI("%s stdev %p", __func__, stdev);
+    pthread_mutex_lock(&stdev->lock);
+    if (handle == NULL || sound_model == NULL) {
+        status = -EINVAL;
+        goto exit;
+    }
+    if (sound_model->data_size == 0 ||
+            sound_model->data_offset < sizeof(struct sound_trigger_sound_model)) {
+        status = -EINVAL;
+        goto exit;
+    }
+
+    if (stdev->model_handle == 1) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    char *data = (char *)sound_model + sound_model->data_offset;
+    ALOGI("%s data size %d data %d - %d", __func__,
+          sound_model->data_size, data[0], data[sound_model->data_size - 1]);
+    stdev->model_handle = 1;
+    stdev->sound_model_callback = callback;
+    stdev->sound_model_cookie = cookie;
+
+    *handle = stdev->model_handle;
+
+exit:
+    pthread_mutex_unlock(&stdev->lock);
+    return status;
+}
+
+static int stdev_unload_sound_model(const struct sound_trigger_hw_device *dev,
+                                    sound_model_handle_t handle)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)dev;
+    int status = 0;
+
+    ALOGI("%s handle %d", __func__, handle);
+    pthread_mutex_lock(&stdev->lock);
+    if (handle != 1) {
+        status = -EINVAL;
+        goto exit;
+    }
+    if (stdev->model_handle == 0) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    stdev->model_handle = 0;
+    if (stdev->recognition_callback != NULL) {
+        stdev->recognition_callback = NULL;
+        pthread_cond_signal(&stdev->cond);
+        pthread_mutex_unlock(&stdev->lock);
+        pthread_join(stdev->callback_thread, (void **) NULL);
+        pthread_mutex_lock(&stdev->lock);
+    }
+
+exit:
+    pthread_mutex_unlock(&stdev->lock);
+    return status;
+}
+
+static int stdev_start_recognition(const struct sound_trigger_hw_device *dev,
+                                   sound_model_handle_t sound_model_handle,
+                                   audio_io_handle_t capture_handle __unused,
+                                   audio_devices_t capture_device __unused,
+                                   recognition_callback_t callback,
+                                   void *cookie,
+                                   unsigned int data_size,
+                                   char *data)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)dev;
+    int status = 0;
+    ALOGI("%s sound model %d", __func__, sound_model_handle);
+    pthread_mutex_lock(&stdev->lock);
+    if (stdev->model_handle != sound_model_handle) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    if (stdev->recognition_callback != NULL) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    if (data_size != 0 && data == NULL) {
+        status = -EINVAL;
+        goto exit;
+    }
+    if (data_size != 0) {
+        ALOGI("%s data size %d data %d - %d", __func__,
+              data_size, data[0], data[data_size - 1]);
+    }
+
+    stdev->recognition_callback = callback;
+    stdev->recognition_cookie = cookie;
+    pthread_create(&stdev->callback_thread, (const pthread_attr_t *) NULL,
+                        callback_thread_loop, stdev);
+exit:
+    pthread_mutex_unlock(&stdev->lock);
+    return status;
+}
+
+static int stdev_stop_recognition(const struct sound_trigger_hw_device *dev,
+                                 sound_model_handle_t sound_model_handle)
+{
+    struct stub_sound_trigger_device *stdev = (struct stub_sound_trigger_device *)dev;
+    int status = 0;
+    ALOGI("%s sound model %d", __func__, sound_model_handle);
+    pthread_mutex_lock(&stdev->lock);
+    if (stdev->model_handle != sound_model_handle) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    if (stdev->recognition_callback == NULL) {
+        status = -ENOSYS;
+        goto exit;
+    }
+    stdev->recognition_callback = NULL;
+    pthread_cond_signal(&stdev->cond);
+    pthread_mutex_unlock(&stdev->lock);
+    pthread_join(stdev->callback_thread, (void **) NULL);
+    pthread_mutex_lock(&stdev->lock);
+
+exit:
+    pthread_mutex_unlock(&stdev->lock);
+    return status;
+}
+
+
+static int stdev_close(hw_device_t *device)
+{
+    free(device);
+    return 0;
+}
+
+static int stdev_open(const hw_module_t* module, const char* name,
+                     hw_device_t** device)
+{
+    struct stub_sound_trigger_device *stdev;
+    int ret;
+
+    if (strcmp(name, SOUND_TRIGGER_HARDWARE_INTERFACE) != 0)
+        return -EINVAL;
+
+    stdev = calloc(1, sizeof(struct stub_sound_trigger_device));
+    if (!stdev)
+        return -ENOMEM;
+
+    stdev->device.common.tag = HARDWARE_DEVICE_TAG;
+    stdev->device.common.version = SOUND_TRIGGER_DEVICE_API_VERSION_1_0;
+    stdev->device.common.module = (struct hw_module_t *) module;
+    stdev->device.common.close = stdev_close;
+    stdev->device.get_properties = stdev_get_properties;
+    stdev->device.load_sound_model = stdev_load_sound_model;
+    stdev->device.unload_sound_model = stdev_unload_sound_model;
+    stdev->device.start_recognition = stdev_start_recognition;
+    stdev->device.stop_recognition = stdev_stop_recognition;
+
+    pthread_mutex_init(&stdev->lock, (const pthread_mutexattr_t *) NULL);
+    pthread_cond_init(&stdev->cond, (const pthread_condattr_t *) NULL);
+
+    *device = &stdev->device.common;
+
+    return 0;
+}
+
+static struct hw_module_methods_t hal_module_methods = {
+    .open = stdev_open,
+};
+
+struct sound_trigger_module HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .module_api_version = SOUND_TRIGGER_MODULE_API_VERSION_1_0,
+        .hal_api_version = HARDWARE_HAL_API_VERSION,
+        .id = SOUND_TRIGGER_HARDWARE_MODULE_ID,
+        .name = "Default sound trigger HAL",
+        .author = "The Android Open Source Project",
+        .methods = &hal_module_methods,
+    },
+};
diff --git a/tests/camera2/Android.mk b/tests/camera2/Android.mk
index 9efac0f..577ba0a 100644
--- a/tests/camera2/Android.mk
+++ b/tests/camera2/Android.mk
@@ -45,6 +45,9 @@
 LOCAL_CFLAGS += -Wall -Wextra
 
 LOCAL_MODULE:= camera2_test
+LOCAL_MODULE_STEM_32 := camera2_test
+LOCAL_MODULE_STEM_64 := camera2_test64
+LOCAL_MULTILIB := both
 LOCAL_MODULE_TAGS := tests
 
 include $(BUILD_NATIVE_TEST)