Merge "Wrong variable being printed in ALOGV statement."
am: f8248731ab

Change-Id: I4f7554a3277f37f662111916f0acf69c73c6a46c
diff --git a/OWNERS b/OWNERS
index 0c22ffd..da2454a 100644
--- a/OWNERS
+++ b/OWNERS
@@ -4,3 +4,4 @@
 malchev@google.com
 smoreland@google.com
 swillden@google.com
+per-file include/hardware/camera*=etalvala@google.com
diff --git a/include/hardware/audio.h b/include/hardware/audio.h
index 2d6eb30..10a8789 100644
--- a/include/hardware/audio.h
+++ b/include/hardware/audio.h
@@ -91,6 +91,17 @@
 /* Bluetooth SCO wideband */
 #define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
 
+/* BT SCO headset name for debug */
+#define AUDIO_PARAMETER_KEY_BT_SCO_HEADSET_NAME "bt_headset_name"
+
+/* BT SCO HFP control */
+#define AUDIO_PARAMETER_KEY_HFP_ENABLE            "hfp_enable"
+#define AUDIO_PARAMETER_KEY_HFP_SET_SAMPLING_RATE "hfp_set_sampling_rate"
+#define AUDIO_PARAMETER_KEY_HFP_VOLUME            "hfp_volume"
+
+/* Set screen orientation */
+#define AUDIO_PARAMETER_KEY_ROTATION "rotation"
+
 /**
  *  audio stream parameters
  */
@@ -201,13 +212,24 @@
                                    give time for gapless track switch */
 } audio_drain_type_t;
 
+typedef struct source_metadata {
+    size_t track_count;
+    /** Array of metadata of each track connected to this source. */
+    struct playback_track_metadata* tracks;
+} source_metadata_t;
+
+typedef struct sink_metadata {
+    size_t track_count;
+    /** Array of metadata of each track connected to this sink. */
+    struct record_track_metadata* tracks;
+} sink_metadata_t;
+
 /**
  * audio_stream_out is the abstraction interface for the audio output hardware.
  *
  * It provides information about various properties of the audio output
  * hardware driver.
  */
-
 struct audio_stream_out {
     /**
      * Common methods of the audio stream out.  This *must* be the first member of audio_stream_out
@@ -392,6 +414,13 @@
      */
     int (*get_mmap_position)(const struct audio_stream_out *stream,
                              struct audio_mmap_position *position);
+
+    /**
+     * Called when the metadata of the stream's source has been changed.
+     * @param source_metadata Description of the audio that is played by the clients.
+     */
+    void (*update_source_metadata)(struct audio_stream_out *stream,
+                                   const struct source_metadata* source_metadata);
 };
 typedef struct audio_stream_out audio_stream_out_t;
 
@@ -501,6 +530,31 @@
      */
     int (*get_mmap_position)(const struct audio_stream_in *stream,
                              struct audio_mmap_position *position);
+
+    /**
+     * Called by the framework to read active microphones
+     *
+     * \param[in] stream the stream object.
+     * \param[out] mic_array Pointer to first element on array with microphone info
+     * \param[out] mic_count When called, this holds the value of the max number of elements
+     *                       allowed in the mic_array. The actual number of elements written
+     *                       is returned here.
+     *                       if mic_count is passed as zero, mic_array will not be populated,
+     *                       and mic_count will return the actual number of active microphones.
+     *
+     * \return 0 if the microphone array is successfully filled.
+     *         -ENOSYS if there is an error filling the data
+     */
+    int (*get_active_microphones)(const struct audio_stream_in *stream,
+                                  struct audio_microphone_characteristic_t *mic_array,
+                                  size_t *mic_count);
+
+    /**
+     * Called when the metadata of the stream's sink has been changed.
+     * @param sink_metadata Description of the audio that is recorded by the clients.
+     */
+    void (*update_sink_metadata)(struct audio_stream_in *stream,
+                                 const struct sink_metadata* sink_metadata);
 };
 typedef struct audio_stream_in audio_stream_in_t;
 
@@ -673,6 +727,25 @@
     void (*close_input_stream)(struct audio_hw_device *dev,
                                struct audio_stream_in *stream_in);
 
+    /**
+     * Called by the framework to read available microphones characteristics.
+     *
+     * \param[in] dev the hw_device object.
+     * \param[out] mic_array Pointer to first element on array with microphone info
+     * \param[out] mic_count When called, this holds the value of the max number of elements
+     *                       allowed in the mic_array. The actual number of elements written
+     *                       is returned here.
+     *                       if mic_count is passed as zero, mic_array will not be populated,
+     *                       and mic_count will return the actual number of microphones in the
+     *                       system.
+     *
+     * \return 0 if the microphone array is successfully filled.
+     *         -ENOSYS if there is an error filling the data
+     */
+    int (*get_microphones)(const struct audio_hw_device *dev,
+                           struct audio_microphone_characteristic_t *mic_array,
+                           size_t *mic_count);
+
     /** This method dumps the state of the audio hardware */
     int (*dump)(const struct audio_hw_device *dev, int fd);
 
diff --git a/include/hardware/camera3.h b/include/hardware/camera3.h
index cec2ab3..c3ea0aa 100644
--- a/include/hardware/camera3.h
+++ b/include/hardware/camera3.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 The Android Open Source Project
+ * Copyright (C) 2013-2018 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.
@@ -21,7 +21,7 @@
 #include "camera_common.h"
 
 /**
- * Camera device HAL 3.4 [ CAMERA_DEVICE_API_VERSION_3_4 ]
+ * Camera device HAL 3.5[ CAMERA_DEVICE_API_VERSION_3_5 ]
  *
  * This is the current recommended version of the camera device HAL.
  *
@@ -29,7 +29,7 @@
  * android.hardware.camera2 API as LIMITED or above hardware level.
  *
  * Camera devices that support this version of the HAL must return
- * CAMERA_DEVICE_API_VERSION_3_4 in camera_device_t.common.version and in
+ * CAMERA_DEVICE_API_VERSION_3_5 in camera_device_t.common.version and in
  * camera_info_t.device_version (from camera_module_t.get_camera_info).
  *
  * CAMERA_DEVICE_API_VERSION_3_3 and above:
@@ -157,6 +157,32 @@
  *     - ANDROID_SENSOR_DYNAMIC_WHITE_LEVEL
  *     - ANDROID_SENSOR_OPAQUE_RAW_SIZE
  *     - ANDROID_SENSOR_OPTICAL_BLACK_REGIONS
+ *
+ * 3.5: Minor revisions to support session parameters and logical multi camera:
+ *
+ *   - Add ANDROID_REQUEST_AVAILABLE_SESSION_KEYS static metadata, which is
+ *     optional for implementations that want to support session parameters. If support is
+ *     needed, then Hal should populate the list with all available capture request keys
+ *     that can cause severe processing delays when modified by client. Typical examples
+ *     include parameters that require time-consuming HW re-configuration or internal camera
+ *     pipeline update.
+ *
+ *   - Add a session parameter field to camera3_stream_configuration which can be populated
+ *     by clients with initial values for the keys found in ANDROID_REQUEST_AVAILABLE_SESSION_KEYS.
+ *
+ *   - Metadata additions for logical multi camera capability:
+ *     - ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA
+ *     - ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS
+ *     - ANDROID_LOGICAL_MULTI_CAMERA_SYNC_TYPE
+ *
+ *   - Add physical camera id field in camera3_stream, so that for a logical
+ *     multi camera, the application has the option to specify which physical camera
+ *     a particular stream is configured on.
+ *
+ *   - Add physical camera id and settings field in camera3_capture_request, so that
+ *     for a logical multi camera, the application has the option to specify individual
+ *     settings for a particular physical device.
+ *
  */
 
 /**
@@ -1687,8 +1713,31 @@
      */
     int rotation;
 
+    /**
+     * The physical camera id this stream belongs to.
+     *
+     * <= CAMERA_DEVICE_API_VERISON_3_4:
+     *
+     *    Not defined and must not be accessed.
+     *
+     * >= CAMERA_DEVICE_API_VERISON_3_5:
+     *
+     *    Always set by camera service. If the camera device is not a logical
+     *    multi camera, or if the camera is a logical multi camera but the stream
+     *    is not a physical output stream, this field will point to a 0-length
+     *    string.
+     *
+     *    A logical multi camera is a camera device backed by multiple physical
+     *    cameras that are also exposed to the application. And for a logical
+     *    multi camera, a physical output stream is an output stream specifically
+     *    requested on an underlying physical camera.
+     *
+     *    For an input stream, this field is guaranteed to be a 0-length string.
+     */
+    const char* physical_camera_id;
+
     /* reserved for future use */
-    void *reserved[7];
+    void *reserved[6];
 
 } camera3_stream_t;
 
@@ -1734,6 +1783,18 @@
      *
      */
     uint32_t operation_mode;
+
+    /**
+     * >= CAMERA_DEVICE_API_VERSION_3_5:
+     *
+     * The session metadata buffer contains the initial values of
+     * ANDROID_REQUEST_AVAILABLE_SESSION_KEYS. This field is optional
+     * and camera clients can choose to ignore it, in which case it will
+     * be set to NULL. If parameters are present, then Hal should examine
+     * the parameter values and configure its internal camera pipeline
+     * accordingly.
+     */
+    const camera_metadata_t *session_parameters;
 } camera3_stream_configuration_t;
 
 /**
@@ -2217,6 +2278,44 @@
      */
     const camera3_stream_buffer_t *output_buffers;
 
+    /**
+     * <= CAMERA_DEVICE_API_VERISON_3_4:
+     *
+     *    Not defined and must not be accessed.
+     *
+     * >= CAMERA_DEVICE_API_VERSION_3_5:
+     *    The number of physical camera settings to be applied. If 'num_physcam_settings'
+     *    equals 0 or a physical device is not included, then Hal must decide the
+     *    specific physical device settings based on the default 'settings'.
+     */
+    uint32_t num_physcam_settings;
+
+    /**
+     * <= CAMERA_DEVICE_API_VERISON_3_4:
+     *
+     *    Not defined and must not be accessed.
+     *
+     * >= CAMERA_DEVICE_API_VERSION_3_5:
+     *    The physical camera ids. The array will contain 'num_physcam_settings'
+     *    camera id strings for all physical devices that have specific settings.
+     *    In case some id is invalid, the process capture request must fail and return
+     *    -EINVAL.
+     */
+    const char **physcam_id;
+
+    /**
+     * <= CAMERA_DEVICE_API_VERISON_3_4:
+     *
+     *    Not defined and must not be accessed.
+     *
+     * >= CAMERA_DEVICE_API_VERSION_3_5:
+     *    The capture settings for the physical cameras. The array will contain
+     *    'num_physcam_settings' settings for invididual physical devices. In
+     *    case the settings at some particular index are empty, the process capture
+     *    request must fail and return -EINVAL.
+     */
+    const camera_metadata_t **physcam_settings;
+
 } camera3_capture_request_t;
 
 /**
@@ -2394,6 +2493,37 @@
       */
      uint32_t partial_result;
 
+     /**
+      * >= CAMERA_DEVICE_API_VERSION_3_5:
+      *
+      * Specifies the number of physical camera metadata this capture result
+      * contains. It must be equal to the number of physical cameras being
+      * requested from.
+      *
+      * If the current camera device is not a logical multi-camera, or the
+      * corresponding capture_request doesn't request on any physical camera,
+      * this field must be 0.
+      */
+     uint32_t num_physcam_metadata;
+
+     /**
+      * >= CAMERA_DEVICE_API_VERSION_3_5:
+      *
+      * An array of strings containing the physical camera ids for the returned
+      * physical camera metadata. The length of the array is
+      * num_physcam_metadata.
+      */
+     const char **physcam_ids;
+
+     /**
+      * >= CAMERA_DEVICE_API_VERSION_3_5:
+      *
+      * The array of physical camera metadata for the physical cameras being
+      * requested upon. This array should have a 1-to-1 mapping with the
+      * physcam_ids. The length of the array is num_physcam_metadata.
+      */
+     const camera_metadata_t **physcam_metadata;
+
 } camera3_capture_result_t;
 
 /**********************************************************************
@@ -2926,7 +3056,8 @@
      *  0:      On a successful start to processing the capture request
      *
      * -EINVAL: If the input is malformed (the settings are NULL when not
-     *          allowed, there are 0 output buffers, etc) and capture processing
+     *          allowed, invalid physical camera settings,
+     *          there are 0 output buffers, etc) and capture processing
      *          cannot start. Failures during request processing should be
      *          handled by calling camera3_callback_ops_t.notify(). In case of
      *          this error, the framework will retain responsibility for the
diff --git a/include/hardware/camera_common.h b/include/hardware/camera_common.h
index 7bafa88..edd1ada 100644
--- a/include/hardware/camera_common.h
+++ b/include/hardware/camera_common.h
@@ -148,10 +148,11 @@
 #define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
 #define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
 #define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
+#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
 
-// Device version 3.4 is current, older HAL camera device versions are not
+// Device version 3.5 is current, older HAL camera device versions are not
 // recommended for new devices.
-#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_4
+#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_5
 
 /**
  * Defined in /system/media/camera/include/system/camera_metadata.h
diff --git a/include/hardware/gralloc1.h b/include/hardware/gralloc1.h
index 0a6843f..03e8432 100644
--- a/include/hardware/gralloc1.h
+++ b/include/hardware/gralloc1.h
@@ -155,7 +155,10 @@
     GRALLOC1_FUNCTION_UNLOCK = 20,
     GRALLOC1_FUNCTION_SET_LAYER_COUNT = 21,
     GRALLOC1_FUNCTION_GET_LAYER_COUNT = 22,
-    GRALLOC1_LAST_FUNCTION = 22,
+    GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE = 23,
+    GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE = 24,
+    GRALLOC1_FUNCTION_IMPORT_BUFFER = 25,
+    GRALLOC1_LAST_FUNCTION = 25,
 } gralloc1_function_descriptor_t;
 
 typedef enum {
@@ -670,6 +673,65 @@
 typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_STRIDE)(
         gralloc1_device_t* device, buffer_handle_t buffer, uint32_t* outStride);
 
+/* getTransportSize(..., outNumFds, outNumInts)
+ * Function descriptor: GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE
+ * This function is optional for all gralloc1 devices.
+ *
+ * Get the transport size of a buffer. An imported buffer handle is a raw
+ * buffer handle with the process-local runtime data appended. This
+ * function, for example, allows a caller to omit the process-local
+ * runtime data at the tail when serializing the imported buffer handle.
+ *
+ * Note that a client might or might not omit the process-local runtime
+ * data when sending an imported buffer handle. The mapper must support
+ * both cases on the receiving end.
+ *
+ * Parameters:
+ *   outNumFds - the number of file descriptors needed for transport
+ *   outNumInts - the number of integers needed for transport
+ *
+ * Returns GRALLOC1_ERROR_NONE or one of the following errors:
+ *   GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
+ *   GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the numFds
+ *       and numInts; see note [1] in this section's header for more information
+ */
+typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_TRANSPORT_SIZE)(
+        gralloc1_device_t* device, buffer_handle_t buffer, uint32_t *outNumFds,
+        uint32_t *outNumInts);
+
+typedef struct gralloc1_buffer_descriptor_info {
+    uint32_t width;
+    uint32_t height;
+    uint32_t layerCount;
+    int32_t /*android_pixel_format_t*/ format;
+    uint64_t producerUsage;
+    uint64_t consumerUsage;
+} gralloc1_buffer_descriptor_info_t;
+
+/* validateBufferSize(..., )
+ * Function descriptor: GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE
+ * This function is optional for all gralloc1 devices.
+ *
+ * Validate that the buffer can be safely accessed by a caller who assumes
+ * the specified descriptorInfo and stride. This must at least validate
+ * that the buffer size is large enough. Validating the buffer against
+ * individual buffer attributes is optional.
+ *
+ * Parameters:
+ *   descriptor - specifies the attributes of the buffer
+ *   stride - the buffer stride returned by IAllocator::allocate
+ *
+ * Returns GRALLOC1_ERROR_NONE or one of the following errors:
+ *   GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
+ *   GRALLOC1_ERROR_BAD_VALUE - when buffer cannot be safely accessed
+ *   GRALLOC1_ERROR_UNSUPPORTED - the device is unable to validate the buffer
+ *       size; see note [1] in this section's header for more information
+ */
+typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_VALIDATE_BUFFER_SIZE)(
+        gralloc1_device_t* device, buffer_handle_t buffer,
+        const gralloc1_buffer_descriptor_info_t* descriptorInfo,
+        uint32_t stride);
+
 /*
  * Buffer management functions
  */
@@ -723,6 +785,37 @@
         const gralloc1_buffer_descriptor_t* descriptors,
         buffer_handle_t* outBuffers);
 
+/* importBuffer(..., rawHandle, outBuffer);
+ * Function descriptor: GRALLOC1_FUNCTION_IMPORT_BUFFER
+ * This function is optional for all gralloc1 devices.
+ * When supported, GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE must also be
+ * supported.
+ *
+ * Explictly imports a buffer into a proccess.
+ *
+ * This function can be called in place of retain when a raw buffer handle is
+ * received by a remote process. Import producess a import handle that can
+ * be used to access the underlying graphic buffer. The new import handle has a
+ * ref count of 1.
+ *
+ * This function must at least validate the raw handle before creating the
+ * imported handle. It must also support importing the same raw handle
+ * multiple times to create multiple imported handles. The imported handle
+ * must be considered valid everywhere in the process.
+ *
+ * Parameters:
+ *   rawHandle - the raw buffer handle to import
+ *   outBuffer - a handle to the newly imported buffer
+ *
+ * Returns GRALLOC1_ERROR_NONE or one of the following errors:
+ *   GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
+ *   GRALLOC1_ERROR_NO_RESOURCES - it is not possible to add a import to this
+ *       buffer at this time
+ */
+typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_IMPORT_BUFFER)(
+        gralloc1_device_t* device, const buffer_handle_t rawHandle,
+        buffer_handle_t* outBuffer);
+
 /* retain(..., buffer)
  * Function descriptor: GRALLOC1_FUNCTION_RETAIN
  * Must be provided by all gralloc1 devices
diff --git a/include/hardware/hwcomposer2.h b/include/hardware/hwcomposer2.h
index 11c9bdd..c9809ce 100644
--- a/include/hardware/hwcomposer2.h
+++ b/include/hardware/hwcomposer2.h
@@ -114,7 +114,7 @@
      * presentDisplay should fail as fast as possible in the case a
      * validateDisplay step is needed.
      */
-    HWC2_CAPABILITY_SKIP_VALIDATE= 4,
+    HWC2_CAPABILITY_SKIP_VALIDATE = 4,
 } hwc2_capability_t;
 
 /* Possible composition types for a given layer */
@@ -262,6 +262,15 @@
     HWC2_FUNCTION_SET_POWER_MODE,
     HWC2_FUNCTION_SET_VSYNC_ENABLED,
     HWC2_FUNCTION_VALIDATE_DISPLAY,
+    HWC2_FUNCTION_SET_LAYER_FLOAT_COLOR,
+    HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA,
+    HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS,
+    HWC2_FUNCTION_SET_READBACK_BUFFER,
+    HWC2_FUNCTION_GET_READBACK_BUFFER_ATTRIBUTES,
+    HWC2_FUNCTION_GET_READBACK_BUFFER_FENCE,
+    HWC2_FUNCTION_GET_RENDER_INTENTS,
+    HWC2_FUNCTION_SET_COLOR_MODE_WITH_RENDER_INTENT,
+    HWC2_FUNCTION_GET_DATASPACE_SATURATION_MATRIX
 } hwc2_function_descriptor_t;
 
 /* Layer requests returned from getDisplayRequests */
@@ -311,6 +320,33 @@
     HWC2_VSYNC_DISABLE = 2,
 } hwc2_vsync_t;
 
+/* MUST match HIDL's V2_2::IComposerClient::PerFrameMetadataKey */
+typedef enum {
+    /* SMPTE ST 2084:2014.
+     * Coordinates defined in CIE 1931 xy chromaticity space
+     */
+    HWC2_DISPLAY_RED_PRIMARY_X = 0,
+    HWC2_DISPLAY_RED_PRIMARY_Y = 1,
+    HWC2_DISPLAY_GREEN_PRIMARY_X = 2,
+    HWC2_DISPLAY_GREEN_PRIMARY_Y = 3,
+    HWC2_DISPLAY_BLUE_PRIMARY_X = 4,
+    HWC2_DISPLAY_BLUE_PRIMARY_Y = 5,
+    HWC2_WHITE_POINT_X = 6,
+    HWC2_WHITE_POINT_Y = 7,
+    /* SMPTE ST 2084:2014.
+     * Units: nits
+     * max as defined by ST 2048: 10,000 nits
+     */
+    HWC2_MAX_LUMINANCE = 8,
+    HWC2_MIN_LUMINANCE = 9,
+
+    /* CTA 861.3
+     * Units: nits
+     */
+    HWC2_MAX_CONTENT_LIGHT_LEVEL = 10,
+    HWC2_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11,
+} hwc2_per_frame_metadata_key_t;
+
 /*
  * Stringification Functions
  */
@@ -479,6 +515,15 @@
         case HWC2_FUNCTION_SET_POWER_MODE: return "SetPowerMode";
         case HWC2_FUNCTION_SET_VSYNC_ENABLED: return "SetVsyncEnabled";
         case HWC2_FUNCTION_VALIDATE_DISPLAY: return "ValidateDisplay";
+        case HWC2_FUNCTION_SET_LAYER_FLOAT_COLOR: return "SetLayerFloatColor";
+        case HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA: return "SetLayerPerFrameMetadata";
+        case HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS: return "GetPerFrameMetadataKeys";
+        case HWC2_FUNCTION_SET_READBACK_BUFFER: return "SetReadbackBuffer";
+        case HWC2_FUNCTION_GET_READBACK_BUFFER_ATTRIBUTES: return "GetReadbackBufferAttributes";
+        case HWC2_FUNCTION_GET_READBACK_BUFFER_FENCE: return "GetReadbackBufferFence";
+        case HWC2_FUNCTION_GET_RENDER_INTENTS: return "GetRenderIntents";
+        case HWC2_FUNCTION_SET_COLOR_MODE_WITH_RENDER_INTENT: return "SetColorModeWithRenderIntent";
+        case HWC2_FUNCTION_GET_DATASPACE_SATURATION_MATRIX: return "GetDataspaceSaturationMatrix";
         default: return "Unknown";
     }
 }
@@ -668,6 +713,15 @@
     SetPowerMode = HWC2_FUNCTION_SET_POWER_MODE,
     SetVsyncEnabled = HWC2_FUNCTION_SET_VSYNC_ENABLED,
     ValidateDisplay = HWC2_FUNCTION_VALIDATE_DISPLAY,
+    SetLayerFloatColor = HWC2_FUNCTION_SET_LAYER_FLOAT_COLOR,
+    SetLayerPerFrameMetadata = HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA,
+    GetPerFrameMetadataKeys = HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS,
+    SetReadbackBuffer = HWC2_FUNCTION_SET_READBACK_BUFFER,
+    GetReadbackBufferAttributes = HWC2_FUNCTION_GET_READBACK_BUFFER_ATTRIBUTES,
+    GetReadbackBufferFence = HWC2_FUNCTION_GET_READBACK_BUFFER_FENCE,
+    GetRenderIntents = HWC2_FUNCTION_GET_RENDER_INTENTS,
+    SetColorModeWithRenderIntent = HWC2_FUNCTION_SET_COLOR_MODE_WITH_RENDER_INTENT,
+    GetDataspaceSaturationMatrix = HWC2_FUNCTION_GET_DATASPACE_SATURATION_MATRIX,
 };
 TO_STRING(hwc2_function_descriptor_t, FunctionDescriptor,
         getFunctionDescriptorName)
@@ -969,6 +1023,27 @@
         int32_t /*hwc2_callback_descriptor_t*/ descriptor,
         hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer);
 
+/* getDataspaceSaturationMatrix(..., dataspace, outMatrix)
+ * Descriptor: HWC2_FUNCTION_GET_DATASPACE_SATURATION_MATRIX
+ * Provided by HWC2 devices which don't return nullptr function pointer.
+ *
+ * Get the saturation matrix of the specified dataspace. The saturation matrix
+ * can be used to approximate the dataspace saturation operation performed by
+ * the HWC2 device when non-colorimetric mapping is allowed. It is to be
+ * applied on linear pixel values.
+ *
+ * Parameters:
+ *   dataspace - the dataspace to query for
+ *   outMatrix - a column-major 4x4 matrix (16 floats). It must be an identity
+ *       matrix unless dataspace is HAL_DATASPACE_SRGB_LINEAR.
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_PARAMETER - dataspace was invalid
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_GET_DATASPACE_SATURATION_MATRIX)(
+        hwc2_device_t* device, int32_t /*android_dataspace_t*/ dataspace,
+        float* outMatrix);
+
 /*
  * Display Functions
  *
@@ -1146,6 +1221,35 @@
         hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumModes,
         int32_t* /*android_color_mode_t*/ outModes);
 
+/* getRenderIntents(..., mode, outNumIntents, outIntents)
+ * Descriptor: HWC2_FUNCTION_GET_RENDER_INTENTS
+ * Provided by HWC2 devices which don't return nullptr function pointer.
+ *
+ * Returns the render intents supported on this display.
+ *
+ * The valid render intents can be found in android_render_intent_v1_1_t in
+ * <system/graphics.h>. All HWC2 devices must support at least
+ * HAL_RENDER_INTENT_COLORIMETRIC.
+ *
+ * outNumIntents may be NULL to retrieve the number of intents which will be
+ * returned.
+ *
+ * Parameters:
+ *   mode - the color mode to query the render intents for
+ *   outNumIntents - if outIntents was NULL, the number of intents which would
+ *       have been returned; if outIntents was not NULL, the number of intents
+ *       returned, which must not exceed the value stored in outNumIntents
+ *       prior to the call; pointer will be non-NULL
+ *   outIntents - an array of render intents
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_GET_RENDER_INTENTS)(
+        hwc2_device_t* device, hwc2_display_t display, int32_t mode,
+        uint32_t* outNumIntents,
+        int32_t* /*android_render_intent_v1_1_t*/ outIntents);
+
 /* getDisplayAttribute(..., config, attribute, outValue)
  * Descriptor: HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE
  * Must be provided by all HWC2 devices
@@ -1470,8 +1574,8 @@
  *
  * Sets the color mode of the given display.
  *
- * Upon returning from this function, the color mode change must have fully
- * taken effect.
+ * This must be called outside of validateDisplay/presentDisplay, and it takes
+ * effect on next presentDisplay.
  *
  * The valid color modes can be found in android_color_mode_t in
  * <system/graphics.h>. All HWC2 devices must support at least
@@ -1490,6 +1594,34 @@
         hwc2_device_t* device, hwc2_display_t display,
         int32_t /*android_color_mode_t*/ mode);
 
+/* setColorModeWithIntent(..., mode, intent)
+ * Descriptor: HWC2_FUNCTION_SET_COLOR_MODE_WITH_RENDER_INTENT
+ * Provided by HWC2 devices which don't return nullptr function pointer.
+ *
+ * This must be called outside of validateDisplay/presentDisplay, and it takes
+ * effect on next presentDisplay.
+ *
+ * The valid color modes and render intents can be found in
+ * android_color_mode_t and android_render_intent_v1_1_t in
+ * <system/graphics.h>. All HWC2 devices must support at least
+ * HAL_COLOR_MODE_NATIVE and HAL_RENDER_INTENT_COLORIMETRIC, and displays are
+ * assumed to be in this mode and intent upon hotplug.
+ *
+ * Parameters:
+ *   mode - the mode to set
+ *   intent - the intent to set
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ *   HWC2_ERROR_BAD_PARAMETER - mode/intent is not a valid color mode or
+ *       render intent
+ *   HWC2_ERROR_UNSUPPORTED - mode or intent is not supported on this display
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_SET_COLOR_MODE_WITH_RENDER_INTENT)(
+        hwc2_device_t* device, hwc2_display_t display,
+        int32_t /*android_color_mode_t*/ mode,
+        int32_t /*android_render_intent_v1_1_t */ intent);
+
 /* setColorTransform(..., matrix, hint)
  * Descriptor: HWC2_FUNCTION_SET_COLOR_TRANSFORM
  * Must be provided by all HWC2 devices
@@ -1537,6 +1669,34 @@
         hwc2_device_t* device, hwc2_display_t display, const float* matrix,
         int32_t /*android_color_transform_t*/ hint);
 
+/* getPerFrameMetadataKeys(..., outKeys)
+ * Descriptor: HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS
+ * Optional for HWC2 devices
+ *
+ * If supported (getFunction(HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS) is non-null),
+ * getPerFrameMetadataKeys returns the list of supported PerFrameMetadataKeys
+ * which are invariant with regard to the active configuration.
+ *
+ * Devices which are not HDR-capable, must return null when getFunction is called
+ * with HWC2_FUNCTION_GET_PER_FRAME_METADATA_KEYS.
+ *
+ * If outKeys is NULL, the required number of PerFrameMetadataKey keys
+ * must be returned in outNumKeys.
+ *
+ * Parameters:
+ *   outNumKeys - if outKeys is NULL, the number of keys which would have
+ *       been returned; if outKeys is not NULL, the number of keys stored in
+ *       outKeys, which must not exceed the value stored in outNumKeys prior
+ *       to the call; pointer will be non-NULL
+ *   outKeys - an array of hwc2_per_frame_metadata_key_t keys
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_GET_PER_FRAME_METADATA_KEYS)(
+        hwc2_device_t* device, hwc2_display_t display, uint32_t* outNumKeys,
+        int32_t* /*hwc2_per_frame_metadata_key_t*/ outKeys);
+
 /* setOutputBuffer(..., buffer, releaseFence)
  * Descriptor: HWC2_FUNCTION_SET_OUTPUT_BUFFER
  * Must be provided by all HWC2 devices
@@ -1591,6 +1751,132 @@
         hwc2_device_t* device, hwc2_display_t display,
         int32_t /*hwc2_power_mode_t*/ mode);
 
+/* getReadbackBufferAttributes(..., outFormat, outDataspace)
+ * Optional for HWC2 devices
+ *
+ * Returns the format which should be used when allocating a buffer for use by
+ * device readback as well as the dataspace in which its contents should be
+ * interpreted.
+ *
+ * If readback is not supported by this HWC implementation, this call will also
+ * be able to return HWC2_ERROR_UNSUPPORTED so we can fall back to another method.
+ * Returning NULL to a getFunction request for this function will also indicate
+ * that readback is not supported.
+ *
+ * The width and height of this buffer will be those of the currently-active
+ * display configuration, and the usage flags will consist of the following:
+ *   BufferUsage::CPU_READ | BufferUsage::GPU_TEXTURE |
+ *   BufferUsage::COMPOSER_OUTPUT
+ *
+ * The format and dataspace provided must be sufficient such that if a
+ * correctly-configured buffer is passed into setReadbackBuffer, filled by
+ * the device, and then displayed by the client as a full-screen buffer, the
+ * output of the display remains the same (subject to the note about protected
+ * content in the description of setReadbackBuffer).
+ *
+ * If the active configuration or color mode of this display has changed since
+ * the previous call to this function, it will be called again prior to setting
+ * a readback buffer such that the returned format and dataspace can be updated
+ * accordingly.
+ *
+ * Parameters:
+ *   outFormat - the format the client should use when allocating a device
+ *       readback buffer; pointer will be non-NULL
+ *   outDataspace - the dataspace the client will use when interpreting the
+ *       contents of a device readback buffer; pointer will be non-NULL
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ *
+ * See also:
+ *   setReadbackBuffer
+ *   getReadbackBufferFence
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_GET_READBACK_BUFFER_ATTRIBUTES)(
+        hwc2_device_t* device, hwc2_display_t display,
+        int32_t* /*android_pixel_format_t*/ outFormat,
+        int32_t* /*android_dataspace_t*/ outDataspace);
+
+/* getReadbackBufferFence(..., outFence)
+ * Optional for HWC2 devices
+ *
+ * Returns an acquire sync fence file descriptor which will signal when the
+ * buffer provided to setReadbackBuffer has been filled by the device and is
+ * safe for the client to read.
+ *
+ * If it is already safe to read from this buffer, -1 may be returned instead.
+ * The client takes ownership of this file descriptor and is responsible for
+ * closing it when it is no longer needed.
+ *
+ * This function will be called immediately after the composition cycle being
+ * captured into the readback buffer. The complete ordering of a readback buffer
+ * capture is as follows:
+ *
+ *   getReadbackBufferAttributes
+ *   // Readback buffer is allocated
+ *   // Many frames may pass
+ *
+ *   setReadbackBuffer
+ *   validateDisplay
+ *   presentDisplay
+ *   getReadbackBufferFence
+ *   // Implicitly wait on the acquire fence before accessing the buffer
+ *
+ * Parameters:
+ *   outFence - a sync fence file descriptor as described above; pointer
+ *       will be non-NULL
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ *   HWC2_ERROR_NO_RESOURCES - the readback operation was successful, but
+ *       resulted in a different validate result than would have occurred
+ *       without readback
+ *   HWC2_ERROR_UNSUPPORTED - the readback operation was unsuccessful because
+ *       of resource constraints, the presence of protected content, or other
+ *       reasons; -1 must be returned in outFence
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_GET_READBACK_BUFFER_FENCE)(
+        hwc2_device_t* device, hwc2_display_t display,
+        int32_t* outFence);
+
+/* setReadbackBuffer(..., buffer, releaseFence)
+ * Optional for HWC2 devices
+ *
+ * Sets the readback buffer to be filled with the contents of the next
+ * composition performed for this display (i.e., the contents present at the
+ * time of the next validateDisplay/presentDisplay cycle).
+ *
+ * This buffer will have been allocated as described in
+ * getReadbackBufferAttributes and will be interpreted as being in the dataspace
+ * provided by the same.
+ *
+ * If there is hardware protected content on the display at the time of the next
+ * composition, the area of the readback buffer covered by such content must be
+ * completely black. Any areas of the buffer not covered by such content may
+ * optionally be black as well.
+ *
+ * The release fence file descriptor provided works identically to the one
+ * described for setOutputBuffer.
+ *
+ * This function will not be called between any call to validateDisplay and a
+ * subsequent call to presentDisplay.
+ *
+ * Parameters:
+ *   buffer - the new readback buffer
+ *   releaseFence - a sync fence file descriptor as described in setOutputBuffer
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ *   HWC2_ERROR_BAD_PARAMETER - the new readback buffer handle was invalid
+ *
+ * See also:
+ *   getReadbackBufferAttributes
+ *   getReadbackBufferFence
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_SET_READBACK_BUFFER)(
+        hwc2_device_t* device, hwc2_display_t display,
+        buffer_handle_t buffer, int32_t releaseFence);
+
 /* setVsyncEnabled(..., enabled)
  * Descriptor: HWC2_FUNCTION_SET_VSYNC_ENABLED
  * Must be provided by all HWC2 devices
@@ -1758,6 +2044,35 @@
         hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
         hwc_region_t damage);
 
+/* setLayerPerFrameMetadata(..., numMetadata, metadata)
+ * Descriptor: HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA
+ * Optional for HWC2 devices
+ *
+ * If supported (getFunction(HWC2_FUNCTION_SET_LAYER_PER_FRAME_METADATA) is
+ * non-null), sets the metadata for the given display for all following
+ * frames.
+ *
+ * Upon returning from this function, the metadata change must have
+ * fully taken effect.
+ *
+ * This function will only be called if getPerFrameMetadataKeys is non-NULL
+ * and returns at least one key.
+ *
+ * Parameters:
+ *   numElements is the number of elements in each of the keys and metadata arrays
+ *   keys is a pointer to the array of keys.
+ *   outMetadata is a pointer to the corresponding array of metadata.
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_DISPLAY - an invalid display handle was passed in
+ *   HWC2_ERROR_BAD_PARAMETER - metadata is not valid
+ *   HWC2_ERROR_UNSUPPORTED - metadata is not supported on this display
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_SET_LAYER_PER_FRAME_METADATA)(
+        hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
+        uint32_t numElements, const int32_t* /*hw2_per_frame_metadata_key_t*/ keys,
+        const float* metadata);
+
 /*
  * Layer State Functions
  *
@@ -1805,6 +2120,25 @@
         hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
         hwc_color_t color);
 
+/* setLayerFloatColor(..., color)
+ * Descriptor: HWC2_FUNCTION_SET_LAYER_FLOAT_COLOR
+ * Provided by HWC2 devices which don't return nullptr function pointer.
+ *
+ * Sets the color of the given layer. If the composition type of the layer is
+ * not HWC2_COMPOSITION_SOLID_COLOR, this call must return HWC2_ERROR_NONE and
+ * have no other effect.
+ *
+ * Parameters:
+ *   color - the new color in float type, rage is [0.0, 1.0], the colorspace is
+ *   defined by the dataspace that gets set by calling setLayerDataspace.
+ *
+ * Returns HWC2_ERROR_NONE or one of the following errors:
+ *   HWC2_ERROR_BAD_LAYER - an invalid layer handle was passed in
+ */
+typedef int32_t /*hwc2_error_t*/ (*HWC2_PFN_SET_LAYER_FLOAT_COLOR)(
+        hwc2_device_t* device, hwc2_display_t display, hwc2_layer_t layer,
+        hwc_float_color_t color);
+
 /* setLayerCompositionType(..., type)
  * Descriptor: HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE
  * Must be provided by all HWC2 devices
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
index 1e81e6e..fd373e3 100644
--- a/include/hardware/hwcomposer_defs.h
+++ b/include/hardware/hwcomposer_defs.h
@@ -58,6 +58,13 @@
     uint8_t a;
 } hwc_color_t;
 
+typedef struct hwc_float_color {
+    float r;
+    float g;
+    float b;
+    float a;
+} hwc_float_color_t;
+
 typedef struct hwc_frect {
     float left;
     float top;
diff --git a/include/hardware/keymaster_defs.h b/include/hardware/keymaster_defs.h
index 7d1b348..cec486e 100644
--- a/include/hardware/keymaster_defs.h
+++ b/include/hardware/keymaster_defs.h
@@ -112,6 +112,8 @@
     KM_TAG_ALLOW_WHILE_ON_BODY = KM_BOOL | 506, /* Allow key to be used after authentication timeout
                                                  * if device is still on-body (requires secure
                                                  * on-body sensor. */
+    KM_TAG_UNLOCKED_DEVICE_REQUIRED = KM_BOOL | 508, /* Require the device screen to be unlocked if the
+                                                      * key is used. */
 
     /* Application access control */
     KM_TAG_ALL_APPLICATIONS = KM_BOOL | 600, /* Specified to indicate key is usable by all
@@ -182,6 +184,7 @@
 
     /* Block ciphers algorithms */
     KM_ALGORITHM_AES = 32,
+    KM_ALGORITHM_TRIPLE_DES = 33,
 
     /* MAC algorithms */
     KM_ALGORITHM_HMAC = 128,
@@ -296,6 +299,8 @@
     KM_PURPOSE_SIGN = 2,       /* Usable with RSA, EC and HMAC keys. */
     KM_PURPOSE_VERIFY = 3,     /* Usable with RSA, EC and HMAC keys. */
     KM_PURPOSE_DERIVE_KEY = 4, /* Usable with EC keys. */
+    KM_PURPOSE_WRAP = 5,       /* Usable with wrapped keys. */
+
 } keymaster_purpose_t;
 
 typedef struct {
@@ -449,6 +454,7 @@
     KM_ERROR_KEYMASTER_NOT_CONFIGURED = -64,
     KM_ERROR_ATTESTATION_APPLICATION_ID_MISSING = -65,
     KM_ERROR_CANNOT_ATTEST_IDS = -66,
+    KM_ERROR_DEVICE_LOCKED = -72,
 
     KM_ERROR_UNIMPLEMENTED = -100,
     KM_ERROR_VERSION_MISMATCH = -101,
diff --git a/include/hardware/vehicle.h b/include/hardware/vehicle.h
deleted file mode 100644
index 8b28e7a..0000000
--- a/include/hardware/vehicle.h
+++ /dev/null
@@ -1,2610 +0,0 @@
-/*
- * Copyright (C) 2015 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_VEHICLE_INTERFACE_H
-#define ANDROID_VEHICLE_INTERFACE_H
-
-#include <stdint.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <math.h>
-#include <errno.h>
-
-#include <hardware/hardware.h>
-#include <cutils/native_handle.h>
-
-__BEGIN_DECLS
-
-/*****************************************************************************/
-
-#define VEHICLE_HEADER_VERSION          1
-#define VEHICLE_MODULE_API_VERSION_1_0  HARDWARE_MODULE_API_VERSION(1, 0)
-#define VEHICLE_DEVICE_API_VERSION_1_0  HARDWARE_DEVICE_API_VERSION_2(1, 0, VEHICLE_HEADER_VERSION)
-
-/**
- * Vehicle HAL to provide interfaces to various Car related sensors. The HAL is
- * designed in a property, value maping where each property has a value which
- * can be "get", "set" and "(un)subscribed" to. Subscribing will require the
- * user of this HAL to provide parameters such as sampling rate.
- */
-
-
-/*
- * The id of this module
- */
-#define VEHICLE_HARDWARE_MODULE_ID  "vehicle"
-
-/**
- *  Name of the vehicle device to open
- */
-#define VEHICLE_HARDWARE_DEVICE     "vehicle_hw_device"
-
-/**
- * Each vehicle property is defined with various annotations to specify the type of information.
- * Annotations will be used by scripts to run some type check or generate some boiler-plate codes.
- * Also the annotations are the specification for each property, and each HAL implementation should
- * follow what is specified as annotations.
- * Here is the list of annotations with explanation on what it does:
- * @value_type: Type of data for this property. One of the value from vehicle_value_type should be
- *              set here.
- * @change_mode: How this property changes. Value set is from vehicle_prop_change_mode. Some
- *               properties can allow either on change or continuous mode and it is up to HAL
- *               implementation to choose which mode to use.
- * @access: Define how this property can be accessed. read only, write only or R/W from
- *          vehicle_prop_access
- * @data_member: Name of member from vehicle_value union to access this data.
- * @data_enum: enum type that should be used for the data.
- * @unit: Unit of data. Should be from vehicle_unit_type.
- * @config_flags: Usage of config_flags in vehicle_prop_config
- * @config_array: Usage of config_array in vehicle_prop_config. When this is specified,
- *                @config_flags will not be used.
- * @config_string: Explains the usage of config_string in vehicle_prop_config. Property with
- *                 this annotation is expected to have additional information in config_string
- *                 for that property to work.
- * @zone_type type of zoned used. defined for zoned property
- * @range_start, @range_end : define range of specific property values.
- * @allow_out_of_range_value : This property allows out of range value to deliver additional
- *                             information. Check VEHICLE_*_OUT_OF_RANGE_* for applicable values.
- */
-//===== Vehicle Information ====
-
-/**
- * Invalid property value used for argument where invalid property gives different result.
- */
-#define VEHICLE_PROPERTY_INVALID (0x0)
-
-/**
- * VIN of vehicle
- * @value_type VEHICLE_VALUE_TYPE_STRING
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member info_vin
- */
-#define VEHICLE_PROPERTY_INFO_VIN                                   (0x00000100)
-
-/**
- * Maker name of vehicle
- * @value_type VEHICLE_VALUE_TYPE_STRING
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member info_make
- */
-#define VEHICLE_PROPERTY_INFO_MAKE                                  (0x00000101)
-
-/**
- * Model of vehicle
- * @value_type VEHICLE_VALUE_TYPE_STRING
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member info_model
- */
-#define VEHICLE_PROPERTY_INFO_MODEL                                 (0x00000102)
-
-/**
- * Model year of vehicle.
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member info_model_year
- * @unit VEHICLE_UNIT_TYPE_YEAR
- */
-#define VEHICLE_PROPERTY_INFO_MODEL_YEAR                            (0x00000103)
-
-/**
- * Fuel capacity of the vehicle
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member info_fuel_capacity
- * @unit VEHICLE_UNIT_TYPE_VEHICLE_UNIT_TYPE_MILLILITER
- */
-#define VEHICLE_PROPERTY_INFO_FUEL_CAPACITY                         (0x00000104)
-
-
-//==== Vehicle Performance Sensors ====
-
-/**
- * Current odometer value of the vehicle
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member odometer
- * @unit VEHICLE_UNIT_TYPE_KILOMETER
- */
-#define VEHICLE_PROPERTY_PERF_ODOMETER                              (0x00000204)
-
-/**
- * Speed of the vehicle
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member vehicle_speed
- * @unit VEHICLE_UNIT_TYPE_METER_PER_SEC
- */
-#define VEHICLE_PROPERTY_PERF_VEHICLE_SPEED                         (0x00000207)
-
-
-//==== Engine Sensors ====
-
-/**
- * Temperature of engine coolant
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member engine_coolant_temperature
- * @unit VEHICLE_UNIT_TYPE_CELCIUS
- */
-#define VEHICLE_PROPERTY_ENGINE_COOLANT_TEMP                        (0x00000301)
-
-/**
- * Temperature of engine oil
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member engine_oil_temperature
- * @unit VEHICLE_UNIT_TYPE_CELCIUS
- */
-#define VEHICLE_PROPERTY_ENGINE_OIL_TEMP                            (0x00000304)
-/**
- * Engine rpm
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member engine_rpm
- * @unit VEHICLE_UNIT_TYPE_RPM
- */
-#define VEHICLE_PROPERTY_ENGINE_RPM                                 (0x00000305)
-
-//==== Event Sensors ====
-
-/**
- * Currently selected gear
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member gear_selection
- * @data_enum vehicle_gear
- */
-#define VEHICLE_PROPERTY_GEAR_SELECTION                             (0x00000400)
-
-/**
- * Current gear. In non-manual case, selected gear does not necessarily match the current gear
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member gear_current_gear
- * @data_enum vehicle_gear
- */
-#define VEHICLE_PROPERTY_CURRENT_GEAR                               (0x00000401)
-
-/**
- * Parking brake state.
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member parking_brake
- * @data_enum vehicle_boolean
- */
-#define VEHICLE_PROPERTY_PARKING_BRAKE_ON                           (0x00000402)
-
-/**
- * Driving status policy.
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member driving_status
- * @data_enum vehicle_driving_status
- */
-#define VEHICLE_PROPERTY_DRIVING_STATUS                             (0x00000404)
-
-/**
- * Warning for fuel low level.
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member is_fuel_level_low
- * @data_enum vehicle_boolean
- */
-#define VEHICLE_PROPERTY_FUEL_LEVEL_LOW                             (0x00000405)
-
-/**
- * Night mode or not.
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member night_mode
- * @data_enum vehicle_boolean
- */
-#define VEHICLE_PROPERTY_NIGHT_MODE                                 (0x00000407)
-
-
-
-//==== HVAC Properties ====
-
-/**
- * Fan speed setting
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member hvac.fan_speed
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @allow_out_of_range_value : OFF
- */
-#define VEHICLE_PROPERTY_HVAC_FAN_SPEED                             (0x00000500)
-
-/**
- * Fan direction setting
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member hvac.fan_direction
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_enum vehicle_hvac_fan_direction
- * @allow_out_of_range_value : OFF
- */
-#define VEHICLE_PROPERTY_HVAC_FAN_DIRECTION                         (0x00000501)
-
-/*
- * Bit flags for fan direction
- */
-enum vehicle_hvac_fan_direction {
-    VEHICLE_HVAC_FAN_DIRECTION_FACE                 = 0x1,
-    VEHICLE_HVAC_FAN_DIRECTION_FLOOR                = 0x2,
-    VEHICLE_HVAC_FAN_DIRECTION_FACE_AND_FLOOR       = 0x3,
-    VEHICLE_HVAC_FAN_DIRECTION_DEFROST              = 0x4,
-    VEHICLE_HVAC_FAN_DIRECTION_DEFROST_AND_FLOOR    = 0x5
-};
-
-/**
- * HVAC current temperature.
- * @value_type VEHICLE_VALUE_TYPE_ZONED_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.temperature_current
- */
-#define VEHICLE_PROPERTY_HVAC_TEMPERATURE_CURRENT                   (0x00000502)
-
-/**
- * HVAC, target temperature set.
- * @value_type VEHICLE_VALUE_TYPE_ZONED_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.temperature_set
- * @allow_out_of_range_value : MIN / MAX / OFF
- */
-#define VEHICLE_PROPERTY_HVAC_TEMPERATURE_SET                       (0x00000503)
-
-/**
- * On/off defrost
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_WINDOW
- * @data_member hvac.defrost_on
- */
-#define VEHICLE_PROPERTY_HVAC_DEFROSTER                             (0x00000504)
-
-/**
- * On/off AC
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_flags Supported zones
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.ac_on
- */
-#define VEHICLE_PROPERTY_HVAC_AC_ON                                 (0x00000505)
-
-/**
- * On/off max AC
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.max_ac_on
- */
-#define VEHICLE_PROPERTY_HVAC_MAX_AC_ON                             (0x00000506)
-
-/**
- * On/off max defrost
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.max_defrost_on
- */
-#define VEHICLE_PROPERTY_HVAC_MAX_DEFROST_ON                        (0x00000507)
-
-/**
- * On/off re-circulation
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.max_recirc_on
- */
-#define VEHICLE_PROPERTY_HVAC_RECIRC_ON                             (0x00000508)
-
-/**
- * On/off dual. This will be defined per each row.
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.dual_on
- */
-#define VEHICLE_PROPERTY_HVAC_DUAL_ON                               (0x00000509)
-
-/**
- * On/off automatic mode
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.auto_on
- */
-#define VEHICLE_PROPERTY_HVAC_AUTO_ON                               (0x0000050A)
-
-/**
- * Seat temperature
- *
- * Negative values indicate cooling.
- * 0 indicates off.
- * Positive values indicate heating.
- *
- * Some vehicles may have multiple levels of heating and cooling. The min/max
- * range defines the allowable range and number of steps in each direction.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_HVAC_SEAT_TEMPERATURE                      (0x0000050B)
-
-/**
- * Side Mirror Heat
- *
- * Increase values denote higher heating levels for side mirrors.
- * 0 indicates heating is turned off.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_HVAC_SIDE_MIRROR_HEAT                      (0x0000050C)
-
-/**
- * Steering Wheel Temperature
- *
- * Sets the temperature for the steering wheel
- * Positive value indicates heating.
- * Negative value indicates cooling.
- * 0 indicates tempreature control is off.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_HVAC_STEERING_WHEEL_TEMP                   (0x0000050D)
-
-/**
- * Temperature units
- *
- * Indicates whether the temperature is in Celsius, Fahrenheit, or a different unit.
- * This parameter affects all HVAC temperatures in the system.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_enum vehicle_unit_type
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_HVAC_TEMPERATURE_UNITS                     (0x0000050E)
-
-/**
- * Actual fan speed
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member hvac.fan_speed
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @allow_out_of_range_value : OFF
- */
-#define VEHICLE_PROPERTY_HVAC_ACTUAL_FAN_SPEED_RPM                  (0x0000050F)
-
-
-/**
- * Represents power state for HVAC. Some HVAC properties will require matching power to be turned on
- * to get out of OFF state. For non-zoned HVAC properties, VEHICLE_ALL_ZONE corresponds to
- * global power state.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_string list of HVAC properties whose power is controlled by this property. Format is
- *                hexa-decimal number (0x...) separated by comma like "0x500,0x503". All zones
- *                defined in these affected properties should be available in the property.
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @data_member hvac.power_on
- */
-#define VEHICLE_PROPERTY_HVAC_POWER_ON                              (0x00000510)
-
-/**
- * Fan Positions Available
- *
- * This is a bit mask of fan positions available for the zone.  Each entry in
- * vehicle_hvac_fan_direction is selected by bit position.  For instance, if
- * only the FAN_DIRECTION_FACE (0x1) and FAN_DIRECTION_DEFROST (0x4) are available,
- * then this value shall be set to 0x12.
- *
- * 0x12 = (1 << 1) | (1 << 4)
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member int32_value
- * @zone_type VEHICLE_ZONE_TYPE_ZONE
- * @allow_out_of_range_value : OFF
- */
-#define VEHICLE_PROPERTY_HVAC_FAN_DIRECTION_AVAILABLE               (0x00000511)
-
-/**
- * Outside temperature
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member outside_temperature
- * @unit VEHICLE_UNIT_TYPE_CELCIUS
- */
-#define VEHICLE_PROPERTY_ENV_OUTSIDE_TEMPERATURE                    (0x00000703)
-
-
-/**
- * Cabin temperature
- * @value_type VEHICLE_VALUE_TYPE_FLOAT
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE|VEHICLE_PROP_CHANGE_MODE_CONTINUOUS
- * @access VEHICLE_PROP_ACCESS_READ
- * @data_member cabin_temperature
- * @unit VEHICLE_UNIT_TYPE_CELCIUS
- */
-#define VEHICLE_PROPERTY_ENV_CABIN_TEMPERATURE                      (0x00000704)
-
-
-/*
- * Radio features.
- */
-/**
- * Radio presets stored on the Car radio module. The data type used is int32
- * array with the following fields:
- * <ul>
- *    <li> int32_array[0]: Preset number </li>
- *    <li> int32_array[1]: Band type (see #RADIO_BAND_FM in
- *    system/core/include/system/radio.h).
- *    <li> int32_array[2]: Channel number </li>
- *    <li> int32_array[3]: Sub channel number </li>
- * </ul>
- *
- * NOTE: When getting a current preset config ONLY set preset number (i.e.
- * int32_array[0]). For setting a preset other fields are required.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC4
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_flags Number of presets supported
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_RADIO_PRESET                               (0x00000801)
-
-/**
- * Constants relevant to radio.
- */
-enum vehicle_radio_consts {
-    /** Minimum value for the radio preset */
-    VEHICLE_RADIO_PRESET_MIN_VALUE = 1,
-};
-
-/**
- * Represents audio focus state of Android side. Note that car's audio module will own audio
- * focus and grant audio focus to Android side when requested by Android side. The focus has both
- * per stream characteristics and global characteristics.
- *
- * Focus request (get of this property) will take the following form in int32_vec4:
- *   int32_array[0]: vehicle_audio_focus_request type
- *   int32_array[1]: bit flags of streams requested by this focus request. There can be up to
- *                   32 streams.
- *   int32_array[2]: External focus state flags. For request, only flag like
- *                   VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY_FLAG or
- *                   VEHICLE_AUDIO_EXT_FOCUS_CAR_MUTE_MEDIA_FLAG can be used.
- *                   VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY_FLAG is for case like radio where android
- *                   side app still needs to hold focus but playback is done outside Android.
- *                   VEHICLE_AUDIO_EXT_FOCUS_CAR_MUTE_MEDIA_FLAG is for muting media channel
- *                   including radio. VEHICLE_AUDIO_EXT_FOCUS_CAR_MUTE_MEDIA_FLAG can be set even
- *                   if android side releases focus (request type REQUEST_RELEASE). In that case,
- *                   audio module should maintain mute state until user's explicit action to
- *                   play some media.
- *   int32_array[3]: Currently active audio contexts. Use combination of flags from
- *                   vehicle_audio_context_flag.
- *                   This can be used as a hint to adjust audio policy or other policy decision.
- *                   Note that there can be multiple context active at the same time. And android
- *                   can send the same focus request type gain due to change in audio contexts.
- * Note that each focus request can request multiple streams that is expected to be used for
- * the current request. But focus request itself is global behavior as GAIN or GAIN_TRANSIENT
- * expects all sounds played by car's audio module to stop. Note that stream already allocated to
- * android before this focus request should not be affected by focus request.
- *
- * Focus response (set and subscription callback for this property) will take the following form:
- *   int32_array[0]: vehicle_audio_focus_state type
- *   int32_array[1]: bit flags of streams allowed.
- *   int32_array[2]: External focus state: bit flags of currently active audio focus in car
- *                   side (outside Android). Active audio focus does not necessarily mean currently
- *                   playing, but represents the state of having focus or waiting for focus
- *                   (pause state).
- *                   One or combination of flags from vehicle_audio_ext_focus_flag.
- *                   0 means no active audio focus holder outside Android.
- *                   The state will have following values for each vehicle_audio_focus_state_type:
- *                   GAIN: 0 or VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY when radio is active in
- *                       Android side.
- *                   GAIN_TRANSIENT: 0. Can be VEHICLE_AUDIO_EXT_FOCUS_CAR_PERMANENT or
- *                       VEHICLE_AUDIO_EXT_FOCUS_CAR_TRANSIENT if android side has requested
- *                       GAIN_TRANSIENT_MAY_DUCK and car side is ducking.
- *                   LOSS: 0 when no focus is audio is active in car side.
- *                       VEHICLE_AUDIO_EXT_FOCUS_CAR_PERMANENT when car side is playing something
- *                       permanent.
- *                   LOSS_TRANSIENT: always should be VEHICLE_AUDIO_EXT_FOCUS_CAR_TRANSIENT
- *   int32_array[3]: context requested by android side when responding to focus request.
- *                   When car side is taking focus away, this should be zero.
- *
- * A focus response should be sent per each focus request even if there is no change in
- * focus state. This can happen in case like focus request only involving context change
- * where android side still needs matching focus response to confirm that audio module
- * has made necessary changes.
- *
- * If car does not support VEHICLE_PROPERTY_AUDIO_FOCUS, focus is assumed to be granted always.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC4
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_AUDIO_FOCUS                                (0x00000900)
-
-enum vehicle_audio_focus_request {
-    VEHICLE_AUDIO_FOCUS_REQUEST_GAIN = 0x1,
-    VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT = 0x2,
-    VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT_MAY_DUCK = 0x3,
-    /**
-     * This is for the case where android side plays sound like UI feedback
-     * and car side does not need to duck existing playback as long as
-     * requested stream is available.
-     */
-    VEHICLE_AUDIO_FOCUS_REQUEST_GAIN_TRANSIENT_NO_DUCK  = 0x4,
-    VEHICLE_AUDIO_FOCUS_REQUEST_RELEASE = 0x5,
-};
-
-enum vehicle_audio_focus_state {
-    /**
-     * Android side has permanent focus and can play allowed streams.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_GAIN = 0x1,
-    /**
-     * Android side has transient focus and can play allowed streams.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_GAIN_TRANSIENT = 0x2,
-    /**
-     * Car audio module is playing guidance kind of sound outside Android. Android side can
-     * still play through allowed streams with ducking.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT_CAN_DUCK = 0x3,
-    /**
-     * Car audio module is playing transient sound outside Android. Android side should stop
-     * playing any sounds.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT = 0x4,
-    /**
-     * Android side has lost focus and cannot play any sound.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_LOSS = 0x5,
-    /**
-     * car audio module is playing safety critical sound, and Android side cannot request focus
-     * until the current state is finished. car audio module should restore it to the previous
-     * state when it can allow Android to play.
-     */
-    VEHICLE_AUDIO_FOCUS_STATE_LOSS_TRANSIENT_EXLCUSIVE = 0x6,
-};
-
-/**
- * Flags to represent multiple streams by combining these.
- */
-enum vehicle_audio_stream_flag {
-    VEHICLE_AUDIO_STREAM_STREAM0_FLAG = (0x1<<0),
-    VEHICLE_AUDIO_STREAM_STREAM1_FLAG = (0x1<<1),
-    VEHICLE_AUDIO_STREAM_STREAM2_FLAG = (0x1<<2),
-};
-
-/**
- * Represents stream number (always 0 to N -1 where N is max number of streams).
- * Can be used for audio related property expecting one stream.
- */
-enum vehicle_audio_stream {
-    VEHICLE_AUDIO_STREAM0 = 0,
-    VEHICLE_AUDIO_STREAM1 = 1,
-};
-
-/**
- * Flag to represent external focus state (outside Android).
- */
-enum vehicle_audio_ext_focus_flag {
-    /**
-     * No external focus holder.
-     */
-    VEHICLE_AUDIO_EXT_FOCUS_NONE_FLAG = 0x0,
-    /**
-     * Car side (outside Android) has component holding GAIN kind of focus state.
-     */
-    VEHICLE_AUDIO_EXT_FOCUS_CAR_PERMANENT_FLAG = 0x1,
-    /**
-     * Car side (outside Android) has component holding GAIN_TRANSIENT kind of focus state.
-     */
-    VEHICLE_AUDIO_EXT_FOCUS_CAR_TRANSIENT_FLAG = 0x2,
-    /**
-     * Car side is expected to play something while focus is held by Android side. One example
-     * can be radio attached in car side. But Android's radio app still should have focus,
-     * and Android side should be in GAIN state, but media stream will not be allocated to Android
-     * side and car side can play radio any time while this flag is active.
-     */
-    VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY_FLAG = 0x4,
-    /**
-     * Car side should mute any media including radio. This can be used with any focus request
-     * including GAIN* and RELEASE.
-     */
-    VEHICLE_AUDIO_EXT_FOCUS_CAR_MUTE_MEDIA_FLAG = 0x8,
-};
-
-/**
- * Index in int32_array for VEHICLE_PROPERTY_AUDIO_FOCUS property.
- */
-enum vehicle_audio_focus_index {
-    VEHICLE_AUDIO_FOCUS_INDEX_FOCUS = 0,
-    VEHICLE_AUDIO_FOCUS_INDEX_STREAMS = 1,
-    VEHICLE_AUDIO_FOCUS_INDEX_EXTERNAL_FOCUS_STATE = 2,
-    VEHICLE_AUDIO_FOCUS_INDEX_AUDIO_CONTEXTS = 3,
-};
-
-/**
- * Flags to tell the current audio context.
- */
-enum vehicle_audio_context_flag {
-    /** Music playback is currently active. */
-    VEHICLE_AUDIO_CONTEXT_MUSIC_FLAG                      = 0x1,
-    /** Navigation is currently running. */
-    VEHICLE_AUDIO_CONTEXT_NAVIGATION_FLAG                 = 0x2,
-    /** Voice command session is currently running. */
-    VEHICLE_AUDIO_CONTEXT_VOICE_COMMAND_FLAG              = 0x4,
-    /** Voice call is currently active. */
-    VEHICLE_AUDIO_CONTEXT_CALL_FLAG                       = 0x8,
-    /** Alarm is active. This may be only used in VEHICLE_PROPERTY_AUDIO_ROUTING_POLICY. */
-    VEHICLE_AUDIO_CONTEXT_ALARM_FLAG                      = 0x10,
-    /**
-     * Notification sound is active. This may be only used in VEHICLE_PROPERTY_AUDIO_ROUTING_POLICY.
-     */
-    VEHICLE_AUDIO_CONTEXT_NOTIFICATION_FLAG               = 0x20,
-    /**
-     * Context unknown. Only used for VEHICLE_PROPERTY_AUDIO_ROUTING_POLICY to represent default
-     * stream for unknown contents.
-     */
-    VEHICLE_AUDIO_CONTEXT_UNKNOWN_FLAG                    = 0x40,
-    /** Safety alert / warning is played. */
-    VEHICLE_AUDIO_CONTEXT_SAFETY_ALERT_FLAG               = 0x80,
-    /** CD / DVD kind of audio is played */
-    VEHICLE_AUDIO_CONTEXT_CD_ROM_FLAG                     = 0x100,
-    /** Aux audio input is played */
-    VEHICLE_AUDIO_CONTEXT_AUX_AUDIO_FLAG                  = 0x200,
-    /** system sound like UI feedback */
-    VEHICLE_AUDIO_CONTEXT_SYSTEM_SOUND_FLAG               = 0x400,
-    /** Radio is played */
-    VEHICLE_AUDIO_CONTEXT_RADIO_FLAG                      = 0x800,
-    /** Ext source is played. This is for tagging generic ext sources. */
-    VEHICLE_AUDIO_CONTEXT_EXT_SOURCE_FLAG                 = 0x1000,
-};
-
-/**
- * Property to control audio volume of each audio context.
- *
- * vehicle_prop_config_t
- *   config_array[0] : bit flags of all supported audio contexts. If this is 0,
- *                     audio volume is controlled per physical stream
- *   config_array[1] : flags defined in vehicle_audio_volume_capability_flag to
- *                     represent audio module's capability.
- *
- * Data type looks like:
- *   int32_array[0] : stream context as defined in vehicle_audio_context_flag. If only physical
-                      stream is supported (config_array[0] == 0), this will represent physical
-                      stream number.
- *   int32_array[1] : volume level, valid range is 0 to int32_max_value defined in config.
- *                    0 will be mute state. int32_min_value in config should be always 0.
- *   int32_array[2] : One of vehicle_audio_volume_state.
- *
- * This property requires per stream based get. HAL implementation should check stream number
- * in get call to return the right volume.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC3
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_flags all audio contexts supported.
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_AUDIO_VOLUME                               (0x00000901)
-
-
-/**
- * flags to represent capability of audio volume property.
- * used in config_array[1] of vehicle_prop_config_t.
- */
-enum vehicle_audio_volume_capability_flag {
-    /**
-     * External audio module or vehicle hal has persistent storage
-     * to keep the volume level. This should be set only when per context
-     * volume level is supproted. When this is set, audio volume level per
-     * each context will be retrieved from the property when systen starts up.
-     * And external audio module is also expected to adjust volume automatically
-     * whenever there is an audio context change.
-     * When this flag is not set, android side will assume that there is no
-     * persistent storage and stored value in android side will be used to
-     * initialize the volume level. And android side will set volume level
-     * of each physical streams whenever there is an audio context change.
-     */
-    VEHICLE_AUDIO_VOLUME_CAPABILITY_PERSISTENT_STORAGE = 0x1,
-    /**
-     * When this flag is set, the H/W can support only single master volume for all streams.
-     * There is no way to set volume level differently per each stream or context.
-     */
-    VEHICLE_AUDIO_VOLUME_CAPABILITY_MASTER_VOLUME_ONLY = 0x2,
-};
-
-
-/**
- * enum to represent audio volume state.
- */
-enum vehicle_audio_volume_state {
-    VEHICLE_AUDIO_VOLUME_STATE_OK            = 0,
-    /**
-     * Audio volume has reached volume limit set in VEHICLE_PROPERTY_AUDIO_VOLUME_LIMIT
-     * and user's request to increase volume further is not allowed.
-     */
-    VEHICLE_AUDIO_VOLUME_STATE_LIMIT_REACHED = 1,
-};
-
-/**
- * Index in int32_array for VEHICLE_PROPERTY_AUDIO_VOLUME property.
- */
-enum vehicle_audio_volume_index {
-    VEHICLE_AUDIO_VOLUME_INDEX_STREAM = 0,
-    VEHICLE_AUDIO_VOLUME_INDEX_VOLUME = 1,
-    VEHICLE_AUDIO_VOLUME_INDEX_STATE = 2,
-};
-
-/**
- * Property for handling volume limit set by user. This limits maximum volume that can be set
- * per each context or physical stream.
- *
- * vehicle_prop_config_t
- *   config_array[0] : bit flags of all supported audio contexts. If this is 0,
- *                     audio volume is controlled per physical stream
- *   config_array[1] : flags defined in vehicle_audio_volume_capability_flag to
- *                     represent audio module's capability.
- *
- * Data type looks like:
- *   int32_array[0] : stream context as defined in vehicle_audio_context_flag. If only physical
- *                    stream is supported (config_array[0] == 0), this will represent physical
- *                    stream number.
- *   int32_array[1] : maximum volume set to the stream. If there is no restriction, this value
- *                    will be  bigger than VEHICLE_PROPERTY_AUDIO_VOLUME's max value.
- *
- * If car does not support this feature, this property should not be populated by HAL.
- * This property requires per stream based get. HAL implementation should check stream number
- * in get call to return the right volume.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC2
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_flags all audio contexts supported.
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_AUDIO_VOLUME_LIMIT                         (0x00000902)
-
-/**
- * Index in int32_array for VEHICLE_PROPERTY_AUDIO_VOLUME_LIMIT property.
- */
-enum vehicle_audio_volume_limit_index {
-    VEHICLE_AUDIO_VOLUME_LIMIT_INDEX_STREAM = 0,
-    VEHICLE_AUDIO_VOLUME_LIMIT_INDEX_MAX_VOLUME = 1,
-};
-
-/**
- * Property to share audio routing policy of android side. This property is set at the beginning
- * to pass audio policy in android side down to vehicle HAL and car audio module.
- * This can be used as a hint to adjust audio policy or other policy decision.
- *
- *   int32_array[0] : audio stream where the audio for the application context will be routed
- *                    by default. Note that this is the default setting from system, but each app
- *                    may still use different audio stream for whatever reason.
- *   int32_array[1] : All audio contexts that will be sent through the physical stream. Flag
- *                    is defined in vehicle_audio_context_flag.
-
- * Setting of this property will be done for all available physical streams based on audio H/W
- * variant information acquired from VEHICLE_PROPERTY_AUDIO_HW_VARIANT property.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC2
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_WRITE
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_AUDIO_ROUTING_POLICY                       (0x00000903)
-
-/**
- * Index in int32_array for VEHICLE_PROPERTY_AUDIO_ROUTING_POLICY property.
- */
-enum vehicle_audio_routing_policy_index {
-    VEHICLE_AUDIO_ROUTING_POLICY_INDEX_STREAM = 0,
-    VEHICLE_AUDIO_ROUTING_POLICY_INDEX_CONTEXTS = 1,
-};
-
-/**
-* Property to return audio H/W variant type used in this car. This allows android side to
-* support different audio policy based on H/W variant used. Note that other components like
-* CarService may need overlay update to support additional variants. If this property does not
-* exist, default audio policy will be used.
-*
-* @value_type VEHICLE_VALUE_TYPE_INT32
-* @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
-* @access VEHICLE_PROP_ACCESS_READ
-* @config_flags Additional info on audio H/W. Should use vehicle_audio_hw_variant_config_flag for
-*               this.
-* @data_member int32_value
-*/
-#define VEHICLE_PROPERTY_AUDIO_HW_VARIANT                           (0x00000904)
-
-/**
- * Flag to be used in vehicle_prop_config.config_flags for VEHICLE_PROPERTY_AUDIO_HW_VARIANT.
- */
-enum vehicle_audio_hw_variant_config_flag {
-    /**
-     * Flag to tell that radio is internal to android and radio should
-     * be treated like other android stream like media.
-     * When this flag is not set or AUDIO_HW_VARIANT does not exist,
-     * radio is treated as external module. This brins some delta in audio focus
-     * handling as well.
-     */
-    VEHICLE_AUDIO_HW_VARIANT_FLAG_INTERNAL_RADIO_FLAG = 0x1,
-};
-
-/** audio routing for AM/FM. This should be also be the value when there is only one
-    radio module in the system. */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_RADIO_AM_FM "RADIO_AM_FM"
-/** Should be added only when there is a separate radio module with HD capability. */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_RADIO_AM_FM_HD "RADIO_AM_FM_HD"
-/** For digial audio broadcasting type of radio */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_RADIO_DAB "RADIO_DAB"
-/** For satellite type of radio */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_RADIO_SATELLITE "RADIO_SATELLITE"
-/** For CD or DVD */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_CD_DVD "CD_DVD"
-/** For 1st auxiliary input */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_AUX_IN0 "AUX_IN0"
-/** For 2nd auxiliary input */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_AUX_IN1 "AUX_IN1"
-/** For navigation guidance from outside android */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_EXT_NAV_GUIDANCE "EXT_NAV_GUIDANCE"
-/** For voice command from outside android */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_EXT_VOICE_COMMAND "EXT_VOICE_COMMAND"
-/** For voice call from outside android */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_EXT_VOICE_CALL "EXT_VOICE_CALL"
-/** For safety alert from outside android */
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_EXT_SAFETY_ALERT "EXT_SAFETY_ALERT"
-
-/**
-* Property to pass hint on external audio routing. When android side request focus
-* with VEHICLE_AUDIO_EXT_FOCUS_CAR_PLAY_ONLY_FLAG flag, this property will be set
-* before setting AUDIO_FOCUS property as a hint for external audio source routing.
-* Note that setting this property alone should not trigger any change.
-* Audio routing should be changed only when AUDIO_FOCUS property is set. Note that
-* this property allows passing custom value as long as it is defined in config_string.
-* This allows supporting non-standard routing options through this property.
-* It is recommended to use separate name space for custom property to prevent conflict in future
-* android releases.
-* Enabling each external routing option is done by enabling each bit flag for the routing.
-* This property can support up to 128 external routings.
-* To give full flexibility, there is no standard definition for each bit flag and
-* assigning each big flag to specific routing type is decided by config_string.
-* config_string has format of each entry separated by ','
-* and each entry has format of bitFlagPositon:typeString[:physicalStreamNumber].
-*  bitFlagPosition: represents which big flag will be set to enable this routing. 0 means
-*    LSB in int32_array[0]. 31 will be MSB in int32_array[0]. 127 will MSB in int32_array[3].
-*  typeString: string representation of external routing. Some types are already defined
-*    in VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_SOURCE_* and use them first before adding something
-*    custom. Applications will find each routing using this string.
-*  physicalStreamNumber: This part is optional and represents physical stream to android
-*    which will be disabled when this routing is enabled. If not specified, this routing
-*    should not affect physical streams to android.
-* As an example, let's assume a system with two physical streams, 0 for media and 1 for
-* nav guidance. And let's assume external routing option of am fm radio, external navigation
-* guidance, satellite radio, and one custom. Let's assume that radio and satellite replaces
-* physical stream 0 and external navigation replaces physical stream 1. And bit flag will be
-* assigned in the order listed above. This configuration will look like this in config_string:
-*  "0:RADIO_AM_FM:0,1:EXT_NAV_GUIDANCE:1,2:RADIO_SATELLITE:0,3:com.test.SOMETHING_CUSTOM"
-* When android requests RADIO_AM_FM, int32_array[0] will be set to 0x1.
-* When android requests RADIO_SATELLITE + EXT_NAV_GUIDANCE, int32_array[0] will be set to 0x2|0x4.
-*
-* @value_type VEHICLE_VALUE_TYPE_INT32_VEC4
-* @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
-* @access VEHICLE_PROP_ACCESS_WRITE|VEHICLE_PROP_ACCESS_READ_WRITE
-* @config_string List of all avaiable external source in the system.
-* @data_member int32_array
-*/
-#define VEHICLE_PROPERTY_AUDIO_EXT_ROUTING_HINT                     (0x00000905)
-
-/**
- * Property to control power state of application processor.
- *
- * It is assumed that AP's power state is controller by separate power controller.
- *
- * For configuration information, vehicle_prop_config.config_flags can have bit flag combining
- * values in vehicle_ap_power_state_config_type.
- *
- * For get / notification, data type looks like this:
- *   int32_array[0] : vehicle_ap_power_state_type
- *   int32_array[1] : additional parameter relevant for each state. should be 0 if not used.
- * For set, data type looks like this:
- *   int32_array[0] : vehicle_ap_power_state_set_type
- *   int32_array[1] : additional parameter relevant for each request. should be 0 if not used.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC2
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_flags Additional info on power state. Should use vehicle_ap_power_state_config_flag.
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_AP_POWER_STATE                             (0x00000A00)
-
-enum vehicle_ap_power_state_config_flag {
-    /**
-     * AP can enter deep sleep state. If not set, AP will always shutdown from
-     * VEHICLE_AP_POWER_STATE_SHUTDOWN_PREPARE power state.
-     */
-    VEHICLE_AP_POWER_STATE_CONFIG_ENABLE_DEEP_SLEEP_FLAG = 0x1,
-
-    /**
-     * The power controller can power on AP from off state after timeout specified in
-     * VEHICLE_AP_POWER_SET_SHUTDOWN_READY message.
-     */
-    VEHICLE_AP_POWER_STATE_CONFIG_SUPPORT_TIMER_POWER_ON_FLAG = 0x2,
-};
-
-enum vehicle_ap_power_state {
-    /** vehicle HAL will never publish this state to AP */
-    VEHICLE_AP_POWER_STATE_OFF = 0,
-    /** vehicle HAL will never publish this state to AP */
-    VEHICLE_AP_POWER_STATE_DEEP_SLEEP = 1,
-    /** AP is on but display should be off. */
-    VEHICLE_AP_POWER_STATE_ON_DISP_OFF = 2,
-    /** AP is on with display on. This state allows full user interaction. */
-    VEHICLE_AP_POWER_STATE_ON_FULL = 3,
-    /**
-     * The power controller has requested AP to shutdown. AP can either enter sleep state or start
-     * full shutdown. AP can also request postponing shutdown by sending
-     * VEHICLE_AP_POWER_SET_SHUTDOWN_POSTPONE message. The power controller should change power
-     * state to this state to shutdown system.
-     *
-     * int32_array[1] : one of enum_vehicle_ap_power_state_shutdown_param_type
-     */
-    VEHICLE_AP_POWER_STATE_SHUTDOWN_PREPARE = 4,
-};
-
-enum vehicle_ap_power_state_shutdown_param {
-    /** AP should shutdown immediately. Postponing is not allowed. */
-    VEHICLE_AP_POWER_SHUTDOWN_PARAM_SHUTDOWN_IMMEDIATELY = 1,
-    /** AP can enter deep sleep instead of shutting down completely. */
-    VEHICLE_AP_POWER_SHUTDOWN_PARAM_CAN_SLEEP = 2,
-    /** AP can only shutdown with postponing allowed. */
-    VEHICLE_AP_POWER_SHUTDOWN_PARAM_SHUTDOWN_ONLY = 3,
-};
-
-enum vehicle_ap_power_set_state {
-    /**
-     * AP has finished boot up, and can start shutdown if requested by power controller.
-     */
-    VEHICLE_AP_POWER_SET_BOOT_COMPLETE = 0x1,
-    /**
-     * AP is entering deep sleep state. How this state is implemented may vary depending on
-     * each H/W, but AP's power should be kept in this state.
-     */
-    VEHICLE_AP_POWER_SET_DEEP_SLEEP_ENTRY = 0x2,
-    /**
-     * AP is exiting from deep sleep state, and is in VEHICLE_AP_POWER_STATE_SHUTDOWN_PREPARE state.
-     * The power controller may change state to other ON states based on the current state.
-     */
-    VEHICLE_AP_POWER_SET_DEEP_SLEEP_EXIT = 0x3,
-    /**
-     * int32_array[1]: Time to postpone shutdown in ms. Maximum value can be 5000 ms.
-     *                 If AP needs more time, it will send another POSTPONE message before
-     *                 the previous one expires.
-     */
-    VEHICLE_AP_POWER_SET_SHUTDOWN_POSTPONE = 0x4,
-    /**
-     * AP is starting shutting down. When system completes shutdown, everything will stop in AP
-     * as kernel will stop all other contexts. It is responsibility of vehicle HAL or lower level
-     * to synchronize that state with external power controller. As an example, some kind of ping
-     * with timeout in power controller can be a solution.
-     *
-     * int32_array[1]: Time to turn on AP in secs. Power controller may turn on AP after specified
-     *                 time so that AP can run tasks like update. If it is set to 0, there is no
-     *                 wake up, and power controller may not necessarily support wake-up.
-     *                 If power controller turns on AP due to timer, it should start with
-     *                 VEHICLE_AP_POWER_STATE_ON_DISP_OFF state, and after receiving
-     *                 VEHICLE_AP_POWER_SET_BOOT_COMPLETE, it shall do state transition to
-     *                 VEHICLE_AP_POWER_STATE_SHUTDOWN_PREPARE.
-     */
-    VEHICLE_AP_POWER_SET_SHUTDOWN_START = 0x5,
-    /**
-     * User has requested to turn off headunit's display, which is detected in android side.
-     * The power controller may change the power state to VEHICLE_AP_POWER_STATE_ON_DISP_OFF.
-     */
-    VEHICLE_AP_POWER_SET_DISPLAY_OFF = 0x6,
-    /**
-     * User has requested to turn on headunit's display, most probably from power key input which
-     * is attached to headunit. The power controller may change the power state to
-     * VEHICLE_AP_POWER_STATE_ON_FULL.
-     */
-    VEHICLE_AP_POWER_SET_DISPLAY_ON = 0x7,
-};
-
-/**
- * Property to represent brightness of the display. Some cars have single control for
- * the brightness of all displays and this property is to share change in that control.
- *
- * If this is writable, android side can set this value when user changes display brightness
- * from Settings. If this is read only, user may still change display brightness from Settings,
- * but that will not be reflected to other displays.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ|VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32
- */
-#define VEHICLE_PROPERTY_DISPLAY_BRIGHTNESS                         (0x00000A01)
-
-
-/**
- * Index in int32_array for VEHICLE_PROPERTY_AP_POWER_STATE property.
- */
-enum vehicle_ap_power_state_index {
-    VEHICLE_AP_POWER_STATE_INDEX_STATE = 0,
-    VEHICLE_AP_POWER_STATE_INDEX_ADDITIONAL = 1,
-};
-
-/**
-* Property to report bootup reason for the current power on. This is a static property that will
-* not change for the whole duration until power off. For example, even if user presses power on
-* button after automatic power on with door unlock, bootup reason should stay with
-* VEHICLE_AP_POWER_BOOTUP_REASON_USER_UNLOCK.
-*
-* int32_value should be vehicle_ap_power_bootup_reason.
-*
-* @value_type VEHICLE_VALUE_TYPE_INT32
-* @change_mode VEHICLE_PROP_CHANGE_MODE_STATIC
-* @access VEHICLE_PROP_ACCESS_READ
-* @data_member int32_value
-*/
-#define VEHICLE_PROPERTY_AP_POWER_BOOTUP_REASON                     (0x00000A02)
-
-/**
- * Enum to represent bootup reason.
- */
-enum vehicle_ap_power_bootup_reason {
-    /**
-     * Power on due to user's pressing of power key or rotating of ignition switch.
-     */
-    VEHICLE_AP_POWER_BOOTUP_REASON_USER_POWER_ON = 0,
-    /**
-     * Automatic power on triggered by door unlock or any other kind of automatic user detection.
-     */
-    VEHICLE_AP_POWER_BOOTUP_REASON_USER_UNLOCK   = 1,
-    /**
-     * Automatic power on triggered by timer. This only happens when AP has asked wake-up after
-     * certain time through time specified in VEHICLE_AP_POWER_SET_SHUTDOWN_START.
-     */
-    VEHICLE_AP_POWER_BOOTUP_REASON_TIMER         = 2,
-};
-
-
-/**
- * Property to feed H/W input events to android
- *
- * int32_array[0] : action defined by vehicle_hw_key_input_action
- * int32_array[1] : key code, should use standard android key code
- * int32_array[2] : target display defined in vehicle_display. Events not tied
- *                  to specific display should be sent to DISPLAY_MAIN.
- * int32_array[3] : reserved for now. should be zero
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC4
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ
- * @config_flags
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_HW_KEY_INPUT                               (0x00000A10)
-
-enum vehicle_hw_key_input_action {
-    /** Key down */
-    VEHICLE_HW_KEY_INPUT_ACTION_DOWN = 0,
-    /** Key up */
-    VEHICLE_HW_KEY_INPUT_ACTION_UP = 1,
-};
-
-enum vehicle_display {
-    /** center console */
-    VEHICLE_DISPLAY_MAIN               = 0,
-    VEHICLE_DISPLAY_INSTRUMENT_CLUSTER = 1,
-};
-
-/**
- * Property to define instrument cluster information.
- * For CLUSTER_TYPE_EXTERNAL_DISPLAY:
- *  READ:
- *   int32_array[0] : The current screen mode index. Screen mode is defined
- *                     as a configuration in car service and represents which
- *                     area of screen is renderable.
- *   int32_array[1] : Android can render to instrument cluster (=1) or not(=0). When this is 0,
- *                    instrument cluster may be rendering some information in the area
- *                    allocated for android and android side rendering is invisible. *
- *   int32_array[2..3] : should be zero
- *  WRITE from android:
- *   int32_array[0] : Preferred mode for android side. Depending on the app rendering to instrument
- *                    cluster, preferred mode can change. Instrument cluster still needs to send
- *                    event with new mode to trigger actual mode change.
- *   int32_array[1] : The current app context relevant for instrument cluster. Use the same flag
- *                    with vehicle_audio_context_flag but this context represents active apps, not
- *                    active audio. Instrument cluster side may change mode depending on the
- *                    currently active contexts.
- *   int32_array[2..3] : should be zero
- *  When system boots up, Android side will write {0, 0, 0, 0} when it is ready to render to
- *  instrument cluster. Before this message, rendering from android should not be visible in the
- *  cluster.
- * @value_type VEHICLE_VALUE_TYPE_INT32_VEC4
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @config_array 0:vehicle_instument_cluster_type 1:hw type
- * @data_member int32_array
- */
-#define VEHICLE_PROPERTY_INSTRUMENT_CLUSTER_INFO                    (0x00000A20)
-
-/**
- * Represents instrument cluster type available in system
- */
-enum vehicle_instument_cluster_type {
-    /** Android has no access to instument cluster */
-    VEHICLE_INSTRUMENT_CLUSTER_TYPE_NONE = 0,
-    /**
-     * Instrument cluster can communicate through vehicle hal with additional
-     * properties to exchange meta-data
-     */
-    VEHICLE_INSTRUMENT_CLUSTER_TYPE_HAL_INTERFACE = 1,
-    /**
-     * Instrument cluster is external display where android can render contents
-     */
-    VEHICLE_INSTRUMENT_CLUSTER_TYPE_EXTERNAL_DISPLAY = 2,
-};
-
-/**
- * Current date and time, encoded as Unix time.
- * This value denotes the number of seconds that have elapsed since 1/1/1970.
- *
- * @value_type VEHICLE_VALUE_TYPE_INT64
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_SET
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int64_value
- * @unit VEHICLE_UNIT_TYPE_SECS
- */
-#define VEHICLE_PROPERTY_UNIX_TIME                                  (0x00000A30)
-
-/**
- * Current time only.
- * Some vehicles may not keep track of date.  This property only affects the current time, in
- * seconds during the day.  Thus, the max value for this parameter is 86,400 (24 * 60 * 60)
- *
- * @value_type VEHICLE_VALUE_TYPE_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_SET
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_value
- * @unit VEHICLE_UNIT_TYPE_SECS
- */
-#define VEHICLE_PROPERTY_CURRENT_TIME_IN_SECONDS                    (0x00000A31)
-
-
-//==== Car Cabin Properties ====
-/**
- * Most Car Cabin properties have both a MOVE and POSITION parameter associated with them.
- *
- * The MOVE parameter will start moving the device in the indicated direction.  The magnitude
- * indicates the relative speed.  For instance, setting the WINDOW_MOVE parameter to +1 will roll
- * the window up.  Setting it to +2 (if available) will roll it up faster.
- *
- * The POSITION parameter will move the device to the desired position.  For instance, if the
- * WINDOW_POS has a range of 0-100, then setting this parameter to 50 will open the window halfway.
- * Depending upon the initial position, the window may move up or down to the 50% value.
- *
- * OEMs may choose to implement one or both of the MOVE/POSITION parameters depending upon the
- * capability of the hardware.
- */
-
-// Doors
-/**
- * Door position
- *
- * This is an integer in case a door may be set to a particular position.  Max
- * value indicates fully open, min value (0) indicates fully closed.
- *
- * Some vehicles (minivans) can open the door electronically.  Hence, the ability
- * to write this property.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_DOOR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_DOOR_POS                                   (0x00000B00)
-
-/**
- * Door move
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_DOOR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_DOOR_MOVE                                  (0x00000B01)
-
-
-/**
- * Door lock
- *
- * 'true' indicates door is locked
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_DOOR
- * @data_member boolean_value
- */
-#define VEHICLE_PROPERTY_DOOR_LOCK                                  (0x00000B02)
-
-// Mirrors
-/**
- * Mirror Z Position
- *
- * Positive value indicates tilt upwards, negative value is downwards
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_MIRROR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_MIRROR_Z_POS                               (0x00000B40)
-
-/**
- * Mirror Z Move
- *
- * Positive value indicates tilt upwards, negative value is downwards
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_MIRROR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_MIRROR_Z_MOVE                              (0x00000B41)
-
-/**
- * Mirror Y Position
- *
- * Positive value indicate tilt right, negative value is left
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_MIRROR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_MIRROR_Y_POS                               (0x00000B42)
-
-/**
- * Mirror Y Move
- *
- * Positive value indicate tilt right, negative value is left
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_MIRROR
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_MIRROR_Y_MOVE                              (0x00000B43)
-
-/**
- * Mirror Lock
- *
- * True indicates mirror positions are locked and not changeable
- *
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member boolean_value
- */
-#define VEHICLE_PROPERTY_MIRROR_LOCK                                (0x00000B44)
-
-/**
- * Mirror Fold
- *
- * True indicates mirrors are folded
- *
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member boolean_value
- */
-#define VEHICLE_PROPERTY_MIRROR_FOLD                                (0x00000B45)
-
-// Seats
-/**
- * Seat memory select
- *
- * This parameter selects the memory preset to use to select the seat position.
- * The minValue is always 0, and the maxValue determines the number of seat
- * positions available.
- *
- * For instance, if the driver's seat has 3 memory presets, the maxValue will be 3.
- * When the user wants to select a preset, the desired preset number (1, 2, or 3)
- * is set.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_MEMORY_SELECT                         (0x00000B80)
-
-/**
- * Seat memory set
- *
- * This setting allows the user to save the current seat position settings into
- * the selected preset slot.  The maxValue for each seat position shall match
- * the maxValue for VEHICLE_PROPERTY_SEAT_MEMORY_SELECT.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_MEMORY_SET                            (0x00000B81)
-
-/**
- * Seatbelt buckled
- *
- * True indicates belt is buckled.
- *
- * Write access indicates automatic seat buckling capabilities.  There are no known cars at this
- * time, but you never know...
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member boolean_value
- */
-#define VEHICLE_PROPERTY_SEAT_BELT_BUCKLED                          (0x00000B82)
-
-/**
- * Seatbelt height position
- *
- * Adjusts the shoulder belt anchor point.
- * Max value indicates highest position
- * Min value indicates lowest position
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BELT_HEIGHT_POS                       (0x00000B83)
-
-/**
- * Seatbelt height move
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BELT_HEIGHT_MOVE                      (0x00000B84)
-
-/**
- * Seat fore/aft position
- *
- * Sets the seat position forward (closer to steering wheel) and backwards.
- * Max value indicates closest to wheel, min value indicates most rearward
- * position.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_FORE_AFT_POS                          (0x00000B85)
-
-/**
- * Seat fore/aft move
- *
- * Moves the seat position forward and aft.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_FORE_AFT_MOVE                         (0x00000B86)
-
-/**
- * Seat backrest angle 1 position
- *
- * Backrest angle 1 is the actuator closest to the bottom of the seat.
- * Max value indicates angling forward towards the steering wheel.
- * Min value indicates full recline.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BACKREST_ANGLE_1_POS                  (0x00000B87)
-
-/**
- * Seat backrest angle 1 move
- *
- * Moves the backrest forward or recline.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BACKREST_ANGLE_1_MOVE                 (0x00000B88)
-
-/**
- * Seat backrest angle 2 position
- *
- * Backrest angle 2 is the next actuator up from the bottom of the seat.
- * Max value indicates angling forward towards the steering wheel.
- * Min value indicates full recline.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BACKREST_ANGLE_2_POS                  (0x00000B89)
-
-/**
- * Seat backrest angle 2 move
- *
- * Moves the backrest forward or recline.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_BACKREST_ANGLE_2_MOVE                 (0x00000B8A)
-
-/**
- * Seat height position
- *
- * Sets the seat height.
- * Max value indicates highest position.
- * Min value indicates lowest position.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEIGHT_POS                            (0x00000B8B)
-
-/**
- * Seat height move
- *
- * Moves the seat height.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEIGHT_MOVE                           (0x00000B8C)
-
-/**
- * Seat depth position
- *
- * Sets the seat depth, distance from back rest to front edge of seat.
- * Max value indicates longest depth position.
- * Min value indicates shortest position.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_DEPTH_POS                             (0x00000B8D)
-
-/**
- * Seat depth move
- *
- * Adjusts the seat depth.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_DEPTH_MOVE                            (0x00000B8E)
-
-/**
- * Seat tilt position
- *
- * Sets the seat tilt.
- * Max value indicates front edge of seat higher than back edge.
- * Min value indicates front edge of seat lower than back edge.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_TILT_POS                              (0x00000B8F)
-
-/**
- * Seat tilt move
- *
- * Tilts the seat.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_TILT_MOVE                             (0x00000B90)
-
-/**
- * Lumber fore/aft position
- *
- * Pushes the lumbar support forward and backwards
- * Max value indicates most forward position.
- * Min value indicates most rearward position.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_LUMBAR_FORE_AFT_POS                   (0x00000B91)
-
-/**
- * Lumbar fore/aft move
- *
- * Adjusts the lumbar support.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_LUMBAR_FORE_AFT_MOVE                  (0x00000B92)
-
-/**
- * Lumbar side support position
- *
- * Sets the amount of lateral lumbar support.
- * Max value indicates widest lumbar setting (i.e. least support)
- * Min value indicates thinnest lumbar setting.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_LUMBAR_SIDE_SUPPORT_POS               (0x00000B93)
-
-/**
- * Lumbar side support move
- *
- * Adjusts the amount of lateral lumbar support.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_LUMBAR_SIDE_SUPPORT_MOVE              (0x00000B94)
-
-/**
- * Headrest height position
- *
- * Sets the headrest height.
- * Max value indicates tallest setting.
- * Min value indicates shortest setting.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_HEIGHT_POS                   (0x00000B95)
-
-/**
- * Headrest height move
- *
- * Moves the headrest up and down.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_HEIGHT_MOVE                  (0x00000B96)
-
-/**
- * Headrest angle position
- *
- * Sets the angle of the headrest.
- * Max value indicates most upright angle.
- * Min value indicates shallowest headrest angle.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_ANGLE_POS                    (0x00000B97)
-
-/**
- * Headrest angle move
- *
- * Adjusts the angle of the headrest
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_ANGLE_MOVE                   (0x00000B98)
-
-/**
- * Headrest fore/aft position
- *
- * Adjusts the headrest forwards and backwards.
- * Max value indicates position closest to front of car.
- * Min value indicates position closest to rear of car.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_FORE_AFT_POS                 (0x00000B99)
-
-/**
- * Headrest fore/aft move
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @zone_type VEHICLE_ZONE_TYPE_SEAT
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_SEAT_HEADREST_FORE_AFT_MOVE                (0x00000B9A)
-
-
-// Windows
-/**
- * Window Position
- *
- * Max = window up / closed
- * Min = window down / open
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_WINDOW_POS                                 (0x00000BC0)
-
-/**
- * Window Move
- *
- * Max = window up / closed
- * Min = window down / open
- * Magnitude denotes relative speed.  I.e. +2 is faster than +1 in raising the window.
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_WINDOW_MOVE                                (0x00000BC1)
-
-/**
- * Window Vent Position
- *
- * This feature is used to control the vent feature on a sunroof.
- *
- * Max = vent open
- * Min = vent closed
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_WINDOW_VENT_POS                            (0x00000BC2)
-
-/**
- * Window Vent Move
- *
- * This feature is used to control the vent feature on a sunroof.
- *
- * Max = vent open
- * Min = vent closed
- *
- * @value_type VEHICLE_VALUE_TYPE_ZONED_INT32
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE|VEHICLE_PROP_ACCESS_WRITE
- * @data_member int32_value
- */
-#define VEHICLE_PROPERTY_WINDOW_VENT_MOVE                           (0x00000BC3)
-
-/**
- * Window Lock
- *
- * True indicates windows are locked and can't be moved.
- *
- * @value_type VEHICLE_VALUE_TYPE_BOOLEAN
- * @change_mode VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
- * @access VEHICLE_PROP_ACCESS_READ_WRITE
- * @data_member boolean_value
- */
-#define VEHICLE_PROPERTY_WINDOW_LOCK                                (0x00000BC4)
-
-
-
-/**
- *  H/W specific, non-standard property can be added as necessary. Such property should use
- *  property number in range of [VEHICLE_PROPERTY_CUSTOM_START, VEHICLE_PROPERTY_CUSTOM_END].
- *  Definition of property in this range is completely up to each HAL implementation.
- *  For such property, it is recommended to fill vehicle_prop_config.config_string with some
- *  additional information to help debugging. For example, company XYZ's custom extension may
- *  include config_string of "com.XYZ.some_further_details".
- *  @range_start
- */
-#define VEHICLE_PROPERTY_CUSTOM_START                               (0x70000000)
-/** @range_end */
-#define VEHICLE_PROPERTY_CUSTOM_END                                 (0x73ffffff)
-
-/**
- * Property range allocated for system's internal usage like testing. HAL should never declare
- * property in this range.
- * @range_start
- */
-#define VEHICLE_PROPERTY_INTERNAL_START                             (0x74000000)
-/**
- * @range_end
- */
-#define VEHICLE_PROPERTY_INTERNAL_END                               (0x74ffffff)
-
-/**
- * Value types for various properties.
- */
-enum vehicle_value_type {
-    VEHICLE_VALUE_TYPE_SHOUD_NOT_USE            = 0x00, // value_type should never set to 0.
-    VEHICLE_VALUE_TYPE_STRING                   = 0x01,
-    VEHICLE_VALUE_TYPE_BYTES                    = 0x02,
-    VEHICLE_VALUE_TYPE_BOOLEAN                  = 0x03,
-    VEHICLE_VALUE_TYPE_ZONED_BOOLEAN            = 0x04,
-    VEHICLE_VALUE_TYPE_INT64                    = 0x05,
-    VEHICLE_VALUE_TYPE_FLOAT                    = 0x10,
-    VEHICLE_VALUE_TYPE_FLOAT_VEC2               = 0x11,
-    VEHICLE_VALUE_TYPE_FLOAT_VEC3               = 0x12,
-    VEHICLE_VALUE_TYPE_FLOAT_VEC4               = 0x13,
-    VEHICLE_VALUE_TYPE_INT32                    = 0x20,
-    VEHICLE_VALUE_TYPE_INT32_VEC2               = 0x21,
-    VEHICLE_VALUE_TYPE_INT32_VEC3               = 0x22,
-    VEHICLE_VALUE_TYPE_INT32_VEC4               = 0x23,
-    VEHICLE_VALUE_TYPE_ZONED_FLOAT              = 0x30,
-    VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2         = 0x31,
-    VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3         = 0x32,
-    VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4         = 0x33,
-    VEHICLE_VALUE_TYPE_ZONED_INT32              = 0x40,
-    VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2         = 0x41,
-    VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3         = 0x42,
-    VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4         = 0x43,
-};
-
-/**
- * Units used for int or float type with no attached enum types.
- */
-enum vehicle_unit_type {
-    VEHICLE_UNIT_TYPE_SHOULD_NOT_USE        = 0x00000000,
-    // speed related items
-    VEHICLE_UNIT_TYPE_METER_PER_SEC         = 0x00000001,
-    VEHICLE_UNIT_TYPE_RPM                   = 0x00000002,
-    VEHICLE_UNIT_TYPE_HZ                    = 0x00000003,
-    // kind of ratio
-    VEHICLE_UNIT_TYPE_PERCENTILE            = 0x00000010,
-    // length
-    VEHICLE_UNIT_TYPE_MILLIMETER            = 0x00000020,
-    VEHICLE_UNIT_TYPE_METER                 = 0x00000021,
-    VEHICLE_UNIT_TYPE_KILOMETER             = 0x00000023,
-    // temperature
-    VEHICLE_UNIT_TYPE_CELSIUS               = 0x00000030,
-    VEHICLE_UNIT_TYPE_FAHRENHEIT            = 0x00000031,
-    VEHICLE_UNIT_TYPE_KELVIN                = 0x00000032,
-    // volume
-    VEHICLE_UNIT_TYPE_MILLILITER            = 0x00000040,
-    // time
-    VEHICLE_UNIT_TYPE_NANO_SECS             = 0x00000050,
-    VEHICLE_UNIT_TYPE_SECS                  = 0x00000053,
-    VEHICLE_UNIT_TYPE_YEAR                  = 0x00000059,
-};
-
-/**
- * This describes how value of property can change.
- */
-enum vehicle_prop_change_mode {
-    /**
-     * Property of this type will *never* change. This property will not support subscription, but
-     * will support get
-     */
-    VEHICLE_PROP_CHANGE_MODE_STATIC         = 0x00,
-    /**
-     * Property of this type will be reported when there is a change.
-     * get call should return the current value.
-     * Set operation for this property is assumed to be asynchronous. When the property is read
-     * (get) after set, it may still return old value until underlying H/W backing this property
-     * has actually changed the state. Once state is changed, the property will dispatch changed
-     * value as event.
-     */
-    VEHICLE_PROP_CHANGE_MODE_ON_CHANGE      = 0x01,
-    /**
-     * Property of this type change continuously and requires fixed rate of sampling to retrieve
-     * the data.
-     */
-    VEHICLE_PROP_CHANGE_MODE_CONTINUOUS     = 0x02,
-    /**
-     * Property of this type may be polled to get the current value.
-     */
-    VEHICLE_PROP_CHANGE_MODE_POLL           = 0x03,
-    /**
-     * This is for property where change event should be sent only when the value is
-     * set from external component. Normal value change will not trigger event.
-     * For example, clock property can send change event only when it is set, outside android,
-     * for case like user setting time or time getting update. There is no need to send it
-     * per every value change.
-     */
-    VEHICLE_PROP_CHANGE_MODE_ON_SET         = 0x04,
-};
-
-/**
- * Property config defines the capabilities of it. User of the API
- * should first get the property config to understand the output from get()
- * commands and also to ensure that set() or events commands are in sync with
- * the expected output.
- */
-enum vehicle_prop_access {
-    VEHICLE_PROP_ACCESS_READ  = 0x01,
-    VEHICLE_PROP_ACCESS_WRITE = 0x02,
-    VEHICLE_PROP_ACCESS_READ_WRITE = 0x03
-};
-
-/**
- * These permissions define how the OEMs want to distribute their information and security they
- * want to apply. On top of these restrictions, android will have additional
- * 'app-level' permissions that the apps will need to ask the user before the apps have the
- * information.
- * This information should be kept in vehicle_prop_config.permission_model.
- */
-enum vehicle_permission_model {
-    /**
-     * No special restriction, but each property can still require specific android app-level
-     * permission.
-     */
-    VEHICLE_PERMISSION_NO_RESTRICTION = 0,
-    /** Signature only. Only APKs signed with OEM keys are allowed. */
-    VEHICLE_PERMISSION_OEM_ONLY = 0x1,
-    /** System only. APKs built-in to system  can access the property. */
-    VEHICLE_PERMISSION_SYSTEM_APP_ONLY = 0x2,
-    /** Equivalent to “system|signature” */
-    VEHICLE_PERMISSION_OEM_OR_SYSTEM_APP = 0x3
-};
-
-
-/**
- *  Special values for INT32/FLOAT (including ZONED types)
- *  These values represent special state, which is outside MIN/MAX range but can happen.
- *  For example, HVAC temperature may use out of range min / max to represent that
- *  it is working in full power although target temperature has separate min / max.
- *  OUT_OF_RANGE_OFF can represent a state where the property is powered off.
- *  Usually such property will have separate property to control power.
- */
-
-#define VEHICLE_INT_OUT_OF_RANGE_MAX (INT32_MAX)
-#define VEHICLE_INT_OUT_OF_RANGE_MIN (INT32_MIN)
-#define VEHICLE_INT_OUT_OF_RANGE_OFF (INT32_MIN + 1)
-
-#define VEHICLE_FLOAT_OUT_OF_RANGE_MAX (INFINITY)
-#define VEHICLE_FLOAT_OUT_OF_RANGE_MIN (-INFINITY)
-#define VEHICLE_FLOAT_OUT_OF_RANGE_OFF (NAN)
-
-/**
- * Car states.
- *
- * The driving states determine what features of the UI will be accessible.
- */
-enum vehicle_driving_status {
-    VEHICLE_DRIVING_STATUS_UNRESTRICTED      = 0x00,
-    VEHICLE_DRIVING_STATUS_NO_VIDEO          = 0x01,
-    VEHICLE_DRIVING_STATUS_NO_KEYBOARD_INPUT = 0x02,
-    VEHICLE_DRIVING_STATUS_NO_VOICE_INPUT    = 0x04,
-    VEHICLE_DRIVING_STATUS_NO_CONFIG         = 0x08,
-    VEHICLE_DRIVING_STATUS_LIMIT_MESSAGE_LEN = 0x10
-};
-
-/**
- * Various gears which can be selected by user and chosen in system.
- */
-enum vehicle_gear {
-    // Gear selections present in both automatic and manual cars.
-    VEHICLE_GEAR_NEUTRAL    = 0x0001,
-    VEHICLE_GEAR_REVERSE    = 0x0002,
-
-    // Gear selections (mostly) present only in automatic cars.
-    VEHICLE_GEAR_PARK       = 0x0004,
-    VEHICLE_GEAR_DRIVE      = 0x0008,
-    VEHICLE_GEAR_LOW        = 0x0010,
-
-    // Other possible gear selections (maybe present in manual or automatic
-    // cars).
-    VEHICLE_GEAR_1          = 0x0010,
-    VEHICLE_GEAR_2          = 0x0020,
-    VEHICLE_GEAR_3          = 0x0040,
-    VEHICLE_GEAR_4          = 0x0080,
-    VEHICLE_GEAR_5          = 0x0100,
-    VEHICLE_GEAR_6          = 0x0200,
-    VEHICLE_GEAR_7          = 0x0400,
-    VEHICLE_GEAR_8          = 0x0800,
-    VEHICLE_GEAR_9          = 0x1000
-};
-
-
-/**
- * Various zones in the car.
- *
- * Zones are used for Air Conditioning purposes and divide the car into physical
- * area zones.
- */
-enum vehicle_zone {
-    VEHICLE_ZONE_ROW_1_LEFT    = 0x00000001,
-    VEHICLE_ZONE_ROW_1_CENTER  = 0x00000002,
-    VEHICLE_ZONE_ROW_1_RIGHT   = 0x00000004,
-    VEHICLE_ZONE_ROW_1_ALL     = 0x00000008,
-    VEHICLE_ZONE_ROW_2_LEFT    = 0x00000010,
-    VEHICLE_ZONE_ROW_2_CENTER  = 0x00000020,
-    VEHICLE_ZONE_ROW_2_RIGHT   = 0x00000040,
-    VEHICLE_ZONE_ROW_2_ALL     = 0x00000080,
-    VEHICLE_ZONE_ROW_3_LEFT    = 0x00000100,
-    VEHICLE_ZONE_ROW_3_CENTER  = 0x00000200,
-    VEHICLE_ZONE_ROW_3_RIGHT   = 0x00000400,
-    VEHICLE_ZONE_ROW_3_ALL     = 0x00000800,
-    VEHICLE_ZONE_ROW_4_LEFT    = 0x00001000,
-    VEHICLE_ZONE_ROW_4_CENTER  = 0x00002000,
-    VEHICLE_ZONE_ROW_4_RIGHT   = 0x00004000,
-    VEHICLE_ZONE_ROW_4_ALL     = 0x00008000,
-    VEHICLE_ZONE_ALL           = 0x80000000,
-};
-
-/**
- * Various Seats in the car.
- */
-enum vehicle_seat {
-    VEHICLE_SEAT_ROW_1_LEFT   = 0x0001,
-    VEHICLE_SEAT_ROW_1_CENTER = 0x0002,
-    VEHICLE_SEAT_ROW_1_RIGHT  = 0x0004,
-    VEHICLE_SEAT_ROW_2_LEFT   = 0x0010,
-    VEHICLE_SEAT_ROW_2_CENTER = 0x0020,
-    VEHICLE_SEAT_ROW_2_RIGHT  = 0x0040,
-    VEHICLE_SEAT_ROW_3_LEFT   = 0x0100,
-    VEHICLE_SEAT_ROW_3_CENTER = 0x0200,
-    VEHICLE_SEAT_ROW_3_RIGHT  = 0x0400
-};
-
-/**
- * Various windshields/windows in the car.
- */
-enum vehicle_window {
-    VEHICLE_WINDOW_FRONT_WINDSHIELD = 0x0001,
-    VEHICLE_WINDOW_REAR_WINDSHIELD  = 0x0002,
-    VEHICLE_WINDOW_ROOF_TOP         = 0x0004,
-    VEHICLE_WINDOW_ROW_1_LEFT       = 0x0010,
-    VEHICLE_WINDOW_ROW_1_RIGHT      = 0x0020,
-    VEHICLE_WINDOW_ROW_2_LEFT       = 0x0100,
-    VEHICLE_WINDOW_ROW_2_RIGHT      = 0x0200,
-    VEHICLE_WINDOW_ROW_3_LEFT       = 0x1000,
-    VEHICLE_WINDOW_ROW_3_RIGHT      = 0x2000,
-};
-
-enum vehicle_door {
-    VEHICLE_DOOR_ROW_1_LEFT    = 0x00000001,
-    VEHICLE_DOOR_ROW_1_RIGHT   = 0x00000004,
-    VEHICLE_DOOR_ROW_2_LEFT    = 0x00000010,
-    VEHICLE_DOOR_ROW_2_RIGHT   = 0x00000040,
-    VEHICLE_DOOR_ROW_3_LEFT    = 0x00000100,
-    VEHICLE_DOOR_ROW_3_RIGHT   = 0x00000400,
-    VEHICLE_DOOR_HOOD          = 0x10000000,
-    VEHICLE_DOOR_REAR          = 0x20000000,
-};
-
-enum vehicle_mirror {
-    VEHICLE_MIRROR_DRIVER_LEFT   = 0x00000001,
-    VEHICLE_MIRROR_DRIVER_RIGHT  = 0x00000002,
-    VEHICLE_MIRROR_DRIVER_CENTER = 0x00000004,
-};
-
-enum vehicle_turn_signal {
-    VEHICLE_SIGNAL_NONE         = 0x00,
-    VEHICLE_SIGNAL_RIGHT        = 0x01,
-    VEHICLE_SIGNAL_LEFT         = 0x02,
-    VEHICLE_SIGNAL_EMERGENCY    = 0x04
-};
-
-enum vehicle_zone_type {
-    VEHICLE_ZONE_TYPE_NONE      = 0x00,
-    VEHICLE_ZONE_TYPE_ZONE    = 0x01,
-    VEHICLE_ZONE_TYPE_SEAT      = 0x02,
-    VEHICLE_ZONE_TYPE_DOOR      = 0x04,
-    VEHICLE_ZONE_TYPE_WINDOW    = 0x10,
-    VEHICLE_ZONE_TYPE_MIRROR    = 0x20,
-};
-
-/*
- * Boolean type.
- */
-enum vehicle_boolean {
-    VEHICLE_FALSE = 0x00,
-    VEHICLE_TRUE  = 0x01
-};
-
-typedef int32_t vehicle_boolean_t;
-
-/**
- * Vehicle string.
- *
- * Defines a UTF8 encoded sequence of bytes that should be used for string
- * representation throughout.
- */
-typedef struct vehicle_str {
-    uint8_t* data;
-    int32_t len;
-} vehicle_str_t;
-
-/**
- * Vehicle byte array.
- * This is for passing generic raw data.
- */
-typedef vehicle_str_t vehicle_bytes_t;
-
-typedef struct vehicle_prop_config {
-    int32_t prop;
-
-    /**
-     * Defines if the property is read or write. Value should be one of
-     * enum vehicle_prop_access.
-     */
-    int32_t access;
-
-    /**
-     * Defines if the property is continuous or on-change. Value should be one
-     * of enum vehicle_prop_change_mode.
-     */
-    int32_t change_mode;
-
-    /**
-     * Type of data used for this property. This type is fixed per each property.
-     * Check vehicle_value_type for allowed value.
-     */
-    int32_t value_type;
-
-    /**
-     * Define necessary permission model to access the data.
-     */
-    int32_t permission_model;
-
-    /**
-     * Some of the properties may have associated zones (such as hvac), in these
-     * cases the config should contain an ORed value for the associated zone.
-     */
-    union {
-        /**
-         * The value is derived by ORing one or more of enum vehicle_zone members.
-         */
-        int32_t vehicle_zone_flags;
-        /** The value is derived by ORing one or more of enum vehicle_seat members. */
-        int32_t vehicle_seat_flags;
-        /** The value is derived by ORing one or more of enum vehicle_window members. */
-        int32_t vehicle_window_flags;
-    };
-
-    /**
-     * Property specific configuration information. Usage of this will be defined per each property.
-     */
-    union {
-        /**
-         * For generic configuration information
-         */
-        int32_t config_flags;
-        /** The number of presets that are stored by the radio module. Pass 0 if
-         * there are no presets available. The range of presets is defined to be
-         * from 1 (see VEHICLE_RADIO_PRESET_MIN_VALUE) to vehicle_radio_num_presets.
-         */
-        int32_t vehicle_radio_num_presets;
-        int32_t config_array[4];
-    };
-
-    /**
-     * Some properties may require additional information passed over this string. Most properties
-     * do not need to set this and in that case, config_string.data should be NULL and
-     * config_string.len should be 0.
-     */
-    vehicle_str_t config_string;
-
-    /**
-     * Specify minimum allowed value for the property. This is necessary for property which does
-     * not have specified enum.
-     */
-    union {
-        float float_min_value;
-        int32_t int32_min_value;
-        int64_t int64_min_value;
-    };
-
-    /**
-     * Specify maximum allowed value for the property. This is necessary for property which does
-     * not have specified enum.
-     */
-    union {
-        float float_max_value;
-        int32_t int32_max_value;
-        int64_t int64_max_value;
-    };
-
-    /**
-     * Array of min values for zoned properties. Zoned property can specify min / max value in two
-     * different ways:
-     *   1. All zones having the same min / max value: *_min/max_value should be set and this
-     *      array should be set to NULL.
-     *   2. All zones having separate min / max value: *_min/max_values array should be populated
-     *      and its length should be the same as number of active zones specified by *_zone_flags.
-     *
-     * Should be NULL if each zone does not have separate max values.
-     */
-    union {
-        float* float_min_values;
-        int32_t* int32_min_values;
-        int64_t* int64_min_values;
-    };
-
-    /**
-     * Array of max values for zoned properties. See above for its usage.
-     * Should be NULL if each zone does not have separate max values.
-     * If not NULL, length of array should match that of min_values.
-     */
-    union {
-        float* float_max_values;
-        int32_t* int32_max_values;
-        int64_t* int64_max_values;
-    };
-
-    /**
-     * Min sample rate in Hz. Should be 0 for sensor type of VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
-     */
-    float min_sample_rate;
-    /**
-     * Max sample rate in Hz. Should be 0 for sensor type of VEHICLE_PROP_CHANGE_MODE_ON_CHANGE
-     */
-    float max_sample_rate;
-    /**
-     * Place holder for putting HAL implementation specific data. Usage is wholly up to HAL
-     * implementation.
-     */
-    void* hal_data;
-} vehicle_prop_config_t;
-
-/**
- * HVAC property fields.
- *
- * Defines various HVAC properties which are packed into vehicle_hvac_t (see
- * below). We define these properties outside in global scope so that HAL
- * implementation and HAL users (JNI) can typecast vehicle_hvac correctly.
- */
-typedef struct vehicle_hvac {
-    /**
-     * Define one structure for each possible HVAC property.
-     * NOTES:
-     * a) Fan speed is a number from (0 - 6) where 6 is the highest speed. (TODO define enum)
-     * b) Temperature is a floating point Celcius scale.
-     * c) Direction is defined in enum vehicle_fan_direction.
-     *
-     * The HAL should create #entries number of vehicle_hvac_properties and
-     * assign it to "properties" variable below.
-     */
-    union {
-        int32_t fan_speed;
-        int32_t fan_direction;
-        vehicle_boolean_t ac_on;
-        vehicle_boolean_t max_ac_on;
-        vehicle_boolean_t max_defrost_on;
-        vehicle_boolean_t recirc_on;
-        vehicle_boolean_t dual_on;
-        vehicle_boolean_t auto_on;
-        vehicle_boolean_t power_on;
-
-        float temperature_current;
-        float temperature_set;
-
-        vehicle_boolean_t defrost_on;
-    };
-} vehicle_hvac_t;
-
-/*
- * Defines how the values for various properties are represented.
- *
- * There are two ways to populate and access the fields:
- * a) Using the individual fields. Use this mechanism (see
- * info_manufacture_date, fuel_capacity fields etc).
- * b) Using the union accessors (see uint32_value, float_value etc).
- *
- * To add a new field make sure that it does not exceed the total union size
- * (defined in int_array) and it is one of the vehicle_value_type. Then add the
- * field name with its unit to union. If the field type is not yet defined (as
- * of this draft, we don't use int64_t) then add that type to vehicle_value_type
- * and have an accessor (so for int64_t it will be int64_t int64_value).
- */
-typedef union vehicle_value {
-    /** Define the max size of this structure. */
-    int32_t int32_array[4];
-    float float_array[4];
-
-    // Easy accessors for union members (HAL implementation SHOULD NOT USE these
-    // fields while populating, use the property specific fields below instead).
-    int32_t int32_value;
-    int64_t int64_value;
-    float float_value;
-    vehicle_str_t str_value;
-    vehicle_bytes_t bytes_value;
-    vehicle_boolean_t boolean_value;
-
-    // Vehicle Information.
-    vehicle_str_t info_vin;
-    vehicle_str_t info_make;
-    vehicle_str_t info_model;
-    int32_t info_model_year;
-
-    // Represented in milliliters.
-    float info_fuel_capacity;
-
-    float vehicle_speed;
-    float odometer;
-
-    // Engine sensors.
-
-    // Represented in milliliters.
-    //float engine_coolant_level;
-    // Represented in celcius.
-    float engine_coolant_temperature;
-    // Represented in a percentage value.
-    //float engine_oil_level;
-    // Represented in celcius.
-    float engine_oil_temperature;
-    float engine_rpm;
-
-    // Event sensors.
-    // Value should be one of enum vehicle_gear_selection.
-    int32_t gear_selection;
-    // Value should be one of enum vehicle_gear.
-    int32_t gear_current_gear;
-    // Value should be one of enum vehicle_boolean.
-    int32_t parking_brake;
-    // If cruise_set_speed > 0 then cruise is ON otherwise cruise is OFF.
-    // Unit: meters / second (m/s).
-    //int32_t cruise_set_speed;
-    // Value should be one of enum vehicle_boolean.
-    int32_t is_fuel_level_low;
-    // Value should be one of enum vehicle_driving_status.
-    int32_t driving_status;
-    int32_t night_mode;
-    // Value should be one of emum vehicle_turn_signal.
-    int32_t turn_signals;
-    // Value should be one of enum vehicle_boolean.
-    //int32_t engine_on;
-
-    // HVAC properties.
-    vehicle_hvac_t hvac;
-
-    float outside_temperature;
-    float cabin_temperature;
-
-} vehicle_value_t;
-
-/*
- * Encapsulates the property name and the associated value. It
- * is used across various API calls to set values, get values or to register for
- * events.
- */
-typedef struct vehicle_prop_value {
-    /* property identifier */
-    int32_t prop;
-
-    /* value type of property for quick conversion from union to appropriate
-     * value. The value must be one of enum vehicle_value_type.
-     */
-    int32_t value_type;
-
-    /** time is elapsed nanoseconds since boot */
-    int64_t timestamp;
-
-    /**
-     * Zone information for zoned property. For non-zoned property, this should be ignored.
-     */
-    union {
-        int32_t zone;
-        int32_t seat;
-        int32_t window;
-    };
-
-    vehicle_value_t value;
-} vehicle_prop_value_t;
-
-/*
- * Event callback happens whenever a variable that the API user has subscribed
- * to needs to be reported. This may be based purely on threshold and frequency
- * (a regular subscription, see subscribe call's arguments) or when the set()
- * command is executed and the actual change needs to be reported.
- *
- * event_data is OWNED by the HAL and should be copied before the callback
- * finishes.
- */
-typedef int (*vehicle_event_callback_fn)(const vehicle_prop_value_t *event_data);
-
-
-/**
- * Represent the operation where the current error has happened.
- */
-enum vehicle_property_operation {
-    /** Generic error to this property which is not tied to any operation. */
-    VEHICLE_OPERATION_GENERIC = 0,
-    /** Error happened while handling property set. */
-    VEHICLE_OPERATION_SET = 1,
-    /** Error happened while handling property get. */
-    VEHICLE_OPERATION_GET = 2,
-    /** Error happened while handling property subscription. */
-    VEHICLE_OPERATION_SUBSCRIBE = 3,
-};
-
-/*
- * Suggests that an error condition has occurred.
- *
- * @param error_code Error code. error_code should be standard error code with
- *                negative value like -EINVAL.
- * @parm property Note a property where error has happened. If this is generic error, property
- *                should be VEHICLE_PROPERTY_INVALID.
- * @param operation Represent the operation where the error has happened. Should be one of
- *                  vehicle_property_operation.
- */
-typedef int (*vehicle_error_callback_fn)(int32_t error_code, int32_t property, int32_t operation);
-
-/************************************************************************************/
-
-/*
- * 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.
- */
-typedef struct vehicle_module {
-    struct hw_module_t common;
-} vehicle_module_t;
-
-
-typedef struct vehicle_hw_device {
-    struct hw_device_t common;
-
-    /**
-     * After calling open on device the user should register callbacks for event and error
-     * functions.
-     */
-    int (*init)(struct vehicle_hw_device* device,
-                vehicle_event_callback_fn event_fn, vehicle_error_callback_fn err_fn);
-    /**
-     * Before calling close the user should destroy the registered callback
-     * functions.
-     * In case the unsubscribe() call is not called on all properties before
-     * release() then release() will unsubscribe the properties itself.
-     */
-    int (*release)(struct vehicle_hw_device* device);
-
-    /**
-     * Enumerate all available properties. The list is returned in "list".
-     * @param num_properties number of properties contained in the retuned array.
-     * @return array of property configs supported by this car. Note that returned data is const
-     *         and caller cannot modify it. HAL implementation should keep this memory until HAL
-     *         is released to avoid copying this again.
-     */
-    vehicle_prop_config_t const *(*list_properties)(struct vehicle_hw_device* device,
-            int* num_properties);
-
-    /**
-     * Get a vehicle property value immediately. data should be allocated
-     * properly.
-     * The caller of the API OWNS the data field.
-     * Caller will set data->prop, data->value_type, and optionally zone value for zoned property.
-     * But HAL implementation needs to fill all entries properly when returning.
-     * For pointer type, HAL implementation should allocate necessary memory and caller is
-     * responsible for calling release_memory_from_get, which allows HAL to release allocated
-     * memory.
-     * For VEHICLE_PROP_CHANGE_MODE_STATIC type of property, get should return the same value
-     * always.
-     * For VEHICLE_PROP_CHANGE_MODE_ON_CHANGE type of property, it should return the latest value.
-     * If there is no data available yet, which can happen during initial stage, this call should
-     * return immediately with error code of -EAGAIN.
-     */
-    int (*get)(struct vehicle_hw_device* device, vehicle_prop_value_t *data);
-
-    /**
-     * Release memory allocated to data in previous get call. get call for byte or string involves
-     * allocating necessary memory from vehicle hal.
-     * To be safe, memory allocated by vehicle hal should be released by vehicle hal and vehicle
-     * network service will call this when data from vehicle hal is no longer necessary.
-     * vehicle hal implementation should only release member of vehicle_prop_value_t like
-     * data->str_value.data or data->bytes_value.data but not data itself as data itself is
-     * allocated from vehicle network service. Once memory is freed, corresponding pointer should
-     * be set to NULL bu vehicle hal.
-     */
-    void (*release_memory_from_get)(struct vehicle_hw_device* device, vehicle_prop_value_t *data);
-
-    /**
-     * Set a vehicle property value.  data should be allocated properly and not
-     * NULL.
-     * The caller of the API OWNS the data field.
-     * timestamp of data will be ignored for set operation.
-     * Setting some properties require having initial state available. Depending on the vehicle hal,
-     * such initial data may not be available for short time after init. In such case, set call
-     * can return -EAGAIN like get call.
-     * For a property with separate power control, set can fail if the property is not powered on.
-     * In such case, hal should return -ESHUTDOWN error.
-     */
-    int (*set)(struct vehicle_hw_device* device, const vehicle_prop_value_t *data);
-
-    /**
-     * Subscribe to events.
-     * Depending on output of list_properties if the property is:
-     * a) on-change: sample_rate should be set to 0.
-     * b) supports frequency: sample_rate should be set from min_sample_rate to
-     * max_sample_rate.
-     * For on-change type of properties, vehicle network service will make another get call to check
-     * the initial state. Due to this, vehicle hal implementation does not need to send initial
-     * state for on-change type of properties.
-     * @param device
-     * @param prop
-     * @param sample_rate
-     * @param zones All subscribed zones for zoned property. can be ignored for non-zoned property.
-     *              0 means all zones supported instead of no zone.
-     */
-    int (*subscribe)(struct vehicle_hw_device* device, int32_t prop, float sample_rate,
-            int32_t zones);
-
-    /** Cancel subscription on a property. */
-    int (*unsubscribe)(struct vehicle_hw_device* device, int32_t prop);
-
-    /**
-     * Print out debugging state for the vehicle hal. This will be called by
-     * the vehicle network service and will be included into the service' dump.
-     *
-     * The passed-in file descriptor can be used to write debugging text using
-     * dprintf() or write(). The text should be in ASCII encoding only.
-     *
-     * Performance requirements:
-     *
-     * This must be a non-blocking call. The HAL should return from this call
-     * in 1ms, must return from this call in 10ms. This call must avoid
-     * deadlocks, as it may be called at any point of operation.
-     * Any synchronization primitives used (such as mutex locks or semaphores)
-     * should be acquired with a timeout.
-     */
-    int (*dump)(struct vehicle_hw_device* device, int fd);
-
-} vehicle_hw_device_t;
-
-__END_DECLS
-
-#endif  // ANDROID_VEHICLE_INTERFACE_H
diff --git a/modules/audio/audio_hw.c b/modules/audio/audio_hw.c
index 8f73f11..041cd47 100644
--- a/modules/audio/audio_hw.c
+++ b/modules/audio/audio_hw.c
@@ -32,6 +32,15 @@
 #include <hardware/hardware.h>
 #include <system/audio.h>
 
+#define STUB_DEFAULT_SAMPLE_RATE   48000
+#define STUB_DEFAULT_AUDIO_FORMAT  AUDIO_FORMAT_PCM_16_BIT
+
+#define STUB_INPUT_BUFFER_MILLISECONDS  20
+#define STUB_INPUT_DEFAULT_CHANNEL_MASK AUDIO_CHANNEL_IN_STEREO
+
+#define STUB_OUTPUT_BUFFER_MILLISECONDS  10
+#define STUB_OUTPUT_DEFAULT_CHANNEL_MASK AUDIO_CHANNEL_OUT_STEREO
+
 struct stub_audio_device {
     struct audio_hw_device device;
 };
@@ -39,46 +48,71 @@
 struct stub_stream_out {
     struct audio_stream_out stream;
     int64_t last_write_time_us;
+    uint32_t sample_rate;
+    audio_channel_mask_t channel_mask;
+    audio_format_t format;
+    size_t frame_count;
 };
 
 struct stub_stream_in {
     struct audio_stream_in stream;
     int64_t last_read_time_us;
+    uint32_t sample_rate;
+    audio_channel_mask_t channel_mask;
+    audio_format_t format;
+    size_t frame_count;
 };
 
 static uint32_t out_get_sample_rate(const struct audio_stream *stream)
 {
-    return 44100;
+    const struct stub_stream_out *out = (const struct stub_stream_out *)stream;
+
+    ALOGV("out_get_sample_rate: %u", out->sample_rate);
+    return out->sample_rate;
 }
 
 static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
 {
-    ALOGV("out_set_sample_rate: %d", 0);
-    return -ENOSYS;
+    struct stub_stream_out *out = (struct stub_stream_out *)stream;
+
+    ALOGV("out_set_sample_rate: %d", rate);
+    out->sample_rate = rate;
+    return 0;
 }
 
 static size_t out_get_buffer_size(const struct audio_stream *stream)
 {
-    ALOGV("out_get_buffer_size: %d", 4096);
-    return 4096;
+    const struct stub_stream_out *out = (const struct stub_stream_out *)stream;
+    size_t buffer_size = out->frame_count *
+                         audio_stream_out_frame_size(&out->stream);
+
+    ALOGV("out_get_buffer_size: %zu", buffer_size);
+    return buffer_size;
 }
 
 static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
 {
-    ALOGV("out_get_channels");
-    return AUDIO_CHANNEL_OUT_STEREO;
+    const struct stub_stream_out *out = (const struct stub_stream_out *)stream;
+
+    ALOGV("out_get_channels: %x", out->channel_mask);
+    return out->channel_mask;
 }
 
 static audio_format_t out_get_format(const struct audio_stream *stream)
 {
-    ALOGV("out_get_format");
-    return AUDIO_FORMAT_PCM_16_BIT;
+    const struct stub_stream_out *out = (const struct stub_stream_out *)stream;
+
+    ALOGV("out_get_format: %d", out->format);
+    return out->format;
 }
 
 static int out_set_format(struct audio_stream *stream, audio_format_t format)
 {
-    ALOGV("out_set_format: %d",format);
-    return -ENOSYS;
+    struct stub_stream_out *out = (struct stub_stream_out *)stream;
+
+    ALOGV("out_set_format: %d", format);
+    out->format = format;
+    return 0;
 }
 
 static int out_standby(struct audio_stream *stream)
@@ -109,7 +143,7 @@
 static uint32_t out_get_latency(const struct audio_stream_out *stream)
 {
     ALOGV("out_get_latency");
-    return 0;
+    return STUB_OUTPUT_BUFFER_MILLISECONDS;
 }
 
 static int out_set_volume(struct audio_stream_out *stream, float left,
@@ -182,36 +216,54 @@
 /** audio_stream_in implementation **/
 static uint32_t in_get_sample_rate(const struct audio_stream *stream)
 {
-    ALOGV("in_get_sample_rate");
-    return 8000;
+    const struct stub_stream_in *in = (const struct stub_stream_in *)stream;
+
+    ALOGV("in_get_sample_rate: %u", in->sample_rate);
+    return in->sample_rate;
 }
 
 static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
 {
-    ALOGV("in_set_sample_rate: %d", rate);
-    return -ENOSYS;
+    struct stub_stream_in *in = (struct stub_stream_in *)stream;
+
+    ALOGV("in_set_sample_rate: %u", rate);
+    in->sample_rate = rate;
+    return 0;
 }
 
 static size_t in_get_buffer_size(const struct audio_stream *stream)
 {
-    ALOGV("in_get_buffer_size: %d", 320);
-    return 320;
+    const struct stub_stream_in *in = (const struct stub_stream_in *)stream;
+    size_t buffer_size = in->frame_count *
+                         audio_stream_in_frame_size(&in->stream);
+
+    ALOGV("in_get_buffer_size: %zu", buffer_size);
+    return buffer_size;
 }
 
 static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
 {
-    ALOGV("in_get_channels: %d", AUDIO_CHANNEL_IN_MONO);
-    return AUDIO_CHANNEL_IN_MONO;
+    const struct stub_stream_in *in = (const struct stub_stream_in *)stream;
+
+    ALOGV("in_get_channels: %x", in->channel_mask);
+    return in->channel_mask;
 }
 
 static audio_format_t in_get_format(const struct audio_stream *stream)
 {
-    return AUDIO_FORMAT_PCM_16_BIT;
+    const struct stub_stream_in *in = (const struct stub_stream_in *)stream;
+
+    ALOGV("in_get_format: %d", in->format);
+    return in->format;
 }
 
 static int in_set_format(struct audio_stream *stream, audio_format_t format)
 {
-    return -ENOSYS;
+    struct stub_stream_in *in = (struct stub_stream_in *)stream;
+
+    ALOGV("in_set_format: %d", format);
+    in->format = format;
+    return 0;
 }
 
 static int in_standby(struct audio_stream *stream)
@@ -290,6 +342,13 @@
     return 0;
 }
 
+static size_t samples_per_milliseconds(size_t milliseconds,
+                                       uint32_t sample_rate,
+                                       size_t channel_count)
+{
+    return milliseconds * sample_rate * channel_count / 1000;
+}
+
 static int adev_open_output_stream(struct audio_hw_device *dev,
                                    audio_io_handle_t handle,
                                    audio_devices_t devices,
@@ -323,7 +382,22 @@
     out->stream.write = out_write;
     out->stream.get_render_position = out_get_render_position;
     out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
+    out->sample_rate = config->sample_rate;
+    if (out->sample_rate == 0)
+        out->sample_rate = STUB_DEFAULT_SAMPLE_RATE;
+    out->channel_mask = config->channel_mask;
+    if (out->channel_mask == AUDIO_CHANNEL_NONE)
+        out->channel_mask = STUB_OUTPUT_DEFAULT_CHANNEL_MASK;
+    out->format = config->format;
+    if (out->format == AUDIO_FORMAT_DEFAULT)
+        out->format = STUB_DEFAULT_AUDIO_FORMAT;
+    out->frame_count = samples_per_milliseconds(
+                           STUB_OUTPUT_BUFFER_MILLISECONDS,
+                           out->sample_rate, 1);
 
+    ALOGV("adev_open_output_stream: sample_rate: %u, channels: %x, format: %d,"
+          " frames: %zu", out->sample_rate, out->channel_mask, out->format,
+          out->frame_count);
     *stream_out = &out->stream;
     return 0;
 }
@@ -405,8 +479,21 @@
 static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
                                          const struct audio_config *config)
 {
-    ALOGV("adev_get_input_buffer_size: %d", 320);
-    return 320;
+    size_t buffer_size = samples_per_milliseconds(
+                             STUB_INPUT_BUFFER_MILLISECONDS,
+                             config->sample_rate,
+                             audio_channel_count_from_in_mask(
+                                 config->channel_mask));
+
+    if (!audio_has_proportional_frames(config->format)) {
+        // Since the audio data is not proportional choose an arbitrary size for
+        // the buffer.
+        buffer_size *= 4;
+    } else {
+        buffer_size *= audio_bytes_per_sample(config->format);
+    }
+    ALOGV("adev_get_input_buffer_size: %zu", buffer_size);
+    return buffer_size;
 }
 
 static int adev_open_input_stream(struct audio_hw_device *dev,
@@ -440,7 +527,21 @@
     in->stream.set_gain = in_set_gain;
     in->stream.read = in_read;
     in->stream.get_input_frames_lost = in_get_input_frames_lost;
+    in->sample_rate = config->sample_rate;
+    if (in->sample_rate == 0)
+        in->sample_rate = STUB_DEFAULT_SAMPLE_RATE;
+    in->channel_mask = config->channel_mask;
+    if (in->channel_mask == AUDIO_CHANNEL_NONE)
+        in->channel_mask = STUB_INPUT_DEFAULT_CHANNEL_MASK;
+    in->format = config->format;
+    if (in->format == AUDIO_FORMAT_DEFAULT)
+        in->format = STUB_DEFAULT_AUDIO_FORMAT;
+    in->frame_count = samples_per_milliseconds(
+                          STUB_INPUT_BUFFER_MILLISECONDS, in->sample_rate, 1);
 
+    ALOGV("adev_open_input_stream: sample_rate: %u, channels: %x, format: %d,"
+          "frames: %zu", in->sample_rate, in->channel_mask, in->format,
+          in->frame_count);
     *stream_in = &in->stream;
     return 0;
 }
diff --git a/modules/audio_remote_submix/audio_hw.cpp b/modules/audio_remote_submix/audio_hw.cpp
index eb6ae92..8c0c097 100644
--- a/modules/audio_remote_submix/audio_hw.cpp
+++ b/modules/audio_remote_submix/audio_hw.cpp
@@ -52,9 +52,9 @@
 
 namespace android {
 
-// Set to 1 to enable extremely verbose logging in this module.
-#define SUBMIX_VERBOSE_LOGGING 0
-#if SUBMIX_VERBOSE_LOGGING
+// Uncomment to enable extremely verbose logging in this module.
+// #define SUBMIX_VERBOSE_LOGGING
+#if defined(SUBMIX_VERBOSE_LOGGING)
 #define SUBMIX_ALOGV(...) ALOGV(__VA_ARGS__)
 #define SUBMIX_ALOGE(...) ALOGE(__VA_ARGS__)
 #else
@@ -205,7 +205,7 @@
     int log_fd;
 #endif // LOG_STREAMS_TO_FILES
 
-    volatile int16_t read_error_count;
+    volatile uint16_t read_error_count;
 };
 
 // Determine whether the specified sample rate is supported by the submix module.
@@ -467,11 +467,9 @@
             rsxadev->routes[route_idx].address);
     if (rsxadev->routes[route_idx].rsxSink != 0) {
         rsxadev->routes[route_idx].rsxSink.clear();
-        rsxadev->routes[route_idx].rsxSink = 0;
     }
     if (rsxadev->routes[route_idx].rsxSource != 0) {
         rsxadev->routes[route_idx].rsxSource.clear();
-        rsxadev->routes[route_idx].rsxSource = 0;
     }
     memset(rsxadev->routes[route_idx].address, 0, AUDIO_DEVICE_MAX_ADDRESS_LEN);
 #ifdef ENABLE_RESAMPLING
@@ -816,8 +814,8 @@
             static uint8_t flush_buffer[64];
             const size_t flushBufferSizeFrames = sizeof(flush_buffer) / frame_size;
             size_t frames_to_flush_from_source = frames - availableToWrite;
-            SUBMIX_ALOGV("out_write(): flushing %d frames from the pipe to avoid blocking",
-                         frames_to_flush_from_source);
+            SUBMIX_ALOGV("out_write(): flushing %llu frames from the pipe to avoid blocking",
+                    (unsigned long long)frames_to_flush_from_source);
             while (frames_to_flush_from_source) {
                 const size_t flush_size = min(frames_to_flush_from_source, flushBufferSizeFrames);
                 frames_to_flush_from_source -= flush_size;
@@ -898,7 +896,8 @@
     }
 
     SUBMIX_ALOGV("out_get_presentation_position() got frames=%llu timestamp sec=%llu",
-            frames ? *frames : -1, timestamp ? timestamp->tv_sec : -1);
+            frames ? (unsigned long long)*frames : -1ULL,
+            timestamp ? (unsigned long long)timestamp->tv_sec : -1ULL);
 
     return ret;
 }
@@ -1541,7 +1540,7 @@
                 audio_bytes_per_sample(config->format);
         const size_t buffer_size = max_buffer_period_size_frames * frame_size_in_bytes;
         SUBMIX_ALOGV("adev_get_input_buffer_size() returns %zu bytes, %zu frames",
-                 buffer_size, buffer_period_size_frames);
+                 buffer_size, max_buffer_period_size_frames);
         return buffer_size;
     }
     return 0;
@@ -1692,10 +1691,10 @@
                     reinterpret_cast<const uint8_t *>(device) -
                             offsetof(struct submix_audio_device, device));
     char msg[100];
-    int n = sprintf(msg, "\nReroute submix audio module:\n");
+    int n = snprintf(msg, sizeof(msg), "\nReroute submix audio module:\n");
     write(fd, &msg, n);
     for (int i=0 ; i < MAX_ROUTES ; i++) {
-        n = sprintf(msg, " route[%d] rate in=%d out=%d, addr=[%s]\n", i,
+        n = snprintf(msg, sizeof(msg), " route[%d] rate in=%d out=%d, addr=[%s]\n", i,
                 rsxadev->routes[i].config.input_sample_rate,
                 rsxadev->routes[i].config.output_sample_rate,
                 rsxadev->routes[i].address);
diff --git a/modules/vehicle/Android.bp b/modules/audio_remote_submix/tests/Android.bp
similarity index 64%
rename from modules/vehicle/Android.bp
rename to modules/audio_remote_submix/tests/Android.bp
index cb0406a..8e4d42d 100644
--- a/modules/vehicle/Android.bp
+++ b/modules/audio_remote_submix/tests/Android.bp
@@ -1,4 +1,4 @@
-// Copyright (C) 2012 The Android Open Source Project
+// Copyright (C) 2018 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.
@@ -12,23 +12,18 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-cc_library_shared {
-    name: "vehicle.default",
+cc_test {
+    name: "r_submix_tests",
 
-    relative_install_path: "hw",
-    vendor: true,
-    srcs: [
-        "vehicle.c",
-        "timeUtil.cpp",
-    ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    header_libs: ["libhardware_headers"],
+    srcs: ["remote_submix_tests.cpp"],
+
     shared_libs: [
+        "libhardware",
         "liblog",
-        "libcutils",
         "libutils",
     ],
+
+    cflags: ["-Wall", "-Werror", "-O0", "-g",],
+
+    header_libs: ["libaudiohal_headers"],
 }
diff --git a/modules/audio_remote_submix/tests/remote_submix_tests.cpp b/modules/audio_remote_submix/tests/remote_submix_tests.cpp
new file mode 100644
index 0000000..2c01c92
--- /dev/null
+++ b/modules/audio_remote_submix/tests/remote_submix_tests.cpp
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+// To run this test (as root):
+// 1) Build it
+// 2) adb push to /vendor/bin
+// 3) adb shell /vendor/bin/r_submix_tests
+
+#define LOG_TAG "RemoteSubmixTest"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+#include <hardware/audio.h>
+#include <utils/Errors.h>
+#include <utils/Log.h>
+
+using namespace android;
+
+static status_t load_audio_interface(const char* if_name, audio_hw_device_t **dev)
+{
+    const hw_module_t *mod;
+    int rc;
+
+    rc = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, if_name, &mod);
+    if (rc) {
+        ALOGE("%s couldn't load audio hw module %s.%s (%s)", __func__,
+                AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
+        goto out;
+    }
+    rc = audio_hw_device_open(mod, dev);
+    if (rc) {
+        ALOGE("%s couldn't open audio hw device in %s.%s (%s)", __func__,
+                AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc));
+        goto out;
+    }
+    if ((*dev)->common.version < AUDIO_DEVICE_API_VERSION_MIN) {
+        ALOGE("%s wrong audio hw device version %04x", __func__, (*dev)->common.version);
+        rc = BAD_VALUE;
+        audio_hw_device_close(*dev);
+        goto out;
+    }
+    return OK;
+
+out:
+    *dev = NULL;
+    return rc;
+}
+
+class RemoteSubmixTest : public testing::Test {
+  protected:
+    void SetUp() override;
+    void TearDown() override;
+
+    void GenerateData(char* buffer, size_t bufferSize);
+    void OpenInputStream(
+            const char* address, bool mono, uint32_t sampleRate, audio_stream_in_t** streamIn);
+    void OpenOutputStream(
+            const char* address, bool mono, uint32_t sampleRate, audio_stream_out_t** streamOut);
+    void ReadFromStream(audio_stream_in_t* streamIn, char* buffer, size_t bufferSize);
+    void VerifyBufferAllZeroes(char* buffer, size_t bufferSize);
+    void VerifyBufferNotZeroes(char* buffer, size_t bufferSize);
+    void VerifyOutputInput(
+        audio_stream_out_t* streamOut, size_t outBufferSize,
+        audio_stream_in_t* streamIn, size_t inBufferSize, size_t repeats);
+    void WriteIntoStream(audio_stream_out_t* streamOut, const char* buffer, size_t bufferSize);
+    void WriteSomethingIntoStream(audio_stream_out_t* streamOut, size_t bufferSize, size_t repeats);
+
+    audio_hw_device_t* mDev;
+};
+
+void RemoteSubmixTest::SetUp() {
+    mDev = nullptr;
+    ASSERT_EQ(OK, load_audio_interface(AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX, &mDev));
+    ASSERT_NE(nullptr, mDev);
+}
+
+void RemoteSubmixTest::TearDown() {
+    if (mDev != nullptr) {
+        int status = audio_hw_device_close(mDev);
+        mDev = nullptr;
+        ALOGE_IF(status, "Error closing audio hw device %p: %s", mDev, strerror(-status));
+        ASSERT_EQ(0, status);
+    }
+}
+
+void RemoteSubmixTest::GenerateData(char* buffer, size_t bufferSize) {
+    for (size_t i = 0; i < bufferSize; ++i) {
+        buffer[i] = static_cast<char>(i & 0x7f);
+    }
+}
+
+void RemoteSubmixTest::OpenInputStream(
+        const char* address, bool mono, uint32_t sampleRate, audio_stream_in_t** streamIn) {
+    *streamIn = nullptr;
+    struct audio_config configIn = {};
+    configIn.channel_mask = mono ? AUDIO_CHANNEL_IN_MONO : AUDIO_CHANNEL_IN_STEREO;
+    configIn.sample_rate = sampleRate;
+    status_t result = mDev->open_input_stream(mDev,
+            AUDIO_IO_HANDLE_NONE, AUDIO_DEVICE_NONE, &configIn,
+            streamIn, AUDIO_INPUT_FLAG_NONE, address, AUDIO_SOURCE_DEFAULT);
+    ASSERT_EQ(OK, result);
+    ASSERT_NE(nullptr, *streamIn);
+}
+
+void RemoteSubmixTest::OpenOutputStream(
+        const char* address, bool mono, uint32_t sampleRate, audio_stream_out_t** streamOut) {
+    *streamOut = nullptr;
+    struct audio_config configOut = {};
+    configOut.channel_mask = mono ? AUDIO_CHANNEL_OUT_MONO : AUDIO_CHANNEL_OUT_STEREO;
+    configOut.sample_rate = sampleRate;
+    status_t result = mDev->open_output_stream(mDev,
+            AUDIO_IO_HANDLE_NONE, AUDIO_DEVICE_NONE, AUDIO_OUTPUT_FLAG_NONE,
+            &configOut, streamOut, address);
+    ASSERT_EQ(OK, result);
+    ASSERT_NE(nullptr, *streamOut);
+}
+
+void RemoteSubmixTest::ReadFromStream(
+        audio_stream_in_t* streamIn, char* buffer, size_t bufferSize) {
+    ssize_t result = streamIn->read(streamIn, buffer, bufferSize);
+    EXPECT_EQ(bufferSize, static_cast<size_t>(result));
+}
+
+void RemoteSubmixTest::VerifyBufferAllZeroes(char* buffer, size_t bufferSize) {
+    for (size_t i = 0; i < bufferSize; ++i) {
+        if (buffer[i]) {
+            ADD_FAILURE();
+            return;
+        }
+    }
+}
+
+void RemoteSubmixTest::VerifyBufferNotZeroes(char* buffer, size_t bufferSize) {
+    for (size_t i = 0; i < bufferSize; ++i) {
+        if (buffer[i]) return;
+    }
+    ADD_FAILURE();
+}
+
+void RemoteSubmixTest::VerifyOutputInput(
+        audio_stream_out_t* streamOut, size_t outBufferSize,
+        audio_stream_in_t* streamIn, size_t inBufferSize,
+        size_t repeats) {
+    std::unique_ptr<char[]> outBuffer(new char[outBufferSize]), inBuffer(new char[inBufferSize]);
+    GenerateData(outBuffer.get(), outBufferSize);
+    for (size_t i = 0; i < repeats; ++i) {
+        WriteIntoStream(streamOut, outBuffer.get(), outBufferSize);
+        memset(inBuffer.get(), 0, inBufferSize);
+        ReadFromStream(streamIn, inBuffer.get(), inBufferSize);
+        if (inBufferSize == outBufferSize) {
+            ASSERT_EQ(0, memcmp(outBuffer.get(), inBuffer.get(), inBufferSize));
+        } else {
+            VerifyBufferNotZeroes(inBuffer.get(), inBufferSize);
+        }
+    }
+}
+
+void RemoteSubmixTest::WriteIntoStream(
+        audio_stream_out_t* streamOut, const char* buffer, size_t bufferSize) {
+    ssize_t result = streamOut->write(streamOut, buffer, bufferSize);
+    EXPECT_EQ(bufferSize, static_cast<size_t>(result));
+}
+
+void RemoteSubmixTest::WriteSomethingIntoStream(
+        audio_stream_out_t* streamOut, size_t bufferSize, size_t repeats) {
+    std::unique_ptr<char[]> buffer(new char[bufferSize]);
+    GenerateData(buffer.get(), bufferSize);
+    for (size_t i = 0; i < repeats; ++i) {
+        WriteIntoStream(streamOut, buffer.get(), bufferSize);
+    }
+}
+
+TEST_F(RemoteSubmixTest, InitSuccess) {
+    // SetUp must finish with no assertions.
+}
+
+// Verifies that when no input was opened, writing into an output stream does not block.
+TEST_F(RemoteSubmixTest, OutputDoesNotBlockWhenNoInput) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    WriteSomethingIntoStream(streamOut, 1024, 16);
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// Verifies that when input is opened but not reading, writing into an output stream does not block.
+// !!! Currently does not finish because requires setting a parameter from another thread !!!
+// TEST_F(RemoteSubmixTest, OutputDoesNotBlockWhenInputStuck) {
+//     const char* address = "1";
+//     audio_stream_out_t* streamOut;
+//     OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+//     audio_stream_in_t* streamIn;
+//     OpenInputStream(address, true /*mono*/, 48000, &streamIn);
+//     WriteSomethingIntoStream(streamOut, 1024, 16);
+//     mDev->close_input_stream(mDev, streamIn);
+//     mDev->close_output_stream(mDev, streamOut);
+// }
+
+TEST_F(RemoteSubmixTest, OutputAndInput) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    audio_stream_in_t* streamIn;
+    OpenInputStream(address, true /*mono*/, 48000, &streamIn);
+    const size_t bufferSize = 1024;
+    VerifyOutputInput(streamOut, bufferSize, streamIn, bufferSize, 16);
+    mDev->close_input_stream(mDev, streamIn);
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// Verifies that reading and writing into a closed stream fails gracefully.
+TEST_F(RemoteSubmixTest, OutputAndInputAfterClose) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    audio_stream_in_t* streamIn;
+    OpenInputStream(address, true /*mono*/, 48000, &streamIn);
+    mDev->close_input_stream(mDev, streamIn);
+    mDev->close_output_stream(mDev, streamOut);
+    const size_t bufferSize = 1024;
+    std::unique_ptr<char[]> buffer(new char[bufferSize]);
+    memset(buffer.get(), 0, bufferSize);
+    ASSERT_EQ(0, streamOut->write(streamOut, buffer.get(), bufferSize));
+    ASSERT_EQ(static_cast<ssize_t>(bufferSize), streamIn->read(streamIn, buffer.get(), bufferSize));
+    VerifyBufferAllZeroes(buffer.get(), bufferSize);
+}
+
+TEST_F(RemoteSubmixTest, PresentationPosition) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    uint64_t frames;
+    struct timespec timestamp;
+    EXPECT_EQ(0, streamOut->get_presentation_position(streamOut, &frames, &timestamp));
+    EXPECT_EQ(uint64_t{0}, frames);
+    uint64_t prevFrames = frames;
+    for (size_t i = 0; i < 16; ++i) {
+        WriteSomethingIntoStream(streamOut, 1024, 1);
+        EXPECT_EQ(0, streamOut->get_presentation_position(streamOut, &frames, &timestamp));
+        EXPECT_LE(prevFrames, frames);
+        prevFrames = frames;
+    }
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+TEST_F(RemoteSubmixTest, RenderPosition) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    uint32_t frames;
+    EXPECT_EQ(0, streamOut->get_render_position(streamOut, &frames));
+    EXPECT_EQ(0U, frames);
+    uint32_t prevFrames = frames;
+    for (size_t i = 0; i < 16; ++i) {
+        WriteSomethingIntoStream(streamOut, 1024, 1);
+        EXPECT_EQ(0, streamOut->get_render_position(streamOut, &frames));
+        EXPECT_LE(prevFrames, frames);
+        prevFrames = frames;
+    }
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// This requires ENABLE_CHANNEL_CONVERSION to be set in the HAL module
+TEST_F(RemoteSubmixTest, MonoToStereoConversion) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    audio_stream_in_t* streamIn;
+    OpenInputStream(address, false /*mono*/, 48000, &streamIn);
+    const size_t bufferSize = 1024;
+    VerifyOutputInput(streamOut, bufferSize, streamIn, bufferSize * 2, 16);
+    mDev->close_input_stream(mDev, streamIn);
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// This requires ENABLE_CHANNEL_CONVERSION to be set in the HAL module
+TEST_F(RemoteSubmixTest, StereoToMonoConversion) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, false /*mono*/, 48000, &streamOut);
+    audio_stream_in_t* streamIn;
+    OpenInputStream(address, true /*mono*/, 48000, &streamIn);
+    const size_t bufferSize = 1024;
+    VerifyOutputInput(streamOut, bufferSize * 2, streamIn, bufferSize, 16);
+    mDev->close_input_stream(mDev, streamIn);
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// This requires ENABLE_RESAMPLING to be set in the HAL module
+TEST_F(RemoteSubmixTest, OutputAndInputResampling) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    audio_stream_in_t* streamIn;
+    OpenInputStream(address, true /*mono*/, 24000, &streamIn);
+    const size_t bufferSize = 1024;
+    VerifyOutputInput(streamOut, bufferSize * 2, streamIn, bufferSize, 16);
+    mDev->close_input_stream(mDev, streamIn);
+    mDev->close_output_stream(mDev, streamOut);
+}
+
+// This requires ENABLE_LEGACY_INPUT_OPEN to be set in the HAL module
+TEST_F(RemoteSubmixTest, OpenInputMultipleTimes) {
+    const char* address = "1";
+    audio_stream_out_t* streamOut;
+    OpenOutputStream(address, true /*mono*/, 48000, &streamOut);
+    const size_t streamInCount = 3;
+    audio_stream_in_t* streamIn[streamInCount];
+    for (size_t i = 0; i < streamInCount; ++i) {
+        OpenInputStream(address, true /*mono*/, 48000, &streamIn[i]);
+    }
+    const size_t bufferSize = 1024;
+    for (size_t i = 0; i < streamInCount; ++i) {
+        VerifyOutputInput(streamOut, bufferSize, streamIn[i], bufferSize, 16);
+        mDev->close_input_stream(mDev, streamIn[i]);
+    }
+    mDev->close_output_stream(mDev, streamOut);
+}
diff --git a/modules/camera/3_4/Android.mk b/modules/camera/3_4/Android.mk
index 05ddf5a..6ecedac 100644
--- a/modules/camera/3_4/Android.mk
+++ b/modules/camera/3_4/Android.mk
@@ -22,21 +22,31 @@
 
 v4l2_shared_libs := \
   libbase \
+  libchrome \
   libcamera_client \
   libcamera_metadata \
   libcutils \
+  libexif \
   libhardware \
   liblog \
   libsync \
   libutils \
 
-v4l2_static_libs :=
+v4l2_static_libs := \
+  libyuv_static \
+  libjpeg_static_ndk \
 
-v4l2_cflags := -fno-short-enums -Wall -Wno-error -Wextra -fvisibility=hidden
+v4l2_cflags := -fno-short-enums -Wall -Wno-error -Wextra -fvisibility=hidden -DHAVE_JPEG
 
-v4l2_c_includes := $(call include-path-for, camera)
+v4l2_c_includes := $(call include-path-for, camera) \
+  external/libyuv/files/include \
 
 v4l2_src_files := \
+  arc/cached_frame.cpp \
+  arc/exif_utils.cpp \
+  arc/frame_buffer.cpp \
+  arc/image_processor.cpp \
+  arc/jpeg_compressor.cpp \
   camera.cpp \
   capture_request.cpp \
   format_metadata_factory.cpp \
@@ -49,7 +59,6 @@
   stream_format.cpp \
   v4l2_camera.cpp \
   v4l2_camera_hal.cpp \
-  v4l2_gralloc.cpp \
   v4l2_metadata_factory.cpp \
   v4l2_wrapper.cpp \
 
diff --git a/modules/camera/3_4/README.md b/modules/camera/3_4/README.md
index 73d0c13..168ba97 100644
--- a/modules/camera/3_4/README.md
+++ b/modules/camera/3_4/README.md
@@ -146,6 +146,3 @@
 
 * A variety of features are unimplemented: High speed capture,
 flash torch mode, hotplugging/unplugging.
-* The HAL uses BGR for RGBA. Again, the HAL was designed for the Raspberry Pi
-camera, which doesn't support RGB, but RGB is a common default format for
-graphics stacks.
diff --git a/modules/camera/3_4/arc/cached_frame.cpp b/modules/camera/3_4/arc/cached_frame.cpp
new file mode 100644
index 0000000..0489be8
--- /dev/null
+++ b/modules/camera/3_4/arc/cached_frame.cpp
@@ -0,0 +1,218 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "arc/cached_frame.h"
+
+#include <errno.h>
+#include <libyuv.h>
+
+#include "arc/common.h"
+#include "arc/common_types.h"
+
+namespace arc {
+
+using android::CameraMetadata;
+
+CachedFrame::CachedFrame()
+    : source_frame_(nullptr),
+      cropped_buffer_capacity_(0),
+      yu12_frame_(new AllocatedFrameBuffer(0)) {}
+
+CachedFrame::~CachedFrame() { UnsetSource(); }
+
+int CachedFrame::SetSource(const FrameBuffer* frame, int rotate_degree) {
+  source_frame_ = frame;
+  int res = ConvertToYU12();
+  if (res != 0) {
+    return res;
+  }
+
+  if (rotate_degree > 0) {
+    res = CropRotateScale(rotate_degree);
+  }
+  return res;
+}
+
+void CachedFrame::UnsetSource() { source_frame_ = nullptr; }
+
+uint8_t* CachedFrame::GetSourceBuffer() const {
+  return source_frame_->GetData();
+}
+
+size_t CachedFrame::GetSourceDataSize() const {
+  return source_frame_->GetDataSize();
+}
+
+uint32_t CachedFrame::GetSourceFourCC() const {
+  return source_frame_->GetFourcc();
+}
+
+uint8_t* CachedFrame::GetCachedBuffer() const { return yu12_frame_->GetData(); }
+
+uint32_t CachedFrame::GetCachedFourCC() const {
+  return yu12_frame_->GetFourcc();
+}
+
+uint32_t CachedFrame::GetWidth() const { return yu12_frame_->GetWidth(); }
+
+uint32_t CachedFrame::GetHeight() const { return yu12_frame_->GetHeight(); }
+
+size_t CachedFrame::GetConvertedSize(int fourcc) const {
+  return ImageProcessor::GetConvertedSize(fourcc, yu12_frame_->GetWidth(),
+                                          yu12_frame_->GetHeight());
+}
+
+int CachedFrame::Convert(const CameraMetadata& metadata, FrameBuffer* out_frame,
+                         bool video_hack) {
+  if (video_hack && out_frame->GetFourcc() == V4L2_PIX_FMT_YVU420) {
+    out_frame->SetFourcc(V4L2_PIX_FMT_YUV420);
+  }
+
+  FrameBuffer* source_frame = yu12_frame_.get();
+  if (GetWidth() != out_frame->GetWidth() ||
+      GetHeight() != out_frame->GetHeight()) {
+    size_t cache_size = ImageProcessor::GetConvertedSize(
+        yu12_frame_->GetFourcc(), out_frame->GetWidth(),
+        out_frame->GetHeight());
+    if (cache_size == 0) {
+      return -EINVAL;
+    } else if (cache_size > scaled_frame_->GetBufferSize()) {
+      scaled_frame_.reset(new AllocatedFrameBuffer(cache_size));
+    }
+    scaled_frame_->SetWidth(out_frame->GetWidth());
+    scaled_frame_->SetHeight(out_frame->GetHeight());
+    ImageProcessor::Scale(*yu12_frame_.get(), scaled_frame_.get());
+
+    source_frame = scaled_frame_.get();
+  }
+  return ImageProcessor::ConvertFormat(metadata, *source_frame, out_frame);
+}
+
+int CachedFrame::ConvertToYU12() {
+  size_t cache_size = ImageProcessor::GetConvertedSize(
+      V4L2_PIX_FMT_YUV420, source_frame_->GetWidth(),
+      source_frame_->GetHeight());
+  if (cache_size == 0) {
+    return -EINVAL;
+  }
+  yu12_frame_->SetDataSize(cache_size);
+  yu12_frame_->SetFourcc(V4L2_PIX_FMT_YUV420);
+  yu12_frame_->SetWidth(source_frame_->GetWidth());
+  yu12_frame_->SetHeight(source_frame_->GetHeight());
+
+  int res = ImageProcessor::ConvertFormat(CameraMetadata(), *source_frame_,
+                                          yu12_frame_.get());
+  if (res) {
+    LOGF(ERROR) << "Convert from " << FormatToString(source_frame_->GetFourcc())
+                << " to YU12 fails.";
+    return res;
+  }
+  return 0;
+}
+
+int CachedFrame::CropRotateScale(int rotate_degree) {
+  // TODO(henryhsu): Move libyuv part to ImageProcessor.
+  if (yu12_frame_->GetHeight() % 2 != 0 || yu12_frame_->GetWidth() % 2 != 0) {
+    LOGF(ERROR) << "yu12_frame_ has odd dimension: " << yu12_frame_->GetWidth()
+                << "x" << yu12_frame_->GetHeight();
+    return -EINVAL;
+  }
+
+  if (yu12_frame_->GetHeight() > yu12_frame_->GetWidth()) {
+    LOGF(ERROR) << "yu12_frame_ is tall frame already: "
+                << yu12_frame_->GetWidth() << "x" << yu12_frame_->GetHeight();
+    return -EINVAL;
+  }
+
+  // Step 1: Crop and rotate
+  //
+  //   Original frame                  Cropped frame              Rotated frame
+  // --------------------               --------
+  // |     |      |     |               |      |                 ---------------
+  // |     |      |     |               |      |                 |             |
+  // |     |      |     |   =======>>   |      |     =======>>   |             |
+  // |     |      |     |               |      |                 ---------------
+  // |     |      |     |               |      |
+  // --------------------               --------
+  //
+  int cropped_width = yu12_frame_->GetHeight() * yu12_frame_->GetHeight() /
+                      yu12_frame_->GetWidth();
+  if (cropped_width % 2 == 1) {
+    // Make cropped_width to the closest even number.
+    cropped_width++;
+  }
+  int cropped_height = yu12_frame_->GetHeight();
+  int margin = (yu12_frame_->GetWidth() - cropped_width) / 2;
+
+  int rotated_height = cropped_width;
+  int rotated_width = cropped_height;
+
+  int rotated_y_stride = rotated_width;
+  int rotated_uv_stride = rotated_width / 2;
+  size_t rotated_size =
+      rotated_y_stride * rotated_height + rotated_uv_stride * rotated_height;
+  if (rotated_size > cropped_buffer_capacity_) {
+    cropped_buffer_.reset(new uint8_t[rotated_size]);
+    cropped_buffer_capacity_ = rotated_size;
+  }
+  uint8_t* rotated_y_plane = cropped_buffer_.get();
+  uint8_t* rotated_u_plane =
+      rotated_y_plane + rotated_y_stride * rotated_height;
+  uint8_t* rotated_v_plane =
+      rotated_u_plane + rotated_uv_stride * rotated_height / 2;
+  libyuv::RotationMode rotation_mode = libyuv::RotationMode::kRotate90;
+  switch (rotate_degree) {
+    case 90:
+      rotation_mode = libyuv::RotationMode::kRotate90;
+      break;
+    case 270:
+      rotation_mode = libyuv::RotationMode::kRotate270;
+      break;
+    default:
+      LOGF(ERROR) << "Invalid rotation degree: " << rotate_degree;
+      return -EINVAL;
+  }
+  // This libyuv method first crops the frame and then rotates it 90 degrees
+  // clockwise.
+  int res = libyuv::ConvertToI420(
+      yu12_frame_->GetData(), yu12_frame_->GetDataSize(), rotated_y_plane,
+      rotated_y_stride, rotated_u_plane, rotated_uv_stride, rotated_v_plane,
+      rotated_uv_stride, margin, 0, yu12_frame_->GetWidth(),
+      yu12_frame_->GetHeight(), cropped_width, cropped_height, rotation_mode,
+      libyuv::FourCC::FOURCC_I420);
+
+  if (res) {
+    LOGF(ERROR) << "ConvertToI420 failed: " << res;
+    return res;
+  }
+
+  // Step 2: Scale
+  //
+  //                               Final frame
+  //  Rotated frame            ---------------------
+  // --------------            |                   |
+  // |            |  =====>>   |                   |
+  // |            |            |                   |
+  // --------------            |                   |
+  //                           |                   |
+  //                           ---------------------
+  //
+  //
+  res = libyuv::I420Scale(
+      rotated_y_plane, rotated_y_stride, rotated_u_plane, rotated_uv_stride,
+      rotated_v_plane, rotated_uv_stride, rotated_width, rotated_height,
+      yu12_frame_->GetData(), yu12_frame_->GetWidth(),
+      yu12_frame_->GetData() +
+          yu12_frame_->GetWidth() * yu12_frame_->GetHeight(),
+      yu12_frame_->GetWidth() / 2,
+      yu12_frame_->GetData() +
+          yu12_frame_->GetWidth() * yu12_frame_->GetHeight() * 5 / 4,
+      yu12_frame_->GetWidth() / 2, yu12_frame_->GetWidth(),
+      yu12_frame_->GetHeight(), libyuv::FilterMode::kFilterNone);
+  LOGF_IF(ERROR, res) << "I420Scale failed: " << res;
+  return res;
+}
+
+}  // namespace arc
diff --git a/modules/camera/3_4/arc/cached_frame.h b/modules/camera/3_4/arc/cached_frame.h
new file mode 100644
index 0000000..fbfcb76
--- /dev/null
+++ b/modules/camera/3_4/arc/cached_frame.h
@@ -0,0 +1,86 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef HAL_USB_CACHED_FRAME_H_
+#define HAL_USB_CACHED_FRAME_H_
+
+#include <memory>
+
+#include <camera/CameraMetadata.h>
+
+#include "arc/image_processor.h"
+
+namespace arc {
+
+// CachedFrame contains a source FrameBuffer and a cached, converted
+// FrameBuffer. The incoming frames would be converted to YU12, the default
+// format of libyuv, to allow convenient processing.
+class CachedFrame {
+ public:
+  CachedFrame();
+  ~CachedFrame();
+
+  // SetSource() doesn't take ownership of |frame|. The caller can only release
+  // |frame| after calling UnsetSource(). SetSource() immediately converts
+  // incoming frame into YU12. Return non-zero values if it encounters errors.
+  // If |rotate_degree| is 90 or 270, |frame| will be cropped, rotated by the
+  // specified amount and scaled.
+  // If |rotate_degree| is -1, |frame| will not be cropped, rotated, and scaled.
+  // This function will return an error if |rotate_degree| is not -1, 90, or
+  // 270.
+  int SetSource(const FrameBuffer* frame, int rotate_degree);
+  void UnsetSource();
+
+  uint8_t* GetSourceBuffer() const;
+  size_t GetSourceDataSize() const;
+  uint32_t GetSourceFourCC() const;
+  uint8_t* GetCachedBuffer() const;
+  uint32_t GetCachedFourCC() const;
+
+  uint32_t GetWidth() const;
+  uint32_t GetHeight() const;
+
+  // Calculate the output buffer size when converting to the specified pixel
+  // format. |fourcc| is defined as V4L2_PIX_FMT_* in linux/videodev2.h. Return
+  // 0 on error.
+  size_t GetConvertedSize(int fourcc) const;
+
+  // Caller should fill everything except |data_size| and |fd| of |out_frame|.
+  // The function will do format conversion and scale to fit |out_frame|
+  // requirement.
+  // If |video_hack| is true, it outputs YU12 when |hal_pixel_format| is YV12
+  // (swapping U/V planes). Caller should fill |fourcc|, |data|, and
+  // Return non-zero error code on failure; return 0 on success.
+  int Convert(const android::CameraMetadata& metadata, FrameBuffer* out_frame,
+              bool video_hack = false);
+
+ private:
+  int ConvertToYU12();
+  // When we have a landscape mounted camera and the current camera activity is
+  // portrait, the frames shown in the activity would be stretched. Therefore,
+  // we want to simulate a native portrait camera. That's why we want to crop,
+  // rotate |rotate_degree| clockwise and scale the frame. HAL would not change
+  // CameraInfo.orientation. Instead, framework would fake the
+  // CameraInfo.orientation. Framework would then tell HAL how much the frame
+  // needs to rotate clockwise by |rotate_degree|.
+  int CropRotateScale(int rotate_degree);
+
+  const FrameBuffer* source_frame_;
+  // const V4L2FrameBuffer* source_frame_;
+
+  // Temporary buffer for cropped and rotated results.
+  std::unique_ptr<uint8_t[]> cropped_buffer_;
+  size_t cropped_buffer_capacity_;
+
+  // Cache YU12 decoded results.
+  std::unique_ptr<AllocatedFrameBuffer> yu12_frame_;
+
+  // Temporary buffer for scaled results.
+  std::unique_ptr<AllocatedFrameBuffer> scaled_frame_;
+};
+
+}  // namespace arc
+
+#endif  // HAL_USB_CACHED_FRAME_H_
diff --git a/modules/camera/3_4/arc/common.h b/modules/camera/3_4/arc/common.h
new file mode 100644
index 0000000..25e4eb5
--- /dev/null
+++ b/modules/camera/3_4/arc/common.h
@@ -0,0 +1,28 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef INCLUDE_ARC_COMMON_H_
+#define INCLUDE_ARC_COMMON_H_
+
+#include <string>
+
+#include <base/logging.h>
+
+#define LOGF(level) LOG(level) << __FUNCTION__ << "(): "
+#define LOGFID(level, id) LOG(level) << __FUNCTION__ << "(): id: " << id << ": "
+#define LOGF_IF(level, res) LOG_IF(level, res) << __FUNCTION__ << "(): "
+
+#define VLOGF(level) VLOG(level) << __FUNCTION__ << "(): "
+#define VLOGFID(level, id) \
+  VLOG(level) << __FUNCTION__ << "(): id: " << id << ": "
+
+#define VLOGF_ENTER() VLOGF(1) << "enter"
+#define VLOGF_EXIT() VLOGF(1) << "exit"
+
+inline std::string FormatToString(int32_t format) {
+  return std::string(reinterpret_cast<char*>(&format), 4);
+}
+
+#endif  // INCLUDE_ARC_COMMON_H_
diff --git a/modules/camera/3_4/arc/common_types.h b/modules/camera/3_4/arc/common_types.h
new file mode 100644
index 0000000..8f62ad6
--- /dev/null
+++ b/modules/camera/3_4/arc/common_types.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef HAL_USB_COMMON_TYPES_H_
+#define HAL_USB_COMMON_TYPES_H_
+
+#include <string>
+#include <vector>
+
+namespace arc {
+
+struct DeviceInfo {
+  // ex: /dev/video0
+  std::string device_path;
+  // USB vender id
+  std::string usb_vid;
+  // USB product id
+  std::string usb_pid;
+  // Some cameras need to wait several frames to output correct images.
+  uint32_t frames_to_skip_after_streamon;
+
+  // Member definitions can be found in https://developer.android.com/
+  // reference/android/hardware/camera2/CameraCharacteristics.html
+  uint32_t lens_facing;
+  int32_t sensor_orientation;
+  float horizontal_view_angle_16_9;
+  float horizontal_view_angle_4_3;
+  std::vector<float> lens_info_available_focal_lengths;
+  float lens_info_minimum_focus_distance;
+  float lens_info_optimal_focus_distance;
+  float vertical_view_angle_16_9;
+  float vertical_view_angle_4_3;
+};
+
+typedef std::vector<DeviceInfo> DeviceInfos;
+
+struct SupportedFormat {
+  uint32_t width;
+  uint32_t height;
+  uint32_t fourcc;
+  // All the supported frame rates in fps with given width, height, and
+  // pixelformat. This is not sorted. For example, suppose width, height, and
+  // fourcc are 640x480 YUYV. If frameRates are 15.0 and 30.0, the camera
+  // supports outputting 640X480 YUYV in 15fps or 30fps.
+  std::vector<float> frameRates;
+};
+
+typedef std::vector<SupportedFormat> SupportedFormats;
+
+}  // namespace arc
+
+#endif  // HAL_USB_COMMON_TYPES_H_
diff --git a/modules/camera/3_4/arc/exif_utils.cpp b/modules/camera/3_4/arc/exif_utils.cpp
new file mode 100644
index 0000000..aec53c5
--- /dev/null
+++ b/modules/camera/3_4/arc/exif_utils.cpp
@@ -0,0 +1,513 @@
+/*
+ * Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "arc/exif_utils.h"
+
+#include <cstdlib>
+#include <ctime>
+
+#include <libyuv.h>
+
+#include "arc/common.h"
+
+namespace std {
+
+template <>
+struct default_delete<ExifEntry> {
+  inline void operator()(ExifEntry* entry) const { exif_entry_unref(entry); }
+};
+
+}  // namespace std
+
+namespace arc {
+
+// This comes from the Exif Version 2.3 standard table 9.
+const uint8_t gExifAsciiPrefix[] = {0x41, 0x53, 0x43, 0x49,
+                                    0x49, 0x0,  0x0,  0x0};
+
+static void SetLatitudeOrLongitudeData(unsigned char* data, double num) {
+  // Take the integer part of |num|.
+  ExifLong degrees = static_cast<ExifLong>(num);
+  ExifLong minutes = static_cast<ExifLong>(60 * (num - degrees));
+  ExifLong microseconds =
+      static_cast<ExifLong>(3600000000u * (num - degrees - minutes / 60.0));
+  exif_set_rational(data, EXIF_BYTE_ORDER_INTEL, {degrees, 1});
+  exif_set_rational(data + sizeof(ExifRational), EXIF_BYTE_ORDER_INTEL,
+                    {minutes, 1});
+  exif_set_rational(data + 2 * sizeof(ExifRational), EXIF_BYTE_ORDER_INTEL,
+                    {microseconds, 1000000});
+}
+
+ExifUtils::ExifUtils()
+    : yu12_buffer_(nullptr),
+      yu12_width_(0),
+      yu12_height_(0),
+      thumbnail_width_(0),
+      thumbnail_height_(0),
+      exif_data_(nullptr),
+      app1_buffer_(nullptr),
+      app1_length_(0) {}
+
+ExifUtils::~ExifUtils() { Reset(); }
+
+bool ExifUtils::Initialize(const uint8_t* buffer, uint16_t width,
+                           uint16_t height, int quality) {
+  Reset();
+
+  if (width % 2 != 0 || height % 2 != 0) {
+    LOGF(ERROR) << "invalid image size " << width << "x" << height;
+    return false;
+  }
+  if (quality < 1 || quality > 100) {
+    LOGF(ERROR) << "invalid jpeg quality " << quality;
+    return false;
+  }
+  thumbnail_jpeg_quality_ = quality;
+  yu12_buffer_ = buffer;
+  yu12_width_ = width;
+  yu12_height_ = height;
+
+  exif_data_ = exif_data_new();
+  if (exif_data_ == nullptr) {
+    LOGF(ERROR) << "allocate memory for exif_data_ failed";
+    return false;
+  }
+  // Set the image options.
+  exif_data_set_option(exif_data_, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
+  exif_data_set_data_type(exif_data_, EXIF_DATA_TYPE_COMPRESSED);
+  exif_data_set_byte_order(exif_data_, EXIF_BYTE_ORDER_INTEL);
+
+  // Set image width and length.
+  SetImageWidth(width);
+  SetImageLength(height);
+
+  return true;
+}
+
+bool ExifUtils::SetMaker(const std::string& maker) {
+  size_t entrySize = maker.length() + 1;
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_0, EXIF_TAG_MAKE, EXIF_FORMAT_ASCII, entrySize, entrySize);
+  if (!entry) {
+    LOGF(ERROR) << "Adding Make exif entry failed";
+    return false;
+  }
+  memcpy(entry->data, maker.c_str(), entrySize);
+  return true;
+}
+
+bool ExifUtils::SetModel(const std::string& model) {
+  size_t entrySize = model.length() + 1;
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_0, EXIF_TAG_MODEL, EXIF_FORMAT_ASCII, entrySize, entrySize);
+  if (!entry) {
+    LOGF(ERROR) << "Adding Model exif entry failed";
+    return false;
+  }
+  memcpy(entry->data, model.c_str(), entrySize);
+  return true;
+}
+
+bool ExifUtils::SetDateTime(const struct tm& t) {
+  // The length is 20 bytes including NULL for termination in Exif standard.
+  char str[20];
+  int result = snprintf(str, sizeof(str), "%04i:%02i:%02i %02i:%02i:%02i",
+                        t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour,
+                        t.tm_min, t.tm_sec);
+  if (result != sizeof(str) - 1) {
+    LOGF(WARNING) << "Input time is invalid";
+    return false;
+  }
+  std::unique_ptr<ExifEntry> entry =
+      AddVariableLengthEntry(EXIF_IFD_0, EXIF_TAG_DATE_TIME, EXIF_FORMAT_ASCII,
+                             sizeof(str), sizeof(str));
+  if (!entry) {
+    LOGF(ERROR) << "Adding DateTime exif entry failed";
+    return false;
+  }
+  memcpy(entry->data, str, sizeof(str));
+  return true;
+}
+
+bool ExifUtils::SetFocalLength(uint32_t numerator, uint32_t denominator) {
+  std::unique_ptr<ExifEntry> entry =
+      AddEntry(EXIF_IFD_EXIF, EXIF_TAG_FOCAL_LENGTH);
+  if (!entry) {
+    LOGF(ERROR) << "Adding FocalLength exif entry failed";
+    return false;
+  }
+  exif_set_rational(entry->data, EXIF_BYTE_ORDER_INTEL,
+                    {numerator, denominator});
+  return true;
+}
+
+bool ExifUtils::SetGpsLatitude(double latitude) {
+  const ExifTag refTag = static_cast<ExifTag>(EXIF_TAG_GPS_LATITUDE_REF);
+  std::unique_ptr<ExifEntry> refEntry =
+      AddVariableLengthEntry(EXIF_IFD_GPS, refTag, EXIF_FORMAT_ASCII, 2, 2);
+  if (!refEntry) {
+    LOGF(ERROR) << "Adding GPSLatitudeRef exif entry failed";
+    return false;
+  }
+  if (latitude >= 0) {
+    memcpy(refEntry->data, "N", sizeof("N"));
+  } else {
+    memcpy(refEntry->data, "S", sizeof("S"));
+    latitude *= -1;
+  }
+
+  const ExifTag tag = static_cast<ExifTag>(EXIF_TAG_GPS_LATITUDE);
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_GPS, tag, EXIF_FORMAT_RATIONAL, 3, 3 * sizeof(ExifRational));
+  if (!entry) {
+    exif_content_remove_entry(exif_data_->ifd[EXIF_IFD_GPS], refEntry.get());
+    LOGF(ERROR) << "Adding GPSLatitude exif entry failed";
+    return false;
+  }
+  SetLatitudeOrLongitudeData(entry->data, latitude);
+
+  return true;
+}
+
+bool ExifUtils::SetGpsLongitude(double longitude) {
+  ExifTag refTag = static_cast<ExifTag>(EXIF_TAG_GPS_LONGITUDE_REF);
+  std::unique_ptr<ExifEntry> refEntry =
+      AddVariableLengthEntry(EXIF_IFD_GPS, refTag, EXIF_FORMAT_ASCII, 2, 2);
+  if (!refEntry) {
+    LOGF(ERROR) << "Adding GPSLongitudeRef exif entry failed";
+    return false;
+  }
+  if (longitude >= 0) {
+    memcpy(refEntry->data, "E", sizeof("E"));
+  } else {
+    memcpy(refEntry->data, "W", sizeof("W"));
+    longitude *= -1;
+  }
+
+  ExifTag tag = static_cast<ExifTag>(EXIF_TAG_GPS_LONGITUDE);
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_GPS, tag, EXIF_FORMAT_RATIONAL, 3, 3 * sizeof(ExifRational));
+  if (!entry) {
+    exif_content_remove_entry(exif_data_->ifd[EXIF_IFD_GPS], refEntry.get());
+    LOGF(ERROR) << "Adding GPSLongitude exif entry failed";
+    return false;
+  }
+  SetLatitudeOrLongitudeData(entry->data, longitude);
+
+  return true;
+}
+
+bool ExifUtils::SetGpsAltitude(double altitude) {
+  ExifTag refTag = static_cast<ExifTag>(EXIF_TAG_GPS_ALTITUDE_REF);
+  std::unique_ptr<ExifEntry> refEntry =
+      AddVariableLengthEntry(EXIF_IFD_GPS, refTag, EXIF_FORMAT_BYTE, 1, 1);
+  if (!refEntry) {
+    LOGF(ERROR) << "Adding GPSAltitudeRef exif entry failed";
+    return false;
+  }
+  if (altitude >= 0) {
+    *refEntry->data = 0;
+  } else {
+    *refEntry->data = 1;
+    altitude *= -1;
+  }
+
+  ExifTag tag = static_cast<ExifTag>(EXIF_TAG_GPS_ALTITUDE);
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_GPS, tag, EXIF_FORMAT_RATIONAL, 1, sizeof(ExifRational));
+  if (!entry) {
+    exif_content_remove_entry(exif_data_->ifd[EXIF_IFD_GPS], refEntry.get());
+    LOGF(ERROR) << "Adding GPSAltitude exif entry failed";
+    return false;
+  }
+  exif_set_rational(entry->data, EXIF_BYTE_ORDER_INTEL,
+                    {static_cast<ExifLong>(altitude * 1000), 1000});
+
+  return true;
+}
+
+bool ExifUtils::SetGpsTimestamp(const struct tm& t) {
+  const ExifTag dateTag = static_cast<ExifTag>(EXIF_TAG_GPS_DATE_STAMP);
+  const size_t kGpsDateStampSize = 11;
+  std::unique_ptr<ExifEntry> entry =
+      AddVariableLengthEntry(EXIF_IFD_GPS, dateTag, EXIF_FORMAT_ASCII,
+                             kGpsDateStampSize, kGpsDateStampSize);
+  if (!entry) {
+    LOGF(ERROR) << "Adding GPSDateStamp exif entry failed";
+    return false;
+  }
+  int result =
+      snprintf(reinterpret_cast<char*>(entry->data), kGpsDateStampSize,
+               "%04i:%02i:%02i", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
+  if (result != kGpsDateStampSize - 1) {
+    LOGF(WARNING) << "Input time is invalid";
+    return false;
+  }
+
+  const ExifTag timeTag = static_cast<ExifTag>(EXIF_TAG_GPS_TIME_STAMP);
+  entry = AddVariableLengthEntry(EXIF_IFD_GPS, timeTag, EXIF_FORMAT_RATIONAL, 3,
+                                 3 * sizeof(ExifRational));
+  if (!entry) {
+    LOGF(ERROR) << "Adding GPSTimeStamp exif entry failed";
+    return false;
+  }
+  exif_set_rational(entry->data, EXIF_BYTE_ORDER_INTEL,
+                    {static_cast<ExifLong>(t.tm_hour), 1});
+  exif_set_rational(entry->data + sizeof(ExifRational), EXIF_BYTE_ORDER_INTEL,
+                    {static_cast<ExifLong>(t.tm_min), 1});
+  exif_set_rational(entry->data + 2 * sizeof(ExifRational),
+                    EXIF_BYTE_ORDER_INTEL,
+                    {static_cast<ExifLong>(t.tm_sec), 1});
+
+  return true;
+}
+
+bool ExifUtils::SetGpsProcessingMethod(const std::string& method) {
+  ExifTag tag = static_cast<ExifTag>(EXIF_TAG_GPS_PROCESSING_METHOD);
+  size_t size = sizeof(gExifAsciiPrefix) + method.length();
+  std::unique_ptr<ExifEntry> entry = AddVariableLengthEntry(
+      EXIF_IFD_GPS, tag, EXIF_FORMAT_UNDEFINED, size, size);
+  if (!entry) {
+    LOGF(ERROR) << "Adding GPSProcessingMethod exif entry failed";
+    return false;
+  }
+  memcpy(entry->data, gExifAsciiPrefix, sizeof(gExifAsciiPrefix));
+  // Since the exif format is undefined, NULL termination is not necessary.
+  memcpy(entry->data + sizeof(gExifAsciiPrefix), method.c_str(),
+         method.length());
+
+  return true;
+}
+
+bool ExifUtils::SetThumbnailSize(uint16_t width, uint16_t height) {
+  if (width % 2 != 0 || height % 2 != 0) {
+    LOGF(ERROR) << "Invalid thumbnail size " << width << "x" << height;
+    return false;
+  }
+  thumbnail_width_ = width;
+  thumbnail_height_ = height;
+  return true;
+}
+
+bool ExifUtils::SetOrientation(uint16_t orientation) {
+  std::unique_ptr<ExifEntry> entry = AddEntry(EXIF_IFD_0, EXIF_TAG_ORIENTATION);
+  if (!entry) {
+    LOGF(ERROR) << "Adding Orientation exif entry failed";
+    return false;
+  }
+  /*
+   * Orientation value:
+   *  1      2      3      4      5          6          7          8
+   *
+   *  888888 888888     88 88     8888888888 88                 88 8888888888
+   *  88         88     88 88     88  88     88  88         88  88     88  88
+   *  8888     8888   8888 8888   88         8888888888 8888888888         88
+   *  88         88     88 88
+   *  88         88 888888 888888
+   */
+  int value = 1;
+  switch (orientation) {
+    case 90:
+      value = 6;
+      break;
+    case 180:
+      value = 3;
+      break;
+    case 270:
+      value = 8;
+      break;
+    default:
+      break;
+  }
+  exif_set_short(entry->data, EXIF_BYTE_ORDER_INTEL, value);
+  return true;
+}
+
+bool ExifUtils::GenerateApp1() {
+  DestroyApp1();
+  if (thumbnail_width_ > 0 && thumbnail_height_ > 0) {
+    if (!GenerateThumbnail()) {
+      LOGF(ERROR) << "Generate thumbnail image failed";
+      return false;
+    }
+    exif_data_->data = const_cast<uint8_t*>(
+        static_cast<const uint8_t*>(compressor_.GetCompressedImagePtr()));
+    exif_data_->size = compressor_.GetCompressedImageSize();
+  }
+  // Save the result into |app1_buffer_|.
+  exif_data_save_data(exif_data_, &app1_buffer_, &app1_length_);
+  if (!app1_length_) {
+    LOGF(ERROR) << "Allocate memory for app1_buffer_ failed";
+    return false;
+  }
+  /*
+   * The JPEG segment size is 16 bits in spec. The size of APP1 segment should
+   * be smaller than 65533 because there are two bytes for segment size field.
+   */
+  if (app1_length_ > 65533) {
+    DestroyApp1();
+    LOGF(ERROR) << "The size of APP1 segment is too large";
+    return false;
+  }
+  return true;
+}
+
+const uint8_t* ExifUtils::GetApp1Buffer() { return app1_buffer_; }
+
+unsigned int ExifUtils::GetApp1Length() { return app1_length_; }
+
+void ExifUtils::Reset() {
+  yu12_buffer_ = nullptr;
+  yu12_width_ = 0;
+  yu12_height_ = 0;
+  thumbnail_width_ = 0;
+  thumbnail_height_ = 0;
+  DestroyApp1();
+  if (exif_data_) {
+    /*
+     * Since we decided to ignore the original APP1, we are sure that there is
+     * no thumbnail allocated by libexif. |exif_data_->data| is actually
+     * allocated by JpegCompressor. Sets |exif_data_->data| to nullptr to
+     * prevent exif_data_unref() destroy it incorrectly.
+     */
+    exif_data_->data = nullptr;
+    exif_data_->size = 0;
+    exif_data_unref(exif_data_);
+    exif_data_ = nullptr;
+  }
+}
+
+std::unique_ptr<ExifEntry> ExifUtils::AddVariableLengthEntry(
+    ExifIfd ifd, ExifTag tag, ExifFormat format, uint64_t components,
+    unsigned int size) {
+  // Remove old entry if exists.
+  exif_content_remove_entry(exif_data_->ifd[ifd],
+                            exif_content_get_entry(exif_data_->ifd[ifd], tag));
+  ExifMem* mem = exif_mem_new_default();
+  if (!mem) {
+    LOGF(ERROR) << "Allocate memory for exif entry failed";
+    return nullptr;
+  }
+  std::unique_ptr<ExifEntry> entry(exif_entry_new_mem(mem));
+  if (!entry) {
+    LOGF(ERROR) << "Allocate memory for exif entry failed";
+    exif_mem_unref(mem);
+    return nullptr;
+  }
+  void* tmpBuffer = exif_mem_alloc(mem, size);
+  if (!tmpBuffer) {
+    LOGF(ERROR) << "Allocate memory for exif entry failed";
+    exif_mem_unref(mem);
+    return nullptr;
+  }
+
+  entry->data = static_cast<unsigned char*>(tmpBuffer);
+  entry->tag = tag;
+  entry->format = format;
+  entry->components = components;
+  entry->size = size;
+
+  exif_content_add_entry(exif_data_->ifd[ifd], entry.get());
+  exif_mem_unref(mem);
+
+  return entry;
+}
+
+std::unique_ptr<ExifEntry> ExifUtils::AddEntry(ExifIfd ifd, ExifTag tag) {
+  std::unique_ptr<ExifEntry> entry(
+      exif_content_get_entry(exif_data_->ifd[ifd], tag));
+  if (entry) {
+    // exif_content_get_entry() won't ref the entry, so we ref here.
+    exif_entry_ref(entry.get());
+    return entry;
+  }
+  entry.reset(exif_entry_new());
+  if (!entry) {
+    LOGF(ERROR) << "Allocate memory for exif entry failed";
+    return nullptr;
+  }
+  entry->tag = tag;
+  exif_content_add_entry(exif_data_->ifd[ifd], entry.get());
+  exif_entry_initialize(entry.get(), tag);
+  return entry;
+}
+
+bool ExifUtils::SetImageWidth(uint16_t width) {
+  std::unique_ptr<ExifEntry> entry = AddEntry(EXIF_IFD_0, EXIF_TAG_IMAGE_WIDTH);
+  if (!entry) {
+    LOGF(ERROR) << "Adding ImageWidth exif entry failed";
+    return false;
+  }
+  exif_set_short(entry->data, EXIF_BYTE_ORDER_INTEL, width);
+  return true;
+}
+
+bool ExifUtils::SetImageLength(uint16_t length) {
+  std::unique_ptr<ExifEntry> entry =
+      AddEntry(EXIF_IFD_0, EXIF_TAG_IMAGE_LENGTH);
+  if (!entry) {
+    LOGF(ERROR) << "Adding ImageLength exif entry failed";
+    return false;
+  }
+  exif_set_short(entry->data, EXIF_BYTE_ORDER_INTEL, length);
+  return true;
+}
+
+bool ExifUtils::GenerateThumbnail() {
+  // Resize yuv image to |thumbnail_width_| x |thumbnail_height_|.
+  std::vector<uint8_t> scaled_buffer;
+  if (!GenerateYuvThumbnail(&scaled_buffer)) {
+    LOGF(ERROR) << "Generate YUV thumbnail failed";
+    return false;
+  }
+
+  // Compress thumbnail to JPEG.
+  if (!compressor_.CompressImage(scaled_buffer.data(), thumbnail_width_,
+                                 thumbnail_height_, thumbnail_jpeg_quality_,
+                                 NULL, 0)) {
+    LOGF(ERROR) << "Compress thumbnail failed";
+    return false;
+  }
+  return true;
+}
+
+bool ExifUtils::GenerateYuvThumbnail(std::vector<uint8_t>* scaled_buffer) {
+  size_t y_plane_size = yu12_width_ * yu12_height_;
+  const uint8* y_plane = yu12_buffer_;
+  const uint8* u_plane = y_plane + y_plane_size;
+  const uint8* v_plane = u_plane + y_plane_size / 4;
+
+  size_t scaled_y_plane_size = thumbnail_width_ * thumbnail_height_;
+  scaled_buffer->resize(scaled_y_plane_size * 3 / 2);
+  uint8* scaled_y_plane = scaled_buffer->data();
+  uint8* scaled_u_plane = scaled_y_plane + scaled_y_plane_size;
+  uint8* scaled_v_plane = scaled_u_plane + scaled_y_plane_size / 4;
+
+  int result = libyuv::I420Scale(
+      y_plane, yu12_width_, u_plane, yu12_width_ / 2, v_plane, yu12_width_ / 2,
+      yu12_width_, yu12_height_, scaled_y_plane, thumbnail_width_,
+      scaled_u_plane, thumbnail_width_ / 2, scaled_v_plane,
+      thumbnail_width_ / 2, thumbnail_width_, thumbnail_height_,
+      libyuv::kFilterNone);
+  if (result != 0) {
+    LOGF(ERROR) << "Scale I420 image failed";
+    return false;
+  }
+  return true;
+}
+
+void ExifUtils::DestroyApp1() {
+  /*
+   * Since there is no API to access ExifMem in ExifData->priv, we use free
+   * here, which is the default free function in libexif. See
+   * exif_data_save_data() for detail.
+   */
+  free(app1_buffer_);
+  app1_buffer_ = nullptr;
+  app1_length_ = 0;
+}
+
+}  // namespace arc
diff --git a/modules/camera/3_4/arc/exif_utils.h b/modules/camera/3_4/arc/exif_utils.h
new file mode 100644
index 0000000..956ee1d
--- /dev/null
+++ b/modules/camera/3_4/arc/exif_utils.h
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef INCLUDE_ARC_EXIF_UTILS_H_
+#define INCLUDE_ARC_EXIF_UTILS_H_
+
+#include <cstddef>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+extern "C" {
+#include <libexif/exif-data.h>
+}
+
+#include "arc/jpeg_compressor.h"
+
+namespace arc {
+
+// ExifUtils can generate APP1 segment with tags which caller set. ExifUtils can
+// also add a thumbnail in the APP1 segment if thumbnail size is specified.
+// ExifUtils can be reused with different images by calling initialize().
+//
+// Example of using this class :
+//  ExifUtils utils;
+//  utils.initialize(inputYU12Buffer, inputWidth, inputHeight,
+//                   outputJpegQuality);
+//  ...
+//  // Call ExifUtils functions to set Exif tags.
+//  ...
+//  utils.generateApp1();
+//  unsigned int app1Length = utils.getApp1Length();
+//  uint8_t* app1Buffer = new uint8_t[app1Length];
+//  memcpy(app1Buffer, utils.getApp1Buffer(), app1Length);
+class ExifUtils {
+ public:
+  ExifUtils();
+  ~ExifUtils();
+
+  // Sets input YU12 image |buffer| with |width| x |height|. |quality| is the
+  // compressed JPEG image quality. The caller should not release |buffer| until
+  // generateApp1() or the destructor is called. initialize() can be called
+  // multiple times. The setting of Exif tags will be cleared.
+  bool Initialize(const uint8_t* buffer, uint16_t width, uint16_t height,
+                  int quality);
+
+  // Sets the manufacturer of camera.
+  // Returns false if memory allocation fails.
+  bool SetMaker(const std::string& maker);
+
+  // Sets the model number of camera.
+  // Returns false if memory allocation fails.
+  bool SetModel(const std::string& model);
+
+  // Sets the date and time of image last modified. It takes local time. The
+  // name of the tag is DateTime in IFD0.
+  // Returns false if memory allocation fails.
+  bool SetDateTime(const struct tm& t);
+
+  // Sets the focal length of lens used to take the image in millimeters.
+  // Returns false if memory allocation fails.
+  bool SetFocalLength(uint32_t numerator, uint32_t denominator);
+
+  // Sets the latitude with degrees minutes seconds format.
+  // Returns false if memory allocation fails.
+  bool SetGpsLatitude(double latitude);
+
+  // Sets the longitude with degrees minutes seconds format.
+  // Returns false if memory allocation fails.
+  bool SetGpsLongitude(double longitude);
+
+  // Sets the altitude in meters.
+  // Returns false if memory allocation fails.
+  bool SetGpsAltitude(double altitude);
+
+  // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time.
+  // Returns false if memory allocation fails.
+  bool SetGpsTimestamp(const struct tm& t);
+
+  // Sets GPS processing method.
+  // Returns false if memory allocation fails.
+  bool SetGpsProcessingMethod(const std::string& method);
+
+  // Since the size of APP1 segment is limited, it is recommended the
+  // resolution of thumbnail is equal to or smaller than 640x480. If the
+  // thumbnail is too big, generateApp1() will return false.
+  // Returns false if |width| or |height| is not even.
+  bool SetThumbnailSize(uint16_t width, uint16_t height);
+
+  // Sets image orientation.
+  // Returns false if memory allocation fails.
+  bool SetOrientation(uint16_t orientation);
+
+  // Generates APP1 segment.
+  // Returns false if generating APP1 segment fails.
+  bool GenerateApp1();
+
+  // Gets buffer of APP1 segment. This method must be called only after calling
+  // generateAPP1().
+  const uint8_t* GetApp1Buffer();
+
+  // Gets length of APP1 segment. This method must be called only after calling
+  // generateAPP1().
+  unsigned int GetApp1Length();
+
+ private:
+  // Resets the pointers and memories.
+  void Reset();
+
+  // Adds a variable length tag to |exif_data_|. It will remove the original one
+  // if the tag exists.
+  // Returns the entry of the tag. The reference count of returned ExifEntry is
+  // two.
+  std::unique_ptr<ExifEntry> AddVariableLengthEntry(ExifIfd ifd, ExifTag tag,
+                                                    ExifFormat format,
+                                                    uint64_t components,
+                                                    unsigned int size);
+
+  // Adds a entry of |tag| in |exif_data_|. It won't remove the original one if
+  // the tag exists.
+  // Returns the entry of the tag. It adds one reference count to returned
+  // ExifEntry.
+  std::unique_ptr<ExifEntry> AddEntry(ExifIfd ifd, ExifTag tag);
+
+  // Sets the width (number of columes) of main image.
+  // Returns false if memory allocation fails.
+  bool SetImageWidth(uint16_t width);
+
+  // Sets the length (number of rows) of main image.
+  // Returns false if memory allocation fails.
+  bool SetImageLength(uint16_t length);
+
+  // Generates a thumbnail. Calls compressor_.getCompressedImagePtr() to get the
+  // result image.
+  // Returns false if failed.
+  bool GenerateThumbnail();
+
+  // Resizes the thumbnail yuv image to |thumbnail_width_| x |thumbnail_height_|
+  // and stores in |scaled_buffer|.
+  // Returns false if scale image failed.
+  bool GenerateYuvThumbnail(std::vector<uint8_t>* scaled_buffer);
+
+  // Destroys the buffer of APP1 segment if exists.
+  void DestroyApp1();
+
+  // The buffer pointer of yuv image (YU12). Not owned by this class.
+  const uint8_t* yu12_buffer_;
+  // The size of yuv image.
+  uint16_t yu12_width_;
+  uint16_t yu12_height_;
+
+  // The size of thumbnail.
+  uint16_t thumbnail_width_;
+  uint16_t thumbnail_height_;
+
+  // The Exif data (APP1). Owned by this class.
+  ExifData* exif_data_;
+  // The raw data of APP1 segment. It's allocated by ExifMem in |exif_data_| but
+  // owned by this class.
+  uint8_t* app1_buffer_;
+  // The length of |app1_buffer_|.
+  unsigned int app1_length_;
+  // The quality of compressed thumbnail image. The size of EXIF thumbnail has
+  // to be smaller than 64KB. If quality is 100, the size may be bigger than
+  // 64KB.
+  int thumbnail_jpeg_quality_;
+
+  // The YU12 to Jpeg compressor.
+  JpegCompressor compressor_;
+};
+
+}  // namespace arc
+
+#endif  // INCLUDE_ARC_EXIF_UTILS_H_
diff --git a/modules/camera/3_4/arc/frame_buffer.cpp b/modules/camera/3_4/arc/frame_buffer.cpp
new file mode 100644
index 0000000..4ae0fe3
--- /dev/null
+++ b/modules/camera/3_4/arc/frame_buffer.cpp
@@ -0,0 +1,188 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "arc/frame_buffer.h"
+
+#include <sys/mman.h>
+
+#include <utility>
+
+#include "arc/common.h"
+#include "arc/image_processor.h"
+
+namespace arc {
+
+FrameBuffer::FrameBuffer()
+    : data_(nullptr),
+      data_size_(0),
+      buffer_size_(0),
+      width_(0),
+      height_(0),
+      fourcc_(0) {}
+
+FrameBuffer::~FrameBuffer() {}
+
+int FrameBuffer::SetDataSize(size_t data_size) {
+  if (data_size > buffer_size_) {
+    LOGF(ERROR) << "Buffer overflow: Buffer only has " << buffer_size_
+                << ", but data needs " << data_size;
+    return -EINVAL;
+  }
+  data_size_ = data_size;
+  return 0;
+}
+
+AllocatedFrameBuffer::AllocatedFrameBuffer(int buffer_size) {
+  buffer_.reset(new uint8_t[buffer_size]);
+  buffer_size_ = buffer_size;
+  data_ = buffer_.get();
+}
+
+AllocatedFrameBuffer::AllocatedFrameBuffer(uint8_t* buffer, int buffer_size) {
+  buffer_.reset(buffer);
+  buffer_size_ = buffer_size;
+  data_ = buffer_.get();
+}
+
+AllocatedFrameBuffer::~AllocatedFrameBuffer() {}
+
+int AllocatedFrameBuffer::SetDataSize(size_t size) {
+  if (size > buffer_size_) {
+    buffer_.reset(new uint8_t[size]);
+    buffer_size_ = size;
+    data_ = buffer_.get();
+  }
+  data_size_ = size;
+  return 0;
+}
+
+void AllocatedFrameBuffer::Reset() { memset(data_, 0, buffer_size_); }
+
+V4L2FrameBuffer::V4L2FrameBuffer(base::ScopedFD fd, int buffer_size,
+                                 uint32_t width, uint32_t height,
+                                 uint32_t fourcc)
+    : fd_(std::move(fd)), is_mapped_(false) {
+  buffer_size_ = buffer_size;
+  width_ = width;
+  height_ = height;
+  fourcc_ = fourcc;
+}
+
+V4L2FrameBuffer::~V4L2FrameBuffer() {
+  if (Unmap()) {
+    LOGF(ERROR) << "Unmap failed";
+  }
+}
+
+int V4L2FrameBuffer::Map() {
+  base::AutoLock l(lock_);
+  if (is_mapped_) {
+    LOGF(ERROR) << "The buffer is already mapped";
+    return -EINVAL;
+  }
+  void* addr = mmap(NULL, buffer_size_, PROT_READ, MAP_SHARED, fd_.get(), 0);
+  if (addr == MAP_FAILED) {
+    LOGF(ERROR) << "mmap() failed: " << strerror(errno);
+    return -EINVAL;
+  }
+  data_ = static_cast<uint8_t*>(addr);
+  is_mapped_ = true;
+  return 0;
+}
+
+int V4L2FrameBuffer::Unmap() {
+  base::AutoLock l(lock_);
+  if (is_mapped_ && munmap(data_, buffer_size_)) {
+    LOGF(ERROR) << "mummap() failed: " << strerror(errno);
+    return -EINVAL;
+  }
+  is_mapped_ = false;
+  return 0;
+}
+
+GrallocFrameBuffer::GrallocFrameBuffer(buffer_handle_t buffer, uint32_t width,
+                                       uint32_t height, uint32_t fourcc,
+                                       uint32_t device_buffer_length,
+                                       uint32_t stream_usage)
+    : buffer_(buffer),
+      is_mapped_(false),
+      device_buffer_length_(device_buffer_length),
+      stream_usage_(stream_usage) {
+  const hw_module_t* module = nullptr;
+  int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
+  if (ret || !module) {
+    LOGF(ERROR) << "Failed to get gralloc module.";
+    return;
+  }
+  gralloc_module_ = reinterpret_cast<const gralloc_module_t*>(module);
+  width_ = width;
+  height_ = height;
+  fourcc_ = fourcc;
+}
+
+GrallocFrameBuffer::~GrallocFrameBuffer() {
+  if (Unmap()) {
+    LOGF(ERROR) << "Unmap failed";
+  }
+}
+
+int GrallocFrameBuffer::Map() {
+  base::AutoLock l(lock_);
+  if (is_mapped_) {
+    LOGF(ERROR) << "The buffer is already mapped";
+    return -EINVAL;
+  }
+
+  void* addr;
+  int ret = 0;
+  switch (fourcc_) {
+    case V4L2_PIX_FMT_YUV420:
+    case V4L2_PIX_FMT_YVU420:
+    case V4L2_PIX_FMT_YUYV:
+      android_ycbcr yuv_data;
+      ret = gralloc_module_->lock_ycbcr(gralloc_module_, buffer_, stream_usage_,
+                                        0, 0, width_, height_, &yuv_data);
+      addr = yuv_data.y;
+      break;
+    case V4L2_PIX_FMT_JPEG:
+      ret = gralloc_module_->lock(gralloc_module_, buffer_, stream_usage_, 0, 0,
+                                  device_buffer_length_, 1, &addr);
+      break;
+    case V4L2_PIX_FMT_BGR32:
+    case V4L2_PIX_FMT_RGB32:
+      ret = gralloc_module_->lock(gralloc_module_, buffer_, stream_usage_, 0, 0,
+                                  width_, height_, &addr);
+      break;
+    default:
+      return -EINVAL;
+  }
+
+  if (ret) {
+    LOGF(ERROR) << "Failed to gralloc lock buffer: " << ret;
+    return ret;
+  }
+
+  data_ = static_cast<uint8_t*>(addr);
+  if (fourcc_ == V4L2_PIX_FMT_YVU420 || fourcc_ == V4L2_PIX_FMT_YUV420 ||
+      fourcc_ == V4L2_PIX_FMT_NV21 || fourcc_ == V4L2_PIX_FMT_RGB32 ||
+      fourcc_ == V4L2_PIX_FMT_BGR32) {
+    buffer_size_ = ImageProcessor::GetConvertedSize(fourcc_, width_, height_);
+  }
+
+  is_mapped_ = true;
+  return 0;
+}
+
+int GrallocFrameBuffer::Unmap() {
+  base::AutoLock l(lock_);
+  if (is_mapped_ && gralloc_module_->unlock(gralloc_module_, buffer_)) {
+    LOGF(ERROR) << "Failed to unmap buffer: ";
+    return -EINVAL;
+  }
+  is_mapped_ = false;
+  return 0;
+}
+
+}  // namespace arc
diff --git a/modules/camera/3_4/arc/frame_buffer.h b/modules/camera/3_4/arc/frame_buffer.h
new file mode 100644
index 0000000..3efeb3b
--- /dev/null
+++ b/modules/camera/3_4/arc/frame_buffer.h
@@ -0,0 +1,135 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef HAL_USB_FRAME_BUFFER_H_
+#define HAL_USB_FRAME_BUFFER_H_
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+
+#include <base/files/scoped_file.h>
+#include <base/synchronization/lock.h>
+
+#include <hardware/gralloc.h>
+
+namespace arc {
+
+class FrameBuffer {
+ public:
+  FrameBuffer();
+  virtual ~FrameBuffer();
+
+  // If mapped successfully, the address will be assigned to |data_| and return
+  // 0. Otherwise, returns -EINVAL.
+  virtual int Map() = 0;
+
+  // Unmaps the mapped address. Returns 0 for success.
+  virtual int Unmap() = 0;
+
+  uint8_t* GetData() const { return data_; }
+  size_t GetDataSize() const { return data_size_; }
+  size_t GetBufferSize() const { return buffer_size_; }
+  uint32_t GetWidth() const { return width_; }
+  uint32_t GetHeight() const { return height_; }
+  uint32_t GetFourcc() const { return fourcc_; }
+
+  void SetFourcc(uint32_t fourcc) { fourcc_ = fourcc; }
+  virtual int SetDataSize(size_t data_size);
+
+ protected:
+  uint8_t* data_;
+
+  // The number of bytes used in the buffer.
+  size_t data_size_;
+
+  // The number of bytes allocated in the buffer.
+  size_t buffer_size_;
+
+  // Frame resolution.
+  uint32_t width_;
+  uint32_t height_;
+
+  // This is V4L2_PIX_FMT_* in linux/videodev2.h.
+  uint32_t fourcc_;
+};
+
+// AllocatedFrameBuffer is used for the buffer from hal malloc-ed. User should
+// be aware to manage the memory.
+class AllocatedFrameBuffer : public FrameBuffer {
+ public:
+  explicit AllocatedFrameBuffer(int buffer_size);
+  explicit AllocatedFrameBuffer(uint8_t* buffer, int buffer_size);
+  ~AllocatedFrameBuffer() override;
+
+  // No-op for the two functions.
+  int Map() override { return 0; }
+  int Unmap() override { return 0; }
+
+  void SetWidth(uint32_t width) { width_ = width; }
+  void SetHeight(uint32_t height) { height_ = height; }
+  int SetDataSize(size_t data_size) override;
+  void Reset();
+
+ private:
+  std::unique_ptr<uint8_t[]> buffer_;
+};
+
+// V4L2FrameBuffer is used for the buffer from V4L2CameraDevice. Maps the fd
+// in constructor. Unmaps and closes the fd in destructor.
+class V4L2FrameBuffer : public FrameBuffer {
+ public:
+  V4L2FrameBuffer(base::ScopedFD fd, int buffer_size, uint32_t width,
+                  uint32_t height, uint32_t fourcc);
+  // Unmaps |data_| and closes |fd_|.
+  ~V4L2FrameBuffer();
+
+  int Map() override;
+  int Unmap() override;
+  int GetFd() const { return fd_.get(); }
+
+ private:
+  // File descriptor of V4L2 frame buffer.
+  base::ScopedFD fd_;
+
+  bool is_mapped_;
+
+  // Lock to guard |is_mapped_|.
+  base::Lock lock_;
+};
+
+// GrallocFrameBuffer is used for the buffer from Android framework. Uses
+// CameraBufferMapper to lock and unlock the buffer.
+class GrallocFrameBuffer : public FrameBuffer {
+ public:
+  GrallocFrameBuffer(buffer_handle_t buffer, uint32_t width, uint32_t height,
+                     uint32_t fourcc, uint32_t device_buffer_length,
+                     uint32_t stream_usage);
+  ~GrallocFrameBuffer();
+
+  int Map() override;
+  int Unmap() override;
+
+ private:
+  // The currently used buffer for |buffer_mapper_| operations.
+  buffer_handle_t buffer_;
+
+  // Used to import gralloc buffer.
+  const gralloc_module_t* gralloc_module_;
+
+  bool is_mapped_;
+
+  // Lock to guard |is_mapped_|.
+  base::Lock lock_;
+
+  // Camera stream and device buffer context.
+  uint32_t device_buffer_length_;
+  uint32_t stream_usage_;
+};
+
+}  // namespace arc
+
+#endif  // HAL_USB_FRAME_BUFFER_H_
diff --git a/modules/camera/3_4/arc/image_processor.cpp b/modules/camera/3_4/arc/image_processor.cpp
new file mode 100644
index 0000000..f0fee91
--- /dev/null
+++ b/modules/camera/3_4/arc/image_processor.cpp
@@ -0,0 +1,491 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "arc/image_processor.h"
+
+#include <errno.h>
+#include <libyuv.h>
+#include <time.h>
+
+#include "arc/common.h"
+#include "arc/common_types.h"
+#include "arc/exif_utils.h"
+#include "arc/jpeg_compressor.h"
+
+namespace arc {
+
+using android::CameraMetadata;
+
+/*
+ * Formats have different names in different header files. Here is the mapping
+ * table:
+ *
+ * android_pixel_format_t          videodev2.h           FOURCC in libyuv
+ * -----------------------------------------------------------------------------
+ * HAL_PIXEL_FORMAT_YV12         = V4L2_PIX_FMT_YVU420 = FOURCC_YV12
+ * HAL_PIXEL_FORMAT_YCrCb_420_SP = V4L2_PIX_FMT_NV21   = FOURCC_NV21
+ * HAL_PIXEL_FORMAT_RGBA_8888    = V4L2_PIX_FMT_RGB32  = FOURCC_BGR4
+ * HAL_PIXEL_FORMAT_YCbCr_422_I  = V4L2_PIX_FMT_YUYV   = FOURCC_YUYV
+ *                                                     = FOURCC_YUY2
+ *                                 V4L2_PIX_FMT_YUV420 = FOURCC_I420
+ *                                                     = FOURCC_YU12
+ *                                 V4L2_PIX_FMT_MJPEG  = FOURCC_MJPG
+ *
+ * Camera device generates FOURCC_YUYV and FOURCC_MJPG.
+ * Preview needs FOURCC_ARGB format.
+ * Software video encoder needs FOURCC_YU12.
+ * CTS requires FOURCC_YV12 and FOURCC_NV21 for applications.
+ *
+ * Android stride requirement:
+ * YV12 horizontal stride should be a multiple of 16 pixels. See
+ * android.graphics.ImageFormat.YV12.
+ * The stride of ARGB, YU12, and NV21 are always equal to the width.
+ *
+ * Conversion Path:
+ * MJPG/YUYV (from camera) -> YU12 -> ARGB (preview)
+ *                                 -> NV21 (apps)
+ *                                 -> YV12 (apps)
+ *                                 -> YU12 (video encoder)
+ */
+
+// YV12 horizontal stride should be a multiple of 16 pixels for each plane.
+// |dst_stride_uv| is the pixel stride of u or v plane.
+static int YU12ToYV12(const void* yv12, void* yu12, int width, int height,
+                      int dst_stride_y, int dst_stride_uv);
+static int YU12ToNV21(const void* yv12, void* nv21, int width, int height);
+static bool ConvertToJpeg(const CameraMetadata& metadata,
+                          const FrameBuffer& in_frame, FrameBuffer* out_frame);
+static bool SetExifTags(const CameraMetadata& metadata, ExifUtils* utils);
+
+// How precise the float-to-rational conversion for EXIF tags would be.
+static const int kRationalPrecision = 10000;
+
+// Default JPEG quality settings.
+static const int DEFAULT_JPEG_QUALITY = 80;
+
+inline static size_t Align16(size_t value) { return (value + 15) & ~15; }
+
+size_t ImageProcessor::GetConvertedSize(int fourcc, uint32_t width,
+                                        uint32_t height) {
+  if ((width % 2) || (height % 2)) {
+    LOGF(ERROR) << "Width or height is not even (" << width << " x " << height
+                << ")";
+    return 0;
+  }
+
+  switch (fourcc) {
+    case V4L2_PIX_FMT_YVU420:  // YV12
+      return Align16(width) * height + Align16(width / 2) * height;
+    case V4L2_PIX_FMT_YUV420:  // YU12
+    // Fall-through.
+    case V4L2_PIX_FMT_NV21:  // NV21
+      return width * height * 3 / 2;
+    case V4L2_PIX_FMT_BGR32:
+    case V4L2_PIX_FMT_RGB32:
+      return width * height * 4;
+    default:
+      LOGF(ERROR) << "Pixel format " << FormatToString(fourcc)
+                  << " is unsupported.";
+      return 0;
+  }
+}
+
+bool ImageProcessor::SupportsConversion(uint32_t from_fourcc,
+                                        uint32_t to_fourcc) {
+  switch (from_fourcc) {
+    case V4L2_PIX_FMT_YUYV:
+      return (to_fourcc == V4L2_PIX_FMT_YUV420);
+    case V4L2_PIX_FMT_YUV420:
+      return (
+          to_fourcc == V4L2_PIX_FMT_YUV420 ||
+          to_fourcc == V4L2_PIX_FMT_YVU420 || to_fourcc == V4L2_PIX_FMT_NV21 ||
+          to_fourcc == V4L2_PIX_FMT_RGB32 || to_fourcc == V4L2_PIX_FMT_BGR32 ||
+          to_fourcc == V4L2_PIX_FMT_JPEG);
+    case V4L2_PIX_FMT_MJPEG:
+      return (to_fourcc == V4L2_PIX_FMT_YUV420);
+    default:
+      return false;
+  }
+}
+
+int ImageProcessor::ConvertFormat(const CameraMetadata& metadata,
+                                  const FrameBuffer& in_frame,
+                                  FrameBuffer* out_frame) {
+  if ((in_frame.GetWidth() % 2) || (in_frame.GetHeight() % 2)) {
+    LOGF(ERROR) << "Width or height is not even (" << in_frame.GetWidth()
+                << " x " << in_frame.GetHeight() << ")";
+    return -EINVAL;
+  }
+
+  size_t data_size = GetConvertedSize(
+      out_frame->GetFourcc(), in_frame.GetWidth(), in_frame.GetHeight());
+
+  if (out_frame->SetDataSize(data_size)) {
+    LOGF(ERROR) << "Set data size failed";
+    return -EINVAL;
+  }
+
+  if (in_frame.GetFourcc() == V4L2_PIX_FMT_YUYV) {
+    switch (out_frame->GetFourcc()) {
+      case V4L2_PIX_FMT_YUV420:  // YU12
+      {
+        int res = libyuv::YUY2ToI420(
+            in_frame.GetData(),      /* src_yuy2 */
+            in_frame.GetWidth() * 2, /* src_stride_yuy2 */
+            out_frame->GetData(),    /* dst_y */
+            out_frame->GetWidth(),   /* dst_stride_y */
+            out_frame->GetData() +
+                out_frame->GetWidth() * out_frame->GetHeight(), /* dst_u */
+            out_frame->GetWidth() / 2, /* dst_stride_u */
+            out_frame->GetData() + out_frame->GetWidth() *
+                                       out_frame->GetHeight() * 5 /
+                                       4, /* dst_v */
+            out_frame->GetWidth() / 2,    /* dst_stride_v */
+            in_frame.GetWidth(), in_frame.GetHeight());
+        LOGF_IF(ERROR, res) << "YUY2ToI420() for YU12 returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      default:
+        LOGF(ERROR) << "Destination pixel format "
+                    << FormatToString(out_frame->GetFourcc())
+                    << " is unsupported for YUYV source format.";
+        return -EINVAL;
+    }
+  } else if (in_frame.GetFourcc() == V4L2_PIX_FMT_YUV420) {
+    // V4L2_PIX_FMT_YVU420 is YV12. I420 is usually referred to YU12
+    // (V4L2_PIX_FMT_YUV420), and YV12 is similar to YU12 except that U/V
+    // planes are swapped.
+    switch (out_frame->GetFourcc()) {
+      case V4L2_PIX_FMT_YVU420:  // YV12
+      {
+        int ystride = Align16(in_frame.GetWidth());
+        int uvstride = Align16(in_frame.GetWidth() / 2);
+        int res = YU12ToYV12(in_frame.GetData(), out_frame->GetData(),
+                             in_frame.GetWidth(), in_frame.GetHeight(), ystride,
+                             uvstride);
+        LOGF_IF(ERROR, res) << "YU12ToYV12() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      case V4L2_PIX_FMT_YUV420:  // YU12
+      {
+        memcpy(out_frame->GetData(), in_frame.GetData(),
+               in_frame.GetDataSize());
+        return 0;
+      }
+      case V4L2_PIX_FMT_NV21:  // NV21
+      {
+        // TODO(henryhsu): Use libyuv::I420ToNV21.
+        int res = YU12ToNV21(in_frame.GetData(), out_frame->GetData(),
+                             in_frame.GetWidth(), in_frame.GetHeight());
+        LOGF_IF(ERROR, res) << "YU12ToNV21() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      case V4L2_PIX_FMT_BGR32: {
+        int res = libyuv::I420ToABGR(
+            in_frame.GetData(),  /* src_y */
+            in_frame.GetWidth(), /* src_stride_y */
+            in_frame.GetData() +
+                in_frame.GetWidth() * in_frame.GetHeight(), /* src_u */
+            in_frame.GetWidth() / 2,                        /* src_stride_u */
+            in_frame.GetData() +
+                in_frame.GetWidth() * in_frame.GetHeight() * 5 / 4, /* src_v */
+            in_frame.GetWidth() / 2,   /* src_stride_v */
+            out_frame->GetData(),      /* dst_abgr */
+            out_frame->GetWidth() * 4, /* dst_stride_abgr */
+            in_frame.GetWidth(), in_frame.GetHeight());
+        LOGF_IF(ERROR, res) << "I420ToABGR() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      case V4L2_PIX_FMT_RGB32: {
+        int res = libyuv::I420ToARGB(
+            in_frame.GetData(),  /* src_y */
+            in_frame.GetWidth(), /* src_stride_y */
+            in_frame.GetData() +
+                in_frame.GetWidth() * in_frame.GetHeight(), /* src_u */
+            in_frame.GetWidth() / 2,                        /* src_stride_u */
+            in_frame.GetData() +
+                in_frame.GetWidth() * in_frame.GetHeight() * 5 / 4, /* src_v */
+            in_frame.GetWidth() / 2,   /* src_stride_v */
+            out_frame->GetData(),      /* dst_argb */
+            out_frame->GetWidth() * 4, /* dst_stride_argb */
+            in_frame.GetWidth(), in_frame.GetHeight());
+        LOGF_IF(ERROR, res) << "I420ToARGB() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      case V4L2_PIX_FMT_JPEG: {
+        bool res = ConvertToJpeg(metadata, in_frame, out_frame);
+        LOGF_IF(ERROR, !res) << "ConvertToJpeg() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      default:
+        LOGF(ERROR) << "Destination pixel format "
+                    << FormatToString(out_frame->GetFourcc())
+                    << " is unsupported for YU12 source format.";
+        return -EINVAL;
+    }
+  } else if (in_frame.GetFourcc() == V4L2_PIX_FMT_MJPEG) {
+    switch (out_frame->GetFourcc()) {
+      case V4L2_PIX_FMT_YUV420:  // YU12
+      {
+        int res = libyuv::MJPGToI420(
+            in_frame.GetData(),     /* sample */
+            in_frame.GetDataSize(), /* sample_size */
+            out_frame->GetData(),   /* dst_y */
+            out_frame->GetWidth(),  /* dst_stride_y */
+            out_frame->GetData() +
+                out_frame->GetWidth() * out_frame->GetHeight(), /* dst_u */
+            out_frame->GetWidth() / 2, /* dst_stride_u */
+            out_frame->GetData() + out_frame->GetWidth() *
+                                       out_frame->GetHeight() * 5 /
+                                       4, /* dst_v */
+            out_frame->GetWidth() / 2,    /* dst_stride_v */
+            in_frame.GetWidth(), in_frame.GetHeight(), out_frame->GetWidth(),
+            out_frame->GetHeight());
+        LOGF_IF(ERROR, res) << "MJPEGToI420() returns " << res;
+        return res ? -EINVAL : 0;
+      }
+      default:
+        LOGF(ERROR) << "Destination pixel format "
+                    << FormatToString(out_frame->GetFourcc())
+                    << " is unsupported for MJPEG source format.";
+        return -EINVAL;
+    }
+  } else {
+    LOGF(ERROR) << "Convert format doesn't support source format "
+                << FormatToString(in_frame.GetFourcc());
+    return -EINVAL;
+  }
+}
+
+int ImageProcessor::Scale(const FrameBuffer& in_frame, FrameBuffer* out_frame) {
+  if (in_frame.GetFourcc() != V4L2_PIX_FMT_YUV420) {
+    LOGF(ERROR) << "Pixel format " << FormatToString(in_frame.GetFourcc())
+                << " is unsupported.";
+    return -EINVAL;
+  }
+
+  size_t data_size = GetConvertedSize(
+      in_frame.GetFourcc(), out_frame->GetWidth(), out_frame->GetHeight());
+
+  if (out_frame->SetDataSize(data_size)) {
+    LOGF(ERROR) << "Set data size failed";
+    return -EINVAL;
+  }
+  out_frame->SetFourcc(in_frame.GetFourcc());
+
+  VLOGF(1) << "Scale image from " << in_frame.GetWidth() << "x"
+           << in_frame.GetHeight() << " to " << out_frame->GetWidth() << "x"
+           << out_frame->GetHeight();
+
+  int ret = libyuv::I420Scale(
+      in_frame.GetData(), in_frame.GetWidth(),
+      in_frame.GetData() + in_frame.GetWidth() * in_frame.GetHeight(),
+      in_frame.GetWidth() / 2,
+      in_frame.GetData() + in_frame.GetWidth() * in_frame.GetHeight() * 5 / 4,
+      in_frame.GetWidth() / 2, in_frame.GetWidth(), in_frame.GetHeight(),
+      out_frame->GetData(), out_frame->GetWidth(),
+      out_frame->GetData() + out_frame->GetWidth() * out_frame->GetHeight(),
+      out_frame->GetWidth() / 2,
+      out_frame->GetData() +
+          out_frame->GetWidth() * out_frame->GetHeight() * 5 / 4,
+      out_frame->GetWidth() / 2, out_frame->GetWidth(), out_frame->GetHeight(),
+      libyuv::FilterMode::kFilterNone);
+  LOGF_IF(ERROR, ret) << "I420Scale failed: " << ret;
+  return ret;
+}
+
+static int YU12ToYV12(const void* yu12, void* yv12, int width, int height,
+                      int dst_stride_y, int dst_stride_uv) {
+  if ((width % 2) || (height % 2)) {
+    LOGF(ERROR) << "Width or height is not even (" << width << " x " << height
+                << ")";
+    return -EINVAL;
+  }
+  if (dst_stride_y < width || dst_stride_uv < width / 2) {
+    LOGF(ERROR) << "Y plane stride (" << dst_stride_y
+                << ") or U/V plane stride (" << dst_stride_uv
+                << ") is invalid for width " << width;
+    return -EINVAL;
+  }
+
+  const uint8_t* src = reinterpret_cast<const uint8_t*>(yu12);
+  uint8_t* dst = reinterpret_cast<uint8_t*>(yv12);
+  const uint8_t* u_src = src + width * height;
+  uint8_t* u_dst = dst + dst_stride_y * height + dst_stride_uv * height / 2;
+  const uint8_t* v_src = src + width * height * 5 / 4;
+  uint8_t* v_dst = dst + dst_stride_y * height;
+
+  return libyuv::I420Copy(src, width, u_src, width / 2, v_src, width / 2, dst,
+                          dst_stride_y, u_dst, dst_stride_uv, v_dst,
+                          dst_stride_uv, width, height);
+}
+
+static int YU12ToNV21(const void* yu12, void* nv21, int width, int height) {
+  if ((width % 2) || (height % 2)) {
+    LOGF(ERROR) << "Width or height is not even (" << width << " x " << height
+                << ")";
+    return -EINVAL;
+  }
+
+  const uint8_t* src = reinterpret_cast<const uint8_t*>(yu12);
+  uint8_t* dst = reinterpret_cast<uint8_t*>(nv21);
+  const uint8_t* u_src = src + width * height;
+  const uint8_t* v_src = src + width * height * 5 / 4;
+  uint8_t* vu_dst = dst + width * height;
+
+  memcpy(dst, src, width * height);
+
+  for (int i = 0; i < height / 2; i++) {
+    for (int j = 0; j < width / 2; j++) {
+      *vu_dst++ = *v_src++;
+      *vu_dst++ = *u_src++;
+    }
+  }
+  return 0;
+}
+
+static bool ConvertToJpeg(const CameraMetadata& metadata,
+                          const FrameBuffer& in_frame, FrameBuffer* out_frame) {
+  ExifUtils utils;
+  int jpeg_quality, thumbnail_jpeg_quality;
+  camera_metadata_ro_entry entry;
+
+  if (metadata.exists(ANDROID_JPEG_QUALITY)) {
+    entry = metadata.find(ANDROID_JPEG_QUALITY);
+    jpeg_quality = entry.data.u8[0];
+  } else {
+    LOGF(ERROR) << "Could not find jpeg quality in metadata, defaulting to "
+                << DEFAULT_JPEG_QUALITY;
+    jpeg_quality = DEFAULT_JPEG_QUALITY;
+  }
+  if (metadata.exists(ANDROID_JPEG_THUMBNAIL_QUALITY)) {
+    entry = metadata.find(ANDROID_JPEG_THUMBNAIL_QUALITY);
+    thumbnail_jpeg_quality = entry.data.u8[0];
+  } else {
+    thumbnail_jpeg_quality = jpeg_quality;
+  }
+
+  if (!utils.Initialize(in_frame.GetData(), in_frame.GetWidth(),
+                        in_frame.GetHeight(), thumbnail_jpeg_quality)) {
+    LOGF(ERROR) << "ExifUtils initialization failed.";
+    return false;
+  }
+  if (!SetExifTags(metadata, &utils)) {
+    LOGF(ERROR) << "Setting Exif tags failed.";
+    return false;
+  }
+  if (!utils.GenerateApp1()) {
+    LOGF(ERROR) << "Generating APP1 segment failed.";
+    return false;
+  }
+  JpegCompressor compressor;
+  if (!compressor.CompressImage(in_frame.GetData(), in_frame.GetWidth(),
+                                in_frame.GetHeight(), jpeg_quality,
+                                utils.GetApp1Buffer(), utils.GetApp1Length())) {
+    LOGF(ERROR) << "JPEG image compression failed";
+    return false;
+  }
+  size_t buffer_length = compressor.GetCompressedImageSize();
+  memcpy(out_frame->GetData(), compressor.GetCompressedImagePtr(),
+         buffer_length);
+  return true;
+}
+
+static bool SetExifTags(const CameraMetadata& metadata, ExifUtils* utils) {
+  time_t raw_time = 0;
+  struct tm time_info;
+  bool time_available = time(&raw_time) != -1;
+  localtime_r(&raw_time, &time_info);
+  if (!utils->SetDateTime(time_info)) {
+    LOGF(ERROR) << "Setting data time failed.";
+    return false;
+  }
+
+  float focal_length;
+  camera_metadata_ro_entry entry = metadata.find(ANDROID_LENS_FOCAL_LENGTH);
+  if (entry.count) {
+    focal_length = entry.data.f[0];
+  } else {
+    LOGF(ERROR) << "Cannot find focal length in metadata.";
+    return false;
+  }
+  if (!utils->SetFocalLength(
+          static_cast<uint32_t>(focal_length * kRationalPrecision),
+          kRationalPrecision)) {
+    LOGF(ERROR) << "Setting focal length failed.";
+    return false;
+  }
+
+  if (metadata.exists(ANDROID_JPEG_GPS_COORDINATES)) {
+    entry = metadata.find(ANDROID_JPEG_GPS_COORDINATES);
+    if (entry.count < 3) {
+      LOGF(ERROR) << "Gps coordinates in metadata is not complete.";
+      return false;
+    }
+    if (!utils->SetGpsLatitude(entry.data.d[0])) {
+      LOGF(ERROR) << "Setting gps latitude failed.";
+      return false;
+    }
+    if (!utils->SetGpsLongitude(entry.data.d[1])) {
+      LOGF(ERROR) << "Setting gps longitude failed.";
+      return false;
+    }
+    if (!utils->SetGpsAltitude(entry.data.d[2])) {
+      LOGF(ERROR) << "Setting gps altitude failed.";
+      return false;
+    }
+  }
+
+  if (metadata.exists(ANDROID_JPEG_GPS_PROCESSING_METHOD)) {
+    entry = metadata.find(ANDROID_JPEG_GPS_PROCESSING_METHOD);
+    std::string method_str(reinterpret_cast<const char*>(entry.data.u8));
+    if (!utils->SetGpsProcessingMethod(method_str)) {
+      LOGF(ERROR) << "Setting gps processing method failed.";
+      return false;
+    }
+  }
+
+  if (time_available && metadata.exists(ANDROID_JPEG_GPS_TIMESTAMP)) {
+    entry = metadata.find(ANDROID_JPEG_GPS_TIMESTAMP);
+    time_t timestamp = static_cast<time_t>(entry.data.i64[0]);
+    if (gmtime_r(&timestamp, &time_info)) {
+      if (!utils->SetGpsTimestamp(time_info)) {
+        LOGF(ERROR) << "Setting gps timestamp failed.";
+        return false;
+      }
+    } else {
+      LOGF(ERROR) << "Time tranformation failed.";
+      return false;
+    }
+  }
+
+  if (metadata.exists(ANDROID_JPEG_ORIENTATION)) {
+    entry = metadata.find(ANDROID_JPEG_ORIENTATION);
+    if (!utils->SetOrientation(entry.data.i32[0])) {
+      LOGF(ERROR) << "Setting orientation failed.";
+      return false;
+    }
+  }
+
+  if (metadata.exists(ANDROID_JPEG_THUMBNAIL_SIZE)) {
+    entry = metadata.find(ANDROID_JPEG_THUMBNAIL_SIZE);
+    if (entry.count < 2) {
+      LOGF(ERROR) << "Thumbnail size in metadata is not complete.";
+      return false;
+    }
+    int thumbnail_width = entry.data.i32[0];
+    int thumbnail_height = entry.data.i32[1];
+    if (thumbnail_width > 0 && thumbnail_height > 0) {
+      if (!utils->SetThumbnailSize(static_cast<uint16_t>(thumbnail_width),
+                                   static_cast<uint16_t>(thumbnail_height))) {
+        LOGF(ERROR) << "Setting thumbnail size failed.";
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
+}  // namespace arc
diff --git a/modules/camera/3_4/arc/image_processor.h b/modules/camera/3_4/arc/image_processor.h
new file mode 100644
index 0000000..323680a
--- /dev/null
+++ b/modules/camera/3_4/arc/image_processor.h
@@ -0,0 +1,48 @@
+/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef HAL_USB_IMAGE_PROCESSOR_H_
+#define HAL_USB_IMAGE_PROCESSOR_H_
+
+#include <string>
+
+// FourCC pixel formats (defined as V4L2_PIX_FMT_*).
+#include <linux/videodev2.h>
+// Declarations of HAL_PIXEL_FORMAT_XXX.
+#include <system/graphics.h>
+
+#include <camera/CameraMetadata.h>
+#include "frame_buffer.h"
+
+namespace arc {
+
+// V4L2_PIX_FMT_YVU420(YV12) in ImageProcessor has alignment requirement.
+// The stride of Y, U, and V planes should a multiple of 16 pixels.
+struct ImageProcessor {
+  // Calculate the output buffer size when converting to the specified pixel
+  // format. |fourcc| is defined as V4L2_PIX_FMT_* in linux/videodev2.h.
+  // Return 0 on error.
+  static size_t GetConvertedSize(int fourcc, uint32_t width, uint32_t height);
+
+  // Return whether this class supports the provided conversion.
+  static bool SupportsConversion(uint32_t from_fourcc, uint32_t to_fourcc);
+
+  // Convert format from |in_frame.fourcc| to |out_frame->fourcc|. Caller should
+  // fill |data|, |buffer_size|, |width|, and |height| of |out_frame|. The
+  // function will fill |out_frame->data_size|. Return non-zero error code on
+  // failure; return 0 on success.
+  static int ConvertFormat(const android::CameraMetadata& metadata,
+                           const FrameBuffer& in_frame, FrameBuffer* out_frame);
+
+  // Scale image size according to |in_frame| and |out_frame|. Only support
+  // V4L2_PIX_FMT_YUV420 format. Caller should fill |data|, |width|, |height|,
+  // and |buffer_size| of |out_frame|. The function will fill |data_size| and
+  // |fourcc| of |out_frame|.
+  static int Scale(const FrameBuffer& in_frame, FrameBuffer* out_frame);
+};
+
+}  // namespace arc
+
+#endif  // HAL_USB_IMAGE_PROCESSOR_H_
diff --git a/modules/camera/3_4/arc/jpeg_compressor.cpp b/modules/camera/3_4/arc/jpeg_compressor.cpp
new file mode 100644
index 0000000..7c61b40
--- /dev/null
+++ b/modules/camera/3_4/arc/jpeg_compressor.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "arc/jpeg_compressor.h"
+
+#include <memory>
+
+#include <errno.h>
+
+#include "arc/common.h"
+
+namespace arc {
+
+// The destination manager that can access |result_buffer_| in JpegCompressor.
+struct destination_mgr {
+ public:
+  struct jpeg_destination_mgr mgr;
+  JpegCompressor* compressor;
+};
+
+JpegCompressor::JpegCompressor() {}
+
+JpegCompressor::~JpegCompressor() {}
+
+bool JpegCompressor::CompressImage(const void* image, int width, int height,
+                                   int quality, const void* app1Buffer,
+                                   unsigned int app1Size) {
+  if (width % 8 != 0 || height % 2 != 0) {
+    LOGF(ERROR) << "Image size can not be handled: " << width << "x" << height;
+    return false;
+  }
+
+  result_buffer_.clear();
+  if (!Encode(image, width, height, quality, app1Buffer, app1Size)) {
+    return false;
+  }
+  LOGF(INFO) << "Compressed JPEG: " << (width * height * 12) / 8 << "[" << width
+             << "x" << height << "] -> " << result_buffer_.size() << " bytes";
+  return true;
+}
+
+const void* JpegCompressor::GetCompressedImagePtr() {
+  return result_buffer_.data();
+}
+
+size_t JpegCompressor::GetCompressedImageSize() {
+  return result_buffer_.size();
+}
+
+void JpegCompressor::InitDestination(j_compress_ptr cinfo) {
+  destination_mgr* dest = reinterpret_cast<destination_mgr*>(cinfo->dest);
+  std::vector<JOCTET>& buffer = dest->compressor->result_buffer_;
+  buffer.resize(kBlockSize);
+  dest->mgr.next_output_byte = &buffer[0];
+  dest->mgr.free_in_buffer = buffer.size();
+}
+
+boolean JpegCompressor::EmptyOutputBuffer(j_compress_ptr cinfo) {
+  destination_mgr* dest = reinterpret_cast<destination_mgr*>(cinfo->dest);
+  std::vector<JOCTET>& buffer = dest->compressor->result_buffer_;
+  size_t oldsize = buffer.size();
+  buffer.resize(oldsize + kBlockSize);
+  dest->mgr.next_output_byte = &buffer[oldsize];
+  dest->mgr.free_in_buffer = kBlockSize;
+  return true;
+}
+
+void JpegCompressor::TerminateDestination(j_compress_ptr cinfo) {
+  destination_mgr* dest = reinterpret_cast<destination_mgr*>(cinfo->dest);
+  std::vector<JOCTET>& buffer = dest->compressor->result_buffer_;
+  buffer.resize(buffer.size() - dest->mgr.free_in_buffer);
+}
+
+void JpegCompressor::OutputErrorMessage(j_common_ptr cinfo) {
+  char buffer[JMSG_LENGTH_MAX];
+
+  /* Create the message */
+  (*cinfo->err->format_message)(cinfo, buffer);
+  LOGF(ERROR) << buffer;
+}
+
+bool JpegCompressor::Encode(const void* inYuv, int width, int height,
+                            int jpegQuality, const void* app1Buffer,
+                            unsigned int app1Size) {
+  jpeg_compress_struct cinfo;
+  jpeg_error_mgr jerr;
+
+  cinfo.err = jpeg_std_error(&jerr);
+  // Override output_message() to print error log with ALOGE().
+  cinfo.err->output_message = &OutputErrorMessage;
+  jpeg_create_compress(&cinfo);
+  SetJpegDestination(&cinfo);
+
+  SetJpegCompressStruct(width, height, jpegQuality, &cinfo);
+  jpeg_start_compress(&cinfo, TRUE);
+
+  if (app1Buffer != nullptr && app1Size > 0) {
+    jpeg_write_marker(&cinfo, JPEG_APP0 + 1,
+                      static_cast<const JOCTET*>(app1Buffer), app1Size);
+  }
+
+  if (!Compress(&cinfo, static_cast<const uint8_t*>(inYuv))) {
+    return false;
+  }
+  jpeg_finish_compress(&cinfo);
+  return true;
+}
+
+void JpegCompressor::SetJpegDestination(jpeg_compress_struct* cinfo) {
+  destination_mgr* dest =
+      static_cast<struct destination_mgr*>((*cinfo->mem->alloc_small)(
+          (j_common_ptr)cinfo, JPOOL_PERMANENT, sizeof(destination_mgr)));
+  dest->compressor = this;
+  dest->mgr.init_destination = &InitDestination;
+  dest->mgr.empty_output_buffer = &EmptyOutputBuffer;
+  dest->mgr.term_destination = &TerminateDestination;
+  cinfo->dest = reinterpret_cast<struct jpeg_destination_mgr*>(dest);
+}
+
+void JpegCompressor::SetJpegCompressStruct(int width, int height, int quality,
+                                           jpeg_compress_struct* cinfo) {
+  cinfo->image_width = width;
+  cinfo->image_height = height;
+  cinfo->input_components = 3;
+  cinfo->in_color_space = JCS_YCbCr;
+  jpeg_set_defaults(cinfo);
+
+  jpeg_set_quality(cinfo, quality, TRUE);
+  jpeg_set_colorspace(cinfo, JCS_YCbCr);
+  cinfo->raw_data_in = TRUE;
+  cinfo->dct_method = JDCT_IFAST;
+
+  // Configure sampling factors. The sampling factor is JPEG subsampling 420
+  // because the source format is YUV420.
+  cinfo->comp_info[0].h_samp_factor = 2;
+  cinfo->comp_info[0].v_samp_factor = 2;
+  cinfo->comp_info[1].h_samp_factor = 1;
+  cinfo->comp_info[1].v_samp_factor = 1;
+  cinfo->comp_info[2].h_samp_factor = 1;
+  cinfo->comp_info[2].v_samp_factor = 1;
+}
+
+bool JpegCompressor::Compress(jpeg_compress_struct* cinfo, const uint8_t* yuv) {
+  JSAMPROW y[kCompressBatchSize];
+  JSAMPROW cb[kCompressBatchSize / 2];
+  JSAMPROW cr[kCompressBatchSize / 2];
+  JSAMPARRAY planes[3]{y, cb, cr};
+
+  size_t y_plane_size = cinfo->image_width * cinfo->image_height;
+  size_t uv_plane_size = y_plane_size / 4;
+  uint8_t* y_plane = const_cast<uint8_t*>(yuv);
+  uint8_t* u_plane = const_cast<uint8_t*>(yuv + y_plane_size);
+  uint8_t* v_plane = const_cast<uint8_t*>(yuv + y_plane_size + uv_plane_size);
+  std::unique_ptr<uint8_t[]> empty(new uint8_t[cinfo->image_width]);
+  memset(empty.get(), 0, cinfo->image_width);
+
+  while (cinfo->next_scanline < cinfo->image_height) {
+    for (int i = 0; i < kCompressBatchSize; ++i) {
+      size_t scanline = cinfo->next_scanline + i;
+      if (scanline < cinfo->image_height) {
+        y[i] = y_plane + scanline * cinfo->image_width;
+      } else {
+        y[i] = empty.get();
+      }
+    }
+    // cb, cr only have half scanlines
+    for (int i = 0; i < kCompressBatchSize / 2; ++i) {
+      size_t scanline = cinfo->next_scanline / 2 + i;
+      if (scanline < cinfo->image_height / 2) {
+        int offset = scanline * (cinfo->image_width / 2);
+        cb[i] = u_plane + offset;
+        cr[i] = v_plane + offset;
+      } else {
+        cb[i] = cr[i] = empty.get();
+      }
+    }
+
+    int processed = jpeg_write_raw_data(cinfo, planes, kCompressBatchSize);
+    if (processed != kCompressBatchSize) {
+      LOGF(ERROR) << "Number of processed lines does not equal input lines.";
+      return false;
+    }
+  }
+  return true;
+}
+
+}  // namespace arc
diff --git a/modules/camera/3_4/arc/jpeg_compressor.h b/modules/camera/3_4/arc/jpeg_compressor.h
new file mode 100644
index 0000000..378f3cd
--- /dev/null
+++ b/modules/camera/3_4/arc/jpeg_compressor.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef INCLUDE_ARC_JPEG_COMPRESSOR_H_
+#define INCLUDE_ARC_JPEG_COMPRESSOR_H_
+
+// We must include cstdio before jpeglib.h. It is a requirement of libjpeg.
+#include <cstdio>
+#include <string>
+#include <vector>
+
+extern "C" {
+#include <jerror.h>
+#include <jpeglib.h>
+}
+
+namespace arc {
+
+// Encapsulates a converter from YU12 to JPEG format. This class is not
+// thread-safe.
+class JpegCompressor {
+ public:
+  JpegCompressor();
+  ~JpegCompressor();
+
+  // Compresses YU12 image to JPEG format. After calling this method, call
+  // GetCompressedImagePtr() to get the image. |quality| is the resulted jpeg
+  // image quality. It ranges from 1 (poorest quality) to 100 (highest quality).
+  // |app1Buffer| is the buffer of APP1 segment (exif) which will be added to
+  // the compressed image. Returns false if errors occur during compression.
+  bool CompressImage(const void* image, int width, int height, int quality,
+                     const void* app1Buffer, unsigned int app1Size);
+
+  // Returns the compressed JPEG buffer pointer. This method must be called only
+  // after calling CompressImage().
+  const void* GetCompressedImagePtr();
+
+  // Returns the compressed JPEG buffer size. This method must be called only
+  // after calling CompressImage().
+  size_t GetCompressedImageSize();
+
+ private:
+  // InitDestination(), EmptyOutputBuffer() and TerminateDestination() are
+  // callback functions to be passed into jpeg library.
+  static void InitDestination(j_compress_ptr cinfo);
+  static boolean EmptyOutputBuffer(j_compress_ptr cinfo);
+  static void TerminateDestination(j_compress_ptr cinfo);
+  static void OutputErrorMessage(j_common_ptr cinfo);
+
+  // Returns false if errors occur.
+  bool Encode(const void* inYuv, int width, int height, int jpegQuality,
+              const void* app1Buffer, unsigned int app1Size);
+  void SetJpegDestination(jpeg_compress_struct* cinfo);
+  void SetJpegCompressStruct(int width, int height, int quality,
+                             jpeg_compress_struct* cinfo);
+  // Returns false if errors occur.
+  bool Compress(jpeg_compress_struct* cinfo, const uint8_t* yuv);
+
+  // The block size for encoded jpeg image buffer.
+  static const int kBlockSize = 16384;
+  // Process 16 lines of Y and 16 lines of U/V each time.
+  // We must pass at least 16 scanlines according to libjpeg documentation.
+  static const int kCompressBatchSize = 16;
+
+  // The buffer that holds the compressed result.
+  std::vector<JOCTET> result_buffer_;
+};
+
+}  // namespace arc
+
+#endif  // INCLUDE_ARC_JPEG_COMPRESSOR_H_
diff --git a/modules/camera/3_4/camera.cpp b/modules/camera/3_4/camera.cpp
index 83905ea..79dca0b 100644
--- a/modules/camera/3_4/camera.cpp
+++ b/modules/camera/3_4/camera.cpp
@@ -455,6 +455,7 @@
                     __func__, mId, strerror(-res), res);
             return res;
         }
+        ::close(buffer->acquire_fence);
     }
 
     // Acquire fence has been waited upon.
diff --git a/modules/camera/3_4/format_metadata_factory.cpp b/modules/camera/3_4/format_metadata_factory.cpp
index a08f9a8..db03678 100644
--- a/modules/camera/3_4/format_metadata_factory.cpp
+++ b/modules/camera/3_4/format_metadata_factory.cpp
@@ -16,6 +16,7 @@
 
 #include "format_metadata_factory.h"
 
+#include "arc/image_processor.h"
 #include "metadata/array_vector.h"
 #include "metadata/partial_metadata_factory.h"
 #include "metadata/property.h"
@@ -35,6 +36,7 @@
     HAL_LOGE("Failed to get device formats.");
     return res;
   }
+
   for (auto v4l2_format : v4l2_formats) {
     int32_t hal_format = StreamFormat::V4L2ToHalPixelFormat(v4l2_format);
     if (hal_format < 0) {
@@ -44,21 +46,17 @@
     result_formats->insert(hal_format);
   }
 
-  // In addition to well-defined formats, there may be an
-  // "Implementation Defined" format chosen by the HAL (in this
-  // case what that means is managed by the StreamFormat class).
-
-  // Get the V4L2 format for IMPLEMENTATION_DEFINED.
-  int v4l2_format = StreamFormat::HalToV4L2PixelFormat(
-      HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
-  // If it's available, add IMPLEMENTATION_DEFINED to the result set.
-  if (v4l2_format && v4l2_formats.count(v4l2_format) > 0) {
-    result_formats->insert(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
-  }
-
   return 0;
 }
 
+static int FpsRangesCompare(std::array<int32_t, 2> a,
+                            std::array<int32_t, 2> b) {
+  if (a[1] == b[1]) {
+    return a[0] > b[0];
+  }
+  return a[1] > b[1];
+}
+
 int AddFormatComponents(
     std::shared_ptr<V4L2Wrapper> device,
     std::insert_iterator<PartialMetadataSet> insertion_point) {
@@ -71,19 +69,39 @@
     return res;
   }
 
-  // Requirements check: need to support YCbCr_420_888, JPEG,
-  // and "Implementation Defined".
+  std::set<int32_t> unsupported_hal_formats;
   if (hal_formats.find(HAL_PIXEL_FORMAT_YCbCr_420_888) == hal_formats.end()) {
-    HAL_LOGE("YCbCr_420_888 not supported by device.");
-    return -ENODEV;
-  } else if (hal_formats.find(HAL_PIXEL_FORMAT_BLOB) == hal_formats.end()) {
-    HAL_LOGE("JPEG not supported by device.");
-    return -ENODEV;
-  } else if (hal_formats.find(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) ==
-             hal_formats.end()) {
-    HAL_LOGE("HAL implementation defined format not supported by device.");
-    return -ENODEV;
+    HAL_LOGW("YCbCr_420_888 (0x%x) not directly supported by device.",
+             HAL_PIXEL_FORMAT_YCbCr_420_888);
+    hal_formats.insert(HAL_PIXEL_FORMAT_YCbCr_420_888);
+    unsupported_hal_formats.insert(HAL_PIXEL_FORMAT_YCbCr_420_888);
   }
+  if (hal_formats.find(HAL_PIXEL_FORMAT_BLOB) == hal_formats.end()) {
+    HAL_LOGW("JPEG (0x%x) not directly supported by device.",
+             HAL_PIXEL_FORMAT_BLOB);
+    hal_formats.insert(HAL_PIXEL_FORMAT_BLOB);
+    unsupported_hal_formats.insert(HAL_PIXEL_FORMAT_BLOB);
+  }
+
+  // As hal_formats is populated by reading and converting V4L2 formats to the
+  // matching HAL formats, we will never see an implementation defined format in
+  // the list. We populate it ourselves and map it to a qualified format. If no
+  // qualified formats exist, this will be the first available format.
+  hal_formats.insert(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
+  unsupported_hal_formats.insert(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
+
+  // Qualified formats are the set of formats supported by this camera that the
+  // image processor can translate into the YU12 format. We additionally check
+  // that the conversion from YU12 to the desired hal format is supported.
+  std::vector<uint32_t> qualified_formats;
+  res = device->GetQualifiedFormats(&qualified_formats);
+  if (res && unsupported_hal_formats.size() > 1) {
+    HAL_LOGE(
+        "Failed to retrieve qualified formats, cannot perform conversions.");
+    return res;
+  }
+
+  HAL_LOGI("Supports %d qualified formats.", qualified_formats.size());
 
   // Find sizes and frame/stall durations for all formats.
   // We also want to find the smallest max frame duration amongst all formats,
@@ -96,7 +114,7 @@
   // Stall durations are {format, width, height, duration} (duration in ns).
   ArrayVector<int64_t, 4> stall_durations;
   int64_t min_max_frame_duration = std::numeric_limits<int64_t>::max();
-  int64_t max_min_frame_duration_yuv = std::numeric_limits<int64_t>::min();
+  std::vector<std::array<int32_t, 2>> fps_ranges;
   for (auto hal_format : hal_formats) {
     // Get the corresponding V4L2 format.
     uint32_t v4l2_format = StreamFormat::HalToV4L2PixelFormat(hal_format);
@@ -105,6 +123,42 @@
       // came from translating a bunch of V4L2 formats above.
       HAL_LOGE("Couldn't find V4L2 format for HAL format %d", hal_format);
       return -ENODEV;
+    } else if (unsupported_hal_formats.find(hal_format) !=
+               unsupported_hal_formats.end()) {
+      if (hal_format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
+        if (qualified_formats.size() != 0) {
+          v4l2_format = qualified_formats[0];
+        } else if (unsupported_hal_formats.size() == 1) {
+          v4l2_format = StreamFormat::HalToV4L2PixelFormat(
+              HAL_PIXEL_FORMAT_YCbCr_420_888);
+        } else {
+          // No-op. If there are no qualified formats, and implementation
+          // defined is not the only unsupported format, then other unsupported
+          // formats will throw an error.
+        }
+        HAL_LOGW(
+            "Implementation-defined format is set to V4L2 pixel format 0x%x",
+            v4l2_format);
+      } else if (qualified_formats.size() == 0) {
+        HAL_LOGE(
+            "Camera does not support required format: 0x%x, and there are no "
+            "qualified"
+            "formats to transform from.",
+            hal_format);
+        return -ENODEV;
+      } else if (!arc::ImageProcessor::SupportsConversion(V4L2_PIX_FMT_YUV420,
+                                                          v4l2_format)) {
+        HAL_LOGE(
+            "The image processor does not support conversion to required "
+            "format: 0x%x",
+            hal_format);
+        return -ENODEV;
+      } else {
+        v4l2_format = qualified_formats[0];
+        HAL_LOGW(
+            "Hal format 0x%x will be converted from V4L2 pixel format 0x%x",
+            hal_format, v4l2_format);
+      }
     }
 
     // Get the available sizes for this format.
@@ -160,39 +214,25 @@
       if (size_max_frame_duration < min_max_frame_duration) {
         min_max_frame_duration = size_max_frame_duration;
       }
-      // We only care about the largest min frame duration
-      // (smallest max frame rate) for YUV sizes.
-      if (hal_format == HAL_PIXEL_FORMAT_YCbCr_420_888 &&
-          size_min_frame_duration > max_min_frame_duration_yuv) {
-        max_min_frame_duration_yuv = size_min_frame_duration;
+      // ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES will contain all
+      // the fps ranges for YUV_420_888 only since YUV_420_888 format is
+      // the default camera format by Android.
+      if (hal_format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
+        // Convert from frame durations measured in ns.
+        // Min, max fps supported by all YUV formats.
+        const int32_t min_fps = 1000000000 / size_max_frame_duration;
+        const int32_t max_fps = 1000000000 / size_min_frame_duration;
+        if (std::find(fps_ranges.begin(), fps_ranges.end(),
+                      std::array<int32_t, 2>{min_fps, max_fps}) ==
+            fps_ranges.end()) {
+          fps_ranges.push_back({min_fps, max_fps});
+        }
       }
     }
   }
 
-  // Convert from frame durations measured in ns.
-  // Min fps supported by all formats.
-  int32_t min_fps = 1000000000 / min_max_frame_duration;
-  if (min_fps > 15) {
-    HAL_LOGE("Minimum FPS %d is larger than HAL max allowable value of 15",
-             min_fps);
-    return -ENODEV;
-  }
-  // Max fps supported by all YUV formats.
-  int32_t max_yuv_fps = 1000000000 / max_min_frame_duration_yuv;
-  // ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES should be at minimum
-  // {mi, ma}, {ma, ma} where mi and ma are min and max frame rates for
-  // YUV_420_888. Min should be at most 15.
-  std::vector<std::array<int32_t, 2>> fps_ranges;
-  fps_ranges.push_back({{min_fps, max_yuv_fps}});
-
-  std::array<int32_t, 2> video_fps_range;
-  int32_t video_fps = 30;
-  if (video_fps >= max_yuv_fps) {
-    video_fps_range = {{max_yuv_fps, max_yuv_fps}};
-  } else {
-    video_fps_range = {{video_fps, video_fps}};
-  }
-  fps_ranges.push_back(video_fps_range);
+  // Sort fps ranges in descending order.
+  std::sort(fps_ranges.begin(), fps_ranges.end(), FpsRangesCompare);
 
   // Construct the metadata components.
   insertion_point = std::make_unique<Property<ArrayVector<int32_t, 4>>>(
@@ -208,10 +248,9 @@
   // TODO(b/31019725): This should probably not be a NoEffect control.
   insertion_point = NoEffectMenuControl<std::array<int32_t, 2>>(
       ANDROID_CONTROL_AE_TARGET_FPS_RANGE,
-      ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
-      fps_ranges,
-      {{CAMERA3_TEMPLATE_VIDEO_RECORD, video_fps_range},
-       {OTHER_TEMPLATES, fps_ranges[0]}});
+      ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, fps_ranges,
+      {{CAMERA3_TEMPLATE_VIDEO_RECORD, fps_ranges.front()},
+       {OTHER_TEMPLATES, fps_ranges.back()}});
 
   return 0;
 }
diff --git a/modules/camera/3_4/format_metadata_factory.h b/modules/camera/3_4/format_metadata_factory.h
index 4cf5952..23c1777 100644
--- a/modules/camera/3_4/format_metadata_factory.h
+++ b/modules/camera/3_4/format_metadata_factory.h
@@ -17,6 +17,7 @@
 #ifndef V4L2_CAMERA_HAL_FORMAT_METADATA_FACTORY_H_
 #define V4L2_CAMERA_HAL_FORMAT_METADATA_FACTORY_H_
 
+#include <algorithm>
 #include <iterator>
 #include <memory>
 #include <set>
diff --git a/modules/camera/3_4/format_metadata_factory_test.cpp b/modules/camera/3_4/format_metadata_factory_test.cpp
index d37b09f..fe5d67f 100644
--- a/modules/camera/3_4/format_metadata_factory_test.cpp
+++ b/modules/camera/3_4/format_metadata_factory_test.cpp
@@ -46,10 +46,12 @@
 };
 
 TEST_F(FormatMetadataFactoryTest, GetFormatMetadata) {
-  std::set<uint32_t> formats{V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420};
+  std::set<uint32_t> formats{V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420,
+                             V4L2_PIX_FMT_YUYV};
   std::map<uint32_t, std::set<std::array<int32_t, 2>>> sizes{
       {V4L2_PIX_FMT_JPEG, {{{10, 20}}, {{30, 60}}, {{120, 240}}}},
-      {V4L2_PIX_FMT_YUV420, {{{1, 2}}, {{3, 6}}, {{12, 24}}}}};
+      {V4L2_PIX_FMT_YUV420, {{{1, 2}}, {{3, 6}}, {{12, 24}}}},
+      {V4L2_PIX_FMT_YUYV, {{{20, 40}}, {{80, 160}}, {{320, 640}}}}};
   // These need to be on the correct order of magnitude,
   // as there is a check for min fps > 15.
   std::map<uint32_t, std::map<std::array<int32_t, 2>, std::array<int64_t, 2>>>
@@ -60,19 +62,24 @@
                 {V4L2_PIX_FMT_YUV420,
                  {{{{1, 2}}, {{10000000000, 20000000000}}},
                   {{{3, 6}}, {{11000000000, 21000000000}}},
-                  {{{12, 24}}, {{10500000000, 19000000000}}}}}};
+                  {{{12, 24}}, {{10500000000, 19000000000}}}}},
+                {V4L2_PIX_FMT_YUYV,
+                 {{{{20, 40}}, {{11000000000, 22000000000}}},
+                  {{{80, 160}}, {{13000000000, 25000000000}}},
+                  {{{320, 640}}, {{10100000000, 19000000000}}}}}};
+  // The camera must report at least one qualified format.
+  std::vector<uint32_t> qualified_formats = {V4L2_PIX_FMT_YUYV};
 
   // Device must support IMPLEMENTATION_DEFINED (as well as JPEG & YUV).
-  // Just duplicate the values from another format.
-  uint32_t imp_defined_format = StreamFormat::HalToV4L2PixelFormat(
-      HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
-  formats.insert(imp_defined_format);
-  sizes[imp_defined_format] = sizes[V4L2_PIX_FMT_YUV420];
-  durations[imp_defined_format] = durations[V4L2_PIX_FMT_YUV420];
+  // For USB cameras, we assume that this format will not be present, and it
+  // will default to a qualified format or one of the other required formats.
 
   EXPECT_CALL(*mock_device_, GetFormats(_))
       .WillOnce(DoAll(SetArgPointee<0>(formats), Return(0)));
 
+  EXPECT_CALL(*mock_device_, GetQualifiedFormats(_))
+      .WillOnce(DoAll(SetArgPointee<0>(qualified_formats), Return(0)));
+
   for (auto format : formats) {
     std::set<std::array<int32_t, 2>> format_sizes = sizes[format];
     EXPECT_CALL(*mock_device_, GetFormatFrameSizes(format, _))
@@ -94,7 +101,7 @@
   for (auto& component : components) {
     android::CameraMetadata metadata;
     component->PopulateStaticFields(&metadata);
-    ASSERT_EQ(metadata.entryCount(), 1);
+    ASSERT_EQ(metadata.entryCount(), 1u);
     int32_t tag = component->StaticTags()[0];
     switch (tag) {
       case ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS:  // Fall through.
@@ -119,39 +126,71 @@
   }
 }
 
-TEST_F(FormatMetadataFactoryTest, GetFormatMetadataMissingJpeg) {
-  uint32_t imp_defined_format = StreamFormat::HalToV4L2PixelFormat(
-      HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
-  std::set<uint32_t> formats{V4L2_PIX_FMT_YUV420, imp_defined_format};
-  EXPECT_CALL(*mock_device_, GetFormats(_))
-      .WillOnce(DoAll(SetArgPointee<0>(formats), Return(0)));
-  PartialMetadataSet components;
-  ASSERT_EQ(AddFormatComponents(mock_device_,
-                                std::inserter(components, components.end())),
-            -ENODEV);
-}
+TEST_F(FormatMetadataFactoryTest, GetFormatMetadataMissingRequired) {
+  std::set<uint32_t> formats{V4L2_PIX_FMT_YUYV};
+  std::map<uint32_t, std::set<std::array<int32_t, 2>>> sizes{
+      {V4L2_PIX_FMT_YUYV, {{{640, 480}}, {{320, 240}}}}};
+  std::map<uint32_t, std::map<std::array<int32_t, 2>, std::array<int64_t, 2>>>
+      durations{{V4L2_PIX_FMT_YUYV,
+                 {{{{640, 480}}, {{100000000, 200000000}}},
+                  {{{320, 240}}, {{100000000, 200000000}}}}}};
 
-TEST_F(FormatMetadataFactoryTest, GetFormatMetadataMissingYuv) {
-  uint32_t imp_defined_format = StreamFormat::HalToV4L2PixelFormat(
-      HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED);
-  std::set<uint32_t> formats{V4L2_PIX_FMT_JPEG, imp_defined_format};
   EXPECT_CALL(*mock_device_, GetFormats(_))
       .WillOnce(DoAll(SetArgPointee<0>(formats), Return(0)));
-  PartialMetadataSet components;
-  ASSERT_EQ(AddFormatComponents(mock_device_,
-                                std::inserter(components, components.end())),
-            -ENODEV);
-}
+  // If a qualified format is present, we expect that required fields are
+  // populated as if they are supported.
+  std::vector<uint32_t> qualified_formats = {V4L2_PIX_FMT_YUYV};
 
-TEST_F(FormatMetadataFactoryTest,
-       GetFormatMetadataMissingImplementationDefined) {
-  std::set<uint32_t> formats{V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420};
-  EXPECT_CALL(*mock_device_, GetFormats(_))
-      .WillOnce(DoAll(SetArgPointee<0>(formats), Return(0)));
+  EXPECT_CALL(*mock_device_, GetQualifiedFormats(_))
+      .WillOnce(DoAll(SetArgPointee<0>(qualified_formats), Return(0)));
+
+  for (auto format : formats) {
+    std::set<std::array<int32_t, 2>> format_sizes = sizes[format];
+    EXPECT_CALL(*mock_device_, GetFormatFrameSizes(format, _))
+        .Times(AtLeast(1))
+        .WillRepeatedly(DoAll(SetArgPointee<1>(format_sizes), Return(0)));
+    for (auto size : format_sizes) {
+      EXPECT_CALL(*mock_device_, GetFormatFrameDurationRange(format, size, _))
+          .Times(AtLeast(1))
+          .WillRepeatedly(
+              DoAll(SetArgPointee<2>(durations[format][size]), Return(0)));
+    }
+  }
+
+  // Check that all required formats are present.
   PartialMetadataSet components;
   ASSERT_EQ(AddFormatComponents(mock_device_,
                                 std::inserter(components, components.end())),
-            -ENODEV);
+            0);
+
+  std::vector<std::array<int32_t, 2>> target_fps_ranges{{{5, 10}}, {{10, 10}}};
+  for (auto& component : components) {
+    android::CameraMetadata metadata;
+    component->PopulateStaticFields(&metadata);
+    ASSERT_EQ(metadata.entryCount(), 1u);
+    int32_t tag = component->StaticTags()[0];
+    switch (tag) {
+      case ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS:  // Fall through.
+      case ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS:    // Fall through.
+      case ANDROID_SCALER_AVAILABLE_STALL_DURATIONS:        // Fall through.
+        // Two sizes per format, four elements per config.
+        // # formats + 3 for YUV420, JPEG, IMPLEMENTATION_DEFINED.
+        ExpectMetadataTagCount(metadata, tag, (formats.size() + 3) * 2 * 4);
+        break;
+      case ANDROID_SENSOR_INFO_MAX_FRAME_DURATION:
+        // The lowest max duration from above.
+        ExpectMetadataEq(metadata, tag, 200000000);
+        break;
+      case ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES:
+        // 2 ranges ({min, max} and {max, max}), each with a min and max.
+        ExpectMetadataTagCount(metadata, tag, 4);
+        ExpectMetadataEq(metadata, tag, target_fps_ranges);
+        break;
+      default:
+        FAIL() << "Unexpected component created.";
+        break;
+    }
+  }
 }
 
 }  // namespace v4l2_camera_hal
diff --git a/modules/camera/3_4/metadata/control_test.cpp b/modules/camera/3_4/metadata/control_test.cpp
index f76376c..6284330 100644
--- a/modules/camera/3_4/metadata/control_test.cpp
+++ b/modules/camera/3_4/metadata/control_test.cpp
@@ -64,15 +64,15 @@
 
   virtual void ExpectTags() {
     if (use_options_ && report_options_) {
-      ASSERT_EQ(control_->StaticTags().size(), 1);
+      ASSERT_EQ(control_->StaticTags().size(), 1u);
       EXPECT_EQ(control_->StaticTags()[0], options_tag_);
     } else {
       EXPECT_TRUE(control_->StaticTags().empty());
     }
     // Controls use the same delgate, and thus tag, for getting and setting.
-    ASSERT_EQ(control_->ControlTags().size(), 1);
+    ASSERT_EQ(control_->ControlTags().size(), 1u);
     EXPECT_EQ(control_->ControlTags()[0], delegate_tag_);
-    ASSERT_EQ(control_->DynamicTags().size(), 1);
+    ASSERT_EQ(control_->DynamicTags().size(), 1u);
     EXPECT_EQ(control_->DynamicTags()[0], delegate_tag_);
   }
 
@@ -81,10 +81,10 @@
     android::CameraMetadata metadata;
     ASSERT_EQ(control_->PopulateStaticFields(&metadata), 0);
     if (use_options_ && report_options_) {
-      EXPECT_EQ(metadata.entryCount(), 1);
+      EXPECT_EQ(metadata.entryCount(), 1u);
       ExpectMetadataEq(metadata, options_tag_, options);
     } else {
-      EXPECT_EQ(metadata.entryCount(), 0);
+      EXPECT_EQ(metadata.entryCount(), 0u);
       // Shouldn't be expecting any options.
       EXPECT_TRUE(options.empty());
     }
@@ -93,7 +93,7 @@
   virtual void ExpectValue(uint8_t value) {
     android::CameraMetadata metadata;
     ASSERT_EQ(control_->PopulateDynamicFields(&metadata), 0);
-    EXPECT_EQ(metadata.entryCount(), 1);
+    EXPECT_EQ(metadata.entryCount(), 1u);
     ExpectMetadataEq(metadata, delegate_tag_, value);
   }
 
diff --git a/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp b/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
index 9ca3a38..3537ed2 100644
--- a/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
+++ b/modules/camera/3_4/metadata/partial_metadata_factory_test.cpp
@@ -44,11 +44,11 @@
   }
 
   virtual void ExpectControlTags() {
-    ASSERT_EQ(control_->StaticTags().size(), 1);
+    ASSERT_EQ(control_->StaticTags().size(), 1u);
     EXPECT_EQ(control_->StaticTags()[0], options_tag_);
-    ASSERT_EQ(control_->ControlTags().size(), 1);
+    ASSERT_EQ(control_->ControlTags().size(), 1u);
     EXPECT_EQ(control_->ControlTags()[0], delegate_tag_);
-    ASSERT_EQ(control_->DynamicTags().size(), 1);
+    ASSERT_EQ(control_->DynamicTags().size(), 1u);
     EXPECT_EQ(control_->DynamicTags()[0], delegate_tag_);
   }
 
@@ -56,14 +56,14 @@
     // Options should be available.
     android::CameraMetadata metadata;
     ASSERT_EQ(control_->PopulateStaticFields(&metadata), 0);
-    EXPECT_EQ(metadata.entryCount(), 1);
+    EXPECT_EQ(metadata.entryCount(), 1u);
     ExpectMetadataEq(metadata, options_tag_, options);
   }
 
   virtual void ExpectControlValue(uint8_t value) {
     android::CameraMetadata metadata;
     ASSERT_EQ(control_->PopulateDynamicFields(&metadata), 0);
-    EXPECT_EQ(metadata.entryCount(), 1);
+    EXPECT_EQ(metadata.entryCount(), 1u);
     ExpectMetadataEq(metadata, delegate_tag_, value);
   }
 
@@ -84,14 +84,14 @@
   uint8_t value = 13;
   std::unique_ptr<State<uint8_t>> state = FixedState(delegate_tag_, value);
 
-  ASSERT_EQ(state->StaticTags().size(), 0);
-  ASSERT_EQ(state->ControlTags().size(), 0);
-  ASSERT_EQ(state->DynamicTags().size(), 1);
+  ASSERT_EQ(state->StaticTags().size(), 0u);
+  ASSERT_EQ(state->ControlTags().size(), 0u);
+  ASSERT_EQ(state->DynamicTags().size(), 1u);
   EXPECT_EQ(state->DynamicTags()[0], delegate_tag_);
 
   android::CameraMetadata metadata;
   ASSERT_EQ(state->PopulateDynamicFields(&metadata), 0);
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   ExpectMetadataEq(metadata, delegate_tag_, value);
 }
 
diff --git a/modules/camera/3_4/metadata/property_test.cpp b/modules/camera/3_4/metadata/property_test.cpp
index 8e947ea..80f8eb8 100644
--- a/modules/camera/3_4/metadata/property_test.cpp
+++ b/modules/camera/3_4/metadata/property_test.cpp
@@ -49,9 +49,9 @@
   Property<int32_t> property(int_tag_, 1);
 
   // Should have only the single tag it was constructed with.
-  EXPECT_EQ(property.ControlTags().size(), 0);
-  EXPECT_EQ(property.DynamicTags().size(), 0);
-  ASSERT_EQ(property.StaticTags().size(), 1);
+  EXPECT_EQ(property.ControlTags().size(), 0u);
+  EXPECT_EQ(property.DynamicTags().size(), 0u);
+  ASSERT_EQ(property.StaticTags().size(), 1u);
   // The macro doesn't like the int_tag_ variable being passed in directly.
   int32_t expected_tag = int_tag_;
   EXPECT_EQ(property.StaticTags()[0], expected_tag);
@@ -68,7 +68,7 @@
 
   // Check the results.
   // Should only have added 1 entry.
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   // Should have added the right entry.
   ExpectMetadataEq(metadata, int_tag_, data);
 }
@@ -86,7 +86,7 @@
 
   // Check the results.
   // Should only have added 1 entry.
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   // Should have added the right entry.
   ExpectMetadataEq(metadata, float_tag_, data);
 }
@@ -102,7 +102,7 @@
 
   // Check the results.
   // Should only have added 1 entry.
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   // Should have added the right entry.
   ExpectMetadataEq(metadata, float_tag_, data);
 }
@@ -120,7 +120,7 @@
 
   // Check the results.
   // Should only have added 1 entry.
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   // Should have added the right entry.
   ExpectMetadataEq(metadata, byte_tag_, data);
 }
diff --git a/modules/camera/3_4/metadata/state_test.cpp b/modules/camera/3_4/metadata/state_test.cpp
index 5c308bc..ecc1d15 100644
--- a/modules/camera/3_4/metadata/state_test.cpp
+++ b/modules/camera/3_4/metadata/state_test.cpp
@@ -59,7 +59,7 @@
   PrepareState();
   EXPECT_TRUE(state_->StaticTags().empty());
   EXPECT_TRUE(state_->ControlTags().empty());
-  ASSERT_EQ(state_->DynamicTags().size(), 1);
+  ASSERT_EQ(state_->DynamicTags().size(), 1u);
   EXPECT_EQ(state_->DynamicTags()[0], tag_);
 }
 
@@ -79,7 +79,7 @@
 
   android::CameraMetadata metadata;
   ASSERT_EQ(state_->PopulateDynamicFields(&metadata), 0);
-  EXPECT_EQ(metadata.entryCount(), 1);
+  EXPECT_EQ(metadata.entryCount(), 1u);
   ExpectMetadataEq(metadata, tag_, expected);
 }
 
diff --git a/modules/camera/3_4/metadata/test_common.h b/modules/camera/3_4/metadata/test_common.h
index 489990f..42e44f0 100644
--- a/modules/camera/3_4/metadata/test_common.h
+++ b/modules/camera/3_4/metadata/test_common.h
@@ -80,9 +80,9 @@
 
 // Vector of arrays.
 template <typename T, size_t N>
-static int ExpectMetadataEq(const android::CameraMetadata& metadata,
-                            int32_t tag,
-                            const std::vector<std::array<T, N>>& expected) {
+static void ExpectMetadataEq(const android::CameraMetadata& metadata,
+                             int32_t tag,
+                             const std::vector<std::array<T, N>>& expected) {
   // Convert to array vector so we know all the elements are contiguous.
   ArrayVector<T, N> array_vector;
   for (const auto& array : expected) {
diff --git a/modules/camera/3_4/stream_format.cpp b/modules/camera/3_4/stream_format.cpp
index c85c26b..5f35e42 100644
--- a/modules/camera/3_4/stream_format.cpp
+++ b/modules/camera/3_4/stream_format.cpp
@@ -20,10 +20,21 @@
 
 #include <system/graphics.h>
 
+#include "arc/image_processor.h"
 #include "common.h"
 
 namespace v4l2_camera_hal {
 
+using arc::SupportedFormat;
+using arc::SupportedFormats;
+
+static const std::vector<uint32_t> GetSupportedFourCCs() {
+  // The preference of supported fourccs in the list is from high to low.
+  static const std::vector<uint32_t> kSupportedFourCCs = {V4L2_PIX_FMT_YUYV,
+                                                          V4L2_PIX_FMT_MJPEG};
+  return kSupportedFourCCs;
+}
+
 StreamFormat::StreamFormat(int format, uint32_t width, uint32_t height)
     // TODO(b/30000211): multiplanar support.
     : type_(V4L2_BUF_TYPE_VIDEO_CAPTURE),
@@ -42,6 +53,14 @@
       bytes_per_line_(format.fmt.pix.bytesperline),
       min_buffer_size_(format.fmt.pix.sizeimage) {}
 
+StreamFormat::StreamFormat(const arc::SupportedFormat& format)
+    : type_(V4L2_BUF_TYPE_VIDEO_CAPTURE),
+      v4l2_pixel_format_(format.fourcc),
+      width_(format.width),
+      height_(format.height),
+      bytes_per_line_(0),
+      min_buffer_size_(0) {}
+
 void StreamFormat::FillFormatRequest(v4l2_format* format) const {
   memset(format, 0, sizeof(*format));
   format->type = type_;
@@ -79,47 +98,127 @@
 
 int StreamFormat::V4L2ToHalPixelFormat(uint32_t v4l2_pixel_format) {
   // Translate V4L2 format to HAL format.
-  int hal_pixel_format = -1;
   switch (v4l2_pixel_format) {
-    case V4L2_PIX_FMT_JPEG:
-      hal_pixel_format = HAL_PIXEL_FORMAT_BLOB;
-      break;
-    case V4L2_PIX_FMT_YUV420:
-      hal_pixel_format = HAL_PIXEL_FORMAT_YCbCr_420_888;
-      break;
     case V4L2_PIX_FMT_BGR32:
-      hal_pixel_format = HAL_PIXEL_FORMAT_RGBA_8888;
-      break;
+      return HAL_PIXEL_FORMAT_RGBA_8888;
+    case V4L2_PIX_FMT_JPEG:
+      return HAL_PIXEL_FORMAT_BLOB;
+    case V4L2_PIX_FMT_NV21:
+      return HAL_PIXEL_FORMAT_YCrCb_420_SP;
+    case V4L2_PIX_FMT_YUV420:
+      return HAL_PIXEL_FORMAT_YCbCr_420_888;
+    case V4L2_PIX_FMT_YUYV:
+      return HAL_PIXEL_FORMAT_YCbCr_422_I;
+    case V4L2_PIX_FMT_YVU420:
+      return HAL_PIXEL_FORMAT_YV12;
     default:
       // Unrecognized format.
       HAL_LOGV("Unrecognized v4l2 pixel format %u", v4l2_pixel_format);
       break;
   }
-  return hal_pixel_format;
+  return -1;
 }
 
 uint32_t StreamFormat::HalToV4L2PixelFormat(int hal_pixel_format) {
-  // Translate HAL format to V4L2 format.
-  uint32_t v4l2_pixel_format = 0;
   switch (hal_pixel_format) {
-    case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:  // fall-through.
-    case HAL_PIXEL_FORMAT_RGBA_8888:
-      // Should be RGB32, but RPi doesn't support that.
-      // For now we accept that the colors will be off.
-      v4l2_pixel_format = V4L2_PIX_FMT_BGR32;
-      break;
-    case HAL_PIXEL_FORMAT_YCbCr_420_888:
-      v4l2_pixel_format = V4L2_PIX_FMT_YUV420;
-      break;
     case HAL_PIXEL_FORMAT_BLOB:
-      v4l2_pixel_format = V4L2_PIX_FMT_JPEG;
-      break;
+      return V4L2_PIX_FMT_JPEG;
+    case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:  // Fall-through
+    case HAL_PIXEL_FORMAT_RGBA_8888:
+      return V4L2_PIX_FMT_BGR32;
+    case HAL_PIXEL_FORMAT_YCbCr_420_888:
+      // This is a flexible YUV format that depends on platform. Different
+      // platform may have different format. It can be YVU420 or NV12. Now we
+      // return YVU420 first.
+      // TODO(): call drm_drv.get_fourcc() to get correct format.
+      return V4L2_PIX_FMT_YUV420;
+    case HAL_PIXEL_FORMAT_YCbCr_422_I:
+      return V4L2_PIX_FMT_YUYV;
+    case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+      return V4L2_PIX_FMT_NV21;
+    case HAL_PIXEL_FORMAT_YV12:
+      return V4L2_PIX_FMT_YVU420;
     default:
-      // Unrecognized format.
-      HAL_LOGV("Unrecognized HAL pixel format %d", hal_pixel_format);
+      HAL_LOGV("Pixel format 0x%x is unsupported.", hal_pixel_format);
       break;
   }
-  return v4l2_pixel_format;
+  return -1;
+}
+
+// Copy the qualified format into out_format and return true if there is a
+// proper and fitting format in the given format lists.
+bool StreamFormat::FindBestFitFormat(const SupportedFormats& supported_formats,
+                                     const SupportedFormats& qualified_formats,
+                                     uint32_t fourcc, uint32_t width,
+                                     uint32_t height,
+                                     SupportedFormat* out_format) {
+  // Match exact format and resolution if possible.
+  for (const auto& format : supported_formats) {
+    if (format.fourcc == fourcc && format.width == width &&
+        format.height == height) {
+      if (out_format != NULL) {
+        *out_format = format;
+      }
+      return true;
+    }
+  }
+  // All conversions will be done through CachedFrame for now, which will
+  // immediately convert the qualified format into YU12 (YUV420). We check
+  // here that the conversion between YU12 and |fourcc| is supported.
+  if (!arc::ImageProcessor::SupportsConversion(V4L2_PIX_FMT_YUV420, fourcc)) {
+    HAL_LOGE("Conversion between YU12 and 0x%x not supported.", fourcc);
+    return false;
+  }
+
+  // Choose the qualified format with a matching resolution.
+  for (const auto& format : qualified_formats) {
+    if (format.width == width && format.height == height) {
+      if (out_format != NULL) {
+        *out_format = format;
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+// Copy corresponding format into out_format and return true by matching
+// resolution |width|x|height| in |formats|.
+bool StreamFormat::FindFormatByResolution(const SupportedFormats& formats,
+                                          uint32_t width, uint32_t height,
+                                          SupportedFormat* out_format) {
+  for (const auto& format : formats) {
+    if (format.width == width && format.height == height) {
+      if (out_format != NULL) {
+        *out_format = format;
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+SupportedFormats StreamFormat::GetQualifiedFormats(
+    const SupportedFormats& supported_formats) {
+  // The preference of supported fourccs in the list is from high to low.
+  const std::vector<uint32_t> supported_fourccs = GetSupportedFourCCs();
+  SupportedFormats qualified_formats;
+  for (const auto& supported_fourcc : supported_fourccs) {
+    for (const auto& supported_format : supported_formats) {
+      if (supported_format.fourcc != supported_fourcc) {
+        continue;
+      }
+
+      // Skip if |qualified_formats| already has the same resolution with a more
+      // preferred fourcc.
+      if (FindFormatByResolution(qualified_formats, supported_format.width,
+                                 supported_format.height, NULL)) {
+        continue;
+      }
+      qualified_formats.push_back(supported_format);
+    }
+  }
+  return qualified_formats;
 }
 
 }  // namespace v4l2_camera_hal
diff --git a/modules/camera/3_4/stream_format.h b/modules/camera/3_4/stream_format.h
index 66c5965..720e380 100644
--- a/modules/camera/3_4/stream_format.h
+++ b/modules/camera/3_4/stream_format.h
@@ -21,6 +21,7 @@
 
 #include <linux/videodev2.h>
 
+#include "arc/common_types.h"
 #include "common.h"
 
 namespace v4l2_camera_hal {
@@ -36,6 +37,7 @@
  public:
   StreamFormat(int format, uint32_t width, uint32_t height);
   StreamFormat(const v4l2_format& format);
+  StreamFormat(const arc::SupportedFormat& format);
   virtual ~StreamFormat() = default;
   // Only uint32_t members, use default generated copy and assign.
 
@@ -44,6 +46,9 @@
 
   // Accessors.
   inline uint32_t type() const { return type_; };
+  inline uint32_t width() const { return width_; };
+  inline uint32_t height() const { return height_; };
+  inline uint32_t v4l2_pixel_format() const { return v4l2_pixel_format_; }
   inline uint32_t bytes_per_line() const { return bytes_per_line_; };
 
   bool operator==(const StreamFormat& other) const;
@@ -55,6 +60,18 @@
   // Returns -1 for unrecognized.
   static int V4L2ToHalPixelFormat(uint32_t v4l2_pixel_format);
 
+  // ARC++ SupportedFormat Helpers
+  static bool FindBestFitFormat(const arc::SupportedFormats& supported_formats,
+                                const arc::SupportedFormats& qualified_formats,
+                                uint32_t fourcc, uint32_t width,
+                                uint32_t height,
+                                arc::SupportedFormat* out_format);
+  static bool FindFormatByResolution(const arc::SupportedFormats& formats,
+                                     uint32_t width, uint32_t height,
+                                     arc::SupportedFormat* out_format);
+  static arc::SupportedFormats GetQualifiedFormats(
+      const arc::SupportedFormats& supported_formats);
+
  private:
   uint32_t type_;
   uint32_t v4l2_pixel_format_;
diff --git a/modules/camera/3_4/v4l2_camera.cpp b/modules/camera/3_4/v4l2_camera.cpp
index 3e5b859..98b8062 100644
--- a/modules/camera/3_4/v4l2_camera.cpp
+++ b/modules/camera/3_4/v4l2_camera.cpp
@@ -123,16 +123,7 @@
 
 int V4L2Camera::flushBuffers() {
   HAL_LOG_ENTER();
-
-  int res = device_->StreamOff();
-
-  // This is not strictly necessary, but prevents a buildup of aborted
-  // requests in the in_flight_ map. These should be cleared
-  // whenever the stream is turned off.
-  std::lock_guard<std::mutex> guard(in_flight_lock_);
-  in_flight_.clear();
-
-  return res;
+  return device_->StreamOff();
 }
 
 int V4L2Camera::initStaticInfo(android::CameraMetadata* out) {
@@ -262,65 +253,55 @@
   }
 
   // Actually enqueue the buffer for capture.
-  {
-    std::lock_guard<std::mutex> guard(in_flight_lock_);
-
-    uint32_t index;
-    res = device_->EnqueueBuffer(&request->output_buffers[0], &index);
-    if (res) {
-      HAL_LOGE("Device failed to enqueue buffer.");
-      completeRequest(request, res);
-      return true;
-    }
-
-    // Make sure the stream is on (no effect if already on).
-    res = device_->StreamOn();
-    if (res) {
-      HAL_LOGE("Device failed to turn on stream.");
-      // Don't really want to send an error for only the request here,
-      // since this is a full device error.
-      // TODO: Should trigger full flush.
-      return true;
-    }
-
-    // Note: the request should be dequeued/flushed from the device
-    // before removal from in_flight_.
-    in_flight_.emplace(index, request);
-    buffers_in_flight_.notify_one();
+  res = device_->EnqueueRequest(request);
+  if (res) {
+    HAL_LOGE("Device failed to enqueue buffer.");
+    completeRequest(request, res);
+    return true;
   }
 
+  // Make sure the stream is on (no effect if already on).
+  res = device_->StreamOn();
+  if (res) {
+    HAL_LOGE("Device failed to turn on stream.");
+    // Don't really want to send an error for only the request here,
+    // since this is a full device error.
+    // TODO: Should trigger full flush.
+    return true;
+  }
+
+  std::unique_lock<std::mutex> lock(in_flight_lock_);
+  in_flight_buffer_count_++;
+  buffers_in_flight_.notify_one();
   return true;
 }
 
 bool V4L2Camera::dequeueRequestBuffers() {
   // Dequeue a buffer.
-  uint32_t result_index;
-  int res = device_->DequeueBuffer(&result_index);
-  if (res) {
-    if (res == -EAGAIN) {
-      // EAGAIN just means nothing to dequeue right now.
-      // Wait until something is available before looping again.
-      std::unique_lock<std::mutex> lock(in_flight_lock_);
-      while (in_flight_.empty()) {
-        buffers_in_flight_.wait(lock);
+  std::shared_ptr<default_camera_hal::CaptureRequest> request;
+  int res;
+
+  {
+    std::unique_lock<std::mutex> lock(in_flight_lock_);
+    res = device_->DequeueRequest(&request);
+    if (!res) {
+      if (request) {
+        completeRequest(request, res);
+        in_flight_buffer_count_--;
       }
-    } else {
-      HAL_LOGW("Device failed to dequeue buffer: %d", res);
+      return true;
     }
-    return true;
   }
 
-  // Find the associated request and complete it.
-  std::lock_guard<std::mutex> guard(in_flight_lock_);
-  auto index_request = in_flight_.find(result_index);
-  if (index_request != in_flight_.end()) {
-    completeRequest(index_request->second, 0);
-    in_flight_.erase(index_request);
+  if (res == -EAGAIN) {
+    // EAGAIN just means nothing to dequeue right now.
+    // Wait until something is available before looping again.
+    std::unique_lock<std::mutex> lock(in_flight_lock_);
+    while (in_flight_buffer_count_ == 0) {
+      buffers_in_flight_.wait(lock);
+    }
   } else {
-    HAL_LOGW(
-        "Dequeued non in-flight buffer index %d. "
-        "This buffer may have been flushed from the HAL but not the device.",
-        index_request->first);
+    HAL_LOGW("Device failed to dequeue buffer: %d", res);
   }
   return true;
 }
@@ -346,10 +327,11 @@
 
   std::lock_guard<std::mutex> guard(in_flight_lock_);
   // The framework should be enforcing this, but doesn't hurt to be safe.
-  if (!in_flight_.empty()) {
+  if (device_->GetInFlightBufferCount() != 0) {
     HAL_LOGE("Can't set device format while frames are in flight.");
     return -EINVAL;
   }
+  in_flight_buffer_count_ = 0;
 
   // stream_config should have been validated; assume at least 1 stream.
   camera3_stream_t* stream = stream_config->streams[0];
@@ -409,6 +391,11 @@
   for (uint32_t i = 0; i < stream_config->num_streams; ++i) {
     stream = stream_config->streams[i];
 
+    // Override HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED format.
+    if (stream->format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
+      stream->format = HAL_PIXEL_FORMAT_RGBA_8888;
+    }
+
     // Max buffers as reported by the device.
     stream->max_buffers = max_buffers;
 
diff --git a/modules/camera/3_4/v4l2_camera.h b/modules/camera/3_4/v4l2_camera.h
index 1db8d40..fc2adb3 100644
--- a/modules/camera/3_4/v4l2_camera.h
+++ b/modules/camera/3_4/v4l2_camera.h
@@ -99,9 +99,7 @@
   std::queue<std::shared_ptr<default_camera_hal::CaptureRequest>>
       request_queue_;
   std::mutex in_flight_lock_;
-  // Maps buffer index : request.
-  std::map<uint32_t, std::shared_ptr<default_camera_hal::CaptureRequest>>
-      in_flight_;
+  uint32_t in_flight_buffer_count_;
   // Threads require holding an Android strong pointer.
   android::sp<android::Thread> buffer_enqueuer_;
   android::sp<android::Thread> buffer_dequeuer_;
diff --git a/modules/camera/3_4/v4l2_gralloc.cpp b/modules/camera/3_4/v4l2_gralloc.cpp
deleted file mode 100644
index 1c8ca48..0000000
--- a/modules/camera/3_4/v4l2_gralloc.cpp
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * Copyright (C) 2016 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 "v4l2_gralloc.h"
-
-#include <linux/videodev2.h>
-
-#include <cerrno>
-#include <cstdlib>
-
-#include <hardware/camera3.h>
-#include <hardware/gralloc.h>
-#include <system/graphics.h>
-
-#include "common.h"
-#include "stream_format.h"
-
-namespace v4l2_camera_hal {
-
-// Copy |height| lines from |src| to |dest|,
-// where |src| and |dest| may have different line lengths.
-void copyWithPadding(uint8_t* dest,
-                     const uint8_t* src,
-                     size_t dest_stride,
-                     size_t src_stride,
-                     size_t height) {
-  size_t copy_stride = dest_stride;
-  if (copy_stride > src_stride) {
-    // Adding padding, not reducing. 0 out the extra memory.
-    memset(dest, 0, src_stride * height);
-    copy_stride = src_stride;
-  }
-  uint8_t* dest_line_start = dest;
-  const uint8_t* src_line_start = src;
-  for (size_t row = 0; row < height;
-       ++row, dest_line_start += dest_stride, src_line_start += src_stride) {
-    memcpy(dest_line_start, src_line_start, copy_stride);
-  }
-}
-
-V4L2Gralloc* V4L2Gralloc::NewV4L2Gralloc() {
-  // Initialize and check the gralloc module.
-  const hw_module_t* module = nullptr;
-  int res = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
-  if (res || !module) {
-    HAL_LOGE("Couldn't get gralloc module.");
-    return nullptr;
-  }
-  const gralloc_module_t* gralloc =
-      reinterpret_cast<const gralloc_module_t*>(module);
-
-  // This class only supports Gralloc v0, not Gralloc V1.
-  if (gralloc->common.module_api_version > GRALLOC_MODULE_API_VERSION_0_3) {
-    HAL_LOGE(
-        "Invalid gralloc version %x. Only 0.3 (%x) "
-        "and below are supported by this HAL.",
-        gralloc->common.module_api_version,
-        GRALLOC_MODULE_API_VERSION_0_3);
-    return nullptr;
-  }
-
-  return new V4L2Gralloc(gralloc);
-}
-
-// Private. As checked by above factory, module will be non-null
-// and a supported version.
-V4L2Gralloc::V4L2Gralloc(const gralloc_module_t* module) : mModule(module) {}
-
-V4L2Gralloc::~V4L2Gralloc() {
-  // Unlock buffers that are still locked.
-  unlockAllBuffers();
-}
-
-int V4L2Gralloc::lock(const camera3_stream_buffer_t* camera_buffer,
-                      uint32_t bytes_per_line,
-                      v4l2_buffer* device_buffer) {
-  // Lock the camera buffer (varies depending on if the buffer is YUV or not).
-  std::unique_ptr<BufferData> buffer_data(
-      new BufferData{camera_buffer, nullptr, bytes_per_line});
-  buffer_handle_t buffer = *camera_buffer->buffer;
-  void* data;
-  camera3_stream_t* stream = camera_buffer->stream;
-  int ret = 0;
-  switch (StreamFormat::HalToV4L2PixelFormat(stream->format)) {
-    // TODO(b/30119452): support more YCbCr formats.
-    case V4L2_PIX_FMT_YUV420:
-      android_ycbcr yuv_data;
-      ret = mModule->lock_ycbcr(mModule,
-                                buffer,
-                                stream->usage,
-                                0,
-                                0,
-                                stream->width,
-                                stream->height,
-                                &yuv_data);
-      if (ret) {
-        HAL_LOGE("Failed to lock ycbcr buffer: %d", ret);
-        return ret;
-      }
-
-      // Check if gralloc format matches v4l2 format
-      // (same padding, not interleaved, contiguous).
-      if (yuv_data.ystride == bytes_per_line &&
-          yuv_data.cstride == bytes_per_line / 2 && yuv_data.chroma_step == 1 &&
-          (reinterpret_cast<uint8_t*>(yuv_data.cb) ==
-           reinterpret_cast<uint8_t*>(yuv_data.y) +
-               (stream->height * yuv_data.ystride)) &&
-          (reinterpret_cast<uint8_t*>(yuv_data.cr) ==
-           reinterpret_cast<uint8_t*>(yuv_data.cb) +
-               (stream->height / 2 * yuv_data.cstride))) {
-        // If so, great, point to the beginning.
-        data = yuv_data.y;
-      } else {
-        // If not, allocate a contiguous buffer of appropriate size
-        // (to be transformed back upon unlock).
-        data = new uint8_t[device_buffer->length];
-        // Make a dynamically-allocated copy of yuv_data,
-        // since it will be needed at transform time.
-        buffer_data->transform_dest.reset(new android_ycbcr(yuv_data));
-      }
-      break;
-    case V4L2_PIX_FMT_JPEG:
-      // Jpeg buffers are just contiguous blobs; lock length * 1.
-      ret = mModule->lock(mModule,
-                          buffer,
-                          stream->usage,
-                          0,
-                          0,
-                          device_buffer->length,
-                          1,
-                          &data);
-      if (ret) {
-        HAL_LOGE("Failed to lock jpeg buffer: %d", ret);
-        return ret;
-      }
-      break;
-    case V4L2_PIX_FMT_BGR32:  // Fall-through.
-    case V4L2_PIX_FMT_RGB32:
-      // RGB formats have nice agreed upon representation. Unless using android
-      // flex formats.
-      ret = mModule->lock(mModule,
-                          buffer,
-                          stream->usage,
-                          0,
-                          0,
-                          stream->width,
-                          stream->height,
-                          &data);
-      if (ret) {
-        HAL_LOGE("Failed to lock RGB buffer: %d", ret);
-        return ret;
-      }
-      break;
-    default:
-      return -EINVAL;
-  }
-
-  if (!data) {
-    ALOGE("Gralloc lock returned null ptr");
-    return -ENODEV;
-  }
-
-  // Set up the device buffer.
-  static_assert(sizeof(unsigned long) >= sizeof(void*),
-                "void* must be able to fit in the v4l2_buffer m.userptr "
-                "field (unsigned long) for this code to work");
-  device_buffer->m.userptr = reinterpret_cast<unsigned long>(data);
-
-  // Note the mapping of data:buffer info for when unlock is called.
-  mBufferMap.emplace(data, buffer_data.release());
-
-  return 0;
-}
-
-int V4L2Gralloc::unlock(const v4l2_buffer* device_buffer) {
-  // TODO(b/30000211): support multi-planar data (video_capture_mplane).
-  if (device_buffer->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-    return -EINVAL;
-  }
-
-  void* data = reinterpret_cast<void*>(device_buffer->m.userptr);
-
-  // Find and pop the matching entry in the map.
-  auto map_entry = mBufferMap.find(data);
-  if (map_entry == mBufferMap.end()) {
-    HAL_LOGE("No matching buffer for data at %p", data);
-    return -EINVAL;
-  }
-  std::unique_ptr<const BufferData> buffer_data(map_entry->second);
-  mBufferMap.erase(map_entry);
-
-  const camera3_stream_buffer_t* camera_buffer = buffer_data->camera_buffer;
-  const buffer_handle_t buffer = *camera_buffer->buffer;
-
-  // Check for transform.
-  if (buffer_data->transform_dest) {
-    HAL_LOGV("Transforming V4L2 YUV to gralloc YUV.");
-    // In this case data was allocated by this class, put it in a unique_ptr
-    // to ensure it gets cleaned up no matter which way this function exits.
-    std::unique_ptr<uint8_t[]> data_cleanup(reinterpret_cast<uint8_t*>(data));
-
-    uint32_t bytes_per_line = buffer_data->v4l2_bytes_per_line;
-    android_ycbcr* yuv_data = buffer_data->transform_dest.get();
-
-    // Should only occur in error situations.
-    if (device_buffer->bytesused == 0) {
-      return -EINVAL;
-    }
-
-    // Transform V4L2 to Gralloc, copying each plane to the correct place,
-    // adjusting padding, and interleaving if necessary.
-    uint32_t height = camera_buffer->stream->height;
-    // Y data first.
-    size_t y_len = bytes_per_line * height;
-    if (yuv_data->ystride == bytes_per_line) {
-      // Data should match exactly.
-      memcpy(yuv_data->y, data, y_len);
-    } else {
-      HAL_LOGV("Changing padding on Y plane from %u to %u.",
-               bytes_per_line,
-               yuv_data->ystride);
-      // Wrong padding from V4L2.
-      copyWithPadding(reinterpret_cast<uint8_t*>(yuv_data->y),
-                      reinterpret_cast<uint8_t*>(data),
-                      yuv_data->ystride,
-                      bytes_per_line,
-                      height);
-    }
-    // C data.
-    // TODO(b/30119452): These calculations assume YCbCr_420_888.
-    size_t c_len = y_len / 4;
-    uint32_t c_bytes_per_line = bytes_per_line / 2;
-    // V4L2 is packed, meaning the data is stored as contiguous {y, cb, cr}.
-    uint8_t* cb_device = reinterpret_cast<uint8_t*>(data) + y_len;
-    uint8_t* cr_device = cb_device + c_len;
-    size_t step = yuv_data->chroma_step;
-    if (step == 1) {
-      // Still planar.
-      if (yuv_data->cstride == c_bytes_per_line) {
-        // Data should match exactly.
-        memcpy(yuv_data->cb, cb_device, c_len);
-        memcpy(yuv_data->cr, cr_device, c_len);
-      } else {
-        HAL_LOGV("Changing padding on C plane from %u to %u.",
-                 c_bytes_per_line,
-                 yuv_data->cstride);
-        // Wrong padding from V4L2.
-        copyWithPadding(reinterpret_cast<uint8_t*>(yuv_data->cb),
-                        cb_device,
-                        yuv_data->cstride,
-                        c_bytes_per_line,
-                        height / 2);
-        copyWithPadding(reinterpret_cast<uint8_t*>(yuv_data->cr),
-                        cr_device,
-                        yuv_data->cstride,
-                        c_bytes_per_line,
-                        height / 2);
-      }
-    } else {
-      // Desire semiplanar (cb and cr interleaved).
-      HAL_LOGV("Interleaving cb and cr. Padding going from %u to %u.",
-               c_bytes_per_line,
-               yuv_data->cstride);
-      uint32_t c_height = height / 2;
-      uint32_t c_width = camera_buffer->stream->width / 2;
-      // Zero out destination
-      uint8_t* cb_gralloc = reinterpret_cast<uint8_t*>(yuv_data->cb);
-      uint8_t* cr_gralloc = reinterpret_cast<uint8_t*>(yuv_data->cr);
-      memset(cb_gralloc, 0, c_width * c_height * step);
-
-      // Interleaving means we need to copy the cb and cr bytes one by one.
-      for (size_t line = 0; line < c_height; ++line,
-                  cb_gralloc += yuv_data->cstride,
-                  cr_gralloc += yuv_data->cstride,
-                  cb_device += c_bytes_per_line,
-                  cr_device += c_bytes_per_line) {
-        for (size_t i = 0; i < c_width; ++i) {
-          *(cb_gralloc + (i * step)) = *(cb_device + i);
-          *(cr_gralloc + (i * step)) = *(cr_device + i);
-        }
-      }
-    }
-  }
-
-  // Unlock.
-  int res = mModule->unlock(mModule, buffer);
-  if (res) {
-    HAL_LOGE("Failed to unlock buffer at %p", buffer);
-    return -ENODEV;
-  }
-
-  return 0;
-}
-
-int V4L2Gralloc::unlockAllBuffers() {
-  HAL_LOG_ENTER();
-
-  bool failed = false;
-  for (auto const& entry : mBufferMap) {
-    int res = mModule->unlock(mModule, *entry.second->camera_buffer->buffer);
-    if (res) {
-      failed = true;
-    }
-    // When there is a transform to be made, the buffer returned by lock()
-    // is dynamically allocated (to hold the pre-transform data).
-    if (entry.second->transform_dest) {
-      delete[] reinterpret_cast<uint8_t*>(entry.first);
-    }
-    // The BufferData entry is always dynamically allocated in lock().
-    delete entry.second;
-  }
-  mBufferMap.clear();
-
-  // If any unlock failed, return error.
-  if (failed) {
-    return -ENODEV;
-  }
-
-  return 0;
-}
-
-}  // namespace default_camera_hal
diff --git a/modules/camera/3_4/v4l2_gralloc.h b/modules/camera/3_4/v4l2_gralloc.h
deleted file mode 100644
index 82129e3..0000000
--- a/modules/camera/3_4/v4l2_gralloc.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2016 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 V4L2_CAMERA_HAL_V4L2_GRALLOC_H_
-#define V4L2_CAMERA_HAL_V4L2_GRALLOC_H_
-
-#include <linux/videodev2.h>
-
-#include <unordered_map>
-
-#include <hardware/camera3.h>
-#include <hardware/gralloc.h>
-#include <system/graphics.h>
-
-namespace v4l2_camera_hal {
-
-// Generously allow up to 6MB (the largest JPEG on the RPi camera is about 5MB).
-static constexpr size_t V4L2_MAX_JPEG_SIZE = 6000000;
-
-// V4L2Gralloc is a wrapper around relevant parts of a gralloc module,
-// with some assistive transformations.
-class V4L2Gralloc {
- public:
-  // Use this method to create V4L2Gralloc objects. Functionally equivalent
-  // to "new V4L2Gralloc", except that it may return nullptr in case of failure.
-  static V4L2Gralloc* NewV4L2Gralloc();
-  virtual ~V4L2Gralloc();
-
-  // Lock a camera buffer. Uses device buffer length, sets user pointer.
-  int lock(const camera3_stream_buffer_t* camera_buffer,
-           uint32_t bytes_per_line,
-           v4l2_buffer* device_buffer);
-  // Unlock a buffer that was locked by this helper (equality determined
-  // based on buffer user pointer, not the specific object).
-  int unlock(const v4l2_buffer* device_buffer);
-  // Release all held locks.
-  int unlockAllBuffers();
-
- private:
-  // Constructor is private to allow failing on bad input.
-  // Use NewV4L2Gralloc instead.
-  V4L2Gralloc(const gralloc_module_t* module);
-
-  const gralloc_module_t* mModule;
-
-  struct BufferData {
-    const camera3_stream_buffer_t* camera_buffer;
-    // Below fields only used when a ycbcr format transform is necessary.
-    std::unique_ptr<android_ycbcr> transform_dest;  // nullptr if no transform.
-    uint32_t v4l2_bytes_per_line;
-  };
-  // Map data pointer : BufferData about that buffer.
-  std::unordered_map<void*, const BufferData*> mBufferMap;
-};
-
-}  // namespace default_camera_hal
-
-#endif  // V4L2_CAMERA_HAL_V4L2_GRALLOC_H_
diff --git a/modules/camera/3_4/v4l2_metadata_factory.cpp b/modules/camera/3_4/v4l2_metadata_factory.cpp
index 67556d9..bc8806f 100644
--- a/modules/camera/3_4/v4l2_metadata_factory.cpp
+++ b/modules/camera/3_4/v4l2_metadata_factory.cpp
@@ -27,7 +27,6 @@
 #include "metadata/partial_metadata_factory.h"
 #include "metadata/property.h"
 #include "metadata/scaling_converter.h"
-#include "v4l2_gralloc.h"
 
 namespace v4l2_camera_hal {
 
@@ -37,6 +36,8 @@
 const int64_t kV4L2ExposureTimeStepNs = 100000;
 // According to spec, each unit of V4L2_CID_ISO_SENSITIVITY is ISO/1000.
 const int32_t kV4L2SensitivityDenominator = 1000;
+// Generously allow up to 6MB (the largest size on the RPi Camera is about 5MB).
+const size_t kV4L2MaxJpegSize = 6000000;
 
 int GetV4L2Metadata(std::shared_ptr<V4L2Wrapper> device,
                     std::unique_ptr<Metadata>* result) {
@@ -433,10 +434,9 @@
       ANDROID_JPEG_THUMBNAIL_SIZE,
       ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
       {{{0, 0}}}));
-  // TODO(b/31022752): Get this from the device,
-  // not constant (from V4L2Gralloc.h).
+  // TODO(b/31022752): Get this from the device, not constant.
   components.insert(std::unique_ptr<PartialMetadataInterface>(
-      new Property<int32_t>(ANDROID_JPEG_MAX_SIZE, V4L2_MAX_JPEG_SIZE)));
+      new Property<int32_t>(ANDROID_JPEG_MAX_SIZE, kV4L2MaxJpegSize)));
   // TODO(b/31021672): Other JPEG controls (GPS, quality, orientation).
   // TODO(b/29939583): V4L2 can only support 1 stream at a time.
   // For now, just reporting minimum allowable for LIMITED devices.
@@ -476,7 +476,7 @@
       new Property<uint8_t>(ANDROID_SCALER_CROPPING_TYPE,
                             ANDROID_SCALER_CROPPING_TYPE_FREEFORM)));
   // Spoof pixel array size for now, eventually get from CROPCAP.
-  std::array<int32_t, 2> pixel_array_size = {{640, 480}};
+  std::array<int32_t, 2> pixel_array_size = {{3280, 2464}};
   components.insert(std::unique_ptr<PartialMetadataInterface>(
       new Property<std::array<int32_t, 2>>(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
                                            pixel_array_size)));
diff --git a/modules/camera/3_4/v4l2_wrapper.cpp b/modules/camera/3_4/v4l2_wrapper.cpp
index 3fafffd..d715e7e 100644
--- a/modules/camera/3_4/v4l2_wrapper.cpp
+++ b/modules/camera/3_4/v4l2_wrapper.cpp
@@ -29,29 +29,35 @@
 
 #include <android-base/unique_fd.h>
 
-#include "common.h"
-#include "stream_format.h"
-#include "v4l2_gralloc.h"
+#include "arc/cached_frame.h"
 
 namespace v4l2_camera_hal {
 
-const int32_t kStandardSizes[][2] = {{640, 480}, {320, 240}};
+using arc::AllocatedFrameBuffer;
+using arc::SupportedFormat;
+using arc::SupportedFormats;
+using default_camera_hal::CaptureRequest;
+
+const int32_t kStandardSizes[][2] = {
+  {4096, 2160}, // 4KDCI (for USB camera)
+  {3840, 2160}, // 4KUHD (for USB camera)
+  {3280, 2464}, // 8MP
+  {2560, 1440}, // QHD
+  {1920, 1080}, // HD1080
+  {1640, 1232}, // 2MP
+  {1280,  720}, // HD
+  {1024,  768}, // XGA
+  { 640,  480}, // VGA
+  { 320,  240}, // QVGA
+  { 176,  144}  // QCIF
+};
 
 V4L2Wrapper* V4L2Wrapper::NewV4L2Wrapper(const std::string device_path) {
-  std::unique_ptr<V4L2Gralloc> gralloc(V4L2Gralloc::NewV4L2Gralloc());
-  if (!gralloc) {
-    HAL_LOGE("Failed to initialize gralloc helper.");
-    return nullptr;
-  }
-
-  return new V4L2Wrapper(device_path, std::move(gralloc));
+  return new V4L2Wrapper(device_path);
 }
 
-V4L2Wrapper::V4L2Wrapper(const std::string device_path,
-                         std::unique_ptr<V4L2Gralloc> gralloc)
-    : device_path_(std::move(device_path)),
-      gralloc_(std::move(gralloc)),
-      connection_count_(0) {}
+V4L2Wrapper::V4L2Wrapper(const std::string device_path)
+    : device_path_(std::move(device_path)), connection_count_(0) {}
 
 V4L2Wrapper::~V4L2Wrapper() {}
 
@@ -85,6 +91,10 @@
   // (Alternatively, better hotplugging support may make this unecessary
   // by disabling cameras that get disconnected and checking newly connected
   // cameras, so Connect() is never called on an unsupported camera)
+
+  supported_formats_ = GetSupportedFormats();
+  qualified_formats_ = StreamFormat::GetQualifiedFormats(supported_formats_);
+
   return 0;
 }
 
@@ -102,15 +112,16 @@
   --connection_count_;
   if (connection_count_ > 0) {
     HAL_LOGV("Disconnected from camera device %s. %d connections remain.",
-             device_path_.c_str());
+             device_path_.c_str(), connection_count_);
     return;
   }
 
   device_fd_.reset(-1);  // Includes close().
   format_.reset();
-  buffers_.clear();
-  // Closing the device releases all queued buffers back to the user.
-  gralloc_->unlockAllBuffers();
+  {
+    std::lock_guard<std::mutex> buffer_lock(buffer_queue_lock_);
+    buffers_.clear();
+  }
 }
 
 // Helper function. Should be used instead of ioctl throughout this class.
@@ -134,7 +145,7 @@
 
   int32_t type = format_->type();
   if (IoctlLocked(VIDIOC_STREAMON, &type) < 0) {
-    HAL_LOGE("STREAMON fails: %s", strerror(errno));
+    HAL_LOGE("STREAMON fails (%d): %s", errno, strerror(errno));
     return -ENODEV;
   }
 
@@ -152,20 +163,16 @@
   int32_t type = format_->type();
   int res = IoctlLocked(VIDIOC_STREAMOFF, &type);
   // Calling STREAMOFF releases all queued buffers back to the user.
-  int gralloc_res = gralloc_->unlockAllBuffers();
   // No buffers in flight.
-  for (size_t i = 0; i < buffers_.size(); ++i) {
-    buffers_[i] = false;
-  }
   if (res < 0) {
     HAL_LOGE("STREAMOFF fails: %s", strerror(errno));
     return -ENODEV;
   }
-  if (gralloc_res < 0) {
-    HAL_LOGE("Failed to unlock all buffers after turning stream off.");
-    return gralloc_res;
+  std::lock_guard<std::mutex> lock(buffer_queue_lock_);
+  for (auto& buffer : buffers_) {
+    buffer.active = false;
+    buffer.request.reset();
   }
-
   HAL_LOGV("Stream turned off.");
   return 0;
 }
@@ -304,6 +311,36 @@
   return 0;
 }
 
+const SupportedFormats V4L2Wrapper::GetSupportedFormats() {
+  SupportedFormats formats;
+  std::set<uint32_t> pixel_formats;
+  int res = GetFormats(&pixel_formats);
+  if (res) {
+    HAL_LOGE("Failed to get device formats.");
+    return formats;
+  }
+
+  arc::SupportedFormat supported_format;
+  std::set<std::array<int32_t, 2>> frame_sizes;
+
+  for (auto pixel_format : pixel_formats) {
+    supported_format.fourcc = pixel_format;
+
+    frame_sizes.clear();
+    res = GetFormatFrameSizes(pixel_format, &frame_sizes);
+    if (res) {
+      HAL_LOGE("Failed to get frame sizes for format: 0x%x", pixel_format);
+      continue;
+    }
+    for (auto frame_size : frame_sizes) {
+      supported_format.width = frame_size[0];
+      supported_format.height = frame_size[1];
+      formats.push_back(supported_format);
+    }
+  }
+  return formats;
+}
+
 int V4L2Wrapper::GetFormats(std::set<uint32_t>* v4l2_formats) {
   HAL_LOG_ENTER();
 
@@ -324,6 +361,22 @@
   return 0;
 }
 
+int V4L2Wrapper::GetQualifiedFormats(std::vector<uint32_t>* v4l2_formats) {
+  HAL_LOG_ENTER();
+  if (!connected()) {
+    HAL_LOGE(
+        "Device is not connected, qualified formats may not have been set.");
+    return -EINVAL;
+  }
+  v4l2_formats->clear();
+  std::set<uint32_t> unique_fourccs;
+  for (auto& format : qualified_formats_) {
+    unique_fourccs.insert(format.fourcc);
+  }
+  v4l2_formats->assign(unique_fourccs.begin(), unique_fourccs.end());
+  return 0;
+}
+
 int V4L2Wrapper::GetFormatFrameSizes(uint32_t v4l2_format,
                                      std::set<std::array<int32_t, 2>>* sizes) {
   v4l2_frmsizeenum size_query;
@@ -364,7 +417,7 @@
                  desired_height,
                  v4l2_format);
         continue;
-      } else if (desired_width > size_query.stepwise.max_width &&
+      } else if (desired_width > size_query.stepwise.max_width ||
                  desired_height > size_query.stepwise.max_height) {
         HAL_LOGV("Standard size %u x %u is too big for format %d",
                  desired_width,
@@ -447,8 +500,6 @@
     return 0;
   }
 
-  // Not in the correct format, set the new one.
-
   if (format_) {
     // If we had an old format, first request 0 buffers to inform the device
     // we're no longer using any previously "allocated" buffers from the old
@@ -461,19 +512,34 @@
     }
   }
 
+  // Select the matching format, or if not available, select a qualified format
+  // we can convert from.
+  SupportedFormat format;
+  if (!StreamFormat::FindBestFitFormat(supported_formats_, qualified_formats_,
+                                       desired_format.v4l2_pixel_format(),
+                                       desired_format.width(),
+                                       desired_format.height(), &format)) {
+    HAL_LOGE(
+        "Unable to find supported resolution in list, "
+        "width: %d, height: %d",
+        desired_format.width(), desired_format.height());
+    return -EINVAL;
+  }
+
   // Set the camera to the new format.
   v4l2_format new_format;
-  desired_format.FillFormatRequest(&new_format);
+  const StreamFormat resolved_format(format);
+  resolved_format.FillFormatRequest(&new_format);
+
   // TODO(b/29334616): When async, this will need to check if the stream
   // is on, and if so, lock it off while setting format.
-
   if (IoctlLocked(VIDIOC_S_FMT, &new_format) < 0) {
     HAL_LOGE("S_FMT failed: %s", strerror(errno));
     return -ENODEV;
   }
 
   // Check that the driver actually set to the requested values.
-  if (desired_format != new_format) {
+  if (resolved_format != new_format) {
     HAL_LOGE("Device doesn't support desired stream configuration.");
     return -EINVAL;
   }
@@ -500,28 +566,22 @@
 
   int res = IoctlLocked(VIDIOC_REQBUFS, &req_buffers);
   // Calling REQBUFS releases all queued buffers back to the user.
-  int gralloc_res = gralloc_->unlockAllBuffers();
   if (res < 0) {
     HAL_LOGE("REQBUFS failed: %s", strerror(errno));
     return -ENODEV;
   }
-  if (gralloc_res < 0) {
-    HAL_LOGE("Failed to unlock all buffers when setting up new buffers.");
-    return gralloc_res;
-  }
 
   // V4L2 will set req_buffers.count to a number of buffers it can handle.
   if (num_requested > 0 && req_buffers.count < 1) {
     HAL_LOGE("REQBUFS claims it can't handle any buffers.");
     return -ENODEV;
   }
-  buffers_.resize(req_buffers.count, false);
-
+  buffers_.resize(req_buffers.count);
   return 0;
 }
 
-int V4L2Wrapper::EnqueueBuffer(const camera3_stream_buffer_t* camera_buffer,
-                               uint32_t* enqueued_index) {
+int V4L2Wrapper::EnqueueRequest(
+    std::shared_ptr<default_camera_hal::CaptureRequest> request) {
   if (!format_) {
     HAL_LOGE("Stream format must be set before enqueuing buffers.");
     return -ENODEV;
@@ -533,8 +593,8 @@
   int index = -1;
   {
     std::lock_guard<std::mutex> guard(buffer_queue_lock_);
-    for (int i = 0; i < buffers_.size(); ++i) {
-      if (!buffers_[i]) {
+    for (size_t i = 0; i < buffers_.size(); ++i) {
+      if (!buffers_[i].active) {
         index = i;
         break;
       }
@@ -557,33 +617,42 @@
   // and fill out remaining fields.
   if (IoctlLocked(VIDIOC_QUERYBUF, &device_buffer) < 0) {
     HAL_LOGE("QUERYBUF fails: %s", strerror(errno));
+    // Return buffer index.
+    std::lock_guard<std::mutex> guard(buffer_queue_lock_);
+    buffers_[index].active = false;
     return -ENODEV;
   }
 
-  // Lock the buffer for writing (fills in the user pointer field).
-  int res =
-      gralloc_->lock(camera_buffer, format_->bytes_per_line(), &device_buffer);
-  if (res) {
-    HAL_LOGE("Gralloc failed to lock buffer.");
-    return res;
+  // Setup our request context and fill in the user pointer field.
+  RequestContext* request_context;
+  void* data;
+  {
+    std::lock_guard<std::mutex> guard(buffer_queue_lock_);
+    request_context = &buffers_[index];
+    request_context->camera_buffer->SetDataSize(device_buffer.length);
+    request_context->camera_buffer->Reset();
+    request_context->camera_buffer->SetFourcc(format_->v4l2_pixel_format());
+    request_context->camera_buffer->SetWidth(format_->width());
+    request_context->camera_buffer->SetHeight(format_->height());
+    request_context->request = request;
+    data = request_context->camera_buffer->GetData();
   }
+  device_buffer.m.userptr = reinterpret_cast<unsigned long>(data);
+
+  // Pass the buffer to the camera.
   if (IoctlLocked(VIDIOC_QBUF, &device_buffer) < 0) {
     HAL_LOGE("QBUF fails: %s", strerror(errno));
-    gralloc_->unlock(&device_buffer);
     return -ENODEV;
   }
 
   // Mark the buffer as in flight.
   std::lock_guard<std::mutex> guard(buffer_queue_lock_);
-  buffers_[index] = true;
+  request_context->active = true;
 
-  if (enqueued_index) {
-    *enqueued_index = index;
-  }
   return 0;
 }
 
-int V4L2Wrapper::DequeueBuffer(uint32_t* dequeued_index) {
+int V4L2Wrapper::DequeueRequest(std::shared_ptr<CaptureRequest>* request) {
   if (!format_) {
     HAL_LOGV(
         "Format not set, so stream can't be on, "
@@ -607,23 +676,63 @@
     }
   }
 
-  // Mark the buffer as no longer in flight.
-  {
-    std::lock_guard<std::mutex> guard(buffer_queue_lock_);
-    buffers_[buffer.index] = false;
+  std::lock_guard<std::mutex> guard(buffer_queue_lock_);
+  RequestContext* request_context = &buffers_[buffer.index];
+
+  // Lock the camera stream buffer for painting.
+  const camera3_stream_buffer_t* stream_buffer =
+      &request_context->request->output_buffers[0];
+  uint32_t fourcc =
+      StreamFormat::HalToV4L2PixelFormat(stream_buffer->stream->format);
+
+  if (request) {
+    *request = request_context->request;
   }
 
-  // Now that we're done painting the buffer, we can unlock it.
-  res = gralloc_->unlock(&buffer);
+  // Note that the device buffer length is passed to the output frame. If the
+  // GrallocFrameBuffer does not have support for the transformation to
+  // |fourcc|, it will assume that the amount of data to lock is based on
+  // |buffer.length|, otherwise it will use the ImageProcessor::ConvertedSize.
+  arc::GrallocFrameBuffer output_frame(
+      *stream_buffer->buffer, stream_buffer->stream->width,
+      stream_buffer->stream->height, fourcc, buffer.length,
+      stream_buffer->stream->usage);
+  res = output_frame.Map();
   if (res) {
-    HAL_LOGE("Gralloc failed to unlock buffer after dequeueing.");
-    return res;
+    HAL_LOGE("Failed to map output frame.");
+    request_context->request.reset();
+    return -EINVAL;
+  }
+  if (request_context->camera_buffer->GetFourcc() == fourcc &&
+      request_context->camera_buffer->GetWidth() ==
+          stream_buffer->stream->width &&
+      request_context->camera_buffer->GetHeight() ==
+          stream_buffer->stream->height) {
+    // If no format conversion needs to be applied, directly copy the data over.
+    memcpy(output_frame.GetData(), request_context->camera_buffer->GetData(),
+           request_context->camera_buffer->GetDataSize());
+  } else {
+    // Perform the format conversion.
+    arc::CachedFrame cached_frame;
+    cached_frame.SetSource(request_context->camera_buffer.get(), 0);
+    cached_frame.Convert(request_context->request->settings, &output_frame);
   }
 
-  if (dequeued_index) {
-    *dequeued_index = buffer.index;
-  }
+  request_context->request.reset();
+  // Mark the buffer as not in flight.
+  request_context->active = false;
   return 0;
 }
 
+int V4L2Wrapper::GetInFlightBufferCount() {
+  int count = 0;
+  std::lock_guard<std::mutex> guard(buffer_queue_lock_);
+  for (auto& buffer : buffers_) {
+    if (buffer.active) {
+      count++;
+    }
+  }
+  return count;
+}
+
 }  // namespace v4l2_camera_hal
diff --git a/modules/camera/3_4/v4l2_wrapper.h b/modules/camera/3_4/v4l2_wrapper.h
index c3ad272..4a8d517 100644
--- a/modules/camera/3_4/v4l2_wrapper.h
+++ b/modules/camera/3_4/v4l2_wrapper.h
@@ -26,11 +26,14 @@
 
 #include <android-base/unique_fd.h>
 
+#include "arc/common_types.h"
+#include "arc/frame_buffer.h"
+#include "capture_request.h"
 #include "common.h"
 #include "stream_format.h"
-#include "v4l2_gralloc.h"
 
 namespace v4l2_camera_hal {
+
 class V4L2Wrapper {
  public:
   // Use this method to create V4L2Wrapper objects. Functionally equivalent
@@ -67,8 +70,10 @@
                          int32_t* result = nullptr);
   // Manage format.
   virtual int GetFormats(std::set<uint32_t>* v4l2_formats);
+  virtual int GetQualifiedFormats(std::vector<uint32_t>* v4l2_formats);
   virtual int GetFormatFrameSizes(uint32_t v4l2_format,
                                   std::set<std::array<int32_t, 2>>* sizes);
+
   // Durations are returned in ns.
   virtual int GetFormatFrameDurationRange(
       uint32_t v4l2_format,
@@ -77,15 +82,16 @@
   virtual int SetFormat(const StreamFormat& desired_format,
                         uint32_t* result_max_buffers);
   // Manage buffers.
-  virtual int EnqueueBuffer(const camera3_stream_buffer_t* camera_buffer,
-                            uint32_t* enqueued_index = nullptr);
-  virtual int DequeueBuffer(uint32_t* dequeued_index = nullptr);
+  virtual int EnqueueRequest(
+      std::shared_ptr<default_camera_hal::CaptureRequest> request);
+  virtual int DequeueRequest(
+      std::shared_ptr<default_camera_hal::CaptureRequest>* request);
+  virtual int GetInFlightBufferCount();
 
  private:
   // Constructor is private to allow failing on bad input.
   // Use NewV4L2Wrapper instead.
-  V4L2Wrapper(const std::string device_path,
-              std::unique_ptr<V4L2Gralloc> gralloc);
+  V4L2Wrapper(const std::string device_path);
 
   // Connect or disconnect to the device. Access by creating/destroying
   // a V4L2Wrapper::Connection object.
@@ -99,20 +105,19 @@
 
   inline bool connected() { return device_fd_.get() >= 0; }
 
+  // Format management.
+  const arc::SupportedFormats GetSupportedFormats();
+
   // The camera device path. For example, /dev/video0.
   const std::string device_path_;
   // The opened device fd.
   android::base::unique_fd device_fd_;
   // The underlying gralloc module.
-  std::unique_ptr<V4L2Gralloc> gralloc_;
+  // std::unique_ptr<V4L2Gralloc> gralloc_;
   // Whether or not the device supports the extended control query.
   bool extended_query_supported_;
   // The format this device is set up for.
   std::unique_ptr<StreamFormat> format_;
-  // Map indecies to buffer status. True if the index is in-flight.
-  // |buffers_.size()| will always be the maximum number of buffers this device
-  // can handle in its current format.
-  std::vector<bool> buffers_;
   // Lock protecting use of the buffer tracker.
   std::mutex buffer_queue_lock_;
   // Lock protecting use of the device.
@@ -121,6 +126,28 @@
   std::mutex connection_lock_;
   // Reference count connections.
   int connection_count_;
+  // Supported formats.
+  arc::SupportedFormats supported_formats_;
+  // Qualified formats.
+  arc::SupportedFormats qualified_formats_;
+
+  class RequestContext {
+   public:
+    RequestContext()
+        : active(false),
+          camera_buffer(std::make_shared<arc::AllocatedFrameBuffer>(0)){};
+    ~RequestContext(){};
+    // Indicates whether this request context is in use.
+    bool active;
+    // Buffer handles of the context.
+    std::shared_ptr<arc::AllocatedFrameBuffer> camera_buffer;
+    std::shared_ptr<default_camera_hal::CaptureRequest> request;
+  };
+
+  // Map of in flight requests.
+  // |buffers_.size()| will always be the maximum number of buffers this device
+  // can handle in its current format.
+  std::vector<RequestContext> buffers_;
 
   friend class Connection;
   friend class V4L2WrapperMock;
diff --git a/modules/camera/3_4/v4l2_wrapper_mock.h b/modules/camera/3_4/v4l2_wrapper_mock.h
index d423cc5..f98bc94 100644
--- a/modules/camera/3_4/v4l2_wrapper_mock.h
+++ b/modules/camera/3_4/v4l2_wrapper_mock.h
@@ -27,7 +27,7 @@
 
 class V4L2WrapperMock : public V4L2Wrapper {
  public:
-  V4L2WrapperMock() : V4L2Wrapper("", nullptr){};
+  V4L2WrapperMock() : V4L2Wrapper(""){};
   MOCK_METHOD0(StreamOn, int());
   MOCK_METHOD0(StreamOff, int());
   MOCK_METHOD2(QueryControl,
@@ -36,17 +36,15 @@
   MOCK_METHOD3(SetControl,
                int(uint32_t control_id, int32_t desired, int32_t* result));
   MOCK_METHOD1(GetFormats, int(std::set<uint32_t>*));
+  MOCK_METHOD1(GetQualifiedFormats, int(std::vector<uint32_t>*));
   MOCK_METHOD2(GetFormatFrameSizes,
                int(uint32_t, std::set<std::array<int32_t, 2>>*));
   MOCK_METHOD3(GetFormatFrameDurationRange,
                int(uint32_t,
                    const std::array<int32_t, 2>&,
                    std::array<int64_t, 2>*));
-  MOCK_METHOD4(SetFormat,
-               int(int format,
-                   uint32_t width,
-                   uint32_t height,
-                   uint32_t* result_max_buffers));
+  MOCK_METHOD2(SetFormat, int(const StreamFormat& desired_format,
+                              uint32_t* result_max_buffers));
   MOCK_METHOD2(EnqueueBuffer,
                int(const camera3_stream_buffer_t* camera_buffer,
                    uint32_t* enqueued_index));
diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp
index 9796457..c171711 100644
--- a/modules/gralloc/framebuffer.cpp
+++ b/modules/gralloc/framebuffer.cpp
@@ -332,6 +332,8 @@
             const_cast<int&>(dev->device.minSwapInterval) = 1;
             const_cast<int&>(dev->device.maxSwapInterval) = 1;
             *device = &dev->device.common;
+        } else {
+            free(dev);
         }
     }
     return status;
diff --git a/modules/sensors/OWNERS b/modules/sensors/OWNERS
index 1af3506..d4393d6 100644
--- a/modules/sensors/OWNERS
+++ b/modules/sensors/OWNERS
@@ -1,2 +1,2 @@
-pengxu@google.com
-ashutoshj@google.com
+arthuri@google.com
+bduddie@google.com
diff --git a/modules/usbaudio/audio_hal.c b/modules/usbaudio/audio_hal.c
index 9b606b7..81c9fd6 100644
--- a/modules/usbaudio/audio_hal.c
+++ b/modules/usbaudio/audio_hal.c
@@ -44,8 +44,6 @@
 #include "alsa_device_proxy.h"
 #include "alsa_logging.h"
 
-#define DEFAULT_INPUT_BUFFER_SIZE_MS 20
-
 /* Lock play & record samples rates at or above this threshold */
 #define RATELOCK_THRESHOLD 96000
 
@@ -69,6 +67,8 @@
     bool mic_muted;
 
     bool standby;
+
+    int32_t inputs_open; /* number of input streams currently open. */
 };
 
 struct stream_lock {
@@ -85,7 +85,12 @@
 
     struct audio_device *adev;           /* hardware information - only using this for the lock */
 
-    alsa_device_profile * profile;      /* Points to the alsa_device_profile in the audio_device */
+    const alsa_device_profile *profile; /* Points to the alsa_device_profile in the audio_device.
+                                         * Const, so modifications go through adev->out_profile
+                                         * and thus should have the hardware lock and ensure
+                                         * stream is not active and no other open output streams.
+                                         */
+
     alsa_device_proxy proxy;            /* state of the stream */
 
     unsigned hal_channel_count;         /* channel count exposed to AudioFlinger.
@@ -116,7 +121,12 @@
 
     struct audio_device *adev;           /* hardware information - only using this for the lock */
 
-    alsa_device_profile * profile;      /* Points to the alsa_device_profile in the audio_device */
+    const alsa_device_profile *profile; /* Points to the alsa_device_profile in the audio_device.
+                                         * Const, so modifications go through adev->out_profile
+                                         * and thus should have the hardware lock and ensure
+                                         * stream is not active and no other open input streams.
+                                         */
+
     alsa_device_proxy proxy;            /* state of the stream */
 
     unsigned hal_channel_count;         /* channel count exposed to AudioFlinger.
@@ -232,7 +242,7 @@
     return *card >= 0 && *device >= 0;
 }
 
-static char * device_get_parameters(alsa_device_profile * profile, const char * keys)
+static char *device_get_parameters(const alsa_device_profile *profile, const char * keys)
 {
     if (profile->card < 0 || profile->device < 0) {
         return strdup("");
@@ -383,12 +393,12 @@
         else {
             int saved_card = out->profile->card;
             int saved_device = out->profile->device;
-            out->profile->card = card;
-            out->profile->device = device;
-            ret_value = profile_read_device_info(out->profile) ? 0 : -EINVAL;
+            out->adev->out_profile.card = card;
+            out->adev->out_profile.device = device;
+            ret_value = profile_read_device_info(&out->adev->out_profile) ? 0 : -EINVAL;
             if (ret_value != 0) {
-                out->profile->card = saved_card;
-                out->profile->device = saved_device;
+                out->adev->out_profile.card = saved_card;
+                out->adev->out_profile.device = saved_device;
             }
         }
     }
@@ -571,9 +581,9 @@
     memset(&proxy_config, 0, sizeof(proxy_config));
 
     /* Pull out the card/device pair */
-    parse_card_device_params(address, &(out->profile->card), &(out->profile->device));
+    parse_card_device_params(address, &out->adev->out_profile.card, &out->adev->out_profile.device);
 
-    profile_read_device_info(out->profile);
+    profile_read_device_info(&out->adev->out_profile);
 
     int ret = 0;
 
@@ -780,18 +790,18 @@
     device_lock(in->adev);
 
     if (card >= 0 && device >= 0 && !profile_is_cached_for(in->profile, card, device)) {
-        /* cannot read pcm device info if playback is active */
-        if (!in->standby)
+        /* cannot read pcm device info if playback is active, or more than one open stream */
+        if (!in->standby || in->adev->inputs_open > 1)
             ret_value = -ENOSYS;
         else {
             int saved_card = in->profile->card;
             int saved_device = in->profile->device;
-            in->profile->card = card;
-            in->profile->device = device;
-            ret_value = profile_read_device_info(in->profile) ? 0 : -EINVAL;
+            in->adev->in_profile.card = card;
+            in->adev->in_profile.device = device;
+            ret_value = profile_read_device_info(&in->adev->in_profile) ? 0 : -EINVAL;
             if (ret_value != 0) {
-                in->profile->card = saved_card;
-                in->profile->device = saved_device;
+                in->adev->in_profile.card = saved_card;
+                in->adev->in_profile.device = saved_device;
             }
         }
     }
@@ -931,10 +941,17 @@
     ALOGV("adev_open_input_stream() rate:%" PRIu32 ", chanMask:0x%" PRIX32 ", fmt:%" PRIu8,
           config->sample_rate, config->channel_mask, config->format);
 
-    struct stream_in *in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
-    int ret = 0;
+    /* Pull out the card/device pair */
+    int32_t card, device;
+    if (!parse_card_device_params(address, &card, &device)) {
+        ALOGW("%s fail - invalid address %s", __func__, address);
+        *stream_in = NULL;
+        return -EINVAL;
+    }
 
+    struct stream_in * const in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
     if (in == NULL) {
+        *stream_in = NULL;
         return -ENOMEM;
     }
 
@@ -966,10 +983,29 @@
     struct pcm_config proxy_config;
     memset(&proxy_config, 0, sizeof(proxy_config));
 
-    /* Pull out the card/device pair */
-    parse_card_device_params(address, &(in->profile->card), &(in->profile->device));
-
-    profile_read_device_info(in->profile);
+    int ret = 0;
+    /* Check if an input stream is already open */
+    if (in->adev->inputs_open > 0) {
+        if (!profile_is_cached_for(in->profile, card, device)) {
+            ALOGW("%s fail - address card:%d device:%d doesn't match existing profile",
+                    __func__, card, device);
+            ret = -EINVAL;
+        }
+    } else {
+        /* Read input profile only if necessary */
+        in->adev->in_profile.card = card;
+        in->adev->in_profile.device = device;
+        if (!profile_read_device_info(&in->adev->in_profile)) {
+            ALOGW("%s fail - cannot read profile", __func__);
+            ret = -EINVAL;
+        }
+    }
+    if (ret != 0) {
+        device_unlock(in->adev);
+        free(in);
+        *stream_in = NULL;
+        return ret;
+    }
 
     /* Rate */
     if (config->sample_rate == 0) {
@@ -1074,6 +1110,10 @@
         free(in);
     }
 
+    device_lock(in->adev);
+    ++in->adev->inputs_open;
+    device_unlock(in->adev);
+
     return ret;
 }
 
@@ -1085,6 +1125,12 @@
 
     adev_remove_stream_from_list(in->adev, &in->list_node);
 
+    device_lock(in->adev);
+    --in->adev->inputs_open;
+    LOG_ALWAYS_FATAL_IF(in->adev->inputs_open < 0,
+            "invalid inputs_open: %d", in->adev->inputs_open);
+    device_unlock(in->adev);
+
     /* Close the pcm device */
     in_standby(&stream->common);
 
diff --git a/modules/vehicle/timeUtil.cpp b/modules/vehicle/timeUtil.cpp
deleted file mode 100644
index fb27dad..0000000
--- a/modules/vehicle/timeUtil.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2015 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 <stdint.h>
-#include <utils/SystemClock.h>
-
-extern "C" {
-    int64_t elapsedRealtimeNano() {
-        return android::elapsedRealtimeNano();
-    }
-}
diff --git a/modules/vehicle/vehicle.c b/modules/vehicle/vehicle.c
deleted file mode 100644
index 66a2137..0000000
--- a/modules/vehicle/vehicle.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- * Copyright (C) 2015 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 "vehicle_hw_default"
-#define LOG_NDEBUG 1
-#define RADIO_PRESET_NUM 6
-
-#define UNUSED __attribute__((__unused__))
-
-#include <errno.h>
-#include <inttypes.h>
-#include <malloc.h>
-#include <pthread.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/prctl.h>
-#include <sys/time.h>
-#include <time.h>
-
-#include <log/log.h>
-#include <system/radio.h>
-#include <hardware/hardware.h>
-#include <hardware/vehicle.h>
-
-extern int64_t elapsedRealtimeNano();
-
-static char VEHICLE_MAKE[] = "android_car";
-
-typedef struct vehicle_device_impl {
-    vehicle_hw_device_t vehicle_device;
-    uint32_t initialized_;
-    vehicle_event_callback_fn event_fn_;
-    vehicle_error_callback_fn error_fn_;
-} vehicle_device_impl_t ;
-
-static pthread_mutex_t lock_;
-
-typedef struct subscription {
-    // Each subscription has it's own thread.
-    pthread_t thread_id;
-    int32_t prop;
-    float sample_rate;
-    pthread_mutex_t lock;
-    // This field should be protected by the above mutex.
-    // TODO change this to something better as flag alone takes long time to finish.
-    uint32_t stop_thread;
-    vehicle_device_impl_t* impl;
-    pthread_t thread;
-    pthread_cond_t cond;
-    char name[100];
-} subscription_t;
-
-static vehicle_prop_config_t CONFIGS[] = {
-    {
-        .prop = VEHICLE_PROPERTY_INFO_MAKE,
-        .access = VEHICLE_PROP_ACCESS_READ,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_STATIC,
-        .value_type = VEHICLE_VALUE_TYPE_STRING,
-        .min_sample_rate = 0,
-        .max_sample_rate = 0,
-        .hal_data = NULL,
-    },
-    {
-        .prop = VEHICLE_PROPERTY_GEAR_SELECTION,
-        .access = VEHICLE_PROP_ACCESS_READ,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
-        .value_type = VEHICLE_VALUE_TYPE_INT32,
-        .min_sample_rate = 0,
-        .max_sample_rate = 0,
-        .hal_data = NULL,
-    },
-    {
-        .prop = VEHICLE_PROPERTY_DRIVING_STATUS,
-        .access = VEHICLE_PROP_ACCESS_READ,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
-        .value_type = VEHICLE_VALUE_TYPE_INT32,
-        .min_sample_rate = 0,
-        .max_sample_rate = 0,
-        .hal_data = NULL,
-    },
-    {
-        .prop = VEHICLE_PROPERTY_PARKING_BRAKE_ON,
-        .access = VEHICLE_PROP_ACCESS_READ,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
-        .value_type = VEHICLE_VALUE_TYPE_BOOLEAN,
-        .min_sample_rate = 0,
-        .max_sample_rate = 0,
-        .hal_data = NULL,
-    },
-    {
-        .prop = VEHICLE_PROPERTY_PERF_VEHICLE_SPEED,
-        .access = VEHICLE_PROP_ACCESS_READ,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_CONTINUOUS,
-        .value_type = VEHICLE_VALUE_TYPE_FLOAT,
-        .min_sample_rate = 0.1,
-        .max_sample_rate = 10.0,
-        .hal_data = NULL,
-    },
-    {
-        .prop = VEHICLE_PROPERTY_RADIO_PRESET,
-        .access = VEHICLE_PROP_ACCESS_READ_WRITE,
-        .change_mode = VEHICLE_PROP_CHANGE_MODE_ON_CHANGE,
-        .value_type = VEHICLE_VALUE_TYPE_INT32_VEC4,
-        .vehicle_radio_num_presets = RADIO_PRESET_NUM,
-        .min_sample_rate = 0,
-        .max_sample_rate = 0,
-        .hal_data = NULL,
-    },
-};
-
-vehicle_prop_config_t* find_config(int prop) {
-    unsigned int i;
-    for (i = 0; i < sizeof(CONFIGS) / sizeof(vehicle_prop_config_t); i++) {
-        if (CONFIGS[i].prop == prop) {
-            return &CONFIGS[i];
-        }
-    }
-    return NULL;
-}
-
-static int alloc_vehicle_str_from_cstr(const char* string, vehicle_str_t* vehicle_str) {
-    int len = strlen(string);
-    vehicle_str->data = (uint8_t*) malloc(len);
-    if (vehicle_str->data == NULL) {
-        return -ENOMEM;
-    }
-    memcpy(vehicle_str->data, string, len);
-    vehicle_str->len = len;
-    return 0;
-}
-
-static vehicle_prop_config_t const * vdev_list_properties(vehicle_hw_device_t* device UNUSED,
-        int* num_properties) {
-    ALOGD("vdev_list_properties.");
-
-    *num_properties = sizeof(CONFIGS) / sizeof(vehicle_prop_config_t);
-    return CONFIGS;
-}
-
-static int vdev_init(vehicle_hw_device_t* device,
-                     vehicle_event_callback_fn event_callback_fn,
-                     vehicle_error_callback_fn error_callback_fn) {
-    ALOGD("vdev_init.");
-    vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
-    pthread_mutex_lock(&lock_);
-    if (impl->initialized_) {
-        ALOGE("vdev_init: Callback and Error functions are already existing.");
-        pthread_mutex_unlock(&lock_);
-        return -EEXIST;
-    }
-
-    impl->initialized_ = 1;
-    impl->event_fn_ = event_callback_fn;
-    impl->error_fn_ = error_callback_fn;
-    pthread_mutex_unlock(&lock_);
-    return 0;
-}
-
-static int vdev_release(vehicle_hw_device_t* device) {
-    vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
-    pthread_mutex_lock(&lock_);
-    if (!impl->initialized_) {
-        ALOGD("vdev_release: Already released before, returning early.");
-    } else {
-        // unsubscribe_all()
-        impl->initialized_ = 0;
-    }
-    pthread_mutex_unlock(&lock_);
-    return 0;
-}
-
-static int vdev_get(vehicle_hw_device_t* device UNUSED, vehicle_prop_value_t* data) {
-    ALOGD("vdev_get.");
-    //TODO all data supporting read should support get
-    if (!data) {
-        ALOGE("vdev_get: Data cannot be null.");
-        return -EINVAL;
-    }
-    vehicle_prop_config_t* config = find_config(data->prop);
-    if (config == NULL) {
-        ALOGE("vdev_get: cannot find config 0x%x", data->prop);
-        return -EINVAL;
-    }
-    data->value_type = config->value_type;
-    // for STATIC type, time can be just 0 instead
-    data->timestamp = elapsedRealtimeNano();
-    int r;
-    switch (data->prop) {
-        case VEHICLE_PROPERTY_INFO_MAKE:
-            r = alloc_vehicle_str_from_cstr(VEHICLE_MAKE, &(data->value.str_value));
-            if (r != 0) {
-                ALOGE("vdev_get: alloc failed");
-                return r;
-            }
-            break;
-
-        case VEHICLE_PROPERTY_RADIO_PRESET: {
-              int radio_preset = data->value.int32_array[0];
-              if (radio_preset < VEHICLE_RADIO_PRESET_MIN_VALUE ||
-                  radio_preset >= RADIO_PRESET_NUM) {
-                  ALOGE("%s Invalid radio preset: %d\n", __func__, radio_preset);
-                  return -1;
-              }
-              ALOGD("%s Radio Preset number: %d", __func__, radio_preset);
-              int32_t selector = radio_preset % 2 == 0;
-              // Populate the channel and subchannel to be some variation of the
-              // preset number for mocking.
-
-              // Restore the preset number.
-              data->value.int32_array[0] = radio_preset;
-              // Channel type values taken from
-              // system/core/include/system/radio.h
-              data->value.int32_array[1] = selector ? RADIO_BAND_FM : RADIO_BAND_AM;
-              // For FM set a value in Mhz and for AM set a value in Khz range
-              // (channel).
-              data->value.int32_array[2] = selector ? 99000000 : 100000;
-              // For FM we have a sub-channel and we care about it, for AM pass
-              // a dummy value.
-              data->value.int32_array[3] = selector ? radio_preset : -1;
-              break;
-        }
-
-        default:
-            // actual implementation will be much complex than this. It should track proper last
-            // state. Here just fill with zero.
-            memset(&(data->value), 0, sizeof(data->value));
-            break;
-    }
-    ALOGI("vdev_get, type 0x%x, time %" PRId64 ", value_type %d", data->prop, data->timestamp,
-            data->value_type);
-    return 0;
-}
-
-static void vdev_release_memory_from_get(struct vehicle_hw_device* device UNUSED,
-        vehicle_prop_value_t *data) {
-    switch (data->value_type) {
-        case VEHICLE_VALUE_TYPE_STRING:
-        case VEHICLE_VALUE_TYPE_BYTES:
-            free(data->value.str_value.data);
-            data->value.str_value.data = NULL;
-            break;
-        default:
-            ALOGW("release_memory_from_get for property 0x%x which is not string or bytes type 0x%x"
-                    , data->prop, data->value_type);
-            break;
-    }
-}
-
-static int vdev_set(vehicle_hw_device_t* device UNUSED, const vehicle_prop_value_t* data) {
-    ALOGD("vdev_set.");
-    // Just print what data will be setting here.
-    ALOGD("Setting property %d with value type %d\n", data->prop, data->value_type);
-    vehicle_prop_config_t* config = find_config(data->prop);
-    if (config == NULL) {
-        ALOGE("vdev_set: cannot find config 0x%x", data->prop);
-        return -EINVAL;
-    }
-    if (config->value_type != data->value_type) {
-        ALOGE("vdev_set: type mismatch, passed 0x%x expecting 0x%x", data->value_type,
-                config->value_type);
-        return -EINVAL;
-    }
-    switch (data->value_type) {
-        case VEHICLE_VALUE_TYPE_FLOAT:
-            ALOGD("Value type: FLOAT\nValue: %f\n", data->value.float_value);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32:
-            ALOGD("Value type: INT32\nValue: %" PRId32 "\n", data->value.int32_value);
-            break;
-        case VEHICLE_VALUE_TYPE_INT64:
-            ALOGD("Value type: INT64\nValue: %" PRId64 "\n", data->value.int64_value);
-            break;
-        case VEHICLE_VALUE_TYPE_BOOLEAN:
-            ALOGD("Value type: BOOLEAN\nValue: %d\n", data->value.boolean_value);
-            break;
-        case VEHICLE_VALUE_TYPE_STRING:
-            ALOGD("Value type: STRING\n Size: %d\n", data->value.str_value.len);
-            // NOTE: We only handle ASCII strings here.
-            // Print the UTF-8 string.
-            char *ascii_out = (char *) malloc ((data->value.str_value.len + 1) * sizeof (char));
-            memcpy(ascii_out, data->value.str_value.data, data->value.str_value.len);
-            ascii_out[data->value.str_value.len] = '\0';
-            ALOGD("Value: %s\n", ascii_out);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC4:
-            ALOGD("Value type: INT32_VEC4\nValue[0]: %d Value[1] %d Value[2] %d Value[3] %d",
-                  data->value.int32_array[0], data->value.int32_array[1],
-                  data->value.int32_array[2], data->value.int32_array[3]);
-            break;
-        default:
-            ALOGD("Value type not yet handled: %d.\n", data->value_type);
-    }
-    return 0;
-}
-
-void print_subscribe_info(vehicle_device_impl_t* impl UNUSED) {
-    unsigned int i;
-    for (i = 0; i < sizeof(CONFIGS) / sizeof(vehicle_prop_config_t); i++) {
-        subscription_t* sub = (subscription_t*)CONFIGS[i].hal_data;
-        if (sub != NULL) {
-            ALOGD("prop: %d rate: %f", sub->prop, sub->sample_rate);
-        }
-    }
-}
-
-// This should be run in a separate thread always.
-void fake_event_thread(struct subscription *sub) {
-    if (!sub) {
-        ALOGE("oops! subscription object cannot be NULL.");
-        exit(-1);
-    }
-    prctl(PR_SET_NAME, (unsigned long)sub->name, 0, 0, 0);
-    // Emit values in a loop, every 2 seconds.
-    while (1) {
-        // Create a random value depending on the property type.
-        vehicle_prop_value_t event;
-        event.prop = sub->prop;
-        event.timestamp = elapsedRealtimeNano();
-        switch (sub->prop) {
-            case VEHICLE_PROPERTY_GEAR_SELECTION:
-                event.value_type = VEHICLE_VALUE_TYPE_INT32;
-                switch ((event.timestamp & 0x30000000)>>28) {
-                    case 0:
-                        event.value.gear_selection = VEHICLE_GEAR_PARK;
-                        break;
-                    case 1:
-                        event.value.gear_selection = VEHICLE_GEAR_NEUTRAL;
-                        break;
-                    case 2:
-                        event.value.gear_selection = VEHICLE_GEAR_DRIVE;
-                        break;
-                    case 3:
-                        event.value.gear_selection = VEHICLE_GEAR_REVERSE;
-                        break;
-                }
-                break;
-            case VEHICLE_PROPERTY_PARKING_BRAKE_ON:
-                event.value_type = VEHICLE_VALUE_TYPE_BOOLEAN;
-                if (event.timestamp & 0x20000000) {
-                    event.value.parking_brake = VEHICLE_FALSE;
-                } else {
-                    event.value.parking_brake = VEHICLE_TRUE;
-                }
-                break;
-            case VEHICLE_PROPERTY_PERF_VEHICLE_SPEED:
-                event.value_type = VEHICLE_VALUE_TYPE_FLOAT;
-                event.value.vehicle_speed = (float) ((event.timestamp & 0xff000000)>>24);
-                break;
-            case VEHICLE_PROPERTY_RADIO_PRESET:
-                event.value_type = VEHICLE_VALUE_TYPE_INT32_VEC4;
-                int presetInfo1[4] = {1  /* preset number */, 0  /* AM Band */, 1000, 0};
-                int presetInfo2[4] = {2  /* preset number */, 1  /* FM Band */, 1000, 0};
-                if (event.timestamp & 0x20000000) {
-                    memcpy(event.value.int32_array, presetInfo1, sizeof(presetInfo1));
-                } else {
-                    memcpy(event.value.int32_array, presetInfo2, sizeof(presetInfo2));
-                }
-                break;
-            default: // unsupported
-                if (sub->impl == NULL) {
-                    ALOGE("subscription impl NULL");
-                    return;
-                }
-                if (sub->impl->error_fn_ != NULL) {
-                    sub->impl->error_fn_(-EINVAL, VEHICLE_PROPERTY_INVALID,
-                            VEHICLE_OPERATION_GENERIC);
-                } else {
-                    ALOGE("Error function is null");
-                }
-                ALOGE("Unsupported prop 0x%x, quit", sub->prop);
-                return;
-        }
-        if (sub->impl->event_fn_ != NULL) {
-            sub->impl->event_fn_(&event);
-        } else {
-            ALOGE("Event function is null");
-            return;
-        }
-        pthread_mutex_lock(&sub->lock);
-        if (sub->stop_thread) {
-            ALOGD("exiting subscription request here.");
-            // Do any cleanup here.
-            pthread_mutex_unlock(&sub->lock);
-            return;
-        }
-        struct timespec now;
-        clock_gettime(CLOCK_REALTIME, &now);
-        now.tv_sec += 1; // sleep for one sec
-        pthread_cond_timedwait(&sub->cond, &sub->lock, &now);
-        pthread_mutex_unlock(&sub->lock);
-    }
-}
-
-static int vdev_subscribe(vehicle_hw_device_t* device, int32_t prop, float sample_rate,
-        int32_t zones UNUSED) {
-    ALOGD("vdev_subscribe 0x%x, %f", prop, sample_rate);
-    vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
-    // Check that the device is initialized.
-    pthread_mutex_lock(&lock_);
-    if (!impl->initialized_) {
-        pthread_mutex_unlock(&lock_);
-        ALOGE("vdev_subscribe: have you called init()?");
-        return -EINVAL;
-    }
-    vehicle_prop_config_t* config = find_config(prop);
-    if (config == NULL) {
-        pthread_mutex_unlock(&lock_);
-        ALOGE("vdev_subscribe not supported property 0x%x", prop);
-        return -EINVAL;
-    }
-    if ((config->access != VEHICLE_PROP_ACCESS_READ) &&
-        (config->access != VEHICLE_PROP_ACCESS_READ_WRITE)) {
-        pthread_mutex_unlock(&lock_);
-        ALOGE("vdev_subscribe read not supported on the property 0x%x", prop);
-        return -EINVAL;
-    }
-    if (config->change_mode == VEHICLE_PROP_CHANGE_MODE_STATIC) {
-        pthread_mutex_unlock(&lock_);
-        ALOGE("vdev_subscribe cannot subscribe static property 0x%x", prop);
-        return -EINVAL;
-    }
-    if ((config->change_mode == VEHICLE_PROP_CHANGE_MODE_ON_CHANGE) && (sample_rate != 0)) {
-        pthread_mutex_unlock(&lock_);
-        ALOGE("vdev_subscribe on change type should have 0 sample rate, property 0x%x, sample rate %f",
-                prop, sample_rate);
-        return -EINVAL;
-    }
-    if ((config->max_sample_rate < sample_rate) || (config->min_sample_rate > sample_rate)) {
-
-        ALOGE("vdev_subscribe property 0x%x, invalid sample rate %f, min:%f, max:%f",
-                prop, sample_rate, config->min_sample_rate, config->max_sample_rate);
-        pthread_mutex_unlock(&lock_);
-        return -EINVAL;
-    }
-    subscription_t* sub = (subscription_t*)config->hal_data;
-    if (sub == NULL) {
-        sub = calloc(1, sizeof(subscription_t));
-        sub->prop = prop;
-        sub->sample_rate = sample_rate;
-        sub->stop_thread = 0;
-        sub->impl = impl;
-        pthread_mutex_init(&sub->lock, NULL);
-        pthread_cond_init(&sub->cond, NULL);
-        config->hal_data = sub;
-        sprintf(sub->name, "vhal0x%x", prop);
-    } else if (sub->sample_rate != sample_rate){ // sample rate changed
-        //TODO notify this to fake sensor thread
-        sub->sample_rate = sample_rate;
-        pthread_mutex_unlock(&lock_);
-        return 0;
-    }
-    int ret_code = pthread_create(
-                                  &sub->thread, NULL, (void *(*)(void*))fake_event_thread, sub);
-    if (ret_code != 0) {
-        return -ret_code;
-    }
-    print_subscribe_info(impl);
-    pthread_mutex_unlock(&lock_);
-    return 0;
-}
-
-static int vdev_unsubscribe(vehicle_hw_device_t* device, int32_t prop) {
-    ALOGD("vdev_unsubscribe 0x%x", prop);
-    vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
-    pthread_mutex_lock(&lock_);
-    vehicle_prop_config_t* config = find_config(prop);
-    if (config == NULL) {
-        pthread_mutex_unlock(&lock_);
-        return -EINVAL;
-    }
-    subscription_t* sub = (subscription_t*)config->hal_data;
-    if (sub == NULL) {
-        pthread_mutex_unlock(&lock_);
-        return -EINVAL;
-    }
-    config->hal_data = NULL;
-    pthread_mutex_unlock(&lock_);
-    pthread_mutex_lock(&sub->lock);
-    sub->stop_thread = 1;
-    pthread_cond_signal(&sub->cond);
-    pthread_mutex_unlock(&sub->lock);
-    pthread_join(sub->thread, NULL);
-    pthread_cond_destroy(&sub->cond);
-    pthread_mutex_destroy(&sub->lock);
-    free(sub);
-    pthread_mutex_lock(&lock_);
-    print_subscribe_info(impl);
-    pthread_mutex_unlock(&lock_);
-    return 0;
-}
-
-static int vdev_close(hw_device_t* device) {
-    vehicle_device_impl_t* impl = (vehicle_device_impl_t*)device;
-    if (impl) {
-        free(impl);
-        return 0;
-    } else {
-        return -1;
-    }
-}
-
-static int vdev_dump(struct vehicle_hw_device* device UNUSED, int fd UNUSED) {
-    //TODO
-    return 0;
-}
-
-/*
- * The open function is provided as an interface in harwdare.h which fills in
- * all the information about specific implementations and version specific
- * informations in hw_device_t structure. After calling open() the client should
- * use the hw_device_t to execute any Vehicle HAL device specific functions.
- */
-static int vdev_open(const hw_module_t* module, const char* name UNUSED,
-                     hw_device_t** device) {
-    ALOGD("vdev_open");
-
-    // Oops, out of memory!
-    vehicle_device_impl_t* vdev = calloc(1, sizeof(vehicle_device_impl_t));
-    if (vdev == NULL) {
-        return -ENOMEM;
-    }
-
-    // Common functions provided by harware.h to access module and device(s).
-    vdev->vehicle_device.common.tag = HARDWARE_DEVICE_TAG;
-    vdev->vehicle_device.common.version = VEHICLE_DEVICE_API_VERSION_1_0;
-    vdev->vehicle_device.common.module = (hw_module_t *) module;
-    vdev->vehicle_device.common.close = vdev_close;
-
-    // Define the Vehicle HAL device specific functions.
-    vdev->vehicle_device.list_properties = vdev_list_properties;
-    vdev->vehicle_device.init = vdev_init;
-    vdev->vehicle_device.release = vdev_release;
-    vdev->vehicle_device.get = vdev_get;
-    vdev->vehicle_device.release_memory_from_get = vdev_release_memory_from_get;
-    vdev->vehicle_device.set = vdev_set;
-    vdev->vehicle_device.subscribe = vdev_subscribe;
-    vdev->vehicle_device.unsubscribe = vdev_unsubscribe;
-    vdev->vehicle_device.dump = vdev_dump;
-
-    *device = (hw_device_t *) vdev;
-    return 0;
-}
-
-static struct hw_module_methods_t hal_module_methods = {
-    .open = vdev_open,
-};
-
-/*
- * This structure is mandatory to be implemented by each HAL implementation. It
- * exposes the open method (see hw_module_methods_t above) which opens a device.
- * The vehicle HAL is supposed to be used as a single device HAL hence all the
- * functions should be implemented inside of the vehicle_hw_device_t struct (see
- * the vehicle.h in include/ folder.
- */
-vehicle_module_t HAL_MODULE_INFO_SYM = {
-    .common = {
-        .tag = HARDWARE_MODULE_TAG,
-        .module_api_version = VEHICLE_MODULE_API_VERSION_1_0,
-        .hal_api_version = HARDWARE_HAL_API_VERSION,
-        .id = VEHICLE_HARDWARE_MODULE_ID,
-        .name = "Default vehicle HW HAL",
-        .author = "",
-        .methods = &hal_module_methods,
-    },
-};
diff --git a/tests/vehicle/Android.bp b/tests/vehicle/Android.bp
deleted file mode 100644
index cbe2a11..0000000
--- a/tests/vehicle/Android.bp
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-//  Copyright (C) 2015 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.
-
-// Build native tests.
-cc_test {
-    name: "vehicle_tests",
-    srcs: ["vehicle_tests.cpp"],
-
-    shared_libs: [
-        "liblog",
-        "libhardware",
-    ],
-
-    cflags: [
-        "-Wall",
-        "-Wextra",
-        "-Werror",
-    ],
-}
-
-// Build HAL command line utility.
-cc_binary {
-    name: "vehicle-hal-tool",
-    srcs: ["vehicle-hal-tool.c"],
-    cflags: [
-        "-Wall",
-        "-Wno-unused-parameter",
-        "-Werror",
-    ],
-
-    shared_libs: [
-        "libcutils",
-        "libhardware",
-        "liblog",
-    ],
-}
diff --git a/tests/vehicle/README b/tests/vehicle/README
deleted file mode 100644
index 42d2210..0000000
--- a/tests/vehicle/README
+++ /dev/null
@@ -1,73 +0,0 @@
-What does this document tell?
-
-This document details how to use the vehicle service if you are implementhing
-HAL. It lists the various places to look for code and how to build and test the
-code on your own dev device.
-
-This code also provides a simple command line utility for the target to test the
-vehicle HAL.
-
-What is the code?
-
-The code is split into folowing logical components:
-a) hardware/libhardware/include/hardware/vehicle.h - this is the main HAL
-interface that will be required to be implemented by the OEMs. It includes all
-documentation necessary to understand what vehicle subsystems are exposed,
-various units, capabilities and any other relevant details about the HAL design
-itself.
-
-b) hardware/libhardware/modules/vehicle/vehicle.c
-This is a reference implementation for the OEMs to have a peek into getting
-started with a barebones structure. There are implementation for each of the
-critical HAL functions such as, get(), set() and subscribe().
-
-c) hardware/libhardware/tests/vehicle/vehicle_test.cpp & vehicle_test_fixtures.h
-These are native tests that can be run on the target to validate basic
-features of HAL implementation. Things such as loading of HAL and
-basic functions are implemented (by check if the returned functions are not NULL
-pointers) can be asserted. It also checks if the subscribe function is doing its
-job by spitting out data at continuous intervals and printed on the stdout.
-
-d) hardware/libhardware/tests/vehicle/vehicle-hal-tool.c
-This tool will provide you with a simple utility which can set commands to the
-HAL such as:
-i) Getting a property (and printing its value).
-ii) Setting a property (and the HAL will take some setting action).
-iii) Subscribe to a property (and the HAL should send you values at some certain
-intevals).
-
-See the usage() function in vehicle-hal-tool.c for details on how to use the
-binary.
-
-How to build and run?
-
-You can build everything by issuing the following from the top of directory. It
-is assumed that you have done a first run of make from the top level so that
-intermediates are generated.
-
-$ croot
-$ mmm hardware/libhardware
-
-This will generate the following binaries that we care about:
-i) out/target/product/XXX/vendor/lib/hw/vehicle.default.so
-ii) out/target/product/XXX/data/nativetest/vehicle_tests
-iii) out/target/product/XXX/system/bin/vehicle-hal-tool
-
-The location for the first shared library would be:
-$ adb push out/target/product/XXX/vendor/lib/hw/vehicle.default.so
-/vendor/lib/hw
-You can also use 'adb sync' if you like, although this is the easiest least
-hassle way of putting it in place.
-
-The second binary is a native test - which is nothing but an executable for the
-target device. You can load it anywhere in your /data directory and run it as:
-$ adb push out/target/product/XXX/data/nativetest/vehicle_tests
-/data/tmp/vehicle_tests
-$ adb shell
-$ ./data/tmp/vehicle_tests
-<...output should be spitted with passing tests for atleast the reference
-implementation ...>
-
-The last binary is the command line tool, to push the binary on your target do:
-$ adb push out/target/product/XXX/system/bin/vehicle-hal-tool
-/data/tmp/vehicle-hal-tool
diff --git a/tests/vehicle/vehicle-hal-tool.c b/tests/vehicle/vehicle-hal-tool.c
deleted file mode 100644
index 94624d3..0000000
--- a/tests/vehicle/vehicle-hal-tool.c
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * Copyright (C) 2015 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 "vehicle-hal-tool"
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <log/log.h>
-
-#include <hardware/hardware.h>
-#include <hardware/vehicle.h>
-
-void usage() {
-    printf("Usage: "
-            "./vehicle-hal-tool [-l] [-m -p -t [-v]]\n"
-            "-l - List properties\n"
-            "-m - Mode (cannot be used with -l). Accepted strings: get, set or sub.\n"
-            "-p - Property (only used with -m)\n"
-            "-t - Type (only used with -m)\n"
-            "-w - Wait time in seconds (only used with -m set to sub)\n"
-            "-v - Value to which vehicle_prop_value is set\n"
-            "Depending on the type pass the value:\n"
-            "Int: pass a quoted integer\n"
-            "Float: pass a quoted float\n"
-            "Int array: pass a quoted space delimited int array, eg: \"1 2 3 4\" for\n:"
-            "setting int32_array's all 4 elements (see VEHICLE_VALUE_TYPE_INT32_VEC4\n"
-            "String: pass a normal string\n\n"
-            "The configurations to use the tool are as follows:\n"
-            "List Properties\n"
-            "---------------\n"
-            "./vehicle-hal-tool -l \n"
-            "Lists the various properties defined in HAL implementation. Use this to check if "
-            "the HAL implementation is correctly set up and exposing the capabilities correctly.\n"
-
-            "Get Properties\n"
-            "---------------\n"
-            "./vehicle-hal-tool -m get -p <prop> -t <type> [-v <vehicle_prop_value>]\n"
-            "Example: ./vehicle-hal-tool -m get -p 1028 -t 3 # VEHICLE_PROPERTY_DRIVING_STATUS\n"
-            "./vehicle-hal-tool -m get -p 257 -t 1 # VEHICLE_PROPERTY_INFO_MAKE\n"
-            "./vehicle-hal-tool -m get -p 2049 -t 19 -v \"3 0 0 0\"\n"
-            "                                 # VEHICLE_PROPERTY_RADIO_PRESET\n"
-            "with preset value set to 3.\n\n"
-            "Set properties\n"
-            "--------------\n"
-            "./vehicle-hal-tool -m set -p 10 -t 1 -v random_property\n"
-            "Set properties may not be applicable to most properties\n\n"
-            "Subscribe properties\n"
-            "--------------------\n"
-            "Subscribes to be notified about a property change (depending on whether\n"
-            "it is a on change property or a continuous property) for seconds provided\n"
-            "as -w paramter.\n"
-            "./vehicle-hal-tool -m sub -p 1028 -w 10\n"
-    );
-}
-
-void list_all_properties(vehicle_hw_device_t *device) {
-    int num_configs = -1;
-    const vehicle_prop_config_t *configs = device->list_properties(device, &num_configs);
-    if (num_configs < 0) {
-        printf("List configs error. %d", num_configs);
-        exit(1);
-    }
-
-    printf("Listing configs\n--------------------\n");
-    int i = 0;
-    for (i = 0; i < num_configs; i++) {
-        const vehicle_prop_config_t *config_temp = configs + i;
-        printf("Property ID: %d\n"
-               "Property config_flags: %d\n"
-               "Property change mode: %d\n"
-               "Property min sample rate: %f\n"
-               "Property max sample rate: %f\n",
-               config_temp->prop, config_temp->config_flags, config_temp->change_mode,
-               config_temp->min_sample_rate, config_temp->max_sample_rate);
-    }
-}
-
-static void print_property(const vehicle_prop_value_t *data) {
-    switch (data->value_type) {
-        case VEHICLE_VALUE_TYPE_STRING:
-            printf("Value type: STRING\n Size: %d\n", data->value.str_value.len);
-            // This implementation only supports ASCII.
-            char *ascii_out = (char *) malloc((data->value.str_value.len + 1) * sizeof(char));
-            memcpy(ascii_out, data->value.str_value.data, data->value.str_value.len);
-            ascii_out[data->value.str_value.len] = '\0';
-            printf("Value Type: STRING %s\n", ascii_out);
-            free(ascii_out);
-            break;
-        case VEHICLE_VALUE_TYPE_BYTES:
-            printf("Value type: BYTES\n Size: %d", data->value.bytes_value.len);
-            for (int i = 0; i < data->value.bytes_value.len; i++) {
-                if ((i % 16) == 0) {
-                    printf("\n %04X: ", i);
-                }
-                printf("%02X ", data->value.bytes_value.data[i]);
-            }
-            printf("\n");
-            break;
-        case VEHICLE_VALUE_TYPE_BOOLEAN:
-            printf("Value type: BOOLEAN\nValue: %d\n", data->value.boolean_value);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_BOOLEAN:
-            printf("Value type: ZONED_BOOLEAN\nZone: %d\n", data->zone);
-            printf("Value: %d\n", data->value.boolean_value);
-            break;
-        case VEHICLE_VALUE_TYPE_INT64:
-            printf("Value type: INT64\nValue: %" PRId64 "\n", data->value.int64_value);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT:
-            printf("Value type: FLOAT\nValue: %f\n", data->value.float_value);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC2:
-            printf("Value type: FLOAT_VEC2\nValue[0]: %f ", data->value.float_array[0]);
-            printf("Value[1]: %f\n", data->value.float_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC3:
-            printf("Value type: FLOAT_VEC3\nValue[0]: %f ", data->value.float_array[0]);
-            printf("Value[1]: %f ", data->value.float_array[1]);
-            printf("Value[2]: %f\n", data->value.float_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC4:
-            printf("Value type: FLOAT_VEC4\nValue[0]: %f ", data->value.float_array[0]);
-            printf("Value[1]: %f ", data->value.float_array[1]);
-            printf("Value[2]: %f ", data->value.float_array[2]);
-            printf("Value[3]: %f\n", data->value.float_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32:
-            printf("Value type: INT32\nValue: %d\n", data->value.int32_value);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC2:
-            printf("Value type: INT32_VEC2\nValue[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d\n", data->value.int32_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC3:
-            printf("Value type: INT32_VEC3\nValue[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d ", data->value.int32_array[1]);
-            printf("Value[2]: %d\n", data->value.int32_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC4:
-            printf("Value type: INT32_VEC4\nValue[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d ", data->value.int32_array[1]);
-            printf("Value[2]: %d ", data->value.int32_array[2]);
-            printf("Value[3]: %d\n", data->value.int32_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
-            printf("Value type: ZONED_FLOAT\nZone: %d ", data->zone);
-            printf("Value: %f\n", data->value.float_value);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2:
-            printf("Value type: ZONED_FLOAT_VEC2\nZone: %d ", data->zone);
-            printf("Value[0]: %f", data->value.float_array[0]);
-            printf("Value[1]: %f\n", data->value.float_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3:
-            printf("Value type: ZONED_FLOAT_VEC3\nZone: %d ", data->zone);
-            printf("Value[0]: %f ", data->value.float_array[0]);
-            printf("Value[1]: %f ", data->value.float_array[1]);
-            printf("Value[2]: %f\n", data->value.float_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4:
-            printf("Value type: ZONED_FLOAT_VEC4\nZone: %d ", data->zone);
-            printf("Value[0]: %f ", data->value.float_array[0]);
-            printf("Value[1]: %f ", data->value.float_array[1]);
-            printf("Value[2]: %f ", data->value.float_array[2]);
-            printf("Value[3]: %f\n", data->value.float_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32:
-            printf("Value type: ZONED_INT32\nZone: %d ", data->zone);
-            printf("Value: %d\n", data->value.int32_value);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2:
-            printf("Value type: ZONED_INT32_VEC2\nZone: %d ", data->zone);
-            printf("Value[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d\n", data->value.int32_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3:
-            printf("Value type: ZONED_INT32_VEC3\nZone: %d ", data->zone);
-            printf("Value[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d ", data->value.int32_array[1]);
-            printf("Value[2]: %d\n", data->value.int32_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4:
-            printf("Value type: ZONED_INT32_VEC4\nZone: %d ", data->zone);
-            printf("Value[0]: %d ", data->value.int32_array[0]);
-            printf("Value[1]: %d ", data->value.int32_array[1]);
-            printf("Value[2]: %d ", data->value.int32_array[2]);
-            printf("Value[3]: %d\n", data->value.int32_array[3]);
-            break;
-        default:
-            printf("Value type not yet handled: %d.\n", data->value_type);
-    }
-}
-
-void get_property(
-    vehicle_hw_device_t *device, int32_t property, int32_t type, char *value_string) {
-    vehicle_prop_value_t *data = (vehicle_prop_value_t *) malloc (sizeof(vehicle_prop_value_t));
-
-    // Parse the string according to type.
-    if (value_string != NULL && strlen(value_string) > 0) {
-        switch (type) {
-            case VEHICLE_VALUE_TYPE_INT32:
-                sscanf(value_string, "%d", &(data->value.int32_value));
-                break;
-            case VEHICLE_VALUE_TYPE_INT32_VEC4:
-            {
-                int32_t vec[4];
-                sscanf(value_string, "%d %d %d %d", &vec[0], &vec[1], &vec[2], &vec[3]);
-                memcpy(data->value.int32_array, vec, sizeof(vec));
-                break;
-            }
-            default:
-                printf("%s Setting value type not supported: %d\n", __func__, type);
-                exit(1);
-        }
-    }
-
-    data->prop = property;
-    int ret_code = device->get(device, data);
-    if (ret_code != 0) {
-        printf("Cannot get property: %d\n", ret_code);
-        exit(1);
-    }
-
-    // We simply convert the data into the type mentioned by the result of the
-    // get call.
-    printf("Get output\n------------\n");
-    print_property(data);
-    free(data);
-}
-
-void set_property(vehicle_hw_device_t *device,
-                  int32_t property,
-                  int32_t type,
-                  char *data) {
-    vehicle_prop_value_t vehicle_data;
-    vehicle_data.prop = property;
-    vehicle_data.value_type = type;
-    int32_t zone = 0;
-    float value = 0.0;
-    switch (type) {
-        case VEHICLE_VALUE_TYPE_STRING:
-            // TODO: Make the code generic to UTF8 characters.
-            vehicle_data.value.str_value.len = strlen(data);
-            vehicle_data.value.str_value.data =
-                (uint8_t *) malloc (strlen(data) * sizeof(uint8_t));
-            memcpy(vehicle_data.value.str_value.data, data, strlen(data) + 1);
-            break;
-        case VEHICLE_VALUE_TYPE_BYTES: {
-                int len = strlen(data);
-                int numBytes = (len + 1) / 3;
-                uint8_t *buf = calloc(numBytes, sizeof(uint8_t));
-                char *byte = strtok(data, " ");
-                for (int i = 0; byte != NULL && i < numBytes; i++) {
-                    buf[i] = strtol(data, NULL, 16);
-                    byte = strtok(NULL, " ");
-                }
-                vehicle_data.value.bytes_value.len = numBytes;
-                vehicle_data.value.bytes_value.data = buf;
-            }
-            break;
-        case VEHICLE_VALUE_TYPE_BOOLEAN:
-            vehicle_data.value.boolean_value = atoi(data);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_BOOLEAN:
-            sscanf(data, "%d %d", &vehicle_data.zone,
-                &vehicle_data.value.boolean_value);
-            break;
-        case VEHICLE_VALUE_TYPE_INT64:
-            vehicle_data.value.int64_value = atoi(data);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT:
-            vehicle_data.value.float_value = atof(data);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC2:
-            sscanf(data, "%f %f", &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC3:
-            sscanf(data, "%f %f %f", &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1],
-                &vehicle_data.value.float_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_FLOAT_VEC4:
-            sscanf(data, "%f %f %f %f", &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1],
-                &vehicle_data.value.float_array[2],
-                &vehicle_data.value.float_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32:
-            vehicle_data.value.int32_value = atoi(data);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC2:
-            sscanf(data, "%d %d", &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC3:
-            sscanf(data, "%d %d %d", &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1],
-                &vehicle_data.value.int32_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_INT32_VEC4:
-            sscanf(data, "%d %d %d %d", &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1],
-                &vehicle_data.value.int32_array[2],
-                &vehicle_data.value.int32_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT:
-            sscanf(data, "%d %f", &zone, &value);
-            vehicle_data.zone = zone;
-            vehicle_data.value.float_value = value;
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC2:
-            sscanf(data, "%d %f %f", &vehicle_data.zone,
-                &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC3:
-            sscanf(data, "%d %f %f %f", &vehicle_data.zone,
-                &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1],
-                &vehicle_data.value.float_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_FLOAT_VEC4:
-            sscanf(data, "%d %f %f %f %f", &vehicle_data.zone,
-                &vehicle_data.value.float_array[0],
-                &vehicle_data.value.float_array[1],
-                &vehicle_data.value.float_array[2],
-                &vehicle_data.value.float_array[3]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32:
-            sscanf(data, "%d %d", &vehicle_data.zone,
-                &vehicle_data.value.int32_value);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC2:
-            sscanf(data, "%d %d %d", &vehicle_data.zone,
-                &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC3:
-            sscanf(data, "%d %d %d %d", &vehicle_data.zone,
-                &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1],
-                &vehicle_data.value.int32_array[2]);
-            break;
-        case VEHICLE_VALUE_TYPE_ZONED_INT32_VEC4:
-            sscanf(data, "%d %d %d %d %d", &vehicle_data.zone,
-                &vehicle_data.value.int32_array[0],
-                &vehicle_data.value.int32_array[1],
-                &vehicle_data.value.int32_array[2],
-                &vehicle_data.value.int32_array[3]);
-            break;
-        default:
-            printf("set_property: Value type not yet handled: %d\n", type);
-            exit(1);
-    }
-    printf("Setting Property id: %d\n", vehicle_data.prop);
-    print_property(&vehicle_data);
-
-    int ret_code = device->set(device, &vehicle_data);
-    if (ret_code != 0) {
-        printf("Cannot set property: %d\n", ret_code);
-        exit(1);
-    }
-}
-
-int vehicle_event_callback(const vehicle_prop_value_t *event_data) {
-    // Print what we got.
-    printf("Got some value from callback property: %d\n", event_data->prop);
-    printf("Timestamp: %" PRId64 "\n", event_data->timestamp);
-    print_property(event_data);
-    return 0;
-}
-
-int vehicle_error_callback(int32_t error_code, int32_t property, int32_t operation) {
-    // Print what we got.
-    printf("Error code obtained: %d\n", error_code);
-    return 0;
-}
-
-void subscribe_to_property(
-    vehicle_hw_device_t *device,
-    int32_t prop,
-    float sample_rate,
-    uint32_t wait_in_seconds) {
-    // Init the device with a callback.
-    int ret_code = device->subscribe(device, prop, 0, 0);
-    if (ret_code != 0) {
-        printf("Could not subscribe: %d\n", ret_code);
-        exit(1);
-    }
-
-    // Callbacks will happen on one of the threads created by the HAL hence we
-    // can simply sleep here and see the output.
-    sleep(wait_in_seconds);
-
-    // Unsubscribe and uninit.
-    ret_code = device->unsubscribe(device, prop);
-    if (ret_code != 0) {
-        printf("Error unsubscribing the HAL, still continuining to uninit HAL ...");
-    }
-}
-
-int main(int argc, char* argv[]) {
-    // Open the vehicle module and just ask for the list of properties.
-    const hw_module_t *hw_module = NULL;
-    int ret_code = hw_get_module(VEHICLE_HARDWARE_MODULE_ID, &hw_module);
-    if (ret_code != 0) {
-        printf("Cannot open the hw module. Does the HAL exist? %d\n", ret_code);
-        return -1;
-    }
-
-    vehicle_module_t *vehicle_module = (vehicle_module_t *)(hw_module);
-    hw_device_t *device = NULL;
-    ret_code = vehicle_module->common.methods->open(hw_module, NULL, &device);
-    if (!device) {
-        printf("Cannot open the hw device: %d\n", ret_code);
-        return -1;
-    }
-    vehicle_hw_device_t *vehicle_device = (vehicle_hw_device_t *) (device);
-    printf("HAL Loaded!\n");
-
-    vehicle_device->init(vehicle_device, vehicle_event_callback, vehicle_error_callback);
-
-    // If this is a list properties command - we check for -l command.
-    int list_properties = 0;
-    // Type of the property (see #defines in vehicle.h).
-    int property = -1;
-    // Type of the value of the property (see enum vehicle_value_type).
-    int type = -1;
-    // Whether the mode is "get" or "set".
-    char mode[100] = "";
-    // Actual value as a string representation (supports only PODs for now).
-    // TODO: Support structures and complex types in the tool.
-    char value[100] = "";
-    // Wait time for the subscribe type of calls.
-    // We keep a default in case the user does not specify one.
-    int wait_time_in_sec = 10;
-    // Sample rate for subscribe type of calls.
-    // Default value is 0 for onchange type of properties.
-    int sample_rate = 0;
-    // Int array string which represents the vehicle_value_t in array of
-    // numbers. See vehicle_prop_value_t.value.int32_array.
-    char int_array_string[1000]; int_array_string[0] = '\0';
-
-    int opt;
-    while ((opt = getopt(argc, argv, "lm:p:t:v:w:s:")) != -1) {
-        switch (opt) {
-            case 'l':
-                list_properties = 1;
-                break;
-            case 'm':
-                strcpy(mode, optarg);
-                break;
-            case 'p':
-                property = atoi(optarg);
-                break;
-            case 't':
-                type = atoi(optarg);
-                break;
-            case 'v':
-                strcpy(value, optarg);
-                break;
-            case 'w':
-                wait_time_in_sec = atoi(optarg);
-                break;
-            case 's':
-                sample_rate = atoi(optarg);
-                break;
-        }
-    }
-
-    // We should have atleast one of list properties or mode (for get or set).
-    if (!list_properties &&
-        !(!strcmp(mode, "get") || !strcmp(mode, "set") || !strcmp(mode, "sub"))) {
-        usage();
-        exit(1);
-    }
-
-    if (list_properties) {
-        printf("Listing properties...\n");
-        list_all_properties(vehicle_device);
-    } else if (!strcmp(mode, "get")) {
-        printf("Getting property ...\n");
-        if (property == -1) {
-            printf("Use -p to pass a valid Property.\n");
-            usage();
-            exit(1);
-        }
-
-        int32_t int_array_list[4];
-        int count = -1;
-        if (strlen(int_array_string) > 0) {
-            count = sscanf(int_array_string, "%d%d%d%d",
-                   &int_array_list[0], &int_array_list[1], &int_array_list[2], &int_array_list[3]);
-        }
-
-        get_property(vehicle_device, property, type, value);
-    } else if (!strcmp(mode, "set")) {
-        printf("Setting property ...\n");
-        if (property == -1 || type == -1) {
-            printf("Use -p to pass a valid Property and -t to pass a valid Type.\n");
-            usage();
-            exit(1);
-        }
-        set_property(vehicle_device, property, type, value);
-    } else if (!strcmp(mode, "sub")) {
-        printf("Subscribing property ...\n");
-        if (property == -1 || wait_time_in_sec <= 0) {
-            printf("Use -p to pass a valid property and -w to pass a valid wait time(s)\n");
-            usage();
-            exit(1);
-        }
-        subscribe_to_property(vehicle_device, property, sample_rate, wait_time_in_sec);
-    }
-
-    ret_code = vehicle_device->release(vehicle_device);
-    if (ret_code != 0) {
-        printf("Error uniniting HAL, exiting anyways.");
-    }
-    return 0;
-}
diff --git a/tests/vehicle/vehicle_test_fixtures.h b/tests/vehicle/vehicle_test_fixtures.h
deleted file mode 100644
index a9572ba..0000000
--- a/tests/vehicle/vehicle_test_fixtures.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2015 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_HAL_VEHICLE_TEST_
-#define __ANDROID_HAL_VEHICLE_TEST_
-
-#include <gtest/gtest.h>
-#include <hardware/hardware.h>
-#include <hardware/vehicle.h>
-
-namespace tests {
-
-static const uint64_t kVersion = HARDWARE_DEVICE_API_VERSION_2(1, 0, 1);
-
-class VehicleModule : public testing::Test {
-public:
-    VehicleModule() :
-        vehicle_module_(NULL) {}
-    ~VehicleModule() {}
-protected:
-    virtual void SetUp() {
-        const hw_module_t *hw_module = NULL;
-        ASSERT_EQ(0, hw_get_module(VEHICLE_HARDWARE_MODULE_ID, &hw_module))
-                    << "Can't get vehicle module";
-        ASSERT_TRUE(NULL != hw_module)
-                    << "hw_get_module didn't return a valid hardware module";
-
-        vehicle_module_ = reinterpret_cast<const vehicle_module_t*>(hw_module);
-    }
-    const vehicle_module_t* vehicle_module() { return vehicle_module_; }
-private:
-    const vehicle_module_t* vehicle_module_;
-};
-
-
-int VehicleEventCallback(const vehicle_prop_value_t* event_data) {
-    // Print what we got.
-    std::cout << "got some value from callback: "
-              << event_data->prop
-              << " uint32 value: "
-              << event_data->value.int32_value << "\n";
-    return 0;
-}
-
- int VehicleErrorCallback(int32_t /*error_code*/, int32_t /*property*/, int32_t /*operation*/) {
-    // Do nothing.
-    return 0;
-}
-
-class VehicleDevice : public VehicleModule {
-public:
-    VehicleDevice() :
-        vehicle_device_(NULL) {}
-    ~VehicleDevice() {}
-protected:
-    virtual void SetUp() {
-        VehicleModule::SetUp();
-        hw_device_t *device = NULL;
-        ASSERT_TRUE(NULL != vehicle_module()->common.methods->open)
-                    << "Vehicle open() is unimplemented";
-        ASSERT_EQ(0, vehicle_module()->common.methods->open(
-            (const hw_module_t*)vehicle_module(), NULL, &device))
-                << "Can't open vehicle device";
-        ASSERT_TRUE(NULL != device)
-                    << "Vehicle open() returned a NULL device";
-        ASSERT_EQ(kVersion, device->version)
-                    << "Unsupported version";
-        vehicle_device_ = reinterpret_cast<vehicle_hw_device_t*>(device);
-    }
-    vehicle_hw_device_t* vehicle_device() { return vehicle_device_; }
-    vehicle_event_callback_fn callback_fn() {
-      return VehicleEventCallback;
-    }
-    vehicle_error_callback_fn error_fn() {
-      return VehicleErrorCallback;
-    }
-
- private:
-    vehicle_hw_device_t* vehicle_device_;
-};
-
-}  // namespace tests
-
-#endif  // __ANDROID_HAL_VEHICLE_TEST_
diff --git a/tests/vehicle/vehicle_tests.cpp b/tests/vehicle/vehicle_tests.cpp
deleted file mode 100644
index 4c15570..0000000
--- a/tests/vehicle/vehicle_tests.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2015 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 <gtest/gtest.h>
-#include "vehicle_test_fixtures.h"
-#include "hardware/vehicle.h"
-
-namespace tests {
-
-// Check if list_properties command exists.
-TEST_F(VehicleDevice, isThereListProperties) {
-    ASSERT_TRUE(NULL != vehicle_device()->list_properties)
-        << "list_properties() function is not implemented";
-    std::cout << "Test succeeds.\n";
-}
-
-// HAL should provide atleast one property. The output of this command should be
-// used to verify the vailidity of the function.
-TEST_F(VehicleDevice, listPropertiesMoreThanOne) {
-    vehicle_prop_config_t const* config;
-    int num_configs = -1;
-    config = vehicle_device()->list_properties(vehicle_device(), &num_configs);
-    ASSERT_TRUE(num_configs > -1) << "list_properties() call failed.";
-    ASSERT_TRUE(num_configs > 0) << "list_properties() returned zero items.";
-    std::cout << "Number of properties reported: " << num_configs << "\n";
-    for (int i = 0; i < num_configs; i++) {
-        // Print each of the properties.
-        const vehicle_prop_config_t& config_temp = config[i];
-        std::cout << "Property ID: " << config_temp.prop << "\n";
-        std::cout << "Property flags: " << config_temp.config_flags << "\n";
-        std::cout << "Property change mode: " << config_temp.change_mode << "\n";
-        std::cout << "Property min sample rate: " << config_temp.min_sample_rate << "\n";
-        std::cout << "Property max sample rate: " << config_temp.max_sample_rate << "\n\n";
-    }
-}
-
-// Test get() command.
-// The fields are hardcoded in the dummy implementation and here.
-TEST_F(VehicleDevice, getDriveState) {
-    vehicle_prop_value_t data;
-    data.prop = VEHICLE_PROPERTY_DRIVING_STATUS;
-    // Set drive_state field to EINVAL so that we can check that its valid when
-    // it comes back.
-    data.value_type = -EINVAL;
-    data.value.driving_status = -EINVAL;
-    vehicle_device()->get(vehicle_device(), &data);
-
-    // Check that retured values are not invalid.
-    ASSERT_NE(data.value_type, -EINVAL) << "Drive state value type should be integer.";
-    ASSERT_NE(data.value.driving_status, -EINVAL) << "Driving status should be positive.";
-
-    std::cout << "Driving status value type: " << data.value_type << "\n"
-              << "Driving status: " << data.value.driving_status << "\n";
-}
-
-// Test the workflows for subscribe and init/release.
-// Subscribe will return error before init() is called or after release() is
-// called.
-TEST_F(VehicleDevice, initTest) {
-    // Test that init on a new device works. When getting an instance, we are
-    // already calling 'open' on the device.
-    int ret_code =
-        vehicle_device()->init(vehicle_device(), callback_fn(), error_fn());
-    ASSERT_EQ(ret_code, 0) << "ret code: " << ret_code;
-
-    // Trying to init again should return an error.
-    ret_code = vehicle_device()->init(vehicle_device(), callback_fn(), error_fn());
-    ASSERT_EQ(ret_code, -EEXIST) << "ret code: " << ret_code;
-
-    // Uninit should always return 0.
-    ret_code = vehicle_device()->release(vehicle_device());
-    ASSERT_EQ(ret_code, 0) << "ret code: " << ret_code;
-
-    // We should be able to init again.
-    ret_code = vehicle_device()->init(vehicle_device(), callback_fn(), error_fn());
-    ASSERT_EQ(ret_code, 0) << "ret code: " << ret_code;
-
-    // Finally release.
-    ret_code = vehicle_device()->release(vehicle_device());
-    ASSERT_EQ(ret_code, 0) << "ret_code: " << ret_code;
-}
-
-// Test that subscribe works.
-// We wait for 10 seconds while which the vehicle.c can post messages from
-// within it's own thread.
-TEST_F(VehicleDevice, subscribeTest) {
-    // If the device is not init subscribe should fail off the bat.
-    int ret_code = vehicle_device()->subscribe(vehicle_device(), VEHICLE_PROPERTY_DRIVING_STATUS,
-            0, 0);
-    ASSERT_EQ(ret_code, -EINVAL) << "Return code is: " << ret_code;
-
-    // Let's init the device.
-    ret_code = vehicle_device()->init(vehicle_device(), callback_fn(), error_fn());
-    ASSERT_EQ(ret_code, 0) << "Return code is: " << ret_code;
-
-    // Subscribe should now go through.
-    ret_code = vehicle_device()->subscribe(vehicle_device(), VEHICLE_PROPERTY_DRIVING_STATUS, 0, 0);
-    ASSERT_EQ(ret_code, 0) << "Return code is: " << ret_code;
-
-    // We should start getting some messages thrown from the callback. Let's
-    // wait for 20 seconds before unsubscribing.
-    std::cout << "Sleeping for 20 seconds.";
-    sleep(20);
-    std::cout << "Waking from sleep.";
-
-    // This property does not exist, so we should get -EINVAL.
-    ret_code = vehicle_device()->unsubscribe(vehicle_device(), VEHICLE_PROPERTY_INFO_VIN);
-    ASSERT_EQ(ret_code, -EINVAL) << "Return code is: " << ret_code;
-
-    // This property exists, so we should get a success return code - also this
-    // will be a blocking call.
-    ret_code = vehicle_device()->unsubscribe(vehicle_device(), VEHICLE_PROPERTY_DRIVING_STATUS);
-    ASSERT_EQ(ret_code, 0) << "Return code is: " << ret_code;
-}
-
-}  // namespace tests