Merge "Update Android.bp and vts/Android.mk for Hidl HALs"
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 ef70215..1e0ab32 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
@@ -97,49 +97,6 @@
   EXPECT_NE(effect, nullptr);
 }
 
-// See b/32834072 -- we should have those operator== generated by hidl-gen.
-
-namespace android {
-namespace hardware {
-namespace audio {
-namespace common {
-namespace V2_0 {
-
-static bool operator==(const Uuid& lhs, const Uuid& rhs) {
-  return lhs.timeLow == rhs.timeLow && lhs.timeMid == rhs.timeMid &&
-         lhs.versionAndTimeHigh == rhs.versionAndTimeHigh &&
-         lhs.variantAndClockSeqHigh == rhs.variantAndClockSeqHigh &&
-         memcmp(lhs.node.data(), rhs.node.data(), lhs.node.size()) == 0;
-}
-
-}  // namespace V2_0
-}  // namespace common
-}  // namespace audio
-}  // namespace hardware
-}  // namespace android
-
-namespace android {
-namespace hardware {
-namespace audio {
-namespace effect {
-namespace V2_0 {
-
-static bool operator==(const EffectDescriptor& lhs,
-                       const EffectDescriptor& rhs) {
-  return lhs.type == rhs.type && lhs.uuid == rhs.uuid &&
-         lhs.flags == rhs.flags && lhs.cpuLoad == rhs.cpuLoad &&
-         lhs.memoryUsage == rhs.memoryUsage &&
-         memcmp(lhs.name.data(), rhs.name.data(), lhs.name.size()) == 0 &&
-         memcmp(lhs.implementor.data(), rhs.implementor.data(),
-                lhs.implementor.size()) == 0;
-}
-
-}  // namespace V2_0
-}  // namespace effect
-}  // namespace audio
-}  // namespace hardware
-}  // namespace android
-
 TEST_F(AudioEffectHidlTest, GetDescriptor) {
   hidl_vec<EffectDescriptor> allDescriptors;
   Return<void> ret = effectsFactory->getAllDescriptors(
diff --git a/graphics/allocator/2.0/default/Gralloc.cpp b/graphics/allocator/2.0/default/Gralloc.cpp
index e3d2703..3a102d1 100644
--- a/graphics/allocator/2.0/default/Gralloc.cpp
+++ b/graphics/allocator/2.0/default/Gralloc.cpp
@@ -47,21 +47,21 @@
 
     Error createDescriptor(
             const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
-            BufferDescriptor& outDescriptor);
+            BufferDescriptor* outDescriptor);
     Error destroyDescriptor(BufferDescriptor descriptor);
 
     Error testAllocate(const hidl_vec<BufferDescriptor>& descriptors);
     Error allocate(const hidl_vec<BufferDescriptor>& descriptors,
-            hidl_vec<Buffer>& outBuffers);
+            hidl_vec<Buffer>* outBuffers);
     Error free(Buffer buffer);
 
-    Error exportHandle(Buffer buffer, const native_handle_t*& outHandle);
+    Error exportHandle(Buffer buffer, const native_handle_t** outHandle);
 
 private:
     void initCapabilities();
 
     template<typename T>
-    void initDispatch(T& func, gralloc1_function_descriptor_t desc);
+    void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn);
     void initDispatch();
 
     bool hasCapability(Capability capability) const;
@@ -143,35 +143,35 @@
 }
 
 template<typename T>
-void GrallocHal::initDispatch(T& func, gralloc1_function_descriptor_t desc)
+void GrallocHal::initDispatch(gralloc1_function_descriptor_t desc, T* outPfn)
 {
     auto pfn = mDevice->getFunction(mDevice, desc);
     if (!pfn) {
         LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc);
     }
 
-    func = reinterpret_cast<T>(pfn);
+    *outPfn = reinterpret_cast<T>(pfn);
 }
 
 void GrallocHal::initDispatch()
 {
-    initDispatch(mDispatch.dump, GRALLOC1_FUNCTION_DUMP);
-    initDispatch(mDispatch.createDescriptor,
-            GRALLOC1_FUNCTION_CREATE_DESCRIPTOR);
-    initDispatch(mDispatch.destroyDescriptor,
-            GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR);
-    initDispatch(mDispatch.setDimensions, GRALLOC1_FUNCTION_SET_DIMENSIONS);
-    initDispatch(mDispatch.setFormat, GRALLOC1_FUNCTION_SET_FORMAT);
+    initDispatch(GRALLOC1_FUNCTION_DUMP, &mDispatch.dump);
+    initDispatch(GRALLOC1_FUNCTION_CREATE_DESCRIPTOR,
+            &mDispatch.createDescriptor);
+    initDispatch(GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR,
+            &mDispatch.destroyDescriptor);
+    initDispatch(GRALLOC1_FUNCTION_SET_DIMENSIONS, &mDispatch.setDimensions);
+    initDispatch(GRALLOC1_FUNCTION_SET_FORMAT, &mDispatch.setFormat);
     if (hasCapability(Capability::LAYERED_BUFFERS)) {
-        initDispatch(
-                mDispatch.setLayerCount, GRALLOC1_FUNCTION_SET_LAYER_COUNT);
+        initDispatch(GRALLOC1_FUNCTION_SET_LAYER_COUNT,
+                &mDispatch.setLayerCount);
     }
-    initDispatch(mDispatch.setConsumerUsage,
-            GRALLOC1_FUNCTION_SET_CONSUMER_USAGE);
-    initDispatch(mDispatch.setProducerUsage,
-            GRALLOC1_FUNCTION_SET_PRODUCER_USAGE);
-    initDispatch(mDispatch.allocate, GRALLOC1_FUNCTION_ALLOCATE);
-    initDispatch(mDispatch.release, GRALLOC1_FUNCTION_RELEASE);
+    initDispatch(GRALLOC1_FUNCTION_SET_CONSUMER_USAGE,
+            &mDispatch.setConsumerUsage);
+    initDispatch(GRALLOC1_FUNCTION_SET_PRODUCER_USAGE,
+            &mDispatch.setProducerUsage);
+    initDispatch(GRALLOC1_FUNCTION_ALLOCATE, &mDispatch.allocate);
+    initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release);
 }
 
 bool GrallocHal::hasCapability(Capability capability) const
@@ -218,7 +218,7 @@
 
 Error GrallocHal::createDescriptor(
         const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
-        BufferDescriptor& outDescriptor)
+        BufferDescriptor* outDescriptor)
 {
     gralloc1_buffer_descriptor_t descriptor;
     int32_t err = mDispatch.createDescriptor(mDevice, &descriptor);
@@ -261,7 +261,7 @@
     }
 
     if (err == GRALLOC1_ERROR_NONE) {
-        outDescriptor = descriptor;
+        *outDescriptor = descriptor;
     } else {
         mDispatch.destroyDescriptor(mDevice, descriptor);
     }
@@ -287,15 +287,15 @@
 }
 
 Error GrallocHal::allocate(const hidl_vec<BufferDescriptor>& descriptors,
-        hidl_vec<Buffer>& outBuffers)
+        hidl_vec<Buffer>* outBuffers)
 {
     std::vector<buffer_handle_t> buffers(descriptors.size());
     int32_t err = mDispatch.allocate(mDevice, descriptors.size(),
             descriptors.data(), buffers.data());
     if (err == GRALLOC1_ERROR_NONE || err == GRALLOC1_ERROR_NOT_SHARED) {
-        outBuffers.resize(buffers.size());
-        for (size_t i = 0; i < outBuffers.size(); i++) {
-            outBuffers[i] = static_cast<Buffer>(
+        outBuffers->resize(buffers.size());
+        for (size_t i = 0; i < outBuffers->size(); i++) {
+            (*outBuffers)[i] = static_cast<Buffer>(
                     reinterpret_cast<uintptr_t>(buffers[i]));
         }
     }
@@ -313,10 +313,10 @@
 }
 
 Error GrallocHal::exportHandle(Buffer buffer,
-        const native_handle_t*& outHandle)
+        const native_handle_t** outHandle)
 {
     // we rely on the caller to validate buffer here
-    outHandle = reinterpret_cast<buffer_handle_t>(
+    *outHandle = reinterpret_cast<buffer_handle_t>(
             static_cast<uintptr_t>(buffer));
     return Error::NONE;
 }
@@ -347,8 +347,8 @@
         const BufferDescriptorInfo& descriptorInfo,
         createDescriptor_cb hidl_cb)
 {
-    BufferDescriptor descriptor;
-    Error err = mHal.createDescriptor(descriptorInfo, descriptor);
+    BufferDescriptor descriptor = 0;
+    Error err = mHal.createDescriptor(descriptorInfo, &descriptor);
 
     if (err == Error::NONE) {
         std::lock_guard<std::mutex> lock(mMutex);
@@ -387,7 +387,7 @@
         const hidl_vec<BufferDescriptor>& descriptors,
         allocate_cb hidl_cb) {
     hidl_vec<Buffer> buffers;
-    Error err = mHal.allocate(descriptors, buffers);
+    Error err = mHal.allocate(descriptors, &buffers);
 
     if (err == Error::NONE || err == Error::NOT_SHARED) {
         std::lock_guard<std::mutex> lock(mMutex);
@@ -440,14 +440,14 @@
         }
     }
 
-    Error err = mHal.exportHandle(buffer, handle);
+    Error err = mHal.exportHandle(buffer, &handle);
 
     hidl_cb(err, handle);
     return Void();
 }
 
 IAllocator* HIDL_FETCH_IAllocator(const char* /* name */) {
-    const hw_module_t* module;
+    const hw_module_t* module = nullptr;
     int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
     if (err) {
         ALOGE("failed to get gralloc module");
diff --git a/graphics/composer/2.1/default/Hwc.cpp b/graphics/composer/2.1/default/Hwc.cpp
index d14de6f..4efb12b 100644
--- a/graphics/composer/2.1/default/Hwc.cpp
+++ b/graphics/composer/2.1/default/Hwc.cpp
@@ -62,88 +62,89 @@
 }
 
 template<typename T>
-void HwcHal::initDispatch(T& func, hwc2_function_descriptor_t desc)
+void HwcHal::initDispatch(hwc2_function_descriptor_t desc, T* outPfn)
 {
     auto pfn = mDevice->getFunction(mDevice, desc);
     if (!pfn) {
         LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc);
     }
 
-    func = reinterpret_cast<T>(pfn);
+    *outPfn = reinterpret_cast<T>(pfn);
 }
 
 void HwcHal::initDispatch()
 {
-    initDispatch(mDispatch.acceptDisplayChanges,
-            HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES);
-    initDispatch(mDispatch.createLayer, HWC2_FUNCTION_CREATE_LAYER);
-    initDispatch(mDispatch.createVirtualDisplay,
-            HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY);
-    initDispatch(mDispatch.destroyLayer, HWC2_FUNCTION_DESTROY_LAYER);
-    initDispatch(mDispatch.destroyVirtualDisplay,
-            HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY);
-    initDispatch(mDispatch.dump, HWC2_FUNCTION_DUMP);
-    initDispatch(mDispatch.getActiveConfig, HWC2_FUNCTION_GET_ACTIVE_CONFIG);
-    initDispatch(mDispatch.getChangedCompositionTypes,
-            HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES);
-    initDispatch(mDispatch.getClientTargetSupport,
-            HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT);
-    initDispatch(mDispatch.getColorModes, HWC2_FUNCTION_GET_COLOR_MODES);
-    initDispatch(mDispatch.getDisplayAttribute,
-            HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE);
-    initDispatch(mDispatch.getDisplayConfigs,
-            HWC2_FUNCTION_GET_DISPLAY_CONFIGS);
-    initDispatch(mDispatch.getDisplayName, HWC2_FUNCTION_GET_DISPLAY_NAME);
-    initDispatch(mDispatch.getDisplayRequests,
-            HWC2_FUNCTION_GET_DISPLAY_REQUESTS);
-    initDispatch(mDispatch.getDisplayType, HWC2_FUNCTION_GET_DISPLAY_TYPE);
-    initDispatch(mDispatch.getDozeSupport, HWC2_FUNCTION_GET_DOZE_SUPPORT);
-    initDispatch(mDispatch.getHdrCapabilities,
-            HWC2_FUNCTION_GET_HDR_CAPABILITIES);
-    initDispatch(mDispatch.getMaxVirtualDisplayCount,
-            HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT);
-    initDispatch(mDispatch.getReleaseFences,
-            HWC2_FUNCTION_GET_RELEASE_FENCES);
-    initDispatch(mDispatch.presentDisplay, HWC2_FUNCTION_PRESENT_DISPLAY);
-    initDispatch(mDispatch.registerCallback, HWC2_FUNCTION_REGISTER_CALLBACK);
-    initDispatch(mDispatch.setActiveConfig, HWC2_FUNCTION_SET_ACTIVE_CONFIG);
-    initDispatch(mDispatch.setClientTarget, HWC2_FUNCTION_SET_CLIENT_TARGET);
-    initDispatch(mDispatch.setColorMode, HWC2_FUNCTION_SET_COLOR_MODE);
-    initDispatch(mDispatch.setColorTransform,
-            HWC2_FUNCTION_SET_COLOR_TRANSFORM);
-    initDispatch(mDispatch.setCursorPosition,
-            HWC2_FUNCTION_SET_CURSOR_POSITION);
-    initDispatch(mDispatch.setLayerBlendMode,
-            HWC2_FUNCTION_SET_LAYER_BLEND_MODE);
-    initDispatch(mDispatch.setLayerBuffer, HWC2_FUNCTION_SET_LAYER_BUFFER);
-    initDispatch(mDispatch.setLayerColor, HWC2_FUNCTION_SET_LAYER_COLOR);
-    initDispatch(mDispatch.setLayerCompositionType,
-            HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE);
-    initDispatch(mDispatch.setLayerDataspace,
-            HWC2_FUNCTION_SET_LAYER_DATASPACE);
-    initDispatch(mDispatch.setLayerDisplayFrame,
-            HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME);
-    initDispatch(mDispatch.setLayerPlaneAlpha,
-            HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA);
+    initDispatch(HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES,
+            &mDispatch.acceptDisplayChanges);
+    initDispatch(HWC2_FUNCTION_CREATE_LAYER, &mDispatch.createLayer);
+    initDispatch(HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY,
+            &mDispatch.createVirtualDisplay);
+    initDispatch(HWC2_FUNCTION_DESTROY_LAYER, &mDispatch.destroyLayer);
+    initDispatch(HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY,
+            &mDispatch.destroyVirtualDisplay);
+    initDispatch(HWC2_FUNCTION_DUMP, &mDispatch.dump);
+    initDispatch(HWC2_FUNCTION_GET_ACTIVE_CONFIG, &mDispatch.getActiveConfig);
+    initDispatch(HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES,
+            &mDispatch.getChangedCompositionTypes);
+    initDispatch(HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT,
+            &mDispatch.getClientTargetSupport);
+    initDispatch(HWC2_FUNCTION_GET_COLOR_MODES, &mDispatch.getColorModes);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE,
+            &mDispatch.getDisplayAttribute);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_CONFIGS,
+            &mDispatch.getDisplayConfigs);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_NAME, &mDispatch.getDisplayName);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_REQUESTS,
+            &mDispatch.getDisplayRequests);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_TYPE, &mDispatch.getDisplayType);
+    initDispatch(HWC2_FUNCTION_GET_DOZE_SUPPORT, &mDispatch.getDozeSupport);
+    initDispatch(HWC2_FUNCTION_GET_HDR_CAPABILITIES,
+            &mDispatch.getHdrCapabilities);
+    initDispatch(HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT,
+            &mDispatch.getMaxVirtualDisplayCount);
+    initDispatch(HWC2_FUNCTION_GET_RELEASE_FENCES,
+            &mDispatch.getReleaseFences);
+    initDispatch(HWC2_FUNCTION_PRESENT_DISPLAY, &mDispatch.presentDisplay);
+    initDispatch(HWC2_FUNCTION_REGISTER_CALLBACK,
+            &mDispatch.registerCallback);
+    initDispatch(HWC2_FUNCTION_SET_ACTIVE_CONFIG, &mDispatch.setActiveConfig);
+    initDispatch(HWC2_FUNCTION_SET_CLIENT_TARGET, &mDispatch.setClientTarget);
+    initDispatch(HWC2_FUNCTION_SET_COLOR_MODE, &mDispatch.setColorMode);
+    initDispatch(HWC2_FUNCTION_SET_COLOR_TRANSFORM,
+            &mDispatch.setColorTransform);
+    initDispatch(HWC2_FUNCTION_SET_CURSOR_POSITION,
+            &mDispatch.setCursorPosition);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_BLEND_MODE,
+            &mDispatch.setLayerBlendMode);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_BUFFER, &mDispatch.setLayerBuffer);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_COLOR, &mDispatch.setLayerColor);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE,
+            &mDispatch.setLayerCompositionType);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_DATASPACE,
+            &mDispatch.setLayerDataspace);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME,
+            &mDispatch.setLayerDisplayFrame);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA,
+            &mDispatch.setLayerPlaneAlpha);
 
     if (hasCapability(Capability::SIDEBAND_STREAM)) {
-        initDispatch(mDispatch.setLayerSidebandStream,
-                HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM);
+        initDispatch(HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM,
+                &mDispatch.setLayerSidebandStream);
     }
 
-    initDispatch(mDispatch.setLayerSourceCrop,
-            HWC2_FUNCTION_SET_LAYER_SOURCE_CROP);
-    initDispatch(mDispatch.setLayerSurfaceDamage,
-            HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE);
-    initDispatch(mDispatch.setLayerTransform,
-            HWC2_FUNCTION_SET_LAYER_TRANSFORM);
-    initDispatch(mDispatch.setLayerVisibleRegion,
-            HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION);
-    initDispatch(mDispatch.setLayerZOrder, HWC2_FUNCTION_SET_LAYER_Z_ORDER);
-    initDispatch(mDispatch.setOutputBuffer, HWC2_FUNCTION_SET_OUTPUT_BUFFER);
-    initDispatch(mDispatch.setPowerMode, HWC2_FUNCTION_SET_POWER_MODE);
-    initDispatch(mDispatch.setVsyncEnabled, HWC2_FUNCTION_SET_VSYNC_ENABLED);
-    initDispatch(mDispatch.validateDisplay, HWC2_FUNCTION_VALIDATE_DISPLAY);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_SOURCE_CROP,
+            &mDispatch.setLayerSourceCrop);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE,
+            &mDispatch.setLayerSurfaceDamage);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_TRANSFORM,
+            &mDispatch.setLayerTransform);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION,
+            &mDispatch.setLayerVisibleRegion);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_Z_ORDER, &mDispatch.setLayerZOrder);
+    initDispatch(HWC2_FUNCTION_SET_OUTPUT_BUFFER, &mDispatch.setOutputBuffer);
+    initDispatch(HWC2_FUNCTION_SET_POWER_MODE, &mDispatch.setPowerMode);
+    initDispatch(HWC2_FUNCTION_SET_VSYNC_ENABLED, &mDispatch.setVsyncEnabled);
+    initDispatch(HWC2_FUNCTION_VALIDATE_DISPLAY, &mDispatch.validateDisplay);
 }
 
 bool HwcHal::hasCapability(Capability capability) const
@@ -165,7 +166,7 @@
 
 Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
 {
-    uint32_t len;
+    uint32_t len = 0;
     mDispatch.dump(mDevice, &len, nullptr);
 
     std::vector<char> buf(len + 1);
@@ -270,12 +271,12 @@
 }
 
 Error HwcHal::createVirtualDisplay(uint32_t width, uint32_t height,
-    PixelFormat& format, Display& display)
+    PixelFormat* format, Display* outDisplay)
 {
-    int32_t hwc_format = static_cast<int32_t>(format);
+    int32_t hwc_format = static_cast<int32_t>(*format);
     int32_t err = mDispatch.createVirtualDisplay(mDevice, width, height,
-            &hwc_format, &display);
-    format = static_cast<PixelFormat>(hwc_format);
+            &hwc_format, outDisplay);
+    *format = static_cast<PixelFormat>(hwc_format);
 
     return static_cast<Error>(err);
 }
@@ -286,9 +287,9 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::createLayer(Display display, Layer& layer)
+Error HwcHal::createLayer(Display display, Layer* outLayer)
 {
-    int32_t err = mDispatch.createLayer(mDevice, display, &layer);
+    int32_t err = mDispatch.createLayer(mDevice, display, outLayer);
     return static_cast<Error>(err);
 }
 
@@ -298,9 +299,9 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getActiveConfig(Display display, Config& config)
+Error HwcHal::getActiveConfig(Display display, Config* outConfig)
 {
-    int32_t err = mDispatch.getActiveConfig(mDevice, display, &config);
+    int32_t err = mDispatch.getActiveConfig(mDevice, display, outConfig);
     return static_cast<Error>(err);
 }
 
@@ -314,7 +315,7 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>& modes)
+Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>* outModes)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getColorModes(mDevice, display, &count, nullptr);
@@ -322,12 +323,12 @@
         return static_cast<Error>(err);
     }
 
-    modes.resize(count);
+    outModes->resize(count);
     err = mDispatch.getColorModes(mDevice, display, &count,
             reinterpret_cast<std::underlying_type<ColorMode>::type*>(
-                modes.data()));
+                outModes->data()));
     if (err != HWC2_ERROR_NONE) {
-        modes = hidl_vec<ColorMode>();
+        *outModes = hidl_vec<ColorMode>();
         return static_cast<Error>(err);
     }
 
@@ -335,14 +336,14 @@
 }
 
 Error HwcHal::getDisplayAttribute(Display display, Config config,
-        IComposerClient::Attribute attribute, int32_t& value)
+        IComposerClient::Attribute attribute, int32_t* outValue)
 {
     int32_t err = mDispatch.getDisplayAttribute(mDevice, display, config,
-            static_cast<int32_t>(attribute), &value);
+            static_cast<int32_t>(attribute), outValue);
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>& configs)
+Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getDisplayConfigs(mDevice, display,
@@ -351,18 +352,18 @@
         return static_cast<Error>(err);
     }
 
-    configs.resize(count);
+    outConfigs->resize(count);
     err = mDispatch.getDisplayConfigs(mDevice, display,
-            &count, configs.data());
+            &count, outConfigs->data());
     if (err != HWC2_ERROR_NONE) {
-        configs = hidl_vec<Config>();
+        *outConfigs = hidl_vec<Config>();
         return static_cast<Error>(err);
     }
 
     return Error::NONE;
 }
 
-Error HwcHal::getDisplayName(Display display, hidl_string& name)
+Error HwcHal::getDisplayName(Display display, hidl_string* outName)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getDisplayName(mDevice, display, &count, nullptr);
@@ -378,44 +379,49 @@
     buf.resize(count + 1);
     buf[count] = '\0';
 
-    name = buf.data();
+    *outName = buf.data();
 
     return Error::NONE;
 }
 
-Error HwcHal::getDisplayType(Display display, IComposerClient::DisplayType& type)
+Error HwcHal::getDisplayType(Display display,
+        IComposerClient::DisplayType* outType)
 {
     int32_t hwc_type = HWC2_DISPLAY_TYPE_INVALID;
     int32_t err = mDispatch.getDisplayType(mDevice, display, &hwc_type);
-    type = static_cast<IComposerClient::DisplayType>(hwc_type);
+    *outType = static_cast<IComposerClient::DisplayType>(hwc_type);
 
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getDozeSupport(Display display, bool& support)
+Error HwcHal::getDozeSupport(Display display, bool* outSupport)
 {
     int32_t hwc_support = 0;
     int32_t err = mDispatch.getDozeSupport(mDevice, display, &hwc_support);
-    support = hwc_support;
+    *outSupport = hwc_support;
 
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>& types,
-        float& maxLuminance, float& maxAverageLuminance, float& minLuminance)
+Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
+        float* outMaxLuminance, float* outMaxAverageLuminance,
+        float* outMinLuminance)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getHdrCapabilities(mDevice, display, &count,
-            nullptr, &maxLuminance, &maxAverageLuminance, &minLuminance);
+            nullptr, outMaxLuminance, outMaxAverageLuminance,
+            outMinLuminance);
     if (err != HWC2_ERROR_NONE) {
         return static_cast<Error>(err);
     }
 
-    types.resize(count);
+    outTypes->resize(count);
     err = mDispatch.getHdrCapabilities(mDevice, display, &count,
-            reinterpret_cast<std::underlying_type<Hdr>::type*>(types.data()),
-            &maxLuminance, &maxAverageLuminance, &minLuminance);
+            reinterpret_cast<std::underlying_type<Hdr>::type*>(
+                outTypes->data()), outMaxLuminance,
+            outMaxAverageLuminance, outMinLuminance);
     if (err != HWC2_ERROR_NONE) {
+        *outTypes = hidl_vec<Hdr>();
         return static_cast<Error>(err);
     }
 
@@ -480,11 +486,11 @@
 }
 
 Error HwcHal::validateDisplay(Display display,
-        std::vector<Layer>& changedLayers,
-        std::vector<IComposerClient::Composition>& compositionTypes,
-        uint32_t& displayRequestMask,
-        std::vector<Layer>& requestedLayers,
-        std::vector<uint32_t>& requestMasks)
+        std::vector<Layer>* outChangedLayers,
+        std::vector<IComposerClient::Composition>* outCompositionTypes,
+        uint32_t* outDisplayRequestMask,
+        std::vector<Layer>* outRequestedLayers,
+        std::vector<uint32_t>* outRequestMasks)
 {
     uint32_t types_count = 0;
     uint32_t reqs_count = 0;
@@ -500,16 +506,16 @@
         return static_cast<Error>(err);
     }
 
-    changedLayers.resize(types_count);
-    compositionTypes.resize(types_count);
+    outChangedLayers->resize(types_count);
+    outCompositionTypes->resize(types_count);
     err = mDispatch.getChangedCompositionTypes(mDevice, display,
-            &types_count, changedLayers.data(),
+            &types_count, outChangedLayers->data(),
             reinterpret_cast<
             std::underlying_type<IComposerClient::Composition>::type*>(
-                compositionTypes.data()));
+                outCompositionTypes->data()));
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
         return static_cast<Error>(err);
     }
 
@@ -517,26 +523,26 @@
     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
             &reqs_count, nullptr, nullptr);
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
         return static_cast<Error>(err);
     }
 
-    requestedLayers.resize(reqs_count);
-    requestMasks.resize(reqs_count);
+    outRequestedLayers->resize(reqs_count);
+    outRequestMasks->resize(reqs_count);
     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
-            &reqs_count, requestedLayers.data(),
-            reinterpret_cast<int32_t*>(requestMasks.data()));
+            &reqs_count, outRequestedLayers->data(),
+            reinterpret_cast<int32_t*>(outRequestMasks->data()));
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
 
-        requestedLayers.clear();
-        requestMasks.clear();
+        outRequestedLayers->clear();
+        outRequestMasks->clear();
         return static_cast<Error>(err);
     }
 
-    displayRequestMask = display_reqs;
+    *outDisplayRequestMask = display_reqs;
 
     return static_cast<Error>(err);
 }
@@ -547,11 +553,11 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::presentDisplay(Display display, int32_t& presentFence,
-        std::vector<Layer>& layers, std::vector<int32_t>& releaseFences)
+Error HwcHal::presentDisplay(Display display, int32_t* outPresentFence,
+        std::vector<Layer>* outLayers, std::vector<int32_t>* outReleaseFences)
 {
-    presentFence = -1;
-    int32_t err = mDispatch.presentDisplay(mDevice, display, &presentFence);
+    *outPresentFence = -1;
+    int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence);
     if (err != HWC2_ERROR_NONE) {
         return static_cast<Error>(err);
     }
@@ -564,14 +570,14 @@
         return Error::NONE;
     }
 
-    layers.resize(count);
-    releaseFences.resize(count);
+    outLayers->resize(count);
+    outReleaseFences->resize(count);
     err = mDispatch.getReleaseFences(mDevice, display, &count,
-            layers.data(), releaseFences.data());
+            outLayers->data(), outReleaseFences->data());
     if (err != HWC2_ERROR_NONE) {
         ALOGW("failed to get release fences");
-        layers.clear();
-        releaseFences.clear();
+        outLayers->clear();
+        outReleaseFences->clear();
         return Error::NONE;
     }
 
@@ -687,7 +693,7 @@
 
 IComposer* HIDL_FETCH_IComposer(const char*)
 {
-    const hw_module_t* module;
+    const hw_module_t* module = nullptr;
     int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module);
     if (err) {
         ALOGE("failed to get hwcomposer module");
diff --git a/graphics/composer/2.1/default/Hwc.h b/graphics/composer/2.1/default/Hwc.h
index 89ac4f7..6420b31 100644
--- a/graphics/composer/2.1/default/Hwc.h
+++ b/graphics/composer/2.1/default/Hwc.h
@@ -58,26 +58,27 @@
 
     uint32_t getMaxVirtualDisplayCount();
     Error createVirtualDisplay(uint32_t width, uint32_t height,
-        PixelFormat& format, Display& display);
+        PixelFormat* format, Display* outDisplay);
     Error destroyVirtualDisplay(Display display);
 
-    Error createLayer(Display display, Layer& layer);
+    Error createLayer(Display display, Layer* outLayer);
     Error destroyLayer(Display display, Layer layer);
 
-    Error getActiveConfig(Display display, Config& config);
+    Error getActiveConfig(Display display, Config* outConfig);
     Error getClientTargetSupport(Display display,
             uint32_t width, uint32_t height,
             PixelFormat format, Dataspace dataspace);
-    Error getColorModes(Display display, hidl_vec<ColorMode>& modes);
+    Error getColorModes(Display display, hidl_vec<ColorMode>* outModes);
     Error getDisplayAttribute(Display display, Config config,
-            IComposerClient::Attribute attribute, int32_t& value);
-    Error getDisplayConfigs(Display display, hidl_vec<Config>& configs);
-    Error getDisplayName(Display display, hidl_string& name);
-    Error getDisplayType(Display display, IComposerClient::DisplayType& type);
-    Error getDozeSupport(Display display, bool& support);
-    Error getHdrCapabilities(Display display, hidl_vec<Hdr>& types,
-            float& maxLuminance, float& maxAverageLuminance,
-            float& minLuminance);
+            IComposerClient::Attribute attribute, int32_t* outValue);
+    Error getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs);
+    Error getDisplayName(Display display, hidl_string* outName);
+    Error getDisplayType(Display display,
+            IComposerClient::DisplayType* outType);
+    Error getDozeSupport(Display display, bool* outSupport);
+    Error getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
+            float* outMaxLuminance, float* outMaxAverageLuminance,
+            float* outMinLuminance);
 
     Error setActiveConfig(Display display, Config config);
     Error setColorMode(Display display, ColorMode mode);
@@ -92,14 +93,15 @@
     Error setOutputBuffer(Display display, buffer_handle_t buffer,
             int32_t releaseFence);
     Error validateDisplay(Display display,
-            std::vector<Layer>& changedLayers,
-            std::vector<IComposerClient::Composition>& compositionTypes,
-            uint32_t& displayRequestMask,
-            std::vector<Layer>& requestedLayers,
-            std::vector<uint32_t>& requestMasks);
+            std::vector<Layer>* outChangedLayers,
+            std::vector<IComposerClient::Composition>* outCompositionTypes,
+            uint32_t* outDisplayRequestMask,
+            std::vector<Layer>* outRequestedLayers,
+            std::vector<uint32_t>* outRequestMasks);
     Error acceptDisplayChanges(Display display);
-    Error presentDisplay(Display display, int32_t& presentFence,
-            std::vector<Layer>& layers, std::vector<int32_t>& releaseFences);
+    Error presentDisplay(Display display, int32_t* outPresentFence,
+            std::vector<Layer>* outLayers,
+            std::vector<int32_t>* outReleaseFences);
 
     Error setLayerCursorPosition(Display display, Layer layer,
             int32_t x, int32_t y);
@@ -131,7 +133,7 @@
     void initCapabilities();
 
     template<typename T>
-    void initDispatch(T& func, hwc2_function_descriptor_t desc);
+    void initDispatch(hwc2_function_descriptor_t desc, T* outPfn);
     void initDispatch();
 
     sp<HwcClient> getClient();
diff --git a/graphics/composer/2.1/default/HwcClient.cpp b/graphics/composer/2.1/default/HwcClient.cpp
index 5599959..ce6c480 100644
--- a/graphics/composer/2.1/default/HwcClient.cpp
+++ b/graphics/composer/2.1/default/HwcClient.cpp
@@ -102,7 +102,7 @@
 #ifdef BINDERIZED
     bool openGralloc()
     {
-        const hw_module_t* module;
+        const hw_module_t* module = nullptr;
         int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
         if (err) {
             ALOGE("failed to get gralloc module");
@@ -308,8 +308,9 @@
         PixelFormat formatHint, uint32_t outputBufferSlotCount,
         createVirtualDisplay_cb hidl_cb)
 {
-    Display display;
-    Error err = mHal.createVirtualDisplay(width, height, formatHint, display);
+    Display display = 0;
+    Error err = mHal.createVirtualDisplay(width, height,
+            &formatHint, &display);
     if (err == Error::NONE) {
         std::lock_guard<std::mutex> lock(mDisplayDataMutex);
 
@@ -336,8 +337,8 @@
 Return<void> HwcClient::createLayer(Display display, uint32_t bufferSlotCount,
         createLayer_cb hidl_cb)
 {
-    Layer layer;
-    Error err = mHal.createLayer(display, layer);
+    Layer layer = 0;
+    Error err = mHal.createLayer(display, &layer);
     if (err == Error::NONE) {
         std::lock_guard<std::mutex> lock(mDisplayDataMutex);
 
@@ -366,8 +367,8 @@
 Return<void> HwcClient::getActiveConfig(Display display,
         getActiveConfig_cb hidl_cb)
 {
-    Config config;
-    Error err = mHal.getActiveConfig(display, config);
+    Config config = 0;
+    Error err = mHal.getActiveConfig(display, &config);
 
     hidl_cb(err, config);
     return Void();
@@ -385,7 +386,7 @@
 Return<void> HwcClient::getColorModes(Display display, getColorModes_cb hidl_cb)
 {
     hidl_vec<ColorMode> modes;
-    Error err = mHal.getColorModes(display, modes);
+    Error err = mHal.getColorModes(display, &modes);
 
     hidl_cb(err, modes);
     return Void();
@@ -395,8 +396,8 @@
         Config config, Attribute attribute,
         getDisplayAttribute_cb hidl_cb)
 {
-    int32_t value;
-    Error err = mHal.getDisplayAttribute(display, config, attribute, value);
+    int32_t value = 0;
+    Error err = mHal.getDisplayAttribute(display, config, attribute, &value);
 
     hidl_cb(err, value);
     return Void();
@@ -406,7 +407,7 @@
         getDisplayConfigs_cb hidl_cb)
 {
     hidl_vec<Config> configs;
-    Error err = mHal.getDisplayConfigs(display, configs);
+    Error err = mHal.getDisplayConfigs(display, &configs);
 
     hidl_cb(err, configs);
     return Void();
@@ -416,7 +417,7 @@
         getDisplayName_cb hidl_cb)
 {
     hidl_string name;
-    Error err = mHal.getDisplayName(display, name);
+    Error err = mHal.getDisplayName(display, &name);
 
     hidl_cb(err, name);
     return Void();
@@ -425,8 +426,8 @@
 Return<void> HwcClient::getDisplayType(Display display,
         getDisplayType_cb hidl_cb)
 {
-    DisplayType type;
-    Error err = mHal.getDisplayType(display, type);
+    DisplayType type = DisplayType::INVALID;
+    Error err = mHal.getDisplayType(display, &type);
 
     hidl_cb(err, type);
     return Void();
@@ -435,8 +436,8 @@
 Return<void> HwcClient::getDozeSupport(Display display,
         getDozeSupport_cb hidl_cb)
 {
-    bool support;
-    Error err = mHal.getDozeSupport(display, support);
+    bool support = false;
+    Error err = mHal.getDozeSupport(display, &support);
 
     hidl_cb(err, support);
     return Void();
@@ -449,8 +450,8 @@
     float max_lumi = 0.0f;
     float max_avg_lumi = 0.0f;
     float min_lumi = 0.0f;
-    Error err = mHal.getHdrCapabilities(display, types,
-            max_lumi, max_avg_lumi, min_lumi);
+    Error err = mHal.getHdrCapabilities(display, &types,
+            &max_lumi, &max_avg_lumi, &min_lumi);
 
     hidl_cb(err, types, max_lumi, max_avg_lumi, min_lumi);
     return Void();
@@ -536,7 +537,7 @@
 
     Error err = mReader.parse();
     if (err == Error::NONE &&
-            !mWriter.writeQueue(outChanged, outLength, outHandles)) {
+            !mWriter.writeQueue(&outChanged, &outLength, &outHandles)) {
         err = Error::NO_RESOURCES;
     }
 
@@ -556,10 +557,10 @@
 Error HwcClient::CommandReader::parse()
 {
     IComposerClient::Command command;
-    uint16_t length;
+    uint16_t length = 0;
 
     while (!isEmpty()) {
-        if (!beginCommand(command, length)) {
+        if (!beginCommand(&command, &length)) {
             break;
         }
 
@@ -698,9 +699,9 @@
         return false;
     }
 
-    bool useCache;
+    bool useCache = false;
     auto slot = read();
-    auto clientTarget = readHandle(useCache);
+    auto clientTarget = readHandle(&useCache);
     auto fence = readFence();
     auto dataspace = readSigned();
     auto damage = readRegion((length - 4) / 4);
@@ -725,9 +726,9 @@
         return false;
     }
 
-    bool useCache;
+    bool useCache = false;
     auto slot = read();
-    auto outputBuffer = readHandle(useCache);
+    auto outputBuffer = readHandle(&useCache);
     auto fence = readFence();
 
     auto err = lookupBuffer(BufferCache::OUTPUT_BUFFERS,
@@ -751,12 +752,13 @@
 
     std::vector<Layer> changedLayers;
     std::vector<IComposerClient::Composition> compositionTypes;
-    uint32_t displayRequestMask;
+    uint32_t displayRequestMask = 0x0;
     std::vector<Layer> requestedLayers;
     std::vector<uint32_t> requestMasks;
 
-    auto err = mHal.validateDisplay(mDisplay, changedLayers, compositionTypes,
-            displayRequestMask, requestedLayers, requestMasks);
+    auto err = mHal.validateDisplay(mDisplay, &changedLayers,
+            &compositionTypes, &displayRequestMask,
+            &requestedLayers, &requestMasks);
     if (err == Error::NONE) {
         mWriter.setChangedCompositionTypes(changedLayers,
                 compositionTypes);
@@ -789,10 +791,10 @@
         return false;
     }
 
-    int presentFence;
+    int presentFence = -1;
     std::vector<Layer> layers;
     std::vector<int> fences;
-    auto err = mHal.presentDisplay(mDisplay, presentFence, layers, fences);
+    auto err = mHal.presentDisplay(mDisplay, &presentFence, &layers, &fences);
     if (err == Error::NONE) {
         mWriter.setPresentFence(presentFence);
         mWriter.setReleaseFences(layers, fences);
@@ -824,9 +826,9 @@
         return false;
     }
 
-    bool useCache;
+    bool useCache = false;
     auto slot = read();
-    auto buffer = readHandle(useCache);
+    auto buffer = readHandle(&useCache);
     auto fence = readFence();
 
     auto err = lookupBuffer(BufferCache::LAYER_BUFFERS,
diff --git a/graphics/composer/2.1/default/IComposerCommandBuffer.h b/graphics/composer/2.1/default/IComposerCommandBuffer.h
index 199a744..8f133fe 100644
--- a/graphics/composer/2.1/default/IComposerCommandBuffer.h
+++ b/graphics/composer/2.1/default/IComposerCommandBuffer.h
@@ -89,8 +89,8 @@
                 static_cast<uint32_t>(IComposerClient::Command::OPCODE_MASK));
     }
 
-    bool writeQueue(bool& queueChanged, uint32_t& commandLength,
-            hidl_vec<hidl_handle>& commandHandles)
+    bool writeQueue(bool* outQueueChanged, uint32_t* outCommandLength,
+            hidl_vec<hidl_handle>* outCommandHandles)
     {
         // write data to queue, optionally resizing it
         if (mQueue && (mDataMaxSize <= mQueue->getQuantumCount())) {
@@ -99,7 +99,7 @@
                 return false;
             }
 
-            queueChanged = false;
+            *outQueueChanged = false;
         } else {
             auto newQueue = std::make_unique<CommandQueueType>(mDataMaxSize);
             if (!newQueue->isValid() ||
@@ -109,11 +109,11 @@
             }
 
             mQueue = std::move(newQueue);
-            queueChanged = true;
+            *outQueueChanged = true;
         }
 
-        commandLength = mDataWritten;
-        commandHandles.setToExternal(
+        *outCommandLength = mDataWritten;
+        outCommandHandles->setToExternal(
                 const_cast<hidl_handle*>(mDataHandles.data()),
                 mDataHandles.size());
 
@@ -682,7 +682,8 @@
         return (mDataRead >= mDataSize);
     }
 
-    bool beginCommand(IComposerClient::Command& command, uint16_t& length)
+    bool beginCommand(IComposerClient::Command* outCommand,
+            uint16_t* outLength)
     {
         if (mCommandEnd) {
             LOG_FATAL("endCommand was not called before command 0x%x",
@@ -695,18 +696,19 @@
             static_cast<uint32_t>(IComposerClient::Command::LENGTH_MASK);
 
         uint32_t val = read();
-        command = static_cast<IComposerClient::Command>(val & opcode_mask);
-        length = static_cast<uint16_t>(val & length_mask);
+        *outCommand = static_cast<IComposerClient::Command>(
+                val & opcode_mask);
+        *outLength = static_cast<uint16_t>(val & length_mask);
 
-        if (mDataRead + length > mDataSize) {
+        if (mDataRead + *outLength > mDataSize) {
             ALOGE("command 0x%x has invalid command length %" PRIu16,
-                    command, length);
+                    *outCommand, *outLength);
             // undo the read() above
             mDataRead--;
             return false;
         }
 
-        mCommandEnd = mDataRead + length;
+        mCommandEnd = mDataRead + *outLength;
 
         return true;
     }
@@ -770,17 +772,17 @@
     }
 
     // ownership of handle is not transferred
-    const native_handle_t* readHandle(bool& useCache)
+    const native_handle_t* readHandle(bool* outUseCache)
     {
         const native_handle_t* handle = nullptr;
 
         int32_t index = readSigned();
         switch (index) {
         case static_cast<int32_t>(IComposerClient::HandleIndex::EMPTY):
-            useCache = false;
+            *outUseCache = false;
             break;
         case static_cast<int32_t>(IComposerClient::HandleIndex::CACHED):
-            useCache = true;
+            *outUseCache = true;
             break;
         default:
             if (static_cast<size_t>(index) < mDataHandles.size()) {
@@ -788,7 +790,7 @@
             } else {
                 ALOGE("invalid handle index %zu", static_cast<size_t>(index));
             }
-            useCache = false;
+            *outUseCache = false;
             break;
         }
 
@@ -798,7 +800,7 @@
     const native_handle_t* readHandle()
     {
         bool useCache;
-        return readHandle(useCache);
+        return readHandle(&useCache);
     }
 
     // ownership of fence is transferred
diff --git a/graphics/mapper/2.0/Android.bp b/graphics/mapper/2.0/Android.bp
index 19b1388..9ac6d50 100644
--- a/graphics/mapper/2.0/Android.bp
+++ b/graphics/mapper/2.0/Android.bp
@@ -1,4 +1,60 @@
-cc_library_static {
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+    name: "android.hardware.graphics.mapper@2.0_genc++",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.graphics.mapper@2.0",
+    srcs: [
+        "types.hal",
+        "IMapper.hal",
+    ],
+    out: [
+        "android/hardware/graphics/mapper/2.0/types.cpp",
+        "android/hardware/graphics/mapper/2.0/MapperAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hardware.graphics.mapper@2.0_genc++_headers",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.graphics.mapper@2.0",
+    srcs: [
+        "types.hal",
+        "IMapper.hal",
+    ],
+    out: [
+        "android/hardware/graphics/mapper/2.0/types.h",
+        "android/hardware/graphics/mapper/2.0/IMapper.h",
+        "android/hardware/graphics/mapper/2.0/IHwMapper.h",
+        "android/hardware/graphics/mapper/2.0/BnMapper.h",
+        "android/hardware/graphics/mapper/2.0/BpMapper.h",
+        "android/hardware/graphics/mapper/2.0/BsMapper.h",
+    ],
+}
+
+cc_library_shared {
     name: "android.hardware.graphics.mapper@2.0",
-    export_include_dirs: ["include"],
+    generated_sources: ["android.hardware.graphics.mapper@2.0_genc++"],
+    generated_headers: ["android.hardware.graphics.mapper@2.0_genc++_headers"],
+    export_generated_headers: ["android.hardware.graphics.mapper@2.0_genc++_headers"],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "liblog",
+        "libutils",
+        "libcutils",
+        "android.hardware.graphics.allocator@2.0",
+        "android.hardware.graphics.common@1.0",
+        "android.hidl.base@1.0",
+    ],
+    export_shared_lib_headers: [
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "libutils",
+        "android.hardware.graphics.allocator@2.0",
+        "android.hardware.graphics.common@1.0",
+        "android.hidl.base@1.0",
+    ],
 }
diff --git a/graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/IMapper.h b/graphics/mapper/2.0/IMapper.hal
similarity index 62%
rename from graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/IMapper.h
rename to graphics/mapper/2.0/IMapper.hal
index ac8ec45..21a6dfa 100644
--- a/graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/IMapper.h
+++ b/graphics/mapper/2.0/IMapper.hal
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 The Android Open Source Project
+ * 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.
@@ -14,165 +14,135 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_IMAPPER_H
-#define ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_IMAPPER_H
+package android.hardware.graphics.mapper@2.0;
 
-#include <type_traits>
+import android.hardware.graphics.common@1.0::PixelFormat;
+import android.hardware.graphics.allocator@2.0;
 
-#include <android/hardware/graphics/mapper/2.0/types.h>
-
-extern "C" {
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace mapper {
-namespace V2_0 {
-
-struct Device {
+interface IMapper {
     struct Rect {
         int32_t left;
         int32_t top;
         int32_t width;
         int32_t height;
     };
-    static_assert(std::is_pod<Rect>::value, "Device::Rect is not POD");
-
-    /*
-     * Create a mapper device.
-     *
-     * @return error is NONE upon success. Otherwise,
-     *                  NOT_SUPPORTED when creation will never succeed.
-     *                  BAD_RESOURCES when creation failed at this time.
-     * @return device is the newly created mapper device.
-     */
-    typedef Error (*createDevice)(Device** outDevice);
-
-    /*
-     * Destroy a mapper device.
-     *
-     * @return error is always NONE.
-     * @param device is the mapper device to destroy.
-     */
-    typedef Error (*destroyDevice)(Device* device);
 
     /*
      * Adds a reference to the given buffer handle.
      *
      * A buffer handle received from a remote process or exported by
-     * IAllocator::exportHandle is unknown to this client-side library. There
-     * is also no guarantee that the buffer's backing store will stay alive.
-     * This function must be called at least once in both cases to intrdouce
-     * the buffer handle to this client-side library and to secure the backing
-     * store. It may also be called more than once to increase the reference
-     * count if two components in the same process want to interact with the
-     * buffer independently.
+     * IAllocator::exportHandle is unknown to the mapper. There is also no
+     * guarantee that the buffer's backing store will stay alive. This
+     * function must be called at least once in both cases to intrdouce the
+     * buffer handle to the mapper and to secure the backing store. It may
+     * also be called more than once to increase the reference count if two
+     * components in the same process want to interact with the buffer
+     * independently.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer to which a reference must be added.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid
      *                  NO_RESOURCES when it is not possible to add a
      *                               reference to this buffer at this time
      */
-    typedef Error (*retain)(Device* device,
-                            const native_handle_t* bufferHandle);
+    @entry
+    @callflow(next="*")
+    retain(handle bufferHandle) generates (Error error);
 
     /*
      * Removes a reference from the given buffer buffer.
      *
-     * If no references remain, the buffer handle should be freed with
-     * native_handle_close/native_handle_delete. When the last buffer handle
-     * referring to a particular backing store is freed, that backing store
-     * should also be freed.
+     * If no references remain, the buffer handle must be freed with
+     * native_handle_close/native_handle_delete by the mapper. When the last
+     * buffer handle referring to a particular backing store is freed, that
+     * backing store must also be freed.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which a reference must be
      *        removed.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      */
-    typedef Error (*release)(Device* device,
-                             const native_handle_t* bufferHandle);
+    @exit
+    release(handle bufferHandle) generates (Error error);
 
     /*
      * Gets the width and height of the buffer in pixels.
      *
      * See IAllocator::BufferDescriptorInfo for more information.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which to get the dimensions.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return width is the width of the buffer in pixels.
      * @return height is the height of the buffer in pixels.
      */
-    typedef Error (*getDimensions)(Device* device,
-                                   const native_handle_t* bufferHandle,
-                                   uint32_t* outWidth,
-                                   uint32_t* outHeight);
+    @callflow(next="*")
+    getDimensions(handle bufferHandle)
+       generates (Error error,
+                  uint32_t width,
+                  uint32_t height);
 
     /*
      * Gets the format of the buffer.
      *
      * See IAllocator::BufferDescriptorInfo for more information.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which to get format.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return format is the format of the buffer.
      */
-    typedef Error (*getFormat)(Device* device,
-                               const native_handle_t* bufferHandle,
-                               PixelFormat* outFormat);
+    @callflow(next="*")
+    getFormat(handle bufferHandle)
+        generates (Error error,
+                   PixelFormat format);
 
     /*
      * Gets the number of layers of the buffer.
      *
      * See IAllocator::BufferDescriptorInfo for more information.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which to get format.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return layerCount is the number of layers of the buffer.
      */
-    typedef Error (*getLayerCount)(Device* device,
-                               const native_handle_t* bufferHandle,
-                               uint32_t* outLayerCount);
+    @callflow(next="*")
+    getLayerCount(handle bufferHandle)
+       generates (Error error,
+                  uint32_t layerCount);
 
     /*
      * Gets the producer usage flags which were used to allocate this buffer.
      *
      * See IAllocator::BufferDescriptorInfo for more information.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which to get the producer usage
      *        flags.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return usageMask contains the producer usage flags of the buffer.
      */
-    typedef Error (*getProducerUsageMask)(Device* device,
-                                          const native_handle_t* bufferHandle,
-                                          uint64_t* outUsageMask);
+    @callflow(next="*")
+    getProducerUsageMask(handle bufferHandle)
+              generates (Error error,
+                         uint64_t usageMask);
 
     /*
      * Gets the consumer usage flags which were used to allocate this buffer.
      *
      * See IAllocator::BufferDescriptorInfo for more information.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer from which to get the consumer usage
      *        flags.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return usageMask contains the consumer usage flags of the buffer.
      */
-    typedef Error (*getConsumerUsageMask)(Device* device,
-                                          const native_handle_t* bufferHandle,
-                                          uint64_t* outUsageMask);
+    @callflow(next="*")
+    getConsumerUsageMask(handle bufferHandle)
+              generates (Error error,
+                         uint64_t usageMask);
 
     /*
      * Gets a value that uniquely identifies the backing store of the given
@@ -190,9 +160,10 @@
      *                  BAD_BUFFER when the buffer handle is invalid.
      * @return store is the backing store identifier for this buffer.
      */
-    typedef Error (*getBackingStore)(Device* device,
-                                     const native_handle_t* bufferHandle,
-                                     BackingStore* outStore);
+    @callflow(next="*")
+    getBackingStore(handle bufferHandle)
+         generates (Error error,
+                    BackingStore store);
 
     /*
      * Gets the stride of the buffer in pixels.
@@ -209,31 +180,10 @@
      *                            meaningful for the buffer format.
      * @return store is the stride in pixels.
      */
-    typedef Error (*getStride)(Device* device,
-                               const native_handle_t* bufferHandle,
-                               uint32_t* outStride);
-
-    /*
-     * Returns the number of flex layout planes which are needed to represent
-     * the given buffer. This may be used to efficiently allocate only as many
-     * plane structures as necessary before calling into lockFlex.
-     *
-     * If the given buffer cannot be locked as a flex format, this function
-     * may return UNSUPPORTED (as lockFlex would).
-     *
-     * @param device is the mapper device.
-     * @param bufferHandle is the buffer for which the number of planes should
-     *        be queried.
-     * @return error is NONE upon success. Otherwise,
-     *                  BAD_BUFFER when the buffer handle is invalid.
-     *                  UNSUPPORTED when the buffer's format cannot be
-     *                              represented in a flex layout.
-     * @return numPlanes is the number of flex planes required to describe the
-     *         given buffer.
-     */
-    typedef Error (*getNumFlexPlanes)(Device* device,
-                                      const native_handle_t* bufferHandle,
-                                      uint32_t* outNumPlanes);
+    @callflow(next="*")
+    getStride(handle bufferHandle)
+        generates (Error error,
+                   uint32_t stride);
 
     /*
      * Locks the given buffer for the specified CPU usage.
@@ -264,7 +214,6 @@
      * the contents of the buffer (prior to locking). If it is already safe to
      * access the buffer contents, -1 may be passed instead.
      *
-     * @param device is the mapper device.
      * @param bufferHandle is the buffer to lock.
      * @param producerUsageMask contains the producer usage flags to request;
      *        either this or consumerUsagemask must be 0, and the other must
@@ -289,13 +238,14 @@
      * @return data will be filled with a CPU-accessible pointer to the buffer
      *         data.
      */
-    typedef Error (*lock)(Device* device,
-                          const native_handle_t* bufferHandle,
-                          uint64_t producerUsageMask,
-                          uint64_t consumerUsageMask,
-                          const Rect* accessRegion,
-                          int32_t acquireFence,
-                          void** outData);
+    @callflow(next="unlock")
+    lock(handle bufferHandle,
+         uint64_t producerUsageMask,
+         uint64_t consumerUsageMask,
+         Rect accessRegion,
+         handle acquireFence)
+        generates (Error error,
+                   pointer data);
 
     /*
      * This is largely the same as lock(), except that instead of returning a
@@ -337,13 +287,14 @@
      * @return flexLayout will be filled with the description of the planes in
      *         the buffer.
      */
-    typedef Error (*lockFlex)(Device* device,
-                              const native_handle_t* bufferHandle,
-                              uint64_t producerUsageMask,
-                              uint64_t consumerUsageMask,
-                              const Rect* accessRegion,
-                              int32_t acquireFence,
-                              FlexLayout* outFlexLayout);
+    @callflow(next="unlock")
+    lockFlex(handle bufferHandle,
+             uint64_t producerUsageMask,
+             uint64_t consumerUsageMask,
+             Rect accessRegion,
+             handle acquireFence)
+        generates (Error error,
+                   FlexLayout layout);
 
     /*
      * This function indicates to the device that the client will be done with
@@ -365,40 +316,8 @@
      * @return releaseFence is a sync fence file descriptor as described
      *         above.
      */
-    typedef Error (*unlock)(Device* device,
-                            const native_handle_t* bufferHandle,
-                            int32_t* outReleaseFence);
+    @callflow(next="*")
+    unlock(handle bufferHandle)
+        generates (Error error,
+                   handle releaseFence);
 };
-static_assert(std::is_pod<Device>::value, "Device is not POD");
-
-struct IMapper {
-    Device::createDevice createDevice;
-    Device::destroyDevice destroyDevice;
-
-    Device::retain retain;
-    Device::release release;
-    Device::getDimensions getDimensions;
-    Device::getFormat getFormat;
-    Device::getLayerCount getLayerCount;
-    Device::getProducerUsageMask getProducerUsageMask;
-    Device::getConsumerUsageMask getConsumerUsageMask;
-    Device::getBackingStore getBackingStore;
-    Device::getStride getStride;
-    Device::getNumFlexPlanes getNumFlexPlanes;
-    Device::lock lock;
-    Device::lockFlex lockFlex;
-    Device::unlock unlock;
-};
-static_assert(std::is_pod<IMapper>::value, "IMapper is not POD");
-
-} // namespace V2_0
-} // namespace mapper
-} // namespace graphics
-} // namespace hardware
-} // namespace android
-
-const void* HALLIB_FETCH_Interface(const char* name);
-
-} // extern "C"
-
-#endif /* ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_IMAPPER_H */
diff --git a/graphics/mapper/2.0/default/Android.bp b/graphics/mapper/2.0/default/Android.bp
index 7da6eb1..02ed877 100644
--- a/graphics/mapper/2.0/default/Android.bp
+++ b/graphics/mapper/2.0/default/Android.bp
@@ -1,3 +1,4 @@
+//
 // Copyright (C) 2016 The Android Open Source Project
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,17 +14,19 @@
 // limitations under the License.
 
 cc_library_shared {
-    name: "android.hardware.graphics.mapper.hallib",
+    name: "android.hardware.graphics.mapper@2.0-impl",
     relative_install_path: "hw",
     srcs: ["GrallocMapper.cpp"],
     cppflags: ["-Wall", "-Wextra"],
-    static_libs: ["android.hardware.graphics.mapper@2.0"],
     shared_libs: [
-        "android.hardware.graphics.allocator@2.0",
+        "android.hardware.graphics.mapper@2.0",
+        "libbase",
+        "libcutils",
         "libhardware",
         "libhidlbase",
         "libhidltransport",
         "libhwbinder",
         "liblog",
+        "libutils",
     ],
 }
diff --git a/graphics/mapper/2.0/default/GrallocMapper.cpp b/graphics/mapper/2.0/default/GrallocMapper.cpp
index 2af1d2c..cd9db38 100644
--- a/graphics/mapper/2.0/default/GrallocMapper.cpp
+++ b/graphics/mapper/2.0/default/GrallocMapper.cpp
@@ -15,13 +15,15 @@
 
 #define LOG_TAG "GrallocMapperPassthrough"
 
-#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
-#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include "GrallocMapper.h"
+
+#include <vector>
+
+#include <string.h>
+
 #include <hardware/gralloc1.h>
 #include <log/log.h>
 
-#include <unordered_set>
-
 namespace android {
 namespace hardware {
 namespace graphics {
@@ -29,50 +31,59 @@
 namespace V2_0 {
 namespace implementation {
 
-using Capability = allocator::V2_0::IAllocator::Capability;
+namespace {
 
-class GrallocDevice : public Device {
+using android::hardware::graphics::allocator::V2_0::Error;
+using android::hardware::graphics::common::V1_0::PixelFormat;
+
+class GrallocMapperHal : public IMapper {
 public:
-    GrallocDevice();
-    ~GrallocDevice();
+    GrallocMapperHal(const hw_module_t* module);
+    ~GrallocMapperHal();
 
     // IMapper interface
-    Error retain(const native_handle_t* bufferHandle);
-    Error release(const native_handle_t* bufferHandle);
-    Error getDimensions(const native_handle_t* bufferHandle,
-            uint32_t* outWidth, uint32_t* outHeight);
-    Error getFormat(const native_handle_t* bufferHandle,
-            PixelFormat* outFormat);
-    Error getLayerCount(const native_handle_t* bufferHandle,
-            uint32_t* outLayerCount);
-    Error getProducerUsageMask(const native_handle_t* bufferHandle,
-            uint64_t* outUsageMask);
-    Error getConsumerUsageMask(const native_handle_t* bufferHandle,
-            uint64_t* outUsageMask);
-    Error getBackingStore(const native_handle_t* bufferHandle,
-            BackingStore* outStore);
-    Error getStride(const native_handle_t* bufferHandle, uint32_t* outStride);
-    Error getNumFlexPlanes(const native_handle_t* bufferHandle,
-            uint32_t* outNumPlanes);
-    Error lock(const native_handle_t* bufferHandle,
+    Return<Error> retain(const hidl_handle& bufferHandle) override;
+    Return<Error> release(const hidl_handle& bufferHandle) override;
+    Return<void> getDimensions(const hidl_handle& bufferHandle,
+            getDimensions_cb hidl_cb) override;
+    Return<void> getFormat(const hidl_handle& bufferHandle,
+            getFormat_cb hidl_cb) override;
+    Return<void> getLayerCount(const hidl_handle& bufferHandle,
+            getLayerCount_cb hidl_cb) override;
+    Return<void> getProducerUsageMask(const hidl_handle& bufferHandle,
+            getProducerUsageMask_cb hidl_cb) override;
+    Return<void> getConsumerUsageMask(const hidl_handle& bufferHandle,
+            getConsumerUsageMask_cb hidl_cb) override;
+    Return<void> getBackingStore(const hidl_handle& bufferHandle,
+            getBackingStore_cb hidl_cb) override;
+    Return<void> getStride(const hidl_handle& bufferHandle,
+            getStride_cb hidl_cb) override;
+    Return<void> lock(const hidl_handle& bufferHandle,
             uint64_t producerUsageMask, uint64_t consumerUsageMask,
-            const Rect* accessRegion, int32_t acquireFence, void** outData);
-    Error lockFlex(const native_handle_t* bufferHandle,
+            const IMapper::Rect& accessRegion, const hidl_handle& acquireFence,
+            lock_cb hidl_cb) override;
+    Return<void> lockFlex(const hidl_handle& bufferHandle,
             uint64_t producerUsageMask, uint64_t consumerUsageMask,
-            const Rect* accessRegion, int32_t acquireFence,
-            FlexLayout* outFlexLayout);
-    Error unlock(const native_handle_t* bufferHandle,
-            int32_t* outReleaseFence);
+            const IMapper::Rect& accessRegion, const hidl_handle& acquireFence,
+            lockFlex_cb hidl_cb) override;
+    Return<void> unlock(const hidl_handle& bufferHandle,
+            unlock_cb hidl_cb) override;
 
 private:
     void initCapabilities();
 
+    template<typename T>
+    void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn);
     void initDispatch();
-    bool hasCapability(Capability capability) const;
+
+    static gralloc1_rect_t asGralloc1Rect(const IMapper::Rect& rect);
+    static bool dupFence(const hidl_handle& fenceHandle, int* outFd);
 
     gralloc1_device_t* mDevice;
 
-    std::unordered_set<Capability> mCapabilities;
+    struct {
+        bool layeredBuffers;
+    } mCapabilities;
 
     struct {
         GRALLOC1_PFN_RETAIN retain;
@@ -91,333 +102,293 @@
     } mDispatch;
 };
 
-GrallocDevice::GrallocDevice()
+GrallocMapperHal::GrallocMapperHal(const hw_module_t* module)
+    : mDevice(nullptr), mCapabilities(), mDispatch()
 {
-    const hw_module_t* module;
-    int status = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
+    int status = gralloc1_open(module, &mDevice);
     if (status) {
-        LOG_ALWAYS_FATAL("failed to get gralloc module");
-    }
-
-    uint8_t major = (module->module_api_version >> 8) & 0xff;
-    if (major != 1) {
-        LOG_ALWAYS_FATAL("unknown gralloc module major version %d", major);
-    }
-
-    status = gralloc1_open(module, &mDevice);
-    if (status) {
-        LOG_ALWAYS_FATAL("failed to open gralloc1 device");
+        LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s",
+                strerror(-status));
     }
 
     initCapabilities();
     initDispatch();
 }
 
-GrallocDevice::~GrallocDevice()
+GrallocMapperHal::~GrallocMapperHal()
 {
     gralloc1_close(mDevice);
 }
 
-void GrallocDevice::initCapabilities()
+void GrallocMapperHal::initCapabilities()
 {
     uint32_t count;
     mDevice->getCapabilities(mDevice, &count, nullptr);
 
-    std::vector<Capability> caps(count);
-    mDevice->getCapabilities(mDevice, &count, reinterpret_cast<
-              std::underlying_type<Capability>::type*>(caps.data()));
+    std::vector<int32_t> caps(count);
+    mDevice->getCapabilities(mDevice, &count, caps.data());
     caps.resize(count);
 
-    mCapabilities.insert(caps.cbegin(), caps.cend());
-}
-
-void GrallocDevice::initDispatch()
-{
-#define CHECK_FUNC(func, desc) do {                                   \
-    mDispatch.func = reinterpret_cast<decltype(mDispatch.func)>(      \
-        mDevice->getFunction(mDevice, desc));                         \
-    if (!mDispatch.func) {                                            \
-        LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc); \
-    }                                                                 \
-} while (0)
-
-    CHECK_FUNC(retain, GRALLOC1_FUNCTION_RETAIN);
-    CHECK_FUNC(release, GRALLOC1_FUNCTION_RELEASE);
-    CHECK_FUNC(getDimensions, GRALLOC1_FUNCTION_GET_DIMENSIONS);
-    CHECK_FUNC(getFormat, GRALLOC1_FUNCTION_GET_FORMAT);
-    if (hasCapability(Capability::LAYERED_BUFFERS)) {
-        CHECK_FUNC(getLayerCount, GRALLOC1_FUNCTION_GET_LAYER_COUNT);
+    for (auto cap : caps) {
+        switch (cap) {
+        case GRALLOC1_CAPABILITY_LAYERED_BUFFERS:
+            mCapabilities.layeredBuffers = true;
+            break;
+        default:
+            break;
+        }
     }
-    CHECK_FUNC(getProducerUsage, GRALLOC1_FUNCTION_GET_PRODUCER_USAGE);
-    CHECK_FUNC(getConsumerUsage, GRALLOC1_FUNCTION_GET_CONSUMER_USAGE);
-    CHECK_FUNC(getBackingStore, GRALLOC1_FUNCTION_GET_BACKING_STORE);
-    CHECK_FUNC(getStride, GRALLOC1_FUNCTION_GET_STRIDE);
-    CHECK_FUNC(getNumFlexPlanes, GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES);
-    CHECK_FUNC(lock, GRALLOC1_FUNCTION_LOCK);
-    CHECK_FUNC(lockFlex, GRALLOC1_FUNCTION_LOCK_FLEX);
-    CHECK_FUNC(unlock, GRALLOC1_FUNCTION_UNLOCK);
-
-#undef CHECK_FUNC
 }
 
-bool GrallocDevice::hasCapability(Capability capability) const
+template<typename T>
+void GrallocMapperHal::initDispatch(gralloc1_function_descriptor_t desc,
+        T* outPfn)
 {
-    return (mCapabilities.count(capability) > 0);
+    auto pfn = mDevice->getFunction(mDevice, desc);
+    if (!pfn) {
+        LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc);
+    }
+
+    *outPfn = reinterpret_cast<T>(pfn);
 }
 
-Error GrallocDevice::retain(const native_handle_t* bufferHandle)
+void GrallocMapperHal::initDispatch()
 {
-    int32_t error = mDispatch.retain(mDevice, bufferHandle);
-    return static_cast<Error>(error);
+    initDispatch(GRALLOC1_FUNCTION_RETAIN, &mDispatch.retain);
+    initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release);
+    initDispatch(GRALLOC1_FUNCTION_GET_DIMENSIONS, &mDispatch.getDimensions);
+    initDispatch(GRALLOC1_FUNCTION_GET_FORMAT, &mDispatch.getFormat);
+    if (mCapabilities.layeredBuffers) {
+        initDispatch(GRALLOC1_FUNCTION_GET_LAYER_COUNT,
+                &mDispatch.getLayerCount);
+    }
+    initDispatch(GRALLOC1_FUNCTION_GET_PRODUCER_USAGE,
+            &mDispatch.getProducerUsage);
+    initDispatch(GRALLOC1_FUNCTION_GET_CONSUMER_USAGE,
+            &mDispatch.getConsumerUsage);
+    initDispatch(GRALLOC1_FUNCTION_GET_BACKING_STORE,
+            &mDispatch.getBackingStore);
+    initDispatch(GRALLOC1_FUNCTION_GET_STRIDE, &mDispatch.getStride);
+    initDispatch(GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES,
+            &mDispatch.getNumFlexPlanes);
+    initDispatch(GRALLOC1_FUNCTION_LOCK, &mDispatch.lock);
+    initDispatch(GRALLOC1_FUNCTION_LOCK_FLEX, &mDispatch.lockFlex);
+    initDispatch(GRALLOC1_FUNCTION_UNLOCK, &mDispatch.unlock);
 }
 
-Error GrallocDevice::release(const native_handle_t* bufferHandle)
+gralloc1_rect_t GrallocMapperHal::asGralloc1Rect(const IMapper::Rect& rect)
 {
-    int32_t error = mDispatch.release(mDevice, bufferHandle);
-    return static_cast<Error>(error);
+    return gralloc1_rect_t{rect.left, rect.top, rect.width, rect.height};
 }
 
-Error GrallocDevice::getDimensions(const native_handle_t* bufferHandle,
-        uint32_t* outWidth, uint32_t* outHeight)
+bool GrallocMapperHal::dupFence(const hidl_handle& fenceHandle, int* outFd)
 {
-    int32_t error = mDispatch.getDimensions(mDevice, bufferHandle,
-            outWidth, outHeight);
-    return static_cast<Error>(error);
+    auto handle = fenceHandle.getNativeHandle();
+    if (!handle || handle->numFds == 0) {
+        *outFd = -1;
+        return true;
+    }
+
+    if (handle->numFds > 1) {
+        ALOGE("invalid fence handle with %d fds", handle->numFds);
+        return false;
+    }
+
+    *outFd = dup(handle->data[0]);
+    return (*outFd >= 0);
 }
 
-Error GrallocDevice::getFormat(const native_handle_t* bufferHandle,
-        PixelFormat* outFormat)
+Return<Error> GrallocMapperHal::retain(const hidl_handle& bufferHandle)
 {
-    int32_t error = mDispatch.getFormat(mDevice, bufferHandle,
-            reinterpret_cast<int32_t*>(outFormat));
-    return static_cast<Error>(error);
+    int32_t err = mDispatch.retain(mDevice, bufferHandle);
+    return static_cast<Error>(err);
 }
 
-Error GrallocDevice::getLayerCount(const native_handle_t* bufferHandle,
-        uint32_t* outLayerCount)
+Return<Error> GrallocMapperHal::release(const hidl_handle& bufferHandle)
 {
-    if (hasCapability(Capability::LAYERED_BUFFERS)) {
-        int32_t error = mDispatch.getLayerCount(mDevice, bufferHandle,
-                outLayerCount);
-        return static_cast<Error>(error);
+    int32_t err = mDispatch.release(mDevice, bufferHandle);
+    return static_cast<Error>(err);
+}
+
+Return<void> GrallocMapperHal::getDimensions(const hidl_handle& bufferHandle,
+        getDimensions_cb hidl_cb)
+{
+    uint32_t width = 0;
+    uint32_t height = 0;
+    int32_t err = mDispatch.getDimensions(mDevice, bufferHandle,
+            &width, &height);
+
+    hidl_cb(static_cast<Error>(err), width, height);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getFormat(const hidl_handle& bufferHandle,
+        getFormat_cb hidl_cb)
+{
+    int32_t format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+    int32_t err = mDispatch.getFormat(mDevice, bufferHandle, &format);
+
+    hidl_cb(static_cast<Error>(err), static_cast<PixelFormat>(format));
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getLayerCount(const hidl_handle& bufferHandle,
+        getLayerCount_cb hidl_cb)
+{
+    int32_t err = GRALLOC1_ERROR_NONE;
+    uint32_t count = 1;
+    if (mCapabilities.layeredBuffers) {
+        err = mDispatch.getLayerCount(mDevice, bufferHandle, &count);
+    }
+
+    hidl_cb(static_cast<Error>(err), count);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getProducerUsageMask(
+        const hidl_handle& bufferHandle, getProducerUsageMask_cb hidl_cb)
+{
+    uint64_t mask = 0x0;
+    int32_t err = mDispatch.getProducerUsage(mDevice, bufferHandle, &mask);
+
+    hidl_cb(static_cast<Error>(err), mask);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getConsumerUsageMask(
+        const hidl_handle& bufferHandle, getConsumerUsageMask_cb hidl_cb)
+{
+    uint64_t mask = 0x0;
+    int32_t err = mDispatch.getConsumerUsage(mDevice, bufferHandle, &mask);
+
+    hidl_cb(static_cast<Error>(err), mask);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getBackingStore(
+        const hidl_handle& bufferHandle, getBackingStore_cb hidl_cb)
+{
+    uint64_t store = 0;
+    int32_t err = mDispatch.getBackingStore(mDevice, bufferHandle, &store);
+
+    hidl_cb(static_cast<Error>(err), store);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::getStride(const hidl_handle& bufferHandle,
+        getStride_cb hidl_cb)
+{
+    uint32_t stride = 0;
+    int32_t err = mDispatch.getStride(mDevice, bufferHandle, &stride);
+
+    hidl_cb(static_cast<Error>(err), stride);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::lock(const hidl_handle& bufferHandle,
+        uint64_t producerUsageMask, uint64_t consumerUsageMask,
+        const IMapper::Rect& accessRegion, const hidl_handle& acquireFence,
+        lock_cb hidl_cb)
+{
+    gralloc1_rect_t rect = asGralloc1Rect(accessRegion);
+
+    int fence = -1;
+    if (!dupFence(acquireFence, &fence)) {
+        hidl_cb(Error::NO_RESOURCES, nullptr);
+        return Void();
+    }
+
+    void* data = nullptr;
+    int32_t err = mDispatch.lock(mDevice, bufferHandle, producerUsageMask,
+            consumerUsageMask, &rect, &data, fence);
+    if (err != GRALLOC1_ERROR_NONE) {
+        close(fence);
+    }
+
+    hidl_cb(static_cast<Error>(err), data);
+    return Void();
+}
+
+Return<void> GrallocMapperHal::lockFlex(const hidl_handle& bufferHandle,
+        uint64_t producerUsageMask, uint64_t consumerUsageMask,
+        const IMapper::Rect& accessRegion, const hidl_handle& acquireFence,
+        lockFlex_cb hidl_cb)
+{
+    FlexLayout layout_reply{};
+
+    uint32_t planeCount = 0;
+    int32_t err = mDispatch.getNumFlexPlanes(mDevice, bufferHandle,
+            &planeCount);
+    if (err != GRALLOC1_ERROR_NONE) {
+        hidl_cb(static_cast<Error>(err), layout_reply);
+        return Void();
+    }
+
+    gralloc1_rect_t rect = asGralloc1Rect(accessRegion);
+
+    int fence = -1;
+    if (!dupFence(acquireFence, &fence)) {
+        hidl_cb(Error::NO_RESOURCES, layout_reply);
+        return Void();
+    }
+
+    std::vector<android_flex_plane_t> planes(planeCount);
+    android_flex_layout_t layout{};
+    layout.num_planes = planes.size();
+    layout.planes = planes.data();
+
+    err = mDispatch.lockFlex(mDevice, bufferHandle, producerUsageMask,
+            consumerUsageMask, &rect, &layout, fence);
+    if (err == GRALLOC1_ERROR_NONE) {
+        layout_reply.format = static_cast<FlexFormat>(layout.format);
+
+        planes.resize(layout.num_planes);
+        layout_reply.planes.setToExternal(
+                reinterpret_cast<FlexPlane*>(planes.data()), planes.size());
     } else {
-        *outLayerCount = 1;
-        return Error::NONE;
+        close(fence);
     }
+
+    hidl_cb(static_cast<Error>(err), layout_reply);
+    return Void();
 }
 
-Error GrallocDevice::getProducerUsageMask(const native_handle_t* bufferHandle,
-        uint64_t* outUsageMask)
+Return<void> GrallocMapperHal::unlock(const hidl_handle& bufferHandle,
+        unlock_cb hidl_cb)
 {
-    int32_t error = mDispatch.getProducerUsage(mDevice, bufferHandle,
-            outUsageMask);
-    return static_cast<Error>(error);
+    int32_t fence = -1;
+    int32_t err = mDispatch.unlock(mDevice, bufferHandle, &fence);
+
+    NATIVE_HANDLE_DECLARE_STORAGE(fenceStorage, 1, 0);
+    hidl_handle fenceHandle;
+    if (err == GRALLOC1_ERROR_NONE && fence >= 0) {
+        auto nativeHandle = native_handle_init(fenceStorage, 1, 0);
+        nativeHandle->data[0] = fence;
+
+        fenceHandle = nativeHandle;
+    }
+
+    hidl_cb(static_cast<Error>(err), fenceHandle);
+    return Void();
 }
 
-Error GrallocDevice::getConsumerUsageMask(const native_handle_t* bufferHandle,
-        uint64_t* outUsageMask)
-{
-    int32_t error = mDispatch.getConsumerUsage(mDevice, bufferHandle,
-            outUsageMask);
-    return static_cast<Error>(error);
-}
+} // anonymous namespace
 
-Error GrallocDevice::getBackingStore(const native_handle_t* bufferHandle,
-        BackingStore* outStore)
-{
-    int32_t error = mDispatch.getBackingStore(mDevice, bufferHandle,
-            outStore);
-    return static_cast<Error>(error);
-}
-
-Error GrallocDevice::getStride(const native_handle_t* bufferHandle,
-        uint32_t* outStride)
-{
-    int32_t error = mDispatch.getStride(mDevice, bufferHandle, outStride);
-    return static_cast<Error>(error);
-}
-
-Error GrallocDevice::getNumFlexPlanes(const native_handle_t* bufferHandle,
-        uint32_t* outNumPlanes)
-{
-    int32_t error = mDispatch.getNumFlexPlanes(mDevice, bufferHandle,
-            outNumPlanes);
-    return static_cast<Error>(error);
-}
-
-Error GrallocDevice::lock(const native_handle_t* bufferHandle,
-        uint64_t producerUsageMask, uint64_t consumerUsageMask,
-        const Rect* accessRegion, int32_t acquireFence,
-        void** outData)
-{
-    int32_t error = mDispatch.lock(mDevice, bufferHandle,
-            producerUsageMask, consumerUsageMask,
-            reinterpret_cast<const gralloc1_rect_t*>(accessRegion),
-            outData, acquireFence);
-    return static_cast<Error>(error);
-}
-
-Error GrallocDevice::lockFlex(const native_handle_t* bufferHandle,
-        uint64_t producerUsageMask, uint64_t consumerUsageMask,
-        const Rect* accessRegion, int32_t acquireFence,
-        FlexLayout* outFlexLayout)
-{
-    int32_t error = mDispatch.lockFlex(mDevice, bufferHandle,
-            producerUsageMask, consumerUsageMask,
-            reinterpret_cast<const gralloc1_rect_t*>(accessRegion),
-            reinterpret_cast<android_flex_layout_t*>(outFlexLayout),
-            acquireFence);
-    return static_cast<Error>(error);
-}
-
-Error GrallocDevice::unlock(const native_handle_t* bufferHandle,
-        int32_t* outReleaseFence)
-{
-    int32_t error = mDispatch.unlock(mDevice, bufferHandle, outReleaseFence);
-    return static_cast<Error>(error);
-}
-
-class GrallocMapper : public IMapper {
-public:
-    GrallocMapper() : IMapper{
-        .createDevice = createDevice,
-        .destroyDevice = destroyDevice,
-        .retain = retain,
-        .release = release,
-        .getDimensions = getDimensions,
-        .getFormat = getFormat,
-        .getLayerCount = getLayerCount,
-        .getProducerUsageMask = getProducerUsageMask,
-        .getConsumerUsageMask = getConsumerUsageMask,
-        .getBackingStore = getBackingStore,
-        .getStride = getStride,
-        .getNumFlexPlanes = getNumFlexPlanes,
-        .lock = lock,
-        .lockFlex = lockFlex,
-        .unlock = unlock,
-    } {}
-
-    const IMapper* getInterface() const
-    {
-        return static_cast<const IMapper*>(this);
+IMapper* HIDL_FETCH_IMapper(const char* /* name */) {
+    const hw_module_t* module = nullptr;
+    int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
+    if (err) {
+        ALOGE("failed to get gralloc module");
+        return nullptr;
     }
 
-private:
-    static GrallocDevice* cast(Device* device)
-    {
-        return reinterpret_cast<GrallocDevice*>(device);
+    uint8_t major = (module->module_api_version >> 8) & 0xff;
+    if (major != 1) {
+        ALOGE("unknown gralloc module major version %d", major);
+        return nullptr;
     }
 
-    static Error createDevice(Device** outDevice)
-    {
-        *outDevice = new GrallocDevice;
-        return Error::NONE;
-    }
-
-    static Error destroyDevice(Device* device)
-    {
-        delete cast(device);
-        return Error::NONE;
-    }
-
-    static Error retain(Device* device,
-            const native_handle_t* bufferHandle)
-    {
-        return cast(device)->retain(bufferHandle);
-    }
-
-    static Error release(Device* device,
-            const native_handle_t* bufferHandle)
-    {
-        return cast(device)->release(bufferHandle);
-    }
-
-    static Error getDimensions(Device* device,
-            const native_handle_t* bufferHandle,
-            uint32_t* outWidth, uint32_t* outHeight)
-    {
-        return cast(device)->getDimensions(bufferHandle, outWidth, outHeight);
-    }
-
-    static Error getFormat(Device* device,
-            const native_handle_t* bufferHandle, PixelFormat* outFormat)
-    {
-        return cast(device)->getFormat(bufferHandle, outFormat);
-    }
-
-    static Error getLayerCount(Device* device,
-            const native_handle_t* bufferHandle, uint32_t* outLayerCount)
-    {
-        return cast(device)->getLayerCount(bufferHandle, outLayerCount);
-    }
-
-    static Error getProducerUsageMask(Device* device,
-            const native_handle_t* bufferHandle, uint64_t* outUsageMask)
-    {
-        return cast(device)->getProducerUsageMask(bufferHandle, outUsageMask);
-    }
-
-    static Error getConsumerUsageMask(Device* device,
-            const native_handle_t* bufferHandle, uint64_t* outUsageMask)
-    {
-        return cast(device)->getConsumerUsageMask(bufferHandle, outUsageMask);
-    }
-
-    static Error getBackingStore(Device* device,
-            const native_handle_t* bufferHandle, BackingStore* outStore)
-    {
-        return cast(device)->getBackingStore(bufferHandle, outStore);
-    }
-
-    static Error getStride(Device* device,
-            const native_handle_t* bufferHandle, uint32_t* outStride)
-    {
-        return cast(device)->getStride(bufferHandle, outStride);
-    }
-
-    static Error getNumFlexPlanes(Device* device,
-            const native_handle_t* bufferHandle, uint32_t* outNumPlanes)
-    {
-        return cast(device)->getNumFlexPlanes(bufferHandle, outNumPlanes);
-    }
-
-    static Error lock(Device* device,
-            const native_handle_t* bufferHandle,
-            uint64_t producerUsageMask, uint64_t consumerUsageMask,
-            const Device::Rect* accessRegion, int32_t acquireFence,
-            void** outData)
-    {
-        return cast(device)->lock(bufferHandle,
-                producerUsageMask, consumerUsageMask,
-                accessRegion, acquireFence, outData);
-    }
-
-    static Error lockFlex(Device* device,
-            const native_handle_t* bufferHandle,
-            uint64_t producerUsageMask, uint64_t consumerUsageMask,
-            const Device::Rect* accessRegion, int32_t acquireFence,
-            FlexLayout* outFlexLayout)
-    {
-        return cast(device)->lockFlex(bufferHandle,
-                producerUsageMask, consumerUsageMask,
-                accessRegion, acquireFence, outFlexLayout);
-    }
-
-    static Error unlock(Device* device,
-            const native_handle_t* bufferHandle, int32_t* outReleaseFence)
-    {
-        return cast(device)->unlock(bufferHandle, outReleaseFence);
-    }
-};
-
-extern "C" const void* HALLIB_FETCH_Interface(const char* name)
-{
-    if (strcmp(name, "android.hardware.graphics.mapper@2.0::IMapper") == 0) {
-        static GrallocMapper sGrallocMapper;
-        return sGrallocMapper.getInterface();
-    }
-
-    return nullptr;
+    return new GrallocMapperHal(module);
 }
 
 } // namespace implementation
diff --git a/graphics/mapper/2.0/default/GrallocMapper.h b/graphics/mapper/2.0/default/GrallocMapper.h
new file mode 100644
index 0000000..a2f89d1
--- /dev/null
+++ b/graphics/mapper/2.0/default/GrallocMapper.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 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_GRAPHICS_MAPPER_V2_0_GRALLOC_MAPPER_H
+#define ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_GRALLOC_MAPPER_H
+
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace mapper {
+namespace V2_0 {
+namespace implementation {
+
+extern "C" IMapper* HIDL_FETCH_IMapper(const char* name);
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace mapper
+} // namespace graphics
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_GRALLOC_MAPPER_H
diff --git a/graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/types.h b/graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/types.h
deleted file mode 100644
index 4054b82..0000000
--- a/graphics/mapper/2.0/include/android/hardware/graphics/mapper/2.0/types.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 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_GRAPHICS_MAPPER_V2_0_TYPES_H
-#define ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H
-
-#include <type_traits>
-
-#include <android/hardware/graphics/allocator/2.0/types.h>
-#include <android/hardware/graphics/common/1.0/types.h>
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace mapper {
-namespace V2_0 {
-
-using android::hardware::graphics::allocator::V2_0::Error;
-using android::hardware::graphics::allocator::V2_0::ProducerUsage;
-using android::hardware::graphics::allocator::V2_0::ConsumerUsage;
-using android::hardware::graphics::common::V1_0::PixelFormat;
-
-/*
- * Structures for describing flexible YUVA/RGBA formats for consumption by
- * applications. Such flexible formats contain a plane for each component
- * (e.g.  red, green, blue), where each plane is laid out in a grid-like
- * pattern occupying unique byte addresses and with consistent byte offsets
- * between neighboring pixels.
- *
- * The FlexLayout structure is used with any pixel format that can be
- * represented by it, such as:
- *
- *  - PixelFormat::YCbCr_*_888
- *  - PixelFormat::FLEX_RGB*_888
- *  - PixelFormat::RGB[AX]_888[8],BGRA_8888,RGB_888
- *  - PixelFormat::YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
- *  - even implementation defined formats that can be represented by the
- *    structures
- *
- * Vertical increment (aka. row increment or stride) describes the distance in
- * bytes from the first pixel of one row to the first pixel of the next row
- * (below) for the component plane. This can be negative.
- *
- * Horizontal increment (aka. column or pixel increment) describes the
- * distance in bytes from one pixel to the next pixel (to the right) on the
- * same row for the component plane. This can be negative.
- *
- * Each plane can be subsampled either vertically or horizontally by a
- * power-of-two factor.
- *
- * The bit-depth of each component can be arbitrary, as long as the pixels are
- * laid out on whole bytes, in native byte-order, using the most significant
- * bits of each unit.
- */
-
-enum class FlexComponent : int32_t {
-    Y          = 1 << 0,  /* luma */
-    Cb         = 1 << 1,  /* chroma blue */
-    Cr         = 1 << 2,  /* chroma red */
-
-    R          = 1 << 10, /* red */
-    G          = 1 << 11, /* green */
-    B          = 1 << 12, /* blue */
-
-    A          = 1 << 30, /* alpha */
-};
-
-inline FlexComponent operator|(FlexComponent lhs, FlexComponent rhs)
-{
-    return static_cast<FlexComponent>(static_cast<int32_t>(lhs) |
-                                      static_cast<int32_t>(rhs));
-}
-
-inline FlexComponent& operator|=(FlexComponent &lhs, FlexComponent rhs)
-{
-    lhs = static_cast<FlexComponent>(static_cast<int32_t>(lhs) |
-                                     static_cast<int32_t>(rhs));
-    return lhs;
-}
-
-enum class FlexFormat : int32_t {
-    /* not a flexible format */
-    INVALID    = 0x0,
-
-    Y          = static_cast<int32_t>(FlexComponent::Y),
-    YCbCr      = static_cast<int32_t>(FlexComponent::Y) |
-                 static_cast<int32_t>(FlexComponent::Cb) |
-                 static_cast<int32_t>(FlexComponent::Cr),
-    YCbCrA     = static_cast<int32_t>(YCbCr) |
-                 static_cast<int32_t>(FlexComponent::A),
-    RGB        = static_cast<int32_t>(FlexComponent::R) |
-                 static_cast<int32_t>(FlexComponent::G) |
-                 static_cast<int32_t>(FlexComponent::B),
-    RGBA       = static_cast<int32_t>(RGB) |
-                 static_cast<int32_t>(FlexComponent::A),
-};
-
-struct FlexPlane {
-    /* pointer to the first byte of the top-left pixel of the plane. */
-    uint8_t *topLeft;
-
-    FlexComponent component;
-
-    /*
-     * bits allocated for the component in each pixel. Must be a positive
-     * multiple of 8.
-     */
-    int32_t bitsPerComponent;
-
-    /*
-     * number of the most significant bits used in the format for this
-     * component. Must be between 1 and bits_per_component, inclusive.
-     */
-    int32_t bitsUsed;
-
-    /* horizontal increment */
-    int32_t hIncrement;
-    /* vertical increment */
-    int32_t vIncrement;
-
-    /* horizontal subsampling. Must be a positive power of 2. */
-    int32_t hSubsampling;
-    /* vertical subsampling. Must be a positive power of 2. */
-    int32_t vSubsampling;
-};
-static_assert(std::is_pod<FlexPlane>::value, "FlexPlane is not POD");
-
-struct FlexLayout {
-    /* the kind of flexible format */
-    FlexFormat format;
-
-    /* number of planes; 0 for FLEX_FORMAT_INVALID */
-    uint32_t numPlanes;
-
-    /*
-     * a plane for each component; ordered in increasing component value order.
-     * E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc.
-     * Can be NULL for FLEX_FORMAT_INVALID
-     */
-    FlexPlane* planes;
-};
-static_assert(std::is_pod<FlexLayout>::value, "FlexLayout is not POD");
-
-typedef uint64_t BackingStore;
-
-} // namespace V2_0
-} // namespace mapper
-} // namespace graphics
-} // namespace hardware
-} // namespace android
-
-#endif /* ANDROID_HARDWARE_GRAPHICS_MAPPER_V2_0_TYPES_H */
diff --git a/graphics/mapper/2.0/types.hal b/graphics/mapper/2.0/types.hal
new file mode 100644
index 0000000..aa33141
--- /dev/null
+++ b/graphics/mapper/2.0/types.hal
@@ -0,0 +1,116 @@
+/*
+ * 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.
+ */
+
+package android.hardware.graphics.mapper@2.0;
+
+/*
+ * Structures for describing flexible YUVA/RGBA formats for consumption by
+ * applications. Such flexible formats contain a plane for each component (e.g.
+ * red, green, blue), where each plane is laid out in a grid-like pattern
+ * occupying unique byte addresses and with consistent byte offsets between
+ * neighboring pixels.
+ *
+ * The FlexLayout structure is used with any pixel format that can be
+ * represented by it, such as:
+ *  - PixelFormat::YCBCR_*_888
+ *  - PixelFormat::FLEX_RGB*_888
+ *  - PixelFormat::RGB[AX]_888[8],BGRA_8888,RGB_888
+ *  - PixelFormat::YV12,Y8,Y16,YCBCR_422_SP/I,YCRCB_420_SP
+ *  - even implementation defined formats that can be represented by
+ *    the structures
+ *
+ * Vertical increment (aka. row increment or stride) describes the distance in
+ * bytes from the first pixel of one row to the first pixel of the next row
+ * (below) for the component plane. This can be negative.
+ *
+ * Horizontal increment (aka. column or pixel increment) describes the distance
+ * in bytes from one pixel to the next pixel (to the right) on the same row for
+ * the component plane. This can be negative.
+ *
+ * Each plane can be subsampled either vertically or horizontally by
+ * a power-of-two factor.
+ *
+ * The bit-depth of each component can be arbitrary, as long as the pixels are
+ * laid out on whole bytes, in native byte-order, using the most significant
+ * bits of each unit.
+ */
+
+enum FlexComponent : int32_t {
+    Y  = 1 << 0, /* luma */
+    CB = 1 << 1, /* chroma blue */
+    CR = 1 << 2, /* chroma red */
+
+    R  = 1 << 10, /* red */
+    G  = 1 << 11, /* green */
+    B  = 1 << 12, /* blue */
+
+    A  = 1 << 30, /* alpha */
+};
+
+enum FlexFormat : int32_t {
+    /* not a flexible format */
+    INVALID = 0x0,
+
+    Y       = FlexComponent:Y,
+    YCBCR   = Y | FlexComponent:CB | FlexComponent:CR,
+    YCBCRA  = YCBCR | FlexComponent:A,
+
+    RGB     = FlexComponent:R | FlexComponent:G | FlexComponent:B,
+    RGBA    = RGB | FlexComponent:A,
+};
+
+struct FlexPlane {
+    /* Pointer to the first byte of the top-left pixel of the plane. */
+    pointer topLeft;
+
+    FlexComponent component;
+
+    /*
+     * Bits allocated for the component in each pixel. Must be a positive
+     * multiple of 8.
+     */
+    int32_t bitsPerComponent;
+
+    /*
+     * Number of the most significant bits used in the format for this
+     * component. Must be between 1 and bitsPerComponent, inclusive.
+     */
+    int32_t bitsUsed;
+
+    /* Horizontal increment. */
+    int32_t hIncrement;
+    /* Vertical increment. */
+    int32_t vIncrement;
+    /* Horizontal subsampling. Must be a positive power of 2. */
+    int32_t hSubsampling;
+    /* Vertical subsampling. Must be a positive power of 2. */
+    int32_t vSubsampling;
+};
+
+struct FlexLayout {
+    /* The kind of flexible format. */
+    FlexFormat format;
+
+    /*
+     * A plane for each component; ordered in increasing component value
+     * order. E.g. FlexFormat::RGBA maps 0 -> R, 1 -> G, etc.  Can have size 0
+     * for FlexFormat::INVALID.
+     */
+    vec<FlexPlane> planes;
+};
+
+/* Backing store ID of a buffer. See IMapper::getBackingStore. */
+typedef uint64_t BackingStore;
diff --git a/vehicle/2.0/default/tests/VehicleHalManager_test.cpp b/vehicle/2.0/default/tests/VehicleHalManager_test.cpp
index 964c7c8..dffcfbb 100644
--- a/vehicle/2.0/default/tests/VehicleHalManager_test.cpp
+++ b/vehicle/2.0/default/tests/VehicleHalManager_test.cpp
@@ -67,6 +67,14 @@
                     pValue = getValuePool()->obtainFloat(42.42);
                 }
                 break;
+            case VehicleProperty::VEHICLE_MAPS_DATA_SERVICE:
+                pValue = getValuePool()->obtainComplex();
+                pValue->value.int32Values = hidl_vec<int32_t> { 10, 20 };
+                pValue->value.int64Values = hidl_vec<int64_t> { 30, 40 };
+                pValue->value.floatValues = hidl_vec<float_t> { 1.1, 2.2 };
+                pValue->value.bytes = hidl_vec<uint8_t> { 1, 2, 3 };
+                pValue->value.stringValue = kCarMake;
+                break;
             default:
                 auto key = makeKey(property, areaId);
                 if (mValues.count(key) == 0) {
@@ -308,6 +316,32 @@
     ASSERT_EQ(StatusCode::OK, res);
 }
 
+TEST_F(VehicleHalManagerTest, get_Complex) {
+    invokeGet(VehicleProperty::VEHICLE_MAPS_DATA_SERVICE, 0);
+
+    ASSERT_EQ(StatusCode::OK, actualStatusCode);
+    ASSERT_EQ(VehicleProperty::VEHICLE_MAPS_DATA_SERVICE, actualValue.prop);
+
+    ASSERT_EQ(3, actualValue.value.bytes.size());
+    ASSERT_EQ(1, actualValue.value.bytes[0]);
+    ASSERT_EQ(2, actualValue.value.bytes[1]);
+    ASSERT_EQ(3, actualValue.value.bytes[2]);
+
+    ASSERT_EQ(2, actualValue.value.int32Values.size());
+    ASSERT_EQ(10, actualValue.value.int32Values[0]);
+    ASSERT_EQ(20, actualValue.value.int32Values[1]);
+
+    ASSERT_EQ(2, actualValue.value.floatValues.size());
+    ASSERT_FLOAT_EQ(1.1, actualValue.value.floatValues[0]);
+    ASSERT_FLOAT_EQ(2.2, actualValue.value.floatValues[1]);
+
+    ASSERT_EQ(2, actualValue.value.int64Values.size());
+    ASSERT_FLOAT_EQ(30, actualValue.value.int64Values[0]);
+    ASSERT_FLOAT_EQ(40, actualValue.value.int64Values[1]);
+
+    ASSERT_STREQ(kCarMake, actualValue.value.stringValue.c_str());
+}
+
 TEST_F(VehicleHalManagerTest, get_StaticString) {
     invokeGet(VehicleProperty::INFO_MAKE, 0);
 
diff --git a/vehicle/2.0/default/tests/VehicleHalTestUtils.h b/vehicle/2.0/default/tests/VehicleHalTestUtils.h
index 77541fc..e1e355e 100644
--- a/vehicle/2.0/default/tests/VehicleHalTestUtils.h
+++ b/vehicle/2.0/default/tests/VehicleHalTestUtils.h
@@ -103,6 +103,13 @@
         .access = VehiclePropertyAccess::READ_WRITE,
         .changeMode = VehiclePropertyChangeMode::ON_CHANGE,
 
+    },
+
+    // Complex data type.
+    {
+        .prop = VehicleProperty::VEHICLE_MAPS_DATA_SERVICE,
+        .access = VehiclePropertyAccess::READ_WRITE,
+        .changeMode = VehiclePropertyChangeMode::ON_CHANGE
     }
 };
 
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.cpp b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.cpp
index 70b93e7..463b333 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.cpp
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.cpp
@@ -80,6 +80,10 @@
     return val;
 }
 
+VehiclePropValuePool::RecyclableType VehiclePropValuePool::obtainComplex() {
+    return obtain(VehiclePropertyType::COMPLEX);
+}
+
 VehiclePropValuePool::RecyclableType VehiclePropValuePool::obtainRecylable(
         VehiclePropertyType type, size_t vecSize) {
     // VehiclePropertyType is not overlapping with vectorSize.
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
index 1ca9211..d9231c3 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleObjectPool.h
@@ -184,13 +184,15 @@
     RecyclableType obtainInt64(int64_t value);
     RecyclableType obtainFloat(float value);
     RecyclableType obtainString(const char* cstr);
+    RecyclableType obtainComplex();
 
     VehiclePropValuePool(VehiclePropValuePool& ) = delete;
     VehiclePropValuePool& operator=(VehiclePropValuePool&) = delete;
 private:
     bool isDisposable(VehiclePropertyType type, size_t vecSize) const {
         return vecSize > mMaxRecyclableVectorSize ||
-               VehiclePropertyType::STRING == type;
+               VehiclePropertyType::STRING == type ||
+               VehiclePropertyType::COMPLEX == type;
     }
 
     RecyclableType obtainDisposable(VehiclePropertyType valueType,
diff --git a/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.cpp b/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.cpp
index c461833..ab1d908 100644
--- a/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.cpp
+++ b/vehicle/2.0/default/vehicle_hal_manager/VehicleUtils.cpp
@@ -47,6 +47,7 @@
             val->value.bytes.resize(vecSize);
             break;
         case VehiclePropertyType::STRING:
+        case VehiclePropertyType::COMPLEX:
             break; // Valid, but nothing to do.
         default:
             ALOGE("createVehiclePropValue: unknown type: %d", type);
diff --git a/vehicle/2.0/types.hal b/vehicle/2.0/types.hal
index 850efa7..28ccb78 100644
--- a/vehicle/2.0/types.hal
+++ b/vehicle/2.0/types.hal
@@ -31,6 +31,12 @@
     FLOAT_VEC      = 0x00610000,
     BYTES          = 0x00700000,
 
+    /*
+     * Any combination of scalar or vector types. The exact format must be
+     * provided in the description of the property.
+     */
+    COMPLEX        = 0x00e00000,
+
     MASK           = 0x00ff0000
 };
 
@@ -1628,9 +1634,7 @@
         | VehicleArea:GLOBAL),
 
     /*
-     * Vehicle Maps Data Service
-     *
-     * A VMDS message.
+     * Vehicle Maps Data Service (VMDS) message
      *
      * @change_mode VehiclePropertyChangeMode:ON_CHANGE
      * @access VehiclePropertyAccess:READ_WRITE
@@ -1638,7 +1642,7 @@
     VEHICLE_MAPS_DATA_SERVICE = (
         0x0C00
         | VehiclePropertyGroup:SYSTEM
-        | VehiclePropertyType:BYTES
+        | VehiclePropertyType:COMPLEX
         | VehicleArea:GLOBAL),
 };