Merge "Camera: Update for torch callbacks" into mnc-dev
diff --git a/include/hardware/bt_sdp.h b/include/hardware/bt_sdp.h
index d298ad6..8f39bc5 100644
--- a/include/hardware/bt_sdp.h
+++ b/include/hardware/bt_sdp.h
@@ -26,12 +26,13 @@
  * These events are handled by the state machine
  */
 typedef enum {
-    SDP_TYPE_RAW, // Used to carry raw SDP search data for unknown UUID's 
-    SDP_TYPE_MAP_MAS,
-    SDP_TYPE_MAP_MNS,
-    SDP_TYPE_PBAP_PSE,
-    SDP_TYPE_PBAP_PCE,
-    SDP_TYPE_OPP_SERVER
+    SDP_TYPE_RAW,        // Used to carry raw SDP search data for unknown UUIDs
+    SDP_TYPE_MAP_MAS,    // Message Access Profile - Server
+    SDP_TYPE_MAP_MNS,    // Message Access Profile - Client (Notification Server)
+    SDP_TYPE_PBAP_PSE,   // Phone Book Profile - Server
+    SDP_TYPE_PBAP_PCE,   // Phone Book Profile - Client
+    SDP_TYPE_OPP_SERVER, // Object Push Profile
+    SDP_TYPE_SAP_SERVER  // SIM Access Profile
 } bluetooth_sdp_types;
 
 typedef struct _bluetooth_sdp_hdr {
@@ -92,6 +93,10 @@
     uint8_t     supported_formats_list[SDP_OPP_SUPPORTED_FORMATS_MAX_LENGTH];
 } bluetooth_sdp_ops_record;
 
+typedef struct _bluetooth_sdp_sap_record {
+    bluetooth_sdp_hdr_overlay hdr;
+} bluetooth_sdp_sap_record;
+
 typedef union {
     bluetooth_sdp_hdr_overlay   hdr;
     bluetooth_sdp_mas_record    mas;
@@ -99,6 +104,7 @@
     bluetooth_sdp_pse_record    pse;
     bluetooth_sdp_pce_record    pce;
     bluetooth_sdp_ops_record    ops;
+    bluetooth_sdp_sap_record    sap;
 } bluetooth_sdp_record;
 
 
diff --git a/include/hardware/bt_sock.h b/include/hardware/bt_sock.h
index 1c937d8..69775e0 100644
--- a/include/hardware/bt_sock.h
+++ b/include/hardware/bt_sock.h
@@ -21,6 +21,7 @@
 #define BTSOCK_FLAG_ENCRYPT 1
 #define BTSOCK_FLAG_AUTH (1 << 1)
 #define BTSOCK_FLAG_NO_SDP (1 << 2)
+#define BTSOCK_FLAG_AUTH_MITM (1 << 3)
 
 typedef enum {
     BTSOCK_RFCOMM = 1,
@@ -34,11 +35,11 @@
     bt_bdaddr_t bd_addr;
     int channel;
     int status;
-    
+
     // The writer must make writes using a buffer of this maximum size
     // to avoid loosing data. (L2CAP only)
     unsigned short max_tx_packet_size;
- 
+
     // The reader must read using a buffer of at least this size to avoid
     // loosing data. (L2CAP only)
     unsigned short max_rx_packet_size;
diff --git a/include/hardware/gralloc.h b/include/hardware/gralloc.h
index 7aeb84e..ef86f90 100644
--- a/include/hardware/gralloc.h
+++ b/include/hardware/gralloc.h
@@ -75,7 +75,7 @@
     GRALLOC_USAGE_SW_READ_OFTEN         = 0x00000003,
     /* mask for the software read values */
     GRALLOC_USAGE_SW_READ_MASK          = 0x0000000F,
-    
+
     /* buffer is never written in software */
     GRALLOC_USAGE_SW_WRITE_NEVER        = 0x00000000,
     /* buffer is rarely written in software */
@@ -95,6 +95,21 @@
     GRALLOC_USAGE_HW_COMPOSER           = 0x00000800,
     /* buffer will be used with the framebuffer device */
     GRALLOC_USAGE_HW_FB                 = 0x00001000,
+
+    /* buffer should be displayed full-screen on an external display when
+     * possible */
+    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000,
+
+    /* Must have a hardware-protected path to external display sink for
+     * this buffer.  If a hardware-protected path is not available, then
+     * either don't composite only this buffer (preferred) to the
+     * external sink, or (less desirable) do not route the entire
+     * composition to the external sink.  */
+    GRALLOC_USAGE_PROTECTED             = 0x00004000,
+
+    /* buffer may be used as a cursor */
+    GRALLOC_USAGE_CURSOR                = 0x00008000,
+
     /* buffer will be used with the HW video encoder */
     GRALLOC_USAGE_HW_VIDEO_ENCODER      = 0x00010000,
     /* buffer will be written by the HW camera pipeline */
@@ -111,27 +126,11 @@
     /* buffer will be used as a RenderScript Allocation */
     GRALLOC_USAGE_RENDERSCRIPT          = 0x00100000,
 
-    /* buffer should be displayed full-screen on an external display when
-     * possible
-     */
-    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000,
-
-    /* Must have a hardware-protected path to external display sink for
-     * this buffer.  If a hardware-protected path is not available, then
-     * either don't composite only this buffer (preferred) to the
-     * external sink, or (less desirable) do not route the entire
-     * composition to the external sink.
-     */
-    GRALLOC_USAGE_PROTECTED             = 0x00004000,
-
-    /* buffer may be used as a cursor */
-    GRALLOC_USAGE_CURSOR                = 0x00008000,
-
     /* Set by the consumer to indicate to the producer that they may attach a
      * buffer that they did not detach from the BufferQueue. Will be filtered
      * out by GRALLOC_USAGE_ALLOC_MASK, so gralloc modules will not need to
      * handle this flag. */
-    GRALLOC_USAGE_FOREIGN_BUFFERS       = 0x00010000,
+    GRALLOC_USAGE_FOREIGN_BUFFERS       = 0x00200000,
 
     /* Mask of all flags which could be passed to a gralloc module for buffer
      * allocation. Any flags not in this mask do not need to be handled by
diff --git a/include/hardware/keymaster1.h b/include/hardware/keymaster1.h
index 1d017fd..77243af 100644
--- a/include/hardware/keymaster1.h
+++ b/include/hardware/keymaster1.h
@@ -298,7 +298,7 @@
      * KM_TAG_APPLICATION_DATA are never returned.
      */
     keymaster_error_t (*generate_key)(const struct keymaster1_device* dev,
-                                      const keymaster_key_param_t* params, size_t params_count,
+                                      const keymaster_key_param_set_t* params,
                                       keymaster_key_blob_t* key_blob,
                                       keymaster_key_characteristics_t** characteristics);
 
@@ -381,9 +381,10 @@
      * ownership and must deallocate with keymaster_free_characteristics().
      */
     keymaster_error_t (*import_key)(const struct keymaster1_device* dev,
-                                    const keymaster_key_param_t* params, size_t params_count,
-                                    keymaster_key_format_t key_format, const uint8_t* key_data,
-                                    size_t key_data_length, keymaster_key_blob_t* key_blob,
+                                    const keymaster_key_param_set_t* params,
+                                    keymaster_key_format_t key_format,
+                                    const keymaster_blob_t* key_data,
+                                    keymaster_key_blob_t* key_blob,
                                     keymaster_key_characteristics_t** characteristics);
 
     /**
@@ -403,8 +404,8 @@
                                     keymaster_key_format_t export_format,
                                     const keymaster_key_blob_t* key_to_export,
                                     const keymaster_blob_t* client_id,
-                                    const keymaster_blob_t* app_data, uint8_t** export_data,
-                                    size_t* export_data_length);
+                                    const keymaster_blob_t* app_data,
+                                    keymaster_blob_t* export_data);
 
     /**
      * Deletes the key, or key pair, associated with the key blob.  After calling this function it
@@ -471,9 +472,9 @@
      * update(), finish() or abort().
      */
     keymaster_error_t (*begin)(const struct keymaster1_device* dev, keymaster_purpose_t purpose,
-                               const keymaster_key_blob_t* key, const keymaster_key_param_t* params,
-                               size_t params_count, keymaster_key_param_t** out_params,
-                               size_t* out_params_count,
+                               const keymaster_key_blob_t* key,
+                               const keymaster_key_param_set_t* in_params,
+                               keymaster_key_param_set_t* out_params,
                                keymaster_operation_handle_t* operation_handle);
 
     /**
@@ -516,9 +517,9 @@
      */
     keymaster_error_t (*update)(const struct keymaster1_device* dev,
                                 keymaster_operation_handle_t operation_handle,
-                                const keymaster_key_param_t* params, size_t params_count,
-                                const uint8_t* input, size_t input_length, size_t* input_consumed,
-                                uint8_t** output, size_t* output_length);
+                                const keymaster_key_param_set_t* in_params,
+                                const keymaster_blob_t* input, size_t* input_consumed,
+                                keymaster_key_param_set_t* out_params, keymaster_blob_t* output);
 
     /**
      * Finalizes a cryptographic operation begun with begin() and invalidates operation_handle
@@ -549,9 +550,9 @@
      */
     keymaster_error_t (*finish)(const struct keymaster1_device* dev,
                                 keymaster_operation_handle_t operation_handle,
-                                const keymaster_key_param_t* params, size_t params_count,
-                                const uint8_t* signature, size_t signature_length, uint8_t** output,
-                                size_t* output_length);
+                                const keymaster_key_param_set_t* in_params,
+                                const keymaster_blob_t* signature,
+                                keymaster_key_param_set_t* out_params, keymaster_blob_t* output);
 
     /**
      * Aborts a cryptographic operation begun with begin(), freeing all internal resources and
diff --git a/include/hardware/keymaster_defs.h b/include/hardware/keymaster_defs.h
index 8e25e6c..77067d5 100644
--- a/include/hardware/keymaster_defs.h
+++ b/include/hardware/keymaster_defs.h
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#ifndef __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif  // __cplusplus
 
@@ -58,9 +58,7 @@
     KM_TAG_BLOCK_MODE = KM_ENUM_REP | 4,  /* keymaster_block_mode_t. */
     KM_TAG_DIGEST = KM_ENUM_REP | 5,      /* keymaster_digest_t. */
     KM_TAG_PADDING = KM_ENUM_REP | 6,     /* keymaster_padding_t. */
-    KM_TAG_RETURN_UNAUTHED = KM_BOOL | 7, /* Allow AEAD decryption to return plaintext before it has
-                                             been authenticated.  WARNING: Not recommended. */
-    KM_TAG_CALLER_NONCE = KM_BOOL | 8,    /* Allow caller to specify nonce or IV. */
+    KM_TAG_CALLER_NONCE = KM_BOOL | 7,    /* Allow caller to specify nonce or IV. */
 
     /* Algorithm-specific. */
     KM_TAG_RSA_PUBLIC_EXPONENT = KM_LONG | 200, /* Defaults to 2^16+1 */
@@ -123,8 +121,9 @@
     /* Tags used only to provide data to or receive data from operations */
     KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
     KM_TAG_NONCE = KM_BYTES | 1001,           /* Nonce or Initialization Vector */
-    KM_TAG_CHUNK_LENGTH = KM_INT | 1002,      /* AEAD mode chunk size, in bytes.  0 means no limit,
-                                                 which requires KM_TAG_RETURN_UNAUTHED. */
+    KM_TAG_AEAD_TAG = KM_BYTES | 1002,        /* AEAD tag data.  Returned from finish() during AEAD
+                                               * encryption and provided to begin() during AEAD
+                                               * decryption.*/
     KM_TAG_AUTH_TOKEN = KM_BYTES | 1003,      /* Authentication token that proves secure user
                                                  authentication has been performed.  Structure
                                                  defined in hw_auth_token_t in hw_auth_token.h. */
@@ -150,22 +149,17 @@
 
 /**
  * Symmetric block cipher modes provided by keymaster implementations.
- *
- * KM_MODE_FIRST_UNAUTHENTICATED and KM_MODE_FIRST_AUTHENTICATED are not modes but markers used to
- * separate the available modes into classes.
  */
 typedef enum {
     /* Unauthenticated modes, usable only for encryption/decryption and not generally recommended
      * except for compatibility with existing other protocols. */
-    KM_MODE_FIRST_UNAUTHENTICATED = 1,
-    KM_MODE_ECB = KM_MODE_FIRST_UNAUTHENTICATED,
+    KM_MODE_ECB = 1,
     KM_MODE_CBC = 2,
-    KM_MODE_CTR = 4,
+    KM_MODE_CTR = 3,
 
     /* Authenticated modes, usable for encryption/decryption and signing/verification.  Recommended
      * over unauthenticated modes for all purposes. */
-    KM_MODE_FIRST_AUTHENTICATED = 32,
-    KM_MODE_GCM = KM_MODE_FIRST_AUTHENTICATED,
+    KM_MODE_GCM = 32,
 } keymaster_block_mode_t;
 
 /**
@@ -343,7 +337,7 @@
     KM_ERROR_UNSUPPORTED_EC_FIELD = -50,
     KM_ERROR_MISSING_NONCE = -51,
     KM_ERROR_INVALID_NONCE = -52,
-    KM_ERROR_UNSUPPORTED_CHUNK_LENGTH = -53,
+    KM_ERROR_MISSING_MAC_LENGTH = -53,
     KM_ERROR_CALLER_NONCE_PROHIBITED = -55,
 
     KM_ERROR_UNIMPLEMENTED = -100,
@@ -516,7 +510,7 @@
     }
 }
 
-#ifndef __cplusplus
+#ifdef __cplusplus
 }  // extern "C"
 #endif  // __cplusplus