Merge changes from topic 'binderized_gnss_hal'

* changes:
  Default implementation Gnss HAL
  Add IGnssConfiguration Interface
  Gnss Hal Minor Cleanup
diff --git a/audio/2.0/IDevice.hal b/audio/2.0/IDevice.hal
index 38bfe21..630a32c 100644
--- a/audio/2.0/IDevice.hal
+++ b/audio/2.0/IDevice.hal
@@ -102,6 +102,8 @@
 
     /*
      * This method creates and opens the audio hardware output stream.
+     * If the stream can not be opened with the proposed audio config,
+     * HAL must provide suggested values for the audio config.
      *
      * @param ioHandle handle assigned by AudioFlinger.
      * @param device device type and (if needed) address.
@@ -109,15 +111,21 @@
      * @param flags additional flags.
      * @return retval operation completion status.
      * @return outStream created output stream.
+     * @return suggestedConfig in case of invalid parameters, suggested config.
      */
     openOutputStream(
             AudioIoHandle ioHandle,
             DeviceAddress device,
             AudioConfig config,
-            AudioOutputFlag flags) generates (Result retval, IStreamOut outStream);
+            AudioOutputFlag flags) generates (
+                    Result retval,
+                    IStreamOut outStream,
+                    AudioConfig suggestedConfig);
 
     /*
      * This method creates and opens the audio hardware input stream.
+     * If the stream can not be opened with the proposed audio config,
+     * HAL must provide suggested values for the audio config.
      *
      * @param ioHandle handle assigned by AudioFlinger.
      * @param device device type and (if needed) address.
@@ -125,14 +133,25 @@
      * @param flags additional flags.
      * @param source source specification.
      * @return retval operation completion status.
-     * @return inStream created input stream.
+     * @return inStream in case of success, created input stream.
+     * @return suggestedConfig in case of invalid parameters, suggested config.
      */
     openInputStream(
             AudioIoHandle ioHandle,
             DeviceAddress device,
             AudioConfig config,
             AudioInputFlag flags,
-            AudioSource source) generates (Result retval, IStreamIn inStream);
+            AudioSource source) generates (
+                    Result retval,
+                    IStreamIn inStream,
+                    AudioConfig suggestedConfig);
+
+    /*
+     * Returns whether HAL supports audio patches.
+     *
+     * @return supports true if audio patches are supported.
+     */
+    supportsAudioPatches() generates (bool supports);
 
     /*
      * Creates an audio patch between several source and sink ports.  The handle
diff --git a/audio/2.0/IStreamOut.hal b/audio/2.0/IStreamOut.hal
index 55a852d..4ba3b2f 100644
--- a/audio/2.0/IStreamOut.hal
+++ b/audio/2.0/IStreamOut.hal
@@ -90,11 +90,25 @@
      * Calling this function implies that all future 'write' and 'drain'
      * must be non-blocking and use the callback to signal completion.
      *
+     * 'clearCallback' method needs to be called in order to release the local
+     * callback proxy on the server side and thus dereference the callback
+     * implementation on the client side.
+     *
      * @return retval operation completion status.
      */
     setCallback(IStreamOutCallback callback) generates (Result retval);
 
     /*
+     * Clears the callback previously set via 'setCallback' method.
+     *
+     * Warning: failure to call this method results in callback implementation
+     * on the client side being held until the HAL server termination.
+     *
+     * @return retval operation completion status: OK or NOT_SUPPORTED.
+     */
+    clearCallback() generates (Result retval);
+
+    /*
      * Returns whether HAL supports pausing and resuming of streams.
      *
      * @return supportsPause true if pausing is supported.
diff --git a/audio/2.0/default/Conversions.cpp b/audio/2.0/default/Conversions.cpp
index 1ba16e1..e669185 100644
--- a/audio/2.0/default/Conversions.cpp
+++ b/audio/2.0/default/Conversions.cpp
@@ -29,27 +29,31 @@
     char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
     memset(halAddress, 0, sizeof(halAddress));
     uint32_t halDevice = static_cast<uint32_t>(address.device);
-    if ((halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0
-            || (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0) {
+    const bool isInput = (halDevice & AUDIO_DEVICE_BIT_IN) != 0;
+    if (isInput) halDevice &= ~AUDIO_DEVICE_BIT_IN;
+    if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0)
+            || (isInput && (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) {
         snprintf(halAddress, sizeof(halAddress),
                 "%02X:%02X:%02X:%02X:%02X:%02X",
                 address.address.mac[0], address.address.mac[1], address.address.mac[2],
                 address.address.mac[3], address.address.mac[4], address.address.mac[5]);
-    } else if ((halDevice & AUDIO_DEVICE_OUT_IP) != 0 || (halDevice & AUDIO_DEVICE_IN_IP) != 0) {
+    } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0)
+            || (isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) {
         snprintf(halAddress, sizeof(halAddress),
                 "%d.%d.%d.%d",
                 address.address.ipv4[0], address.address.ipv4[1],
                 address.address.ipv4[2], address.address.ipv4[3]);
-    } else if ((halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0
-            || (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0) {
+    } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0)
+            || (isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) {
         snprintf(halAddress, sizeof(halAddress),
                 "card=%d;device=%d",
                 address.address.alsa.card, address.address.alsa.device);
-    } else if ((halDevice & AUDIO_DEVICE_OUT_BUS) != 0 || (halDevice & AUDIO_DEVICE_IN_BUS) != 0) {
+    } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0)
+            || (isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) {
         snprintf(halAddress, sizeof(halAddress),
                 "%s", address.busAddress.c_str());
-    } else if ((halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) != 0
-            || (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0) {
+    } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0
+            || (isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) {
         snprintf(halAddress, sizeof(halAddress),
                 "%s", address.rSubmixAddress.c_str());
     }
diff --git a/audio/2.0/default/Device.cpp b/audio/2.0/default/Device.cpp
index 339f371..8a51cd7 100644
--- a/audio/2.0/default/Device.cpp
+++ b/audio/2.0/default/Device.cpp
@@ -15,15 +15,17 @@
  */
 
 #define LOG_TAG "DeviceHAL"
+//#define LOG_NDEBUG 0
 
 #include <algorithm>
 #include <memory.h>
 #include <string.h>
 
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "Conversions.h"
 #include "Device.h"
+#include "HidlUtils.h"
 #include "StreamIn.h"
 #include "StreamOut.h"
 
@@ -43,267 +45,6 @@
     mDevice = nullptr;
 }
 
-// static
-void Device::audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig) {
-    memset(halConfig, 0, sizeof(audio_config_t));
-    halConfig->sample_rate = config.sampleRateHz;
-    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
-    halConfig->format = static_cast<audio_format_t>(config.format);
-    audioOffloadInfoToHal(config.offloadInfo, &halConfig->offload_info);
-    halConfig->frame_count = config.frameCount;
-}
-
-// static
-void Device::audioGainConfigFromHal(
-        const struct audio_gain_config& halConfig, AudioGainConfig* config) {
-    config->index = halConfig.index;
-    config->mode = AudioGainMode(halConfig.mode);
-    config->channelMask = AudioChannelMask(halConfig.channel_mask);
-    for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
-        config->values[i] = halConfig.values[i];
-    }
-    config->rampDurationMs = halConfig.ramp_duration_ms;
-}
-
-// static
-void Device::audioGainConfigToHal(
-        const AudioGainConfig& config, struct audio_gain_config* halConfig) {
-    halConfig->index = config.index;
-    halConfig->mode = static_cast<audio_gain_mode_t>(config.mode);
-    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
-    memset(halConfig->values, 0, sizeof(halConfig->values));
-    for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
-        halConfig->values[i] = config.values[i];
-    }
-    halConfig->ramp_duration_ms = config.rampDurationMs;
-}
-
-// static
-void Device::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) {
-    gain->mode = AudioGainMode(halGain.mode);
-    gain->channelMask = AudioChannelMask(halGain.channel_mask);
-    gain->minValue = halGain.min_value;
-    gain->maxValue = halGain.max_value;
-    gain->defaultValue = halGain.default_value;
-    gain->stepValue = halGain.step_value;
-    gain->minRampMs = halGain.min_ramp_ms;
-    gain->maxRampMs = halGain.max_ramp_ms;
-}
-
-// static
-void Device::audioGainToHal(const AudioGain& gain, struct audio_gain* halGain) {
-    halGain->mode = static_cast<audio_gain_mode_t>(gain.mode);
-    halGain->channel_mask = static_cast<audio_channel_mask_t>(gain.channelMask);
-    halGain->min_value = gain.minValue;
-    halGain->max_value = gain.maxValue;
-    halGain->default_value = gain.defaultValue;
-    halGain->step_value = gain.stepValue;
-    halGain->min_ramp_ms = gain.minRampMs;
-    halGain->max_ramp_ms = gain.maxRampMs;
-}
-
-// static
-void Device::audioOffloadInfoToHal(
-        const AudioOffloadInfo& offload, audio_offload_info_t* halOffload) {
-    *halOffload = AUDIO_INFO_INITIALIZER;
-    halOffload->sample_rate = offload.sampleRateHz;
-    halOffload->channel_mask = static_cast<audio_channel_mask_t>(offload.channelMask);
-    halOffload->stream_type = static_cast<audio_stream_type_t>(offload.streamType);
-    halOffload->bit_rate = offload.bitRatePerSecond;
-    halOffload->duration_us = offload.durationMicroseconds;
-    halOffload->has_video = offload.hasVideo;
-    halOffload->is_streaming = offload.isStreaming;
-}
-
-// static
-void Device::audioPortConfigFromHal(
-        const struct audio_port_config& halConfig, AudioPortConfig* config) {
-    config->id = halConfig.id;
-    config->role = AudioPortRole(halConfig.role);
-    config->type = AudioPortType(halConfig.type);
-    config->configMask = AudioPortConfigMask(halConfig.config_mask);
-    config->sampleRateHz = halConfig.sample_rate;
-    config->channelMask = AudioChannelMask(halConfig.channel_mask);
-    config->format = AudioFormat(halConfig.format);
-    audioGainConfigFromHal(halConfig.gain, &config->gain);
-    switch (halConfig.type) {
-        case AUDIO_PORT_TYPE_NONE: break;
-        case AUDIO_PORT_TYPE_DEVICE: {
-            config->ext.device.hwModule = halConfig.ext.device.hw_module;
-            config->ext.device.type = AudioDevice(halConfig.ext.device.type);
-            memcpy(config->ext.device.address.data(),
-                    halConfig.ext.device.address,
-                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
-            break;
-        }
-        case AUDIO_PORT_TYPE_MIX: {
-            config->ext.mix.hwModule = halConfig.ext.mix.hw_module;
-            config->ext.mix.ioHandle = halConfig.ext.mix.handle;
-            if (halConfig.role == AUDIO_PORT_ROLE_SOURCE) {
-                config->ext.mix.useCase.source = AudioSource(halConfig.ext.mix.usecase.source);
-            } else if (halConfig.role == AUDIO_PORT_ROLE_SINK) {
-                config->ext.mix.useCase.stream = AudioStreamType(halConfig.ext.mix.usecase.stream);
-            }
-            break;
-        }
-        case AUDIO_PORT_TYPE_SESSION: {
-            config->ext.session.session = halConfig.ext.session.session;
-            break;
-        }
-    }
-}
-
-// static
-void Device::audioPortConfigToHal(
-        const AudioPortConfig& config, struct audio_port_config* halConfig) {
-    memset(halConfig, 0, sizeof(audio_port_config));
-    halConfig->id = config.id;
-    halConfig->role = static_cast<audio_port_role_t>(config.role);
-    halConfig->type = static_cast<audio_port_type_t>(config.type);
-    halConfig->config_mask = static_cast<unsigned int>(config.configMask);
-    halConfig->sample_rate = config.sampleRateHz;
-    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
-    halConfig->format = static_cast<audio_format_t>(config.format);
-    audioGainConfigToHal(config.gain, &halConfig->gain);
-    switch (config.type) {
-        case AudioPortType::NONE: break;
-        case AudioPortType::DEVICE: {
-            halConfig->ext.device.hw_module = config.ext.device.hwModule;
-            halConfig->ext.device.type = static_cast<audio_devices_t>(config.ext.device.type);
-            memcpy(halConfig->ext.device.address,
-                    config.ext.device.address.data(),
-                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
-            break;
-        }
-        case AudioPortType::MIX: {
-            halConfig->ext.mix.hw_module = config.ext.mix.hwModule;
-            halConfig->ext.mix.handle = config.ext.mix.ioHandle;
-            if (config.role == AudioPortRole::SOURCE) {
-                halConfig->ext.mix.usecase.source =
-                        static_cast<audio_source_t>(config.ext.mix.useCase.source);
-            } else if (config.role == AudioPortRole::SINK) {
-                halConfig->ext.mix.usecase.stream =
-                        static_cast<audio_stream_type_t>(config.ext.mix.useCase.stream);
-            }
-            break;
-        }
-        case AudioPortType::SESSION: {
-            halConfig->ext.session.session =
-                    static_cast<audio_session_t>(config.ext.session.session);
-            break;
-        }
-    }
-}
-
-// static
-std::unique_ptr<audio_port_config[]> Device::audioPortConfigsToHal(
-        const hidl_vec<AudioPortConfig>& configs) {
-    std::unique_ptr<audio_port_config[]> halConfigs(new audio_port_config[configs.size()]);
-    for (size_t i = 0; i < configs.size(); ++i) {
-        audioPortConfigToHal(configs[i], &halConfigs[i]);
-    }
-    return halConfigs;
-}
-
-// static
-void Device::audioPortFromHal(const struct audio_port& halPort, AudioPort* port) {
-    port->id = halPort.id;
-    port->role = AudioPortRole(halPort.role);
-    port->type = AudioPortType(halPort.type);
-    port->name.setToExternal(halPort.name, strlen(halPort.name));
-    port->sampleRates.resize(halPort.num_sample_rates);
-    for (size_t i = 0; i < halPort.num_sample_rates; ++i) {
-        port->sampleRates[i] = halPort.sample_rates[i];
-    }
-    port->channelMasks.resize(halPort.num_channel_masks);
-    for (size_t i = 0; i < halPort.num_channel_masks; ++i) {
-        port->channelMasks[i] = AudioChannelMask(halPort.channel_masks[i]);
-    }
-    port->formats.resize(halPort.num_formats);
-    for (size_t i = 0; i < halPort.num_formats; ++i) {
-        port->formats[i] = AudioFormat(halPort.formats[i]);
-    }
-    port->gains.resize(halPort.num_gains);
-    for (size_t i = 0; i < halPort.num_gains; ++i) {
-        audioGainFromHal(halPort.gains[i], &port->gains[i]);
-    }
-    audioPortConfigFromHal(halPort.active_config, &port->activeConfig);
-    switch (halPort.type) {
-        case AUDIO_PORT_TYPE_NONE: break;
-        case AUDIO_PORT_TYPE_DEVICE: {
-            port->ext.device.hwModule = halPort.ext.device.hw_module;
-            port->ext.device.type = AudioDevice(halPort.ext.device.type);
-            memcpy(port->ext.device.address.data(),
-                    halPort.ext.device.address,
-                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
-            break;
-        }
-        case AUDIO_PORT_TYPE_MIX: {
-            port->ext.mix.hwModule = halPort.ext.mix.hw_module;
-            port->ext.mix.ioHandle = halPort.ext.mix.handle;
-            port->ext.mix.latencyClass = AudioMixLatencyClass(halPort.ext.mix.latency_class);
-            break;
-        }
-        case AUDIO_PORT_TYPE_SESSION: {
-            port->ext.session.session = halPort.ext.session.session;
-            break;
-        }
-    }
-}
-
-// static
-void Device::audioPortToHal(const AudioPort& port, struct audio_port* halPort) {
-    memset(halPort, 0, sizeof(audio_port));
-    halPort->id = port.id;
-    halPort->role = static_cast<audio_port_role_t>(port.role);
-    halPort->type = static_cast<audio_port_type_t>(port.type);
-    memcpy(halPort->name,
-            port.name.c_str(),
-            std::min(port.name.size(), static_cast<size_t>(AUDIO_PORT_MAX_NAME_LEN)));
-    halPort->num_sample_rates =
-            std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES));
-    for (size_t i = 0; i < halPort->num_sample_rates; ++i) {
-        halPort->sample_rates[i] = port.sampleRates[i];
-    }
-    halPort->num_channel_masks =
-            std::min(port.channelMasks.size(), static_cast<size_t>(AUDIO_PORT_MAX_CHANNEL_MASKS));
-    for (size_t i = 0; i < halPort->num_channel_masks; ++i) {
-        halPort->channel_masks[i] = static_cast<audio_channel_mask_t>(port.channelMasks[i]);
-    }
-    halPort->num_formats =
-            std::min(port.formats.size(), static_cast<size_t>(AUDIO_PORT_MAX_FORMATS));
-    for (size_t i = 0; i < halPort->num_formats; ++i) {
-        halPort->formats[i] = static_cast<audio_format_t>(port.formats[i]);
-    }
-    halPort->num_gains = std::min(port.gains.size(), static_cast<size_t>(AUDIO_PORT_MAX_GAINS));
-    for (size_t i = 0; i < halPort->num_gains; ++i) {
-        audioGainToHal(port.gains[i], &halPort->gains[i]);
-    }
-    audioPortConfigToHal(port.activeConfig, &halPort->active_config);
-    switch (port.type) {
-        case AudioPortType::NONE: break;
-        case AudioPortType::DEVICE: {
-            halPort->ext.device.hw_module = port.ext.device.hwModule;
-            halPort->ext.device.type = static_cast<audio_devices_t>(port.ext.device.type);
-            memcpy(halPort->ext.device.address,
-                    port.ext.device.address.data(),
-                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
-            break;
-        }
-        case AudioPortType::MIX: {
-            halPort->ext.mix.hw_module = port.ext.mix.hwModule;
-            halPort->ext.mix.handle = port.ext.mix.ioHandle;
-            halPort->ext.mix.latency_class =
-                    static_cast<audio_mix_latency_class_t>(port.ext.mix.latencyClass);
-            break;
-        }
-        case AudioPortType::SESSION: {
-            halPort->ext.session.session = static_cast<audio_session_t>(port.ext.session.session);
-            break;
-        }
-    }
-}
-
 Result Device::analyzeStatus(const char* funcName, int status) {
     if (status != 0) {
         ALOGW("Device %p %s: %s", mDevice, funcName, strerror(-status));
@@ -381,7 +122,7 @@
 Return<void> Device::getInputBufferSize(
         const AudioConfig& config, getInputBufferSize_cb _hidl_cb)  {
     audio_config_t halConfig;
-    audioConfigToHal(config, &halConfig);
+    HidlUtils::audioConfigToHal(config, &halConfig);
     size_t halBufferSize = mDevice->get_input_buffer_size(mDevice, &halConfig);
     Result retval(Result::INVALID_ARGUMENTS);
     uint64_t bufferSize = 0;
@@ -400,8 +141,14 @@
         AudioOutputFlag flags,
         openOutputStream_cb _hidl_cb)  {
     audio_config_t halConfig;
-    audioConfigToHal(config, &halConfig);
+    HidlUtils::audioConfigToHal(config, &halConfig);
     audio_stream_out_t *halStream;
+    ALOGV("open_output_stream handle: %d devices: %x flags: %#x "
+            "srate: %d format %#x channels %x address %s",
+            ioHandle,
+            static_cast<audio_devices_t>(device.device), static_cast<audio_output_flags_t>(flags),
+            halConfig.sample_rate, halConfig.format, halConfig.channel_mask,
+            deviceAddressToHal(device).c_str());
     int status = mDevice->open_output_stream(
             mDevice,
             ioHandle,
@@ -410,11 +157,14 @@
             &halConfig,
             &halStream,
             deviceAddressToHal(device).c_str());
+    ALOGV("open_output_stream status %d stream %p", status, halStream);
     sp<IStreamOut> streamOut;
     if (status == OK) {
         streamOut = new StreamOut(mDevice, halStream);
     }
-    _hidl_cb(analyzeStatus("open_output_stream", status), streamOut);
+    AudioConfig suggestedConfig;
+    HidlUtils::audioConfigFromHal(halConfig, &suggestedConfig);
+    _hidl_cb(analyzeStatus("open_output_stream", status), streamOut, suggestedConfig);
     return Void();
 }
 
@@ -426,8 +176,14 @@
         AudioSource source,
         openInputStream_cb _hidl_cb)  {
     audio_config_t halConfig;
-    audioConfigToHal(config, &halConfig);
+    HidlUtils::audioConfigToHal(config, &halConfig);
     audio_stream_in_t *halStream;
+    ALOGV("open_input_stream handle: %d devices: %x flags: %#x "
+            "srate: %d format %#x channels %x address %s source %d",
+            ioHandle,
+            static_cast<audio_devices_t>(device.device), static_cast<audio_input_flags_t>(flags),
+            halConfig.sample_rate, halConfig.format, halConfig.channel_mask,
+            deviceAddressToHal(device).c_str(), static_cast<audio_source_t>(source));
     int status = mDevice->open_input_stream(
             mDevice,
             ioHandle,
@@ -437,14 +193,21 @@
             static_cast<audio_input_flags_t>(flags),
             deviceAddressToHal(device).c_str(),
             static_cast<audio_source_t>(source));
+    ALOGV("open_input_stream status %d stream %p", status, halStream);
     sp<IStreamIn> streamIn;
     if (status == OK) {
         streamIn = new StreamIn(mDevice, halStream);
     }
-    _hidl_cb(analyzeStatus("open_input_stream", status), streamIn);
+    AudioConfig suggestedConfig;
+    HidlUtils::audioConfigFromHal(halConfig, &suggestedConfig);
+    _hidl_cb(analyzeStatus("open_input_stream", status), streamIn, suggestedConfig);
     return Void();
 }
 
+Return<bool> Device::supportsAudioPatches() {
+    return version() >= AUDIO_DEVICE_API_VERSION_3_0;
+}
+
 Return<void> Device::createAudioPatch(
         const hidl_vec<AudioPortConfig>& sources,
         const hidl_vec<AudioPortConfig>& sinks,
@@ -452,8 +215,8 @@
     Result retval(Result::NOT_SUPPORTED);
     AudioPatchHandle patch = 0;
     if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
-        std::unique_ptr<audio_port_config[]> halSources(audioPortConfigsToHal(sources));
-        std::unique_ptr<audio_port_config[]> halSinks(audioPortConfigsToHal(sinks));
+        std::unique_ptr<audio_port_config[]> halSources(HidlUtils::audioPortConfigsToHal(sources));
+        std::unique_ptr<audio_port_config[]> halSinks(HidlUtils::audioPortConfigsToHal(sinks));
         audio_patch_handle_t halPatch;
         retval = analyzeStatus(
                 "create_audio_patch",
@@ -481,11 +244,11 @@
 
 Return<void> Device::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb)  {
     audio_port halPort;
-    audioPortToHal(port, &halPort);
+    HidlUtils::audioPortToHal(port, &halPort);
     Result retval = analyzeStatus("get_audio_port", mDevice->get_audio_port(mDevice, &halPort));
     AudioPort resultPort = port;
     if (retval == Result::OK) {
-        audioPortFromHal(halPort, &resultPort);
+        HidlUtils::audioPortFromHal(halPort, &resultPort);
     }
     _hidl_cb(retval, resultPort);
     return Void();
@@ -494,7 +257,7 @@
 Return<Result> Device::setAudioPortConfig(const AudioPortConfig& config)  {
     if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
         struct audio_port_config halPortConfig;
-        audioPortConfigToHal(config, &halPortConfig);
+        HidlUtils::audioPortConfigToHal(config, &halPortConfig);
         return analyzeStatus(
                 "set_audio_port_config", mDevice->set_audio_port_config(mDevice, &halPortConfig));
     }
diff --git a/audio/2.0/default/Device.h b/audio/2.0/default/Device.h
index 49d6b2c..46177fc 100644
--- a/audio/2.0/default/Device.h
+++ b/audio/2.0/default/Device.h
@@ -36,22 +36,13 @@
 namespace implementation {
 
 using ::android::hardware::audio::common::V2_0::AudioConfig;
-using ::android::hardware::audio::common::V2_0::AudioGain;
-using ::android::hardware::audio::common::V2_0::AudioGainConfig;
-using ::android::hardware::audio::common::V2_0::AudioGainMode;
 using ::android::hardware::audio::common::V2_0::AudioHwSync;
 using ::android::hardware::audio::common::V2_0::AudioInputFlag;
-using ::android::hardware::audio::common::V2_0::AudioMixLatencyClass;
-using ::android::hardware::audio::common::V2_0::AudioOffloadInfo;
 using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
 using ::android::hardware::audio::common::V2_0::AudioPatchHandle;
 using ::android::hardware::audio::common::V2_0::AudioPort;
 using ::android::hardware::audio::common::V2_0::AudioPortConfig;
-using ::android::hardware::audio::common::V2_0::AudioPortConfigMask;
-using ::android::hardware::audio::common::V2_0::AudioPortRole;
-using ::android::hardware::audio::common::V2_0::AudioPortType;
 using ::android::hardware::audio::common::V2_0::AudioSource;
-using ::android::hardware::audio::common::V2_0::AudioStreamType;
 using ::android::hardware::audio::V2_0::DeviceAddress;
 using ::android::hardware::audio::V2_0::IDevice;
 using ::android::hardware::audio::V2_0::IStreamIn;
@@ -90,6 +81,7 @@
             AudioInputFlag flags,
             AudioSource source,
             openInputStream_cb _hidl_cb)  override;
+    Return<bool> supportsAudioPatches()  override;
     Return<void> createAudioPatch(
             const hidl_vec<AudioPortConfig>& sources,
             const hidl_vec<AudioPortConfig>& sinks,
@@ -111,24 +103,6 @@
   private:
     audio_hw_device_t *mDevice;
 
-    static void audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig);
-    static void audioGainConfigFromHal(
-            const struct audio_gain_config& halConfig, AudioGainConfig* config);
-    static void audioGainConfigToHal(
-            const AudioGainConfig& config, struct audio_gain_config* halConfig);
-    static void audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain);
-    static void audioGainToHal(const AudioGain& gain, struct audio_gain* halGain);
-    static void audioOffloadInfoToHal(
-            const AudioOffloadInfo& offload, audio_offload_info_t* halOffload);
-    static void audioPortConfigFromHal(
-            const struct audio_port_config& halConfig, AudioPortConfig* config);
-    static void audioPortConfigToHal(
-            const AudioPortConfig& config, struct audio_port_config* halConfig);
-    static std::unique_ptr<audio_port_config[]> audioPortConfigsToHal(
-            const hidl_vec<AudioPortConfig>& configs);
-    static void audioPortFromHal(const struct audio_port& halPort, AudioPort* port);
-    static void audioPortToHal(const AudioPort& port, struct audio_port* halPort);
-
     virtual ~Device();
 
     // Methods from ParametersUtil.
diff --git a/audio/2.0/default/DevicesFactory.cpp b/audio/2.0/default/DevicesFactory.cpp
index 1e087f2..12ef2c8 100644
--- a/audio/2.0/default/DevicesFactory.cpp
+++ b/audio/2.0/default/DevicesFactory.cpp
@@ -18,7 +18,7 @@
 
 #include <string.h>
 
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "Device.h"
 #include "DevicesFactory.h"
diff --git a/audio/2.0/default/PrimaryDevice.cpp b/audio/2.0/default/PrimaryDevice.cpp
index a8aa5ec..905203b 100644
--- a/audio/2.0/default/PrimaryDevice.cpp
+++ b/audio/2.0/default/PrimaryDevice.cpp
@@ -83,6 +83,10 @@
     return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
 }
 
+Return<bool> PrimaryDevice::supportsAudioPatches() {
+    return mDevice->supportsAudioPatches();
+}
+
 Return<void> PrimaryDevice::createAudioPatch(
         const hidl_vec<AudioPortConfig>& sources,
         const hidl_vec<AudioPortConfig>& sinks,
diff --git a/audio/2.0/default/PrimaryDevice.h b/audio/2.0/default/PrimaryDevice.h
index 8177b68..d95511b 100644
--- a/audio/2.0/default/PrimaryDevice.h
+++ b/audio/2.0/default/PrimaryDevice.h
@@ -76,6 +76,7 @@
             AudioInputFlag flags,
             AudioSource source,
             openInputStream_cb _hidl_cb)  override;
+    Return<bool> supportsAudioPatches()  override;
     Return<void> createAudioPatch(
             const hidl_vec<AudioPortConfig>& sources,
             const hidl_vec<AudioPortConfig>& sinks,
diff --git a/audio/2.0/default/Stream.cpp b/audio/2.0/default/Stream.cpp
index 6d68f55..1b6d593 100644
--- a/audio/2.0/default/Stream.cpp
+++ b/audio/2.0/default/Stream.cpp
@@ -21,7 +21,7 @@
 #include <hardware/audio.h>
 #include <hardware/audio_effect.h>
 #include <media/TypeConverter.h>
-#include <utils/Log.h>
+#include <android/log.h>
 #include <utils/SortedVector.h>
 #include <utils/Vector.h>
 
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp
index 791e519..1bc9dfb 100644
--- a/audio/2.0/default/StreamIn.cpp
+++ b/audio/2.0/default/StreamIn.cpp
@@ -17,7 +17,7 @@
 #define LOG_TAG "StreamInHAL"
 
 #include <hardware/audio.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "StreamIn.h"
 
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index 2106256..546b264 100644
--- a/audio/2.0/default/StreamOut.cpp
+++ b/audio/2.0/default/StreamOut.cpp
@@ -17,7 +17,7 @@
 #define LOG_TAG "StreamOutHAL"
 
 #include <hardware/audio.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "StreamOut.h"
 
@@ -191,23 +191,27 @@
     return mStreamCommon->analyzeStatus("set_callback", result);
 }
 
+Return<Result> StreamOut::clearCallback()  {
+    if (mStream->set_callback == NULL) return Result::NOT_SUPPORTED;
+    mCallback.clear();
+    return Result::OK;
+}
+
 // static
 int StreamOut::asyncCallback(stream_callback_event_t event, void*, void *cookie) {
     wp<StreamOut> weakSelf(reinterpret_cast<StreamOut*>(cookie));
     sp<StreamOut> self = weakSelf.promote();
-    if (self == 0) return 0;
-    sp<IStreamOutCallback> callback = self->mCallback.promote();
-    if (callback == 0) return 0;
+    if (self == nullptr || self->mCallback == nullptr) return 0;
     ALOGV("asyncCallback() event %d", event);
     switch (event) {
         case STREAM_CBK_EVENT_WRITE_READY:
-            callback->onWriteReady();
+            self->mCallback->onWriteReady();
             break;
         case STREAM_CBK_EVENT_DRAIN_READY:
-            callback->onDrainReady();
+            self->mCallback->onDrainReady();
             break;
         case STREAM_CBK_EVENT_ERROR:
-            callback->onError();
+            self->mCallback->onError();
             break;
         default:
             ALOGW("asyncCallback() unknown event %d", event);
diff --git a/audio/2.0/default/StreamOut.h b/audio/2.0/default/StreamOut.h
index d51fc66..dc9a604 100644
--- a/audio/2.0/default/StreamOut.h
+++ b/audio/2.0/default/StreamOut.h
@@ -83,6 +83,7 @@
     Return<void> getRenderPosition(getRenderPosition_cb _hidl_cb)  override;
     Return<void> getNextWriteTimestamp(getNextWriteTimestamp_cb _hidl_cb)  override;
     Return<Result> setCallback(const sp<IStreamOutCallback>& callback)  override;
+    Return<Result> clearCallback()  override;
     Return<void> supportsPauseAndResume(supportsPauseAndResume_cb _hidl_cb)  override;
     Return<Result> pause()  override;
     Return<Result> resume()  override;
@@ -95,9 +96,7 @@
     audio_hw_device_t *mDevice;
     audio_stream_out_t *mStream;
     sp<Stream> mStreamCommon;
-    // Do not store sp<> to avoid creating a reference loop if the entity that holds
-    // onto the output stream owns or implements the callback.
-    wp<IStreamOutCallback> mCallback;
+    sp<IStreamOutCallback> mCallback;
 
     virtual ~StreamOut();
 
diff --git a/audio/common/2.0/default/Android.mk b/audio/common/2.0/default/Android.mk
index aa60eb2..8e2fed4 100644
--- a/audio/common/2.0/default/Android.mk
+++ b/audio/common/2.0/default/Android.mk
@@ -20,10 +20,13 @@
 LOCAL_MODULE := android.hardware.audio.common@2.0-util
 LOCAL_SRC_FILES := \
     EffectMap.cpp \
+    HidlUtils.cpp \
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
 
 LOCAL_SHARED_LIBRARIES := \
     libutils \
+    libhidlbase \
+    android.hardware.audio.common@2.0 \
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/audio/common/2.0/default/HidlUtils.cpp b/audio/common/2.0/default/HidlUtils.cpp
new file mode 100644
index 0000000..f25fc5c
--- /dev/null
+++ b/audio/common/2.0/default/HidlUtils.cpp
@@ -0,0 +1,328 @@
+/*
+ * 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 <string.h>
+
+#include "HidlUtils.h"
+
+using ::android::hardware::audio::common::V2_0::AudioChannelMask;
+using ::android::hardware::audio::common::V2_0::AudioDevice;
+using ::android::hardware::audio::common::V2_0::AudioFormat;
+using ::android::hardware::audio::common::V2_0::AudioGainMode;
+using ::android::hardware::audio::common::V2_0::AudioMixLatencyClass;
+using ::android::hardware::audio::common::V2_0::AudioPortConfigMask;
+using ::android::hardware::audio::common::V2_0::AudioPortRole;
+using ::android::hardware::audio::common::V2_0::AudioPortType;
+using ::android::hardware::audio::common::V2_0::AudioSource;
+using ::android::hardware::audio::common::V2_0::AudioStreamType;
+
+namespace android {
+
+void HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) {
+    config->sampleRateHz = halConfig.sample_rate;
+    config->channelMask = AudioChannelMask(halConfig.channel_mask);
+    config->format = AudioFormat(halConfig.format);
+    audioOffloadInfoFromHal(halConfig.offload_info, &config->offloadInfo);
+    config->frameCount = halConfig.frame_count;
+}
+
+void HidlUtils::audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig) {
+    memset(halConfig, 0, sizeof(audio_config_t));
+    halConfig->sample_rate = config.sampleRateHz;
+    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
+    halConfig->format = static_cast<audio_format_t>(config.format);
+    audioOffloadInfoToHal(config.offloadInfo, &halConfig->offload_info);
+    halConfig->frame_count = config.frameCount;
+}
+
+void HidlUtils::audioGainConfigFromHal(
+        const struct audio_gain_config& halConfig, AudioGainConfig* config) {
+    config->index = halConfig.index;
+    config->mode = AudioGainMode(halConfig.mode);
+    config->channelMask = AudioChannelMask(halConfig.channel_mask);
+    for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
+        config->values[i] = halConfig.values[i];
+    }
+    config->rampDurationMs = halConfig.ramp_duration_ms;
+}
+
+void HidlUtils::audioGainConfigToHal(
+        const AudioGainConfig& config, struct audio_gain_config* halConfig) {
+    halConfig->index = config.index;
+    halConfig->mode = static_cast<audio_gain_mode_t>(config.mode);
+    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
+    memset(halConfig->values, 0, sizeof(halConfig->values));
+    for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
+        halConfig->values[i] = config.values[i];
+    }
+    halConfig->ramp_duration_ms = config.rampDurationMs;
+}
+
+void HidlUtils::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) {
+    gain->mode = AudioGainMode(halGain.mode);
+    gain->channelMask = AudioChannelMask(halGain.channel_mask);
+    gain->minValue = halGain.min_value;
+    gain->maxValue = halGain.max_value;
+    gain->defaultValue = halGain.default_value;
+    gain->stepValue = halGain.step_value;
+    gain->minRampMs = halGain.min_ramp_ms;
+    gain->maxRampMs = halGain.max_ramp_ms;
+}
+
+void HidlUtils::audioGainToHal(const AudioGain& gain, struct audio_gain* halGain) {
+    halGain->mode = static_cast<audio_gain_mode_t>(gain.mode);
+    halGain->channel_mask = static_cast<audio_channel_mask_t>(gain.channelMask);
+    halGain->min_value = gain.minValue;
+    halGain->max_value = gain.maxValue;
+    halGain->default_value = gain.defaultValue;
+    halGain->step_value = gain.stepValue;
+    halGain->min_ramp_ms = gain.minRampMs;
+    halGain->max_ramp_ms = gain.maxRampMs;
+}
+
+void HidlUtils::audioOffloadInfoFromHal(
+        const audio_offload_info_t& halOffload, AudioOffloadInfo* offload) {
+    offload->sampleRateHz = halOffload.sample_rate;
+    offload->channelMask = AudioChannelMask(halOffload.channel_mask);
+    offload->streamType = AudioStreamType(halOffload.stream_type);
+    offload->bitRatePerSecond = halOffload.bit_rate;
+    offload->durationMicroseconds = halOffload.duration_us;
+    offload->hasVideo = halOffload.has_video;
+    offload->isStreaming = halOffload.is_streaming;
+}
+
+void HidlUtils::audioOffloadInfoToHal(
+        const AudioOffloadInfo& offload, audio_offload_info_t* halOffload) {
+    *halOffload = AUDIO_INFO_INITIALIZER;
+    halOffload->sample_rate = offload.sampleRateHz;
+    halOffload->channel_mask = static_cast<audio_channel_mask_t>(offload.channelMask);
+    halOffload->stream_type = static_cast<audio_stream_type_t>(offload.streamType);
+    halOffload->bit_rate = offload.bitRatePerSecond;
+    halOffload->duration_us = offload.durationMicroseconds;
+    halOffload->has_video = offload.hasVideo;
+    halOffload->is_streaming = offload.isStreaming;
+}
+
+void HidlUtils::audioPortConfigFromHal(
+        const struct audio_port_config& halConfig, AudioPortConfig* config) {
+    config->id = halConfig.id;
+    config->role = AudioPortRole(halConfig.role);
+    config->type = AudioPortType(halConfig.type);
+    config->configMask = AudioPortConfigMask(halConfig.config_mask);
+    config->sampleRateHz = halConfig.sample_rate;
+    config->channelMask = AudioChannelMask(halConfig.channel_mask);
+    config->format = AudioFormat(halConfig.format);
+    audioGainConfigFromHal(halConfig.gain, &config->gain);
+    switch (halConfig.type) {
+        case AUDIO_PORT_TYPE_NONE: break;
+        case AUDIO_PORT_TYPE_DEVICE: {
+            config->ext.device.hwModule = halConfig.ext.device.hw_module;
+            config->ext.device.type = AudioDevice(halConfig.ext.device.type);
+            memcpy(config->ext.device.address.data(),
+                    halConfig.ext.device.address,
+                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
+            break;
+        }
+        case AUDIO_PORT_TYPE_MIX: {
+            config->ext.mix.hwModule = halConfig.ext.mix.hw_module;
+            config->ext.mix.ioHandle = halConfig.ext.mix.handle;
+            if (halConfig.role == AUDIO_PORT_ROLE_SOURCE) {
+                config->ext.mix.useCase.source = AudioSource(halConfig.ext.mix.usecase.source);
+            } else if (halConfig.role == AUDIO_PORT_ROLE_SINK) {
+                config->ext.mix.useCase.stream = AudioStreamType(halConfig.ext.mix.usecase.stream);
+            }
+            break;
+        }
+        case AUDIO_PORT_TYPE_SESSION: {
+            config->ext.session.session = halConfig.ext.session.session;
+            break;
+        }
+    }
+}
+
+void HidlUtils::audioPortConfigToHal(
+        const AudioPortConfig& config, struct audio_port_config* halConfig) {
+    memset(halConfig, 0, sizeof(audio_port_config));
+    halConfig->id = config.id;
+    halConfig->role = static_cast<audio_port_role_t>(config.role);
+    halConfig->type = static_cast<audio_port_type_t>(config.type);
+    halConfig->config_mask = static_cast<unsigned int>(config.configMask);
+    halConfig->sample_rate = config.sampleRateHz;
+    halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
+    halConfig->format = static_cast<audio_format_t>(config.format);
+    audioGainConfigToHal(config.gain, &halConfig->gain);
+    switch (config.type) {
+        case AudioPortType::NONE: break;
+        case AudioPortType::DEVICE: {
+            halConfig->ext.device.hw_module = config.ext.device.hwModule;
+            halConfig->ext.device.type = static_cast<audio_devices_t>(config.ext.device.type);
+            memcpy(halConfig->ext.device.address,
+                    config.ext.device.address.data(),
+                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
+            break;
+        }
+        case AudioPortType::MIX: {
+            halConfig->ext.mix.hw_module = config.ext.mix.hwModule;
+            halConfig->ext.mix.handle = config.ext.mix.ioHandle;
+            if (config.role == AudioPortRole::SOURCE) {
+                halConfig->ext.mix.usecase.source =
+                        static_cast<audio_source_t>(config.ext.mix.useCase.source);
+            } else if (config.role == AudioPortRole::SINK) {
+                halConfig->ext.mix.usecase.stream =
+                        static_cast<audio_stream_type_t>(config.ext.mix.useCase.stream);
+            }
+            break;
+        }
+        case AudioPortType::SESSION: {
+            halConfig->ext.session.session =
+                    static_cast<audio_session_t>(config.ext.session.session);
+            break;
+        }
+    }
+}
+
+void HidlUtils::audioPortConfigsFromHal(
+        unsigned int numHalConfigs, const struct audio_port_config *halConfigs,
+        hidl_vec<AudioPortConfig> *configs) {
+    configs->resize(numHalConfigs);
+    for (unsigned int i = 0; i < numHalConfigs; ++i) {
+        audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
+    }
+}
+
+std::unique_ptr<audio_port_config[]> HidlUtils::audioPortConfigsToHal(
+        const hidl_vec<AudioPortConfig>& configs) {
+    std::unique_ptr<audio_port_config[]> halConfigs(new audio_port_config[configs.size()]);
+    for (size_t i = 0; i < configs.size(); ++i) {
+        audioPortConfigToHal(configs[i], &halConfigs[i]);
+    }
+    return halConfigs;
+}
+
+void HidlUtils::audioPortFromHal(const struct audio_port& halPort, AudioPort* port) {
+    port->id = halPort.id;
+    port->role = AudioPortRole(halPort.role);
+    port->type = AudioPortType(halPort.type);
+    port->name.setToExternal(halPort.name, strlen(halPort.name));
+    port->sampleRates.resize(halPort.num_sample_rates);
+    for (size_t i = 0; i < halPort.num_sample_rates; ++i) {
+        port->sampleRates[i] = halPort.sample_rates[i];
+    }
+    port->channelMasks.resize(halPort.num_channel_masks);
+    for (size_t i = 0; i < halPort.num_channel_masks; ++i) {
+        port->channelMasks[i] = AudioChannelMask(halPort.channel_masks[i]);
+    }
+    port->formats.resize(halPort.num_formats);
+    for (size_t i = 0; i < halPort.num_formats; ++i) {
+        port->formats[i] = AudioFormat(halPort.formats[i]);
+    }
+    port->gains.resize(halPort.num_gains);
+    for (size_t i = 0; i < halPort.num_gains; ++i) {
+        audioGainFromHal(halPort.gains[i], &port->gains[i]);
+    }
+    audioPortConfigFromHal(halPort.active_config, &port->activeConfig);
+    switch (halPort.type) {
+        case AUDIO_PORT_TYPE_NONE: break;
+        case AUDIO_PORT_TYPE_DEVICE: {
+            port->ext.device.hwModule = halPort.ext.device.hw_module;
+            port->ext.device.type = AudioDevice(halPort.ext.device.type);
+            memcpy(port->ext.device.address.data(),
+                    halPort.ext.device.address,
+                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
+            break;
+        }
+        case AUDIO_PORT_TYPE_MIX: {
+            port->ext.mix.hwModule = halPort.ext.mix.hw_module;
+            port->ext.mix.ioHandle = halPort.ext.mix.handle;
+            port->ext.mix.latencyClass = AudioMixLatencyClass(halPort.ext.mix.latency_class);
+            break;
+        }
+        case AUDIO_PORT_TYPE_SESSION: {
+            port->ext.session.session = halPort.ext.session.session;
+            break;
+        }
+    }
+}
+
+void HidlUtils::audioPortToHal(const AudioPort& port, struct audio_port* halPort) {
+    memset(halPort, 0, sizeof(audio_port));
+    halPort->id = port.id;
+    halPort->role = static_cast<audio_port_role_t>(port.role);
+    halPort->type = static_cast<audio_port_type_t>(port.type);
+    memcpy(halPort->name,
+            port.name.c_str(),
+            std::min(port.name.size(), static_cast<size_t>(AUDIO_PORT_MAX_NAME_LEN)));
+    halPort->num_sample_rates =
+            std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES));
+    for (size_t i = 0; i < halPort->num_sample_rates; ++i) {
+        halPort->sample_rates[i] = port.sampleRates[i];
+    }
+    halPort->num_channel_masks =
+            std::min(port.channelMasks.size(), static_cast<size_t>(AUDIO_PORT_MAX_CHANNEL_MASKS));
+    for (size_t i = 0; i < halPort->num_channel_masks; ++i) {
+        halPort->channel_masks[i] = static_cast<audio_channel_mask_t>(port.channelMasks[i]);
+    }
+    halPort->num_formats =
+            std::min(port.formats.size(), static_cast<size_t>(AUDIO_PORT_MAX_FORMATS));
+    for (size_t i = 0; i < halPort->num_formats; ++i) {
+        halPort->formats[i] = static_cast<audio_format_t>(port.formats[i]);
+    }
+    halPort->num_gains = std::min(port.gains.size(), static_cast<size_t>(AUDIO_PORT_MAX_GAINS));
+    for (size_t i = 0; i < halPort->num_gains; ++i) {
+        audioGainToHal(port.gains[i], &halPort->gains[i]);
+    }
+    audioPortConfigToHal(port.activeConfig, &halPort->active_config);
+    switch (port.type) {
+        case AudioPortType::NONE: break;
+        case AudioPortType::DEVICE: {
+            halPort->ext.device.hw_module = port.ext.device.hwModule;
+            halPort->ext.device.type = static_cast<audio_devices_t>(port.ext.device.type);
+            memcpy(halPort->ext.device.address,
+                    port.ext.device.address.data(),
+                    AUDIO_DEVICE_MAX_ADDRESS_LEN);
+            break;
+        }
+        case AudioPortType::MIX: {
+            halPort->ext.mix.hw_module = port.ext.mix.hwModule;
+            halPort->ext.mix.handle = port.ext.mix.ioHandle;
+            halPort->ext.mix.latency_class =
+                    static_cast<audio_mix_latency_class_t>(port.ext.mix.latencyClass);
+            break;
+        }
+        case AudioPortType::SESSION: {
+            halPort->ext.session.session = static_cast<audio_session_t>(port.ext.session.session);
+            break;
+        }
+    }
+}
+
+void HidlUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) {
+    uuid->timeLow = halUuid.timeLow;
+    uuid->timeMid = halUuid.timeMid;
+    uuid->versionAndTimeHigh = halUuid.timeHiAndVersion;
+    uuid->variantAndClockSeqHigh = halUuid.clockSeq;
+    memcpy(uuid->node.data(), halUuid.node, uuid->node.size());
+}
+
+void HidlUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) {
+    halUuid->timeLow = uuid.timeLow;
+    halUuid->timeMid = uuid.timeMid;
+    halUuid->timeHiAndVersion = uuid.versionAndTimeHigh;
+    halUuid->clockSeq = uuid.variantAndClockSeqHigh;
+    memcpy(halUuid->node, uuid.node.data(), uuid.node.size());
+}
+
+}  // namespace android
diff --git a/audio/common/2.0/default/HidlUtils.h b/audio/common/2.0/default/HidlUtils.h
new file mode 100644
index 0000000..3fde4d7
--- /dev/null
+++ b/audio/common/2.0/default/HidlUtils.h
@@ -0,0 +1,67 @@
+/*
+ * 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 android_hardware_audio_V2_0_Hidl_Utils_H_
+#define android_hardware_audio_V2_0_Hidl_Utils_H_
+
+#include <memory>
+
+#include <android/hardware/audio/common/2.0/types.h>
+#include <system/audio.h>
+
+using ::android::hardware::audio::common::V2_0::AudioConfig;
+using ::android::hardware::audio::common::V2_0::AudioGain;
+using ::android::hardware::audio::common::V2_0::AudioGainConfig;
+using ::android::hardware::audio::common::V2_0::AudioOffloadInfo;
+using ::android::hardware::audio::common::V2_0::AudioPort;
+using ::android::hardware::audio::common::V2_0::AudioPortConfig;
+using ::android::hardware::audio::common::V2_0::Uuid;
+using ::android::hardware::hidl_vec;
+
+namespace android {
+
+class HidlUtils {
+  public:
+    static void audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config);
+    static void audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig);
+    static void audioGainConfigFromHal(
+            const struct audio_gain_config& halConfig, AudioGainConfig* config);
+    static void audioGainConfigToHal(
+            const AudioGainConfig& config, struct audio_gain_config* halConfig);
+    static void audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain);
+    static void audioGainToHal(const AudioGain& gain, struct audio_gain* halGain);
+    static void audioOffloadInfoFromHal(
+            const audio_offload_info_t& halOffload, AudioOffloadInfo* offload);
+    static void audioOffloadInfoToHal(
+            const AudioOffloadInfo& offload, audio_offload_info_t* halOffload);
+    static void audioPortConfigFromHal(
+            const struct audio_port_config& halConfig, AudioPortConfig* config);
+    static void audioPortConfigToHal(
+            const AudioPortConfig& config, struct audio_port_config* halConfig);
+    static void audioPortConfigsFromHal(
+            unsigned int numHalConfigs, const struct audio_port_config *halConfigs,
+            hidl_vec<AudioPortConfig> *configs);
+    static std::unique_ptr<audio_port_config[]> audioPortConfigsToHal(
+            const hidl_vec<AudioPortConfig>& configs);
+    static void audioPortFromHal(const struct audio_port& halPort, AudioPort* port);
+    static void audioPortToHal(const AudioPort& port, struct audio_port* halPort);
+    static void uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid);
+    static void uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid);
+};
+
+}  // namespace android
+
+#endif  // android_hardware_audio_V2_0_Hidl_Utils_H_
diff --git a/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp b/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp
index c2f50f9..341466f 100644
--- a/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp
+++ b/audio/effect/2.0/default/AcousticEchoCancelerEffect.cpp
@@ -16,7 +16,7 @@
 
 #define LOG_TAG "AEC_Effect_HAL"
 #include <system/audio_effects/effect_aec.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "AcousticEchoCancelerEffect.h"
 
diff --git a/audio/effect/2.0/default/AutomaticGainControlEffect.cpp b/audio/effect/2.0/default/AutomaticGainControlEffect.cpp
index 34cbe97..6ebfb3c 100644
--- a/audio/effect/2.0/default/AutomaticGainControlEffect.cpp
+++ b/audio/effect/2.0/default/AutomaticGainControlEffect.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "AGC_Effect_HAL"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "AutomaticGainControlEffect.h"
 
diff --git a/audio/effect/2.0/default/BassBoostEffect.cpp b/audio/effect/2.0/default/BassBoostEffect.cpp
index 1b12f76..8a64806 100644
--- a/audio/effect/2.0/default/BassBoostEffect.cpp
+++ b/audio/effect/2.0/default/BassBoostEffect.cpp
@@ -16,7 +16,7 @@
 
 #define LOG_TAG "BassBoost_HAL"
 #include <system/audio_effects/effect_bassboost.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "BassBoostEffect.h"
 
diff --git a/audio/effect/2.0/default/Conversions.cpp b/audio/effect/2.0/default/Conversions.cpp
index ef2374c..e7d4c46 100644
--- a/audio/effect/2.0/default/Conversions.cpp
+++ b/audio/effect/2.0/default/Conversions.cpp
@@ -18,6 +18,7 @@
 #include <stdio.h>
 
 #include "Conversions.h"
+#include "HidlUtils.h"
 
 namespace android {
 namespace hardware {
@@ -28,8 +29,8 @@
 
 void effectDescriptorFromHal(
         const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor) {
-    uuidFromHal(halDescriptor.type, &descriptor->type);
-    uuidFromHal(halDescriptor.uuid, &descriptor->uuid);
+    HidlUtils::uuidFromHal(halDescriptor.type, &descriptor->type);
+    HidlUtils::uuidFromHal(halDescriptor.uuid, &descriptor->uuid);
     descriptor->flags = EffectFlags(halDescriptor.flags);
     descriptor->cpuLoad = halDescriptor.cpuLoad;
     descriptor->memoryUsage = halDescriptor.memoryUsage;
@@ -38,22 +39,6 @@
             halDescriptor.implementor, descriptor->implementor.size());
 }
 
-void uuidFromHal(const effect_uuid_t& halUuid, Uuid* uuid) {
-    uuid->timeLow = halUuid.timeLow;
-    uuid->timeMid = halUuid.timeMid;
-    uuid->versionAndTimeHigh = halUuid.timeHiAndVersion;
-    uuid->variantAndClockSeqHigh = halUuid.clockSeq;
-    memcpy(uuid->node.data(), halUuid.node, uuid->node.size());
-}
-
-void uuidToHal(const Uuid& uuid, effect_uuid_t* halUuid) {
-    halUuid->timeLow = uuid.timeLow;
-    halUuid->timeMid = uuid.timeMid;
-    halUuid->timeHiAndVersion = uuid.versionAndTimeHigh;
-    halUuid->clockSeq = uuid.variantAndClockSeqHigh;
-    memcpy(halUuid->node, uuid.node.data(), uuid.node.size());
-}
-
 std::string uuidToString(const effect_uuid_t& halUuid) {
     char str[64];
     snprintf(str, sizeof(str), "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
diff --git a/audio/effect/2.0/default/Conversions.h b/audio/effect/2.0/default/Conversions.h
index 5348ae6..7cef362 100644
--- a/audio/effect/2.0/default/Conversions.h
+++ b/audio/effect/2.0/default/Conversions.h
@@ -29,13 +29,10 @@
 namespace V2_0 {
 namespace implementation {
 
-using ::android::hardware::audio::common::V2_0::Uuid;
 using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
 
 void effectDescriptorFromHal(
         const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor);
-void uuidFromHal(const effect_uuid_t& halUuid, Uuid* uuid);
-void uuidToHal(const Uuid& uuid, effect_uuid_t* halUuid);
 std::string uuidToString(const effect_uuid_t& halUuid);
 
 } // namespace implementation
diff --git a/audio/effect/2.0/default/DownmixEffect.cpp b/audio/effect/2.0/default/DownmixEffect.cpp
index 4c0a0bf..40bb5ec 100644
--- a/audio/effect/2.0/default/DownmixEffect.cpp
+++ b/audio/effect/2.0/default/DownmixEffect.cpp
@@ -16,7 +16,7 @@
 
 #define LOG_TAG "Downmix_HAL"
 #include <system/audio_effects/effect_downmix.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "DownmixEffect.h"
 
diff --git a/audio/effect/2.0/default/Effect.cpp b/audio/effect/2.0/default/Effect.cpp
index 82d0292..1a7ea9c 100644
--- a/audio/effect/2.0/default/Effect.cpp
+++ b/audio/effect/2.0/default/Effect.cpp
@@ -14,12 +14,11 @@
  * limitations under the License.
  */
 
-#include <memory>
 #include <memory.h>
 
 #define LOG_TAG "EffectHAL"
 #include <media/EffectsFactoryApi.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "Conversions.h"
 #include "Effect.h"
@@ -56,10 +55,15 @@
 }
 
 // static
-template<typename T> void Effect::hidlVecToHal(
-        const hidl_vec<T>& vec, uint32_t* halDataSize, void** halData) {
-    *halDataSize = static_cast<T>(vec.size() * sizeof(T));
-    *halData = static_cast<void*>(const_cast<T*>(&vec[0]));
+template<typename T> std::unique_ptr<uint8_t[]> Effect::hidlVecToHal(
+        const hidl_vec<T>& vec, uint32_t* halDataSize) {
+    // Due to bugs in HAL, they may attempt to write into the provided
+    // input buffer. The original binder buffer is r/o, thus it is needed
+    // to create a r/w version.
+    *halDataSize = vec.size() * sizeof(T);
+    std::unique_ptr<uint8_t[]> halData(new uint8_t[*halDataSize]);
+    memcpy(&halData[0], &vec[0], *halDataSize);
+    return halData;
 }
 
 // static
@@ -393,12 +397,13 @@
 Return<void> Effect::setAndGetVolume(
         const hidl_vec<uint32_t>& volumes, setAndGetVolume_cb _hidl_cb)  {
     uint32_t halDataSize;
-    void *halData;
-    hidlVecToHal(volumes, &halDataSize, &halData);
+    std::unique_ptr<uint8_t[]> halData = hidlVecToHal(volumes, &halDataSize);
     uint32_t halResultSize = halDataSize;
     uint32_t halResult[volumes.size()];
     Result retval = sendCommandReturningData(
-            EFFECT_CMD_SET_VOLUME, "SET_VOLUME", halDataSize, halData, &halResultSize, halResult);
+            EFFECT_CMD_SET_VOLUME, "SET_VOLUME",
+            halDataSize, &halData[0],
+            &halResultSize, halResult);
     hidl_vec<uint32_t> result;
     if (retval == Result::OK) {
         result.setToExternal(&halResult[0], halResultSize);
@@ -528,13 +533,12 @@
         uint32_t resultMaxSize,
         command_cb _hidl_cb)  {
     uint32_t halDataSize;
-    void *halData;
-    hidlVecToHal(data, &halDataSize, &halData);
+    std::unique_ptr<uint8_t[]> halData = hidlVecToHal(data, &halDataSize);
     uint32_t halResultSize = resultMaxSize;
     std::unique_ptr<uint8_t[]> halResult(new uint8_t[halResultSize]);
     memset(&halResult[0], 0, halResultSize);
     status_t status = (*mHandle)->command(
-            mHandle, commandId, halDataSize, halData, &halResultSize, &halResult[0]);
+            mHandle, commandId, halDataSize, &halData[0], &halResultSize, &halResult[0]);
     hidl_vec<uint8_t> result;
     if (status == OK) {
         result.setToExternal(&halResult[0], halResultSize);
diff --git a/audio/effect/2.0/default/Effect.h b/audio/effect/2.0/default/Effect.h
index 82eb1f2..61d0121 100644
--- a/audio/effect/2.0/default/Effect.h
+++ b/audio/effect/2.0/default/Effect.h
@@ -17,6 +17,7 @@
 #ifndef ANDROID_HARDWARE_AUDIO_EFFECT_V2_0_EFFECT_H
 #define ANDROID_HARDWARE_AUDIO_EFFECT_V2_0_EFFECT_H
 
+#include <memory>
 #include <vector>
 
 #include <android/hardware/audio/effect/2.0/IEffect.h>
@@ -180,8 +181,8 @@
     virtual ~Effect();
 
     template<typename T> static size_t alignedSizeIn(size_t s);
-    template<typename T> static void hidlVecToHal(
-            const hidl_vec<T>& vec, uint32_t* halDataSize, void** halData);
+    template<typename T> std::unique_ptr<uint8_t[]> hidlVecToHal(
+            const hidl_vec<T>& vec, uint32_t* halDataSize);
     static void effectAuxChannelsConfigFromHal(
             const channel_config_t& halConfig, EffectAuxChannelsConfig* config);
     static void effectAuxChannelsConfigToHal(
diff --git a/audio/effect/2.0/default/EffectsFactory.cpp b/audio/effect/2.0/default/EffectsFactory.cpp
index 2b5d70b..572a428 100644
--- a/audio/effect/2.0/default/EffectsFactory.cpp
+++ b/audio/effect/2.0/default/EffectsFactory.cpp
@@ -27,14 +27,15 @@
 #include <system/audio_effects/effect_presetreverb.h>
 #include <system/audio_effects/effect_virtualizer.h>
 #include <system/audio_effects/effect_visualizer.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "AcousticEchoCancelerEffect.h"
 #include "AutomaticGainControlEffect.h"
 #include "BassBoostEffect.h"
 #include "Conversions.h"
-#include "EffectsFactory.h"
 #include "DownmixEffect.h"
+#include "EffectsFactory.h"
+#include "HidlUtils.h"
 #include "Effect.h"
 #include "EffectMap.h"
 #include "EnvironmentalReverbEffect.h"
@@ -131,7 +132,7 @@
 
 Return<void> EffectsFactory::getDescriptor(const Uuid& uid, getDescriptor_cb _hidl_cb)  {
     effect_uuid_t halUuid;
-    uuidToHal(uid, &halUuid);
+    HidlUtils::uuidToHal(uid, &halUuid);
     effect_descriptor_t halDescriptor;
     status_t status = EffectGetDescriptor(&halUuid, &halDescriptor);
     EffectDescriptor descriptor;
@@ -153,7 +154,7 @@
 Return<void> EffectsFactory::createEffect(
         const Uuid& uid, int32_t session, int32_t ioHandle, createEffect_cb _hidl_cb)  {
     effect_uuid_t halUuid;
-    uuidToHal(uid, &halUuid);
+    HidlUtils::uuidToHal(uid, &halUuid);
     effect_handle_t handle;
     Result retval(Result::OK);
     status_t status = EffectCreate(&halUuid, session, ioHandle, &handle);
diff --git a/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp b/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp
index 4485be4..db1ad51 100644
--- a/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp
+++ b/audio/effect/2.0/default/EnvironmentalReverbEffect.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "EnvReverb_HAL"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "EnvironmentalReverbEffect.h"
 
diff --git a/audio/effect/2.0/default/EqualizerEffect.cpp b/audio/effect/2.0/default/EqualizerEffect.cpp
index 9e20b8a..490a300 100644
--- a/audio/effect/2.0/default/EqualizerEffect.cpp
+++ b/audio/effect/2.0/default/EqualizerEffect.cpp
@@ -17,7 +17,7 @@
 #include <memory.h>
 
 #define LOG_TAG "Equalizer_HAL"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "EqualizerEffect.h"
 
diff --git a/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp b/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp
index 1e724e0..a49019c 100644
--- a/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp
+++ b/audio/effect/2.0/default/LoudnessEnhancerEffect.cpp
@@ -18,7 +18,7 @@
 
 #define LOG_TAG "LoudnessEnhancer_HAL"
 #include <system/audio_effects/effect_aec.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "LoudnessEnhancerEffect.h"
 
diff --git a/audio/effect/2.0/default/NoiseSuppressionEffect.cpp b/audio/effect/2.0/default/NoiseSuppressionEffect.cpp
index 5c392df..69a1226 100644
--- a/audio/effect/2.0/default/NoiseSuppressionEffect.cpp
+++ b/audio/effect/2.0/default/NoiseSuppressionEffect.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "NS_Effect_HAL"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "NoiseSuppressionEffect.h"
 
diff --git a/audio/effect/2.0/default/PresetReverbEffect.cpp b/audio/effect/2.0/default/PresetReverbEffect.cpp
index 988bc51..0e6d1b8 100644
--- a/audio/effect/2.0/default/PresetReverbEffect.cpp
+++ b/audio/effect/2.0/default/PresetReverbEffect.cpp
@@ -16,7 +16,7 @@
 
 #define LOG_TAG "PresetReverb_HAL"
 #include <system/audio_effects/effect_presetreverb.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "PresetReverbEffect.h"
 
diff --git a/audio/effect/2.0/default/VirtualizerEffect.cpp b/audio/effect/2.0/default/VirtualizerEffect.cpp
index af5252b..313674d 100644
--- a/audio/effect/2.0/default/VirtualizerEffect.cpp
+++ b/audio/effect/2.0/default/VirtualizerEffect.cpp
@@ -18,7 +18,7 @@
 
 #define LOG_TAG "Virtualizer_HAL"
 #include <system/audio_effects/effect_virtualizer.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "VirtualizerEffect.h"
 
diff --git a/audio/effect/2.0/default/VisualizerEffect.cpp b/audio/effect/2.0/default/VisualizerEffect.cpp
index a1f92a6..a53eabc 100644
--- a/audio/effect/2.0/default/VisualizerEffect.cpp
+++ b/audio/effect/2.0/default/VisualizerEffect.cpp
@@ -16,7 +16,7 @@
 
 #define LOG_TAG "Visualizer_HAL"
 #include <system/audio_effects/effect_visualizer.h>
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "VisualizerEffect.h"
 
diff --git a/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp b/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp
index c7878d5..ef70215 100644
--- a/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp
+++ b/audio/effect/2.0/vts/functional/audio_effect_hidl_hal_test.cpp
@@ -164,6 +164,6 @@
   ::testing::AddGlobalTestEnvironment(new AudioEffectHidlEnvironment);
   ::testing::InitGoogleTest(&argc, argv);
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
   return status;
 }
diff --git a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h
index de8727b..0a8a22c 100644
--- a/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h
+++ b/biometrics/fingerprint/2.1/default/BiometricsFingerprint.h
@@ -17,7 +17,7 @@
 #ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H
 #define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include <hidl/MQDescriptor.h>
 #include <android/hardware/biometrics/fingerprint/2.1/IBiometricsFingerprint.h>
 #include <hidl/Status.h>
diff --git a/boot/1.0/default/BootControl.cpp b/boot/1.0/default/BootControl.cpp
index 56d7b33..54c1928 100644
--- a/boot/1.0/default/BootControl.cpp
+++ b/boot/1.0/default/BootControl.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 #define LOG_TAG "android.hardware.boot@1.0-impl"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include <hardware/hardware.h>
 #include <hardware/boot_control.h>
diff --git a/broadcastradio/1.0/default/BroadcastRadio.cpp b/broadcastradio/1.0/default/BroadcastRadio.cpp
index b97b609..32331ce 100644
--- a/broadcastradio/1.0/default/BroadcastRadio.cpp
+++ b/broadcastradio/1.0/default/BroadcastRadio.cpp
@@ -16,7 +16,7 @@
 #define LOG_TAG "BroadcastRadio"
 //#define LOG_NDEBUG 0
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include <hardware/radio.h>
 
 #include "BroadcastRadio.h"
diff --git a/broadcastradio/1.0/default/Tuner.cpp b/broadcastradio/1.0/default/Tuner.cpp
index 0c1d8ab..27b298b 100644
--- a/broadcastradio/1.0/default/Tuner.cpp
+++ b/broadcastradio/1.0/default/Tuner.cpp
@@ -17,7 +17,7 @@
 #define LOG_TAG "Tuner"
 //#define LOG_NDEBUG 0
 
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "BroadcastRadio.h"
 #include "Tuner.h"
diff --git a/broadcastradio/1.0/default/Utils.cpp b/broadcastradio/1.0/default/Utils.cpp
index bdaae00..c2c2ff3 100644
--- a/broadcastradio/1.0/default/Utils.cpp
+++ b/broadcastradio/1.0/default/Utils.cpp
@@ -16,7 +16,7 @@
 #define LOG_TAG "BroadcastRadioHalUtils"
 //#define LOG_NDEBUG 0
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include <utils/misc.h>
 #include <system/radio_metadata.h>
 
diff --git a/example/extension/light/2.0/default/service.cpp b/example/extension/light/2.0/default/service.cpp
index ae00506..3eb7bdf 100644
--- a/example/extension/light/2.0/default/service.cpp
+++ b/example/extension/light/2.0/default/service.cpp
@@ -15,7 +15,7 @@
  */
 #define LOG_TAG "android.hardware.light@2.0-service"
 
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include "Light.h"
 
diff --git a/gatekeeper/1.0/default/Gatekeeper.cpp b/gatekeeper/1.0/default/Gatekeeper.cpp
index 35b8c02..36e044c 100644
--- a/gatekeeper/1.0/default/Gatekeeper.cpp
+++ b/gatekeeper/1.0/default/Gatekeeper.cpp
@@ -15,7 +15,7 @@
  */
 #define LOG_TAG "android.hardware.gatekeeper@1.0-service"
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include <dlfcn.h>
 
 #include "Gatekeeper.h"
diff --git a/gatekeeper/1.0/vts/Gatekeeper.vts b/gatekeeper/1.0/vts/Gatekeeper.vts
new file mode 100644
index 0000000..25dc32f
--- /dev/null
+++ b/gatekeeper/1.0/vts/Gatekeeper.vts
@@ -0,0 +1,93 @@
+component_class: HAL_HIDL
+component_type_version: 1.0
+component_name: "IGatekeeper"
+
+package: "android.hardware.gatekeeper"
+
+import: "android.hardware.gatekeeper@1.0::types"
+
+interface: {
+    api: {
+        name: "enroll"
+        return_type_hidl: {
+            type: TYPE_STRUCT
+            predefined_type: "::android::hardware::gatekeeper::V1_0::GatekeeperResponse"
+        }
+        arg: {
+            type: TYPE_SCALAR
+            scalar_type: "uint32_t"
+        }
+        arg: {
+            type: TYPE_VECTOR
+            vector_value: {
+                type: TYPE_SCALAR
+                scalar_type: "uint8_t"
+            }
+        }
+        arg: {
+            type: TYPE_VECTOR
+            vector_value: {
+                type: TYPE_SCALAR
+                scalar_type: "uint8_t"
+            }
+        }
+        arg: {
+            type: TYPE_VECTOR
+            vector_value: {
+                type: TYPE_SCALAR
+                scalar_type: "uint8_t"
+            }
+        }
+    }
+
+    api: {
+        name: "verify"
+        return_type_hidl: {
+            type: TYPE_STRUCT
+            predefined_type: "::android::hardware::gatekeeper::V1_0::GatekeeperResponse"
+        }
+        arg: {
+            type: TYPE_SCALAR
+            scalar_type: "uint32_t"
+        }
+        arg: {
+            type: TYPE_SCALAR
+            scalar_type: "uint64_t"
+        }
+        arg: {
+            type: TYPE_VECTOR
+            vector_value: {
+                type: TYPE_SCALAR
+                scalar_type: "uint8_t"
+            }
+        }
+        arg: {
+            type: TYPE_VECTOR
+            vector_value: {
+                type: TYPE_SCALAR
+                scalar_type: "uint8_t"
+            }
+        }
+    }
+
+    api: {
+        name: "deleteUser"
+        return_type_hidl: {
+            type: TYPE_STRUCT
+            predefined_type: "::android::hardware::gatekeeper::V1_0::GatekeeperResponse"
+        }
+        arg: {
+            type: TYPE_SCALAR
+            scalar_type: "uint32_t"
+        }
+    }
+
+    api: {
+        name: "deleteAllUsers"
+        return_type_hidl: {
+            type: TYPE_STRUCT
+            predefined_type: "::android::hardware::gatekeeper::V1_0::GatekeeperResponse"
+        }
+    }
+
+}
diff --git a/gatekeeper/1.0/vts/functional/Android.bp b/gatekeeper/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000..9c72b81
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/Android.bp
@@ -0,0 +1,37 @@
+//
+// 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.
+//
+
+cc_test {
+    name: "gatekeeper_hidl_hal_test",
+    gtest: true,
+    srcs: ["gatekeeper_hidl_hal_test.cpp"],
+    shared_libs: [
+        "libbase",
+        "liblog",
+        "libcutils",
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "libnativehelper",
+        "libutils",
+        "android.hardware.gatekeeper@1.0",
+    ],
+    static_libs: ["libgtest"],
+    cflags: [
+        "-O0",
+        "-g",
+    ],
+}
diff --git a/gatekeeper/1.0/vts/functional/gatekeeper_hidl_hal_test.cpp b/gatekeeper/1.0/vts/functional/gatekeeper_hidl_hal_test.cpp
new file mode 100644
index 0000000..e919b48
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/gatekeeper_hidl_hal_test.cpp
@@ -0,0 +1,408 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "gatekeeper_hidl_hal_test"
+
+#include <algorithm>
+#include <cmath>
+#include <string>
+#include <vector>
+
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <hardware/hw_auth_token.h>
+
+#include <android/log.h>
+#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
+#include <android/hardware/gatekeeper/1.0/types.h>
+
+#include <gtest/gtest.h>
+
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::gatekeeper::V1_0::IGatekeeper;
+using ::android::hardware::gatekeeper::V1_0::GatekeeperResponse;
+using ::android::hardware::gatekeeper::V1_0::GatekeeperStatusCode;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct GatekeeperRequest {
+  uint32_t uid;
+  uint64_t challenge;
+  hidl_vec<uint8_t> curPwdHandle;
+  hidl_vec<uint8_t> curPwd;
+  hidl_vec<uint8_t> newPwd;
+  GatekeeperRequest() : uid(0), challenge(0) {}
+};
+
+// ASSERT_* macros generate return "void" internally
+// we have to use EXPECT_* if we return anything but "void"
+static const hw_auth_token_t *toAuthToken(GatekeeperResponse &rsp) {
+  const hw_auth_token_t *auth_token =
+      reinterpret_cast<hw_auth_token_t *>(rsp.data.data());
+  const size_t auth_token_size = rsp.data.size();
+
+  EXPECT_NE(nullptr, auth_token);
+  EXPECT_EQ(sizeof(hw_auth_token_t), auth_token_size);
+
+  if (auth_token != nullptr && auth_token_size >= sizeof(*auth_token)) {
+    // these are in network order: translate to host
+    uint32_t auth_type = ntohl(auth_token->authenticator_type);
+    uint64_t auth_tstamp = ntohq(auth_token->timestamp);
+
+    EXPECT_EQ(HW_AUTH_PASSWORD, auth_type);
+    EXPECT_NE(UINT64_C(~0), auth_tstamp);
+    EXPECT_EQ(HW_AUTH_TOKEN_VERSION, auth_token->version);
+    //        EXPECT_NE(UINT64_C(0), auth_token->authenticator_id);
+    ALOGI("Authenticator ID: %016" PRIX64, auth_token->authenticator_id);
+    EXPECT_NE(UINT32_C(0), auth_token->user_id);
+  }
+  return auth_token;
+}
+
+// The main test class for Gatekeeper HIDL HAL.
+class GatekeeperHidlTest : public ::testing::Test {
+ protected:
+  void setUid(uint32_t uid) { uid_ = uid; }
+
+  void doEnroll(GatekeeperRequest &req, GatekeeperResponse &rsp) {
+    while (true) {
+      auto ret = gatekeeper_->enroll(
+          uid_, req.curPwdHandle, req.curPwd, req.newPwd,
+          [&rsp](const GatekeeperResponse &cbRsp) { rsp = cbRsp; });
+      ASSERT_TRUE(ret.getStatus().isOk());
+      if (rsp.code != GatekeeperStatusCode::ERROR_RETRY_TIMEOUT) break;
+      ALOGI("%s: got retry code; retrying in 1 sec", __func__);
+      sleep(1);
+    }
+  }
+
+  void doVerify(GatekeeperRequest &req, GatekeeperResponse &rsp) {
+    while (true) {
+      auto ret = gatekeeper_->verify(
+          uid_, req.challenge, req.curPwdHandle, req.newPwd,
+          [&rsp](const GatekeeperResponse &cb_rsp) { rsp = cb_rsp; });
+      ASSERT_TRUE(ret.getStatus().isOk());
+      if (rsp.code != GatekeeperStatusCode::ERROR_RETRY_TIMEOUT) break;
+      ALOGI("%s: got retry code; retrying in 1 sec", __func__);
+      sleep(1);
+    }
+  }
+
+  void doDeleteUser(GatekeeperResponse &rsp) {
+    while (true) {
+      auto ret = gatekeeper_->deleteUser(
+          uid_, [&rsp](const GatekeeperResponse &cb_rsp) { rsp = cb_rsp; });
+      ASSERT_TRUE(ret.getStatus().isOk());
+      if (rsp.code != GatekeeperStatusCode::ERROR_RETRY_TIMEOUT) break;
+      ALOGI("%s: got retry code; retrying in 1 sec", __func__);
+      sleep(1);
+    }
+  }
+
+  void doDeleteAllUsers(GatekeeperResponse &rsp) {
+    while (true) {
+      auto ret = gatekeeper_->deleteAllUsers(
+          [&rsp](const GatekeeperResponse &cb_rsp) { rsp = cb_rsp; });
+      ASSERT_TRUE(ret.getStatus().isOk());
+      if (rsp.code != GatekeeperStatusCode::ERROR_RETRY_TIMEOUT) break;
+      ALOGI("%s: got retry code; retrying in 1 sec", __func__);
+      sleep(1);
+    }
+  }
+
+  void generatePassword(hidl_vec<uint8_t> &password, uint8_t seed) {
+    password.resize(16);
+    memset(password.data(), seed, password.size());
+  }
+
+  void checkEnroll(GatekeeperResponse &rsp, bool expectSuccess) {
+    if (expectSuccess) {
+      EXPECT_EQ(GatekeeperStatusCode::STATUS_OK, rsp.code);
+      EXPECT_NE(nullptr, rsp.data.data());
+      EXPECT_GT(rsp.data.size(), UINT32_C(0));
+    } else {
+      EXPECT_EQ(GatekeeperStatusCode::ERROR_GENERAL_FAILURE, rsp.code);
+      EXPECT_EQ(UINT32_C(0), rsp.data.size());
+    }
+  }
+
+  void checkVerify(GatekeeperResponse &rsp, uint64_t challenge,
+                   bool expectSuccess) {
+    if (expectSuccess) {
+      EXPECT_GE(rsp.code, GatekeeperStatusCode::STATUS_OK);
+      EXPECT_LE(rsp.code, GatekeeperStatusCode::STATUS_REENROLL);
+
+      const hw_auth_token_t *auth_token = toAuthToken(rsp);
+      ASSERT_NE(nullptr, auth_token);
+      EXPECT_EQ(challenge, auth_token->challenge);
+    } else {
+      EXPECT_EQ(GatekeeperStatusCode::ERROR_GENERAL_FAILURE, rsp.code);
+      EXPECT_EQ(UINT32_C(0), rsp.data.size());
+    }
+  }
+
+  void enrollNewPassword(hidl_vec<uint8_t> &password, GatekeeperResponse &rsp,
+                         bool expectSuccess) {
+    GatekeeperRequest req;
+    req.newPwd.setToExternal(password.data(), password.size());
+    doEnroll(req, rsp);
+    checkEnroll(rsp, expectSuccess);
+  }
+
+  void verifyPassword(hidl_vec<uint8_t> &password,
+                      hidl_vec<uint8_t> &passwordHandle, uint64_t challenge,
+                      GatekeeperResponse &verifyRsp, bool expectSuccess) {
+    GatekeeperRequest verifyReq;
+
+    // build verify request for the same password (we want it to succeed)
+    verifyReq.newPwd = password;
+    // use enrolled password handle we've got
+    verifyReq.curPwdHandle = passwordHandle;
+    verifyReq.challenge = challenge;
+    doVerify(verifyReq, verifyRsp);
+    checkVerify(verifyRsp, challenge, expectSuccess);
+  }
+
+ protected:
+  sp<IGatekeeper> gatekeeper_;
+  uint32_t uid_;
+
+ public:
+  GatekeeperHidlTest() : uid_(0) {}
+  virtual void SetUp() override {
+    GatekeeperResponse rsp;
+    gatekeeper_ = IGatekeeper::getService("gatekeeper", false);
+    ASSERT_NE(nullptr, gatekeeper_.get());
+    doDeleteAllUsers(rsp);
+  }
+
+  virtual void TearDown() override {
+    GatekeeperResponse rsp;
+    doDeleteAllUsers(rsp);
+  }
+};
+
+/**
+ * Ensure we can enroll new password
+ */
+TEST_F(GatekeeperHidlTest, EnrollSuccess) {
+  hidl_vec<uint8_t> password;
+  GatekeeperResponse rsp;
+  ALOGI("Testing Enroll (expected success)");
+  generatePassword(password, 0);
+  enrollNewPassword(password, rsp, true);
+  ALOGI("Testing Enroll done");
+}
+
+/**
+ * Ensure we can not enroll empty password
+ */
+TEST_F(GatekeeperHidlTest, EnrollNoPassword) {
+  hidl_vec<uint8_t> password;
+  GatekeeperResponse rsp;
+  ALOGI("Testing Enroll (expected failure)");
+  enrollNewPassword(password, rsp, false);
+  ALOGI("Testing Enroll done");
+}
+
+/**
+ * Ensure we can successfully verify previously enrolled password
+ */
+TEST_F(GatekeeperHidlTest, VerifySuccess) {
+  GatekeeperResponse enrollRsp;
+  GatekeeperResponse verifyRsp;
+  hidl_vec<uint8_t> password;
+
+  ALOGI("Testing Enroll+Verify (expected success)");
+  generatePassword(password, 0);
+  enrollNewPassword(password, enrollRsp, true);
+  verifyPassword(password, enrollRsp.data, 1, verifyRsp, true);
+  ALOGI("Testing Enroll+Verify done");
+}
+
+/**
+ * Ensure we can securely update password (keep the same
+ * secure user_id) if we prove we know old password
+ */
+TEST_F(GatekeeperHidlTest, TrustedReenroll) {
+  GatekeeperResponse enrollRsp;
+  GatekeeperRequest reenrollReq;
+  GatekeeperResponse reenrollRsp;
+  GatekeeperResponse verifyRsp;
+  GatekeeperResponse reenrollVerifyRsp;
+  hidl_vec<uint8_t> password;
+  hidl_vec<uint8_t> newPassword;
+
+  generatePassword(password, 0);
+
+  ALOGI("Testing Trusted Reenroll (expected success)");
+  enrollNewPassword(password, enrollRsp, true);
+  verifyPassword(password, enrollRsp.data, 0, verifyRsp, true);
+  ALOGI("Primary Enroll+Verify done");
+
+  generatePassword(newPassword, 1);
+  reenrollReq.newPwd.setToExternal(newPassword.data(), newPassword.size());
+  reenrollReq.curPwd.setToExternal(password.data(), password.size());
+  reenrollReq.curPwdHandle.setToExternal(enrollRsp.data.data(),
+                                         enrollRsp.data.size());
+
+  doEnroll(reenrollReq, reenrollRsp);
+  checkEnroll(reenrollRsp, true);
+  verifyPassword(newPassword, reenrollRsp.data, 0, reenrollVerifyRsp, true);
+  ALOGI("Trusted ReEnroll+Verify done");
+
+  const hw_auth_token_t *first = toAuthToken(verifyRsp);
+  const hw_auth_token_t *second = toAuthToken(reenrollVerifyRsp);
+  if (first != nullptr && second != nullptr) {
+    EXPECT_EQ(first->user_id, second->user_id);
+  }
+  ALOGI("Testing Trusted Reenroll done");
+}
+
+/**
+ * Ensure we can update password (and get new
+ * secure user_id) if we don't know old password
+ */
+TEST_F(GatekeeperHidlTest, UntrustedReenroll) {
+  GatekeeperResponse enrollRsp;
+  GatekeeperRequest reenrollReq;
+  GatekeeperResponse reenrollRsp;
+  GatekeeperResponse verifyRsp;
+  GatekeeperResponse reenrollVerifyRsp;
+  hidl_vec<uint8_t> password;
+  hidl_vec<uint8_t> newPassword;
+
+  ALOGI("Testing Untrusted Reenroll (expected success)");
+  generatePassword(password, 0);
+  enrollNewPassword(password, enrollRsp, true);
+  verifyPassword(password, enrollRsp.data, 0, verifyRsp, true);
+  ALOGI("Primary Enroll+Verify done");
+
+  generatePassword(newPassword, 1);
+  enrollNewPassword(newPassword, reenrollRsp, true);
+  verifyPassword(newPassword, reenrollRsp.data, 0, reenrollVerifyRsp, true);
+  ALOGI("Untrusted ReEnroll+Verify done");
+
+  const hw_auth_token_t *first = toAuthToken(verifyRsp);
+  const hw_auth_token_t *second = toAuthToken(reenrollVerifyRsp);
+  if (first != nullptr && second != nullptr) {
+    EXPECT_NE(first->user_id, second->user_id);
+  }
+  ALOGI("Testing Untrusted Reenroll done");
+}
+
+/**
+ * Ensure we dont get successful verify with invalid data
+ */
+TEST_F(GatekeeperHidlTest, VerifyNoData) {
+  hidl_vec<uint8_t> password;
+  hidl_vec<uint8_t> passwordHandle;
+  GatekeeperResponse verifyRsp;
+
+  ALOGI("Testing Verify (expected failure)");
+  verifyPassword(password, passwordHandle, 0, verifyRsp, false);
+  EXPECT_EQ(GatekeeperStatusCode::ERROR_GENERAL_FAILURE, verifyRsp.code);
+  ALOGI("Testing Verify done");
+}
+
+/**
+ * Ensure we can not verify password after we enrolled it and then deleted user
+ */
+TEST_F(GatekeeperHidlTest, DeleteUserTest) {
+  hidl_vec<uint8_t> password;
+  GatekeeperResponse enrollRsp;
+  GatekeeperResponse verifyRsp;
+  GatekeeperResponse delRsp;
+  ALOGI("Testing deleteUser (expected success)");
+  setUid(10001);
+  generatePassword(password, 0);
+  enrollNewPassword(password, enrollRsp, true);
+  verifyPassword(password, enrollRsp.data, 0, verifyRsp, true);
+  ALOGI("Enroll+Verify done");
+  doDeleteUser(delRsp);
+  EXPECT_EQ(UINT32_C(0), delRsp.data.size());
+  EXPECT_TRUE(delRsp.code == GatekeeperStatusCode::ERROR_NOT_IMPLEMENTED ||
+              delRsp.code == GatekeeperStatusCode::STATUS_OK);
+  ALOGI("DeleteUser done");
+  if (delRsp.code == GatekeeperStatusCode::STATUS_OK) {
+    verifyPassword(password, enrollRsp.data, 0, verifyRsp, false);
+    EXPECT_EQ(GatekeeperStatusCode::ERROR_GENERAL_FAILURE, verifyRsp.code);
+    ALOGI("Verify after Delete done (must fail)");
+  }
+  ALOGI("Testing deleteUser done: rsp=%" PRIi32, delRsp.code);
+}
+
+/**
+ * Ensure we can not verify passwords after we enrolled them and then deleted
+ * all users
+ */
+TEST_F(GatekeeperHidlTest, DeleteAllUsersTest) {
+  struct UserData {
+    uint32_t userId;
+    hidl_vec<uint8_t> password;
+    GatekeeperResponse enrollRsp;
+    GatekeeperResponse verifyRsp;
+    UserData(int id) { userId = id; }
+  } users[3]{10001, 10002, 10003};
+  GatekeeperResponse delAllRsp;
+  ALOGI("Testing deleteAllUsers (expected success)");
+
+  // enroll multiple users
+  for (size_t i = 0; i < sizeof(users) / sizeof(users[0]); ++i) {
+    setUid(users[i].userId);
+    generatePassword(users[i].password, (i % 255) + 1);
+    enrollNewPassword(users[i].password, users[i].enrollRsp, true);
+  }
+  ALOGI("Multiple users enrolled");
+
+  // verify multiple users
+  for (size_t i = 0; i < sizeof(users) / sizeof(users[0]); ++i) {
+    setUid(users[i].userId);
+    verifyPassword(users[i].password, users[i].enrollRsp.data, 0,
+                   users[i].verifyRsp, true);
+  }
+  ALOGI("Multiple users verified");
+
+  doDeleteAllUsers(delAllRsp);
+  EXPECT_EQ(UINT32_C(0), delAllRsp.data.size());
+  EXPECT_TRUE(delAllRsp.code == GatekeeperStatusCode::ERROR_NOT_IMPLEMENTED ||
+              delAllRsp.code == GatekeeperStatusCode::STATUS_OK);
+  ALOGI("All users deleted");
+
+  if (delAllRsp.code == GatekeeperStatusCode::STATUS_OK) {
+    // verify multiple users after they are deleted; all must fail
+    for (size_t i = 0; i < sizeof(users) / sizeof(users[0]); ++i) {
+      setUid(users[i].userId);
+      verifyPassword(users[i].password, users[i].enrollRsp.data, 0,
+                     users[i].verifyRsp, false);
+      EXPECT_EQ(GatekeeperStatusCode::ERROR_GENERAL_FAILURE,
+                users[i].verifyRsp.code);
+    }
+    ALOGI("Multiple users verified after delete (all must fail)");
+  }
+
+  ALOGI("Testing deleteAllUsers done: rsp=%" PRIi32, delAllRsp.code);
+}
+
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  int status = RUN_ALL_TESTS();
+  ALOGI("Test result = %d", status);
+  return status;
+}
diff --git a/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/__init__.py b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/__init__.py
diff --git a/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/__init__.py b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/__init__.py
diff --git a/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/Android.mk b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/Android.mk
new file mode 100644
index 0000000..59bfe17
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/Android.mk
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call all-subdir-makefiles)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := HalGatekeeperHidlTargetBasicTest
+VTS_CONFIG_SRC_DIR := testcases/hal/gatekeeper/hidl/target
+include test/vts/tools/build/Android.host_config.mk
diff --git a/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/AndroidTest.xml b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/AndroidTest.xml
new file mode 100644
index 0000000..9256823
--- /dev/null
+++ b/gatekeeper/1.0/vts/functional/vts/testcases/hal/gatekeeper/hidl/target/AndroidTest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<configuration description="Config for VTS Gatekeeper HIDL HAL's basic target-side test cases">
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
+        <option name="push-group" value="HidlHalTest.push" />
+    </target_preparer>
+    <target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer" />
+    <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
+        <option name="test-module-name" value="HalGatekeeperHidlTargetBasicTest" />
+        <option name="binary-test-sources" value="
+            _32bit::DATA/nativetest/gatekeeper_hidl_hal_test/gatekeeper_hidl_hal_test,
+            _64bit::DATA/nativetest64/gatekeeper_hidl_hal_test/gatekeeper_hidl_hal_test,
+            "/>
+        <option name="binary-test-type" value="gtest" />
+        <option name="test-timeout" value="1m" />
+    </test>
+</configuration>
diff --git a/gatekeeper/1.0/vts/types.vts b/gatekeeper/1.0/vts/types.vts
new file mode 100644
index 0000000..3de9a14
--- /dev/null
+++ b/gatekeeper/1.0/vts/types.vts
@@ -0,0 +1,59 @@
+component_class: HAL_HIDL
+component_type_version: 1.0
+component_name: "types"
+
+package: "android.hardware.gatekeeper"
+
+
+attribute: {
+    name: "::android::hardware::gatekeeper::V1_0::GatekeeperStatusCode"
+    type: TYPE_ENUM
+    enum_value: {
+        scalar_type: "int32_t"
+
+        enumerator: "STATUS_REENROLL"
+        scalar_value: {
+            int32_t: 1
+        }
+        enumerator: "STATUS_OK"
+        scalar_value: {
+            int32_t: 0
+        }
+        enumerator: "ERROR_GENERAL_FAILURE"
+        scalar_value: {
+            int32_t: -1
+        }
+        enumerator: "ERROR_RETRY_TIMEOUT"
+        scalar_value: {
+            int32_t: -2
+        }
+        enumerator: "ERROR_NOT_IMPLEMENTED"
+        scalar_value: {
+            int32_t: -3
+        }
+    }
+}
+
+attribute: {
+    name: "::android::hardware::gatekeeper::V1_0::GatekeeperResponse"
+    type: TYPE_STRUCT
+    struct_value: {
+        name: "code"
+        type: TYPE_ENUM
+        predefined_type: "::android::hardware::gatekeeper::V1_0::GatekeeperStatusCode"
+    }
+    struct_value: {
+        name: "timeout"
+        type: TYPE_SCALAR
+        scalar_type: "uint32_t"
+    }
+    struct_value: {
+        name: "data"
+        type: TYPE_VECTOR
+        vector_value: {
+            type: TYPE_SCALAR
+            scalar_type: "uint8_t"
+        }
+    }
+}
+
diff --git a/gatekeeper/Android.bp b/gatekeeper/Android.bp
index bbb3e4b..33f70eb 100644
--- a/gatekeeper/Android.bp
+++ b/gatekeeper/Android.bp
@@ -1,4 +1,5 @@
 // This is an autogenerated file, do not edit.
 subdirs = [
     "1.0",
+    "1.0/vts/functional",
 ]
diff --git a/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp b/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
index bd846c4..22131ee 100644
--- a/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
+++ b/graphics/allocator/2.0/vts/functional/graphics_allocator_hidl_hal_test.cpp
@@ -307,7 +307,7 @@
   ::testing::InitGoogleTest(&argc, argv);
 
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
 
   return status;
 }
diff --git a/light/2.0/default/Light.cpp b/light/2.0/default/Light.cpp
index eb1f559..f52c6af 100644
--- a/light/2.0/default/Light.cpp
+++ b/light/2.0/default/Light.cpp
@@ -13,6 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#define LOG_TAG "light"
+#include <android/log.h>
+
 #include "Light.h"
 
 namespace android {
diff --git a/light/2.0/vts/functional/Android.bp b/light/2.0/vts/functional/Android.bp
index c3475a6..b290b59 100644
--- a/light/2.0/vts/functional/Android.bp
+++ b/light/2.0/vts/functional/Android.bp
@@ -19,6 +19,7 @@
     gtest: true,
     srcs: ["light_hidl_hal_test.cpp"],
     shared_libs: [
+        "libbase",
         "liblog",
         "libutils",
         "android.hardware.light@2.0",
diff --git a/light/2.0/vts/functional/light_hidl_hal_test.cpp b/light/2.0/vts/functional/light_hidl_hal_test.cpp
index db67467..7c081e9 100644
--- a/light/2.0/vts/functional/light_hidl_hal_test.cpp
+++ b/light/2.0/vts/functional/light_hidl_hal_test.cpp
@@ -44,7 +44,7 @@
         light = ILight::getService(LIGHT_SERVICE_NAME);
 
         ASSERT_NE(light, nullptr);
-        ALOGI("Test is remote: %d", light->isRemote());
+        LOG(INFO) << "Test is remote " << light->isRemote();
     }
 
     virtual void TearDown() override {}
@@ -98,6 +98,6 @@
     ::testing::AddGlobalTestEnvironment(new LightHidlEnvironment);
     ::testing::InitGoogleTest(&argc, argv);
     int status = RUN_ALL_TESTS();
-    ALOGI("Test result = %d", status);
+    LOG(INFO) << "Test result = " << status;
     return status;
 }
diff --git a/media/1.0/types.hal b/media/1.0/types.hal
index 25931f8..98dfe14 100644
--- a/media/1.0/types.hal
+++ b/media/1.0/types.hal
@@ -23,7 +23,6 @@
  */
 typedef handle FileDescriptor; // This must have no more than one fd.
 typedef FileDescriptor Fence;
-typedef int32_t Status; // TODO: convert to an enum
 typedef vec<uint8_t> Bytes;
 
 /**
diff --git a/media/omx/1.0/types.hal b/media/omx/1.0/types.hal
index 5918b59..79c3a44 100644
--- a/media/omx/1.0/types.hal
+++ b/media/omx/1.0/types.hal
@@ -22,6 +22,23 @@
 typedef uint32_t BufferId;
 
 /**
+ * Ref: system/core/include/utils/Errors.h
+ * Ref: bionic/libc/kernel/uapi/asm-generic/errno-base.h
+ * Ref: bionic/libc/kernel/uapi/asm-generic/errno.h
+ * Ref: frameworks/av/include/media/stagefright/MediaError.h
+ * Ref: frameworks/av/media/libstagefright/omx/OMXUtils.cpp: StatusFromOMXError
+ */
+enum Status : int32_t {
+    OK                      = 0,
+    NO_ERROR                = 0,
+
+    NAME_NOT_FOUND          = -2,
+    NO_MEMORY               = -12,
+    ERROR_UNSUPPORTED       = -1010,
+    UNKNOWN_ERROR           = -2147483648,
+};
+
+/**
  * Ref: frameworks/av/include/media/IOMX.h: omx_message
  *
  * Data structure for an OMX message. This is essentially a union of different
diff --git a/memtrack/1.0/default/Memtrack.cpp b/memtrack/1.0/default/Memtrack.cpp
index b953e7c..b93227f 100644
--- a/memtrack/1.0/default/Memtrack.cpp
+++ b/memtrack/1.0/default/Memtrack.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "android.hardware.memtrack@1.0-impl"
 #include <hardware/hardware.h>
 #include <hardware/memtrack.h>
+#include <android/log.h>
 
 #include "Memtrack.h"
 namespace android {
diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp
index bee374d..44c8e42 100644
--- a/nfc/1.0/default/Nfc.cpp
+++ b/nfc/1.0/default/Nfc.cpp
@@ -1,5 +1,5 @@
 #define LOG_TAG "android.hardware.nfc@1.0-impl"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include <hardware/hardware.h>
 #include <hardware/nfc.h>
diff --git a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
index 4d7c557..3e40a9c 100644
--- a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
+++ b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
@@ -356,7 +356,7 @@
   sleep(5);
 
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
 
   std::system("svc nfc enable"); /* Turn on NFC */
   sleep(5);
diff --git a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/passthrough/NfcHidlPassthroughBasicTest.config b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/passthrough/NfcHidlPassthroughBasicTest.config
index 3e957e3..9300c6f 100644
--- a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/passthrough/NfcHidlPassthroughBasicTest.config
+++ b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/host/passthrough/NfcHidlPassthroughBasicTest.config
@@ -1,6 +1,11 @@
 {
     "passthrough_mode": True,
-    "modules": ["system/lib64/hw/nfc_nci.bullhead"],
-    "git_project_path": "system/nfc",
-    "git_project_name": "platform/system/nfc"
+    "coverage": True,
+    "modules": [{
+                    "module_name": "system/lib64/hw/nfc_nci.bullhead",
+                    "git_project": {
+                        "name": "platform/system/nfc",
+                        "path": "system/nfc"
+                    }
+                }]
 }
diff --git a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/target/HalNfcHidlTargetBasicTest.config b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/target/HalNfcHidlTargetBasicTest.config
index 60623b1..2574bda 100644
--- a/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/target/HalNfcHidlTargetBasicTest.config
+++ b/nfc/1.0/vts/functional/vts/testcases/hal/nfc/hidl/target/HalNfcHidlTargetBasicTest.config
@@ -1,5 +1,10 @@
 {
-    "modules": ["system/lib64/hw/nfc_nci.bullhead"],
-    "git_project_path": "system/nfc",
-    "git_project_name": "platform/system/nfc"
+    "coverage": True,
+    "modules": [{
+                    "module_name": "system/lib64/hw/nfc_nci.bullhead",
+                    "git_project": {
+                        "name": "platform/system/nfc",
+                        "path": "system/nfc"
+                    }
+                }]
 }
diff --git a/power/1.0/default/Power.cpp b/power/1.0/default/Power.cpp
index 5d0593b..6453f33 100644
--- a/power/1.0/default/Power.cpp
+++ b/power/1.0/default/Power.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "android.hardware.power@1.0-impl"
 #include <hardware/hardware.h>
 #include <hardware/power.h>
+#include <android/log.h>
 #include "Power.h"
 
 namespace android {
diff --git a/power/1.0/vts/functional/power_hidl_hal_test.cpp b/power/1.0/vts/functional/power_hidl_hal_test.cpp
index ac56f1a..af6eb86 100644
--- a/power/1.0/vts/functional/power_hidl_hal_test.cpp
+++ b/power/1.0/vts/functional/power_hidl_hal_test.cpp
@@ -103,6 +103,6 @@
 int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
   return status;
 }
diff --git a/soundtrigger/2.0/default/SoundTriggerHalImpl.cpp b/soundtrigger/2.0/default/SoundTriggerHalImpl.cpp
index 1ae996a..73066e6 100644
--- a/soundtrigger/2.0/default/SoundTriggerHalImpl.cpp
+++ b/soundtrigger/2.0/default/SoundTriggerHalImpl.cpp
@@ -17,7 +17,7 @@
 #define LOG_TAG "SoundTriggerHalImpl"
 //#define LOG_NDEBUG 0
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include "SoundTriggerHalImpl.h"
 
 
diff --git a/soundtrigger/2.0/vts/functional/soundtrigger_hidl_hal_test.cpp b/soundtrigger/2.0/vts/functional/soundtrigger_hidl_hal_test.cpp
index cbd8128..e5bf086 100644
--- a/soundtrigger/2.0/vts/functional/soundtrigger_hidl_hal_test.cpp
+++ b/soundtrigger/2.0/vts/functional/soundtrigger_hidl_hal_test.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "SoundTriggerHidlHalTest"
-#include <android-base/logging.h>
+#include <android/log.h>
 #include <cutils/native_handle.h>
 
 #include <android/hardware/audio/common/2.0/types.h>
diff --git a/tests/foo/1.0/default/Foo.cpp b/tests/foo/1.0/default/Foo.cpp
index 5a51532..850d716 100644
--- a/tests/foo/1.0/default/Foo.cpp
+++ b/tests/foo/1.0/default/Foo.cpp
@@ -112,16 +112,7 @@
                   << DELAY_S
                   << " seconds";
         c[1] = systemTime();
-        Return<bool> ret = cb->heyItsYouIsntIt(cb);
-        if (!ret.isOk()) {
-            LOG(ERROR) << "SERVER(Foo) callMe "
-                      << cb.get()
-                      << " encountered transport error ("
-                      << ret.getStatus().exceptionCode()
-                      << ").";
-            return Void();
-        }
-        bool answer = ret.get();
+        bool answer = cb->heyItsYouIsntIt(cb);
         c[1] = systemTime() - c[1];
 
         LOG(INFO) << "SERVER(Foo) callMe "
diff --git a/thermal/1.0/default/Thermal.cpp b/thermal/1.0/default/Thermal.cpp
index 6c2111f..580b540 100644
--- a/thermal/1.0/default/Thermal.cpp
+++ b/thermal/1.0/default/Thermal.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "android.hardware.thermal@1.0-impl"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include <errno.h>
 #include <hardware/hardware.h>
diff --git a/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
index e3b00ab..8a5ea2c 100644
--- a/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
+++ b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
@@ -214,6 +214,6 @@
 int main(int argc, char** argv) {
   ::testing::InitGoogleTest(&argc, argv);
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
   return status;
 }
diff --git a/vehicle/2.0/default/VehicleService.cpp b/vehicle/2.0/default/VehicleService.cpp
index e21dcd9..651a2ad 100644
--- a/vehicle/2.0/default/VehicleService.cpp
+++ b/vehicle/2.0/default/VehicleService.cpp
@@ -15,7 +15,7 @@
  */
 
 #define LOG_TAG "android.hardware.vehicle@2.0-service"
-#include <utils/Log.h>
+#include <android/log.h>
 
 #include <iostream>
 
diff --git a/vehicle/2.0/default/impl/DefaultVehicleHal.cpp b/vehicle/2.0/default/impl/DefaultVehicleHal.cpp
index 5054cfe..4e27bdc 100644
--- a/vehicle/2.0/default/impl/DefaultVehicleHal.cpp
+++ b/vehicle/2.0/default/impl/DefaultVehicleHal.cpp
@@ -16,6 +16,9 @@
 
 #include "DefaultVehicleHal.h"
 
+#define LOG_TAG "default_vehicle"
+#include <android/log.h>
+
 namespace android {
 namespace hardware {
 namespace vehicle {
diff --git a/vehicle/2.0/default/vehicle_hal_manager/SubscriptionManager.h b/vehicle/2.0/default/vehicle_hal_manager/SubscriptionManager.h
index 903bde5..9f2ed8d 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/SubscriptionManager.h
+++ b/vehicle/2.0/default/vehicle_hal_manager/SubscriptionManager.h
@@ -22,7 +22,7 @@
 #include <set>
 #include <list>
 
-#include <utils/Log.h>
+#include <android/log.h>
 #include <hwbinder/IPCThreadState.h>
 
 #include <android/hardware/vehicle/2.0/IVehicle.h>
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleHalManager.cpp b/vehicle/2.0/default/vehicle_hal_manager/VehicleHalManager.cpp
index a84f991..1260f20 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleHalManager.cpp
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleHalManager.cpp
@@ -18,7 +18,7 @@
 #include <cmath>
 
 #include <utils/Errors.h>
-#include <utils/Log.h>
+#include <android/log.h>
 #include <hidl/Status.h>
 #include <future>
 #include <bitset>
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
index b4a4b3e..0029380 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
@@ -14,9 +14,12 @@
  * limitations under the License.
  */
 
+
 #ifndef android_hardware_vehicle_V2_0_VehicleObjectPool_H_
 #define android_hardware_vehicle_V2_0_VehicleObjectPool_H_
 
+#include "VehicleUtils.h" // defines LOG_TAG and includes <android/log.h>
+
 #include <iostream>
 #include <memory>
 #include <deque>
@@ -24,10 +27,12 @@
 #include <map>
 #include <mutex>
 
+#ifndef LOG_TAG
+#define LOG_TAG "android.hardware.vehicle@2.0-impl"
+#endif
+#include <android/log.h>
 #include <android/hardware/vehicle/2.0/types.h>
 
-#include "VehicleUtils.h"
-
 namespace android {
 namespace hardware {
 namespace vehicle {
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.h b/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.h
index 5751eb1..f06e97e 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.h
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.h
@@ -17,6 +17,11 @@
 #ifndef android_hardware_vehicle_V2_0_VehicleUtils_H_
 #define android_hardware_vehicle_V2_0_VehicleUtils_H_
 
+#ifndef LOG_TAG
+#define LOG_TAG "android.hardware.vehicle@2.0-impl"
+#endif
+#include <android/log.h>
+
 #include <memory>
 
 #include <hidl/HidlSupport.h>
diff --git a/vibrator/1.0/default/Vibrator.cpp b/vibrator/1.0/default/Vibrator.cpp
index 4cd3b30..ee3a458 100644
--- a/vibrator/1.0/default/Vibrator.cpp
+++ b/vibrator/1.0/default/Vibrator.cpp
@@ -15,9 +15,9 @@
  */
 
 #define LOG_TAG "VibratorService"
-
 #include <hardware/hardware.h>
 #include <hardware/vibrator.h>
+#include <android/log.h>
 #include "Vibrator.h"
 
 namespace android {
diff --git a/vibrator/1.0/vts/functional/Android.bp b/vibrator/1.0/vts/functional/Android.bp
index 22b7536..e893ec6 100644
--- a/vibrator/1.0/vts/functional/Android.bp
+++ b/vibrator/1.0/vts/functional/Android.bp
@@ -19,6 +19,7 @@
     gtest: true,
     srcs: ["vibrator_hidl_hal_test.cpp"],
     shared_libs: [
+        "libbase",
         "liblog",
         "libutils",
         "android.hardware.vibrator@1.0",
diff --git a/vibrator/1.0/vts/functional/vibrator_hidl_hal_test.cpp b/vibrator/1.0/vts/functional/vibrator_hidl_hal_test.cpp
index 659508d..ec8db3a 100644
--- a/vibrator/1.0/vts/functional/vibrator_hidl_hal_test.cpp
+++ b/vibrator/1.0/vts/functional/vibrator_hidl_hal_test.cpp
@@ -62,6 +62,6 @@
   ::testing::AddGlobalTestEnvironment(new VibratorHidlEnvironment);
   ::testing::InitGoogleTest(&argc, argv);
   int status = RUN_ALL_TESTS();
-  ALOGI("Test result = %d", status);
+  LOG(INFO) << "Test result = " << status;
   return status;
 }
diff --git a/vr/1.0/default/Vr.cpp b/vr/1.0/default/Vr.cpp
index 4b2c603..2b2372b 100644
--- a/vr/1.0/default/Vr.cpp
+++ b/vr/1.0/default/Vr.cpp
@@ -18,6 +18,7 @@
 
 #include <hardware/hardware.h>
 #include <hardware/vr.h>
+#include <android/log.h>
 #include "Vr.h"
 
 namespace android {