Merge "Don't set hidl_string's buffer to nullptr"
diff --git a/audio/effect/2.0/IDownmixEffect.hal b/audio/effect/2.0/IDownmixEffect.hal
index 06409a3..1232095 100644
--- a/audio/effect/2.0/IDownmixEffect.hal
+++ b/audio/effect/2.0/IDownmixEffect.hal
@@ -25,7 +25,13 @@
         FOLD   // mix the extra channels with FL/FR
     };
 
+    /**
+     * Sets the current downmix preset.
+     */
     setType(Type preset) generates (Result retval);
 
+    /**
+     * Gets the current downmix preset.
+     */
     getType() generates (Result retval, Type preset);
 };
diff --git a/audio/effect/2.0/IEnvironmentalReverbEffect.hal b/audio/effect/2.0/IEnvironmentalReverbEffect.hal
index dca89f9..58d6d97 100644
--- a/audio/effect/2.0/IEnvironmentalReverbEffect.hal
+++ b/audio/effect/2.0/IEnvironmentalReverbEffect.hal
@@ -64,12 +64,12 @@
     getRoomLevel() generates (Result retval, int16_t roomLevel);
 
     /**
-     * Sets the room high frequences level.
+     * Sets the room high frequencies level.
      */
     setRoomHfLevel(int16_t roomHfLevel) generates (Result retval);
 
     /**
-     * Gets the room high frequences level.
+     * Gets the room high frequencies level.
      */
     getRoomHfLevel() generates (Result retval, int16_t roomHfLevel);
 
@@ -84,12 +84,12 @@
     getDecayTime() generates (Result retval, uint32_t decayTime);
 
     /**
-     * Sets the ratio of high frequences decay.
+     * Sets the ratio of high frequencies decay.
      */
     setDecayHfRatio(int16_t decayHfRatio) generates (Result retval);
 
     /**
-     * Gets the ratio of high frequences decay.
+     * Gets the ratio of high frequencies decay.
      */
     getDecayHfRatio() generates (Result retval, int16_t decayHfRatio);
 
diff --git a/audio/effect/2.0/IPresetReverbEffect.hal b/audio/effect/2.0/IPresetReverbEffect.hal
index 2237bc4..f37e56a 100644
--- a/audio/effect/2.0/IPresetReverbEffect.hal
+++ b/audio/effect/2.0/IPresetReverbEffect.hal
@@ -31,7 +31,13 @@
         LAST = PLATE
     };
 
+    /**
+     * Sets the current preset.
+     */
     setPreset(Preset preset) generates (Result retval);
 
+    /**
+     * Gets the current preset.
+     */
     getPreset() generates (Result retval, Preset preset);
 };
diff --git a/audio/effect/2.0/IVisualizerEffect.hal b/audio/effect/2.0/IVisualizerEffect.hal
index fd3edbd..fffc70b 100644
--- a/audio/effect/2.0/IVisualizerEffect.hal
+++ b/audio/effect/2.0/IVisualizerEffect.hal
@@ -100,7 +100,7 @@
         } value;
     };
     /**
-     * Retrieves the lastest measurements. The measurements to be made
+     * Retrieves the latest measurements. The measurements to be made
      * are specified by 'setMeasurementMode' parameter.
      *
      * @return retval operation completion status.
diff --git a/automotive/vehicle/2.1/types.hal b/automotive/vehicle/2.1/types.hal
index 5594d19..7be611c 100644
--- a/automotive/vehicle/2.1/types.hal
+++ b/automotive/vehicle/2.1/types.hal
@@ -588,14 +588,17 @@
   /* A client declaring layers offering. */
   OFFERING = 4,
 
-  /* Update for the available layers. */
-  AVAILABILITY = 5,
+  /* Requesting the list of available layers. */
+  AVAILABILITY_REQUEST = 5,
+
+  /* Returning the list of available layers. */
+  AVAILABILITY_RESPONSE = 6,
 
   /** Requesting layers that have subscribers. */
-  SUBSCRIPTION_REQUEST = 6,
+  SUBSCRIPTION_REQUEST = 7,
 
   /** Returning layers that have subscribers. */
-  SUBSCRIPTION_RESPONSE = 7,
+  SUBSCRIPTION_RESPONSE = 8,
 };
 
 /**
diff --git a/current.txt b/current.txt
index 575e8fa..8a2a56a 100644
--- a/current.txt
+++ b/current.txt
@@ -15,17 +15,17 @@
 fa8fbae3d1da3c264e4f3110728076abc09b4e65f12af6ae136367328de988ab android.hardware.audio.effect@2.0::IAcousticEchoCancelerEffect
 ca4752545d54547ff069eae161af7550cb5f5a7e8b60316ddd132a30906a68e7 android.hardware.audio.effect@2.0::IAutomaticGainControlEffect
 d2b8af988dc66f514d886bcee44b440d8034bc2a762f7161717ef3c956073067 android.hardware.audio.effect@2.0::IBassBoostEffect
-7649e7c3646e49141ef3b7edd89f87dd68b43a1dc3d3a918c5e1a859b87a738b android.hardware.audio.effect@2.0::IDownmixEffect
+611bc09c75e796f3512b1ca6be508b0a9ba996759b8a2c60507784ff58076229 android.hardware.audio.effect@2.0::IDownmixEffect
 36a57369dfdc75180e8b64ae80b1970db8f6d9085dbff6ca931715038cc056e1 android.hardware.audio.effect@2.0::IEffect
 d2aa2df6d189c580f5be8460fa0ff4134d9c05a383f3204659baee426a6f0edf android.hardware.audio.effect@2.0::IEffectBufferProviderCallback
 217f9161983a48d3bf3faeb158f868aa8bf0ce25889e4ee3d2bab1a2e8d33e77 android.hardware.audio.effect@2.0::IEffectsFactory
-21ca8a2316e36fb55028c5b9e1bf2436beb48e386258eaaa62f8141d2838361f android.hardware.audio.effect@2.0::IEnvironmentalReverbEffect
+c2b38bc07991e880c83ca8cb88181411eeef708b8b936aedd2f2e0acade7df69 android.hardware.audio.effect@2.0::IEnvironmentalReverbEffect
 2ff9f9704be5f167745b4de790e9dafc3cc4719e2f6e2e5497085e679853cfe7 android.hardware.audio.effect@2.0::IEqualizerEffect
 c31447fb02dbc8b56c359941dad22f416511860173c5c5fd278d1bf2312b13de android.hardware.audio.effect@2.0::ILoudnessEnhancerEffect
 804831ca258802eb3eb65a0a7b5d5e3d37d4a15ba8c2836b4276eda98b47e1d0 android.hardware.audio.effect@2.0::INoiseSuppressionEffect
-ff74e984b37275bb1deaee13d7c0b3c6b4d976009f09b53a4973772140f12cb0 android.hardware.audio.effect@2.0::IPresetReverbEffect
+778fd5b9837f481d8e47425b3e2a3bd0c6362a0b6870291518e2d863530fdb61 android.hardware.audio.effect@2.0::IPresetReverbEffect
 c93cb25a1a92d07aa80a617c01e8d22fc97bf8cefd3962b6a5be386ad4704d89 android.hardware.audio.effect@2.0::IVirtualizerEffect
-4aac97e196cb27e61adfe2e57107bde5a1af213325bf858992b906e6669166a4 android.hardware.audio.effect@2.0::IVisualizerEffect
+918f331780c9c7b04f2151a2e563aab088198ede8e6f865302ebaa13905bd9ce android.hardware.audio.effect@2.0::IVisualizerEffect
 4caad099f8fc00262b6c03ba41271808b37cea90ac98b534299bbf4ee823af02 android.hardware.audio.effect@2.0::types
 f2904a4c108ad1b93eb2fa4e43b82bd01ce1ff26156316e49d1d9fc80dfecaad android.hardware.automotive.evs@1.0::IEvsCamera
 94cba6ad04c83aa840de2ed52b74ba2126a26dd960225e61ac36703315279a80 android.hardware.automotive.evs@1.0::IEvsCameraStream
@@ -91,7 +91,7 @@
 af85aa0f48ae99a39f4688c344e4419304f681f9af818a5c8d759286fc4418de android.hardware.gnss@1.0::IGnssNavigationMessage
 649b1b0fb98bdd3a1ace84f4e08bfa2df813afdd4862856693f107c281a929ba android.hardware.gnss@1.0::IGnssNavigationMessageCallback
 248bcf51da4273d64f367bf6877baef2feeaca365459842fd3c214a2dc6e0224 android.hardware.gnss@1.0::IGnssNi
-e4f2c1b80172a73e2e743fba3ddc24ef58bc42d40bdb8f7352c9e19440b220eb android.hardware.gnss@1.0::IGnssNiCallback
+c781b7b125f68be5db8a8c3d412d526acdbdf77dcc592a4c0ed70b8ce4fe6c49 android.hardware.gnss@1.0::IGnssNiCallback
 c1142657de16fdb292a502372fe938614d65270ab8359217d6e13604fe4dbca4 android.hardware.gnss@1.0::IGnssXtra
 bd366b83d8d565d0e8bfabff3adfcab0259d75b4e2a9f8e1b91e11d1593a2ffb android.hardware.gnss@1.0::IGnssXtraCallback
 881bc2f94026784d194cffbff166c6e8bf911de4e02abe96fc7d89ec75b0574a android.hardware.gnss@1.0::types
@@ -103,7 +103,7 @@
 b19d00eb8a8b3b0034a0321f22e8f32162bf4c2aebbce6da22c025f56e459ea2 android.hardware.graphics.composer@2.1::IComposerCallback
 e992684e690dfe67a8cbeab5005bfa3fa9c2bf3d4b0b75657fb1f0c2d5dd2bae android.hardware.graphics.composer@2.1::IComposerClient
 1c98c2f5154345312ec054871792a2982ec5f3e2bc2abfb61a10c0b517978e20 android.hardware.graphics.composer@2.1::types
-04fbe91f2a860d463fa6287fbcfa05a8cc4f17848cabcd2aa9eef0f2aa1fedc0 android.hardware.graphics.mapper@2.0::IMapper
+a695898589e1ef15b2b2510f11edd6aafac9918d9cf8d74b4b6143b309dee542 android.hardware.graphics.mapper@2.0::IMapper
 28507d385a3dd224bf3c32f1bfd9f96092c4701b9c1cc66caa578fc3efc97877 android.hardware.graphics.mapper@2.0::types
 91e2ba3805c923f01fc1231ec9ff838942aee3346f2d7614ecc0caeadbe57ed4 android.hardware.health@1.0::IHealth
 1275aa2e8732909101b26aec49ed2285489e89d97b8610a8908b7868e35a3cc5 android.hardware.health@1.0::types
diff --git a/drm/1.0/vts/functional/drm_hal_clearkey_test.cpp b/drm/1.0/vts/functional/drm_hal_clearkey_test.cpp
index 2947d2e..26641e8 100644
--- a/drm/1.0/vts/functional/drm_hal_clearkey_test.cpp
+++ b/drm/1.0/vts/functional/drm_hal_clearkey_test.cpp
@@ -128,6 +128,7 @@
  */
 TEST_F(DrmHalClearkeyFactoryTest, EmptyPluginUUIDNotSupported) {
     hidl_array<uint8_t, 16> emptyUUID;
+    memset(emptyUUID.data(), 0, 16);
     EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(emptyUUID));
     EXPECT_FALSE(cryptoFactory->isCryptoSchemeSupported(emptyUUID));
 }
diff --git a/drm/1.0/vts/functional/drm_hal_vendor_test.cpp b/drm/1.0/vts/functional/drm_hal_vendor_test.cpp
index 2290df1..e2c9cca 100644
--- a/drm/1.0/vts/functional/drm_hal_vendor_test.cpp
+++ b/drm/1.0/vts/functional/drm_hal_vendor_test.cpp
@@ -189,6 +189,7 @@
  */
 TEST_P(DrmHalVendorFactoryTest, EmptyPluginUUIDNotSupported) {
     hidl_array<uint8_t, 16> emptyUUID;
+    memset(emptyUUID.data(), 0, 16);
     EXPECT_FALSE(drmFactory->isCryptoSchemeSupported(emptyUUID));
     EXPECT_FALSE(cryptoFactory->isCryptoSchemeSupported(emptyUUID));
 }
diff --git a/gnss/1.0/IGnssNiCallback.hal b/gnss/1.0/IGnssNiCallback.hal
index 163ba25..3e3071a 100644
--- a/gnss/1.0/IGnssNiCallback.hal
+++ b/gnss/1.0/IGnssNiCallback.hal
@@ -25,7 +25,8 @@
     enum GnssNiType : uint8_t {
         VOICE           = 1,
         UMTS_SUPL       = 2,
-        UMTS_CTRL_PLANE = 3
+        UMTS_CTRL_PLANE = 3,
+        EMERGENCY_SUPL  = 4
     };
 
     /**
diff --git a/graphics/composer/2.1/default/Android.bp b/graphics/composer/2.1/default/Android.bp
index fb75beb..037f810 100644
--- a/graphics/composer/2.1/default/Android.bp
+++ b/graphics/composer/2.1/default/Android.bp
@@ -5,8 +5,8 @@
     export_include_dirs: ["."],
     srcs: ["ComposerClient.cpp"],
     shared_libs: [
-        "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.composer@2.1",
+        "android.hardware.graphics.mapper@2.0",
         "libbase",
         "libcutils",
         "libfmq",
@@ -27,8 +27,8 @@
     srcs: ["Hwc.cpp"],
     static_libs: ["libhwcomposer-client"],
     shared_libs: [
-        "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.composer@2.1",
+        "android.hardware.graphics.mapper@2.0",
         "libbase",
         "libcutils",
         "libfmq",
@@ -51,7 +51,6 @@
     init_rc: ["android.hardware.graphics.composer@2.1-service.rc"],
     static_libs: ["libhwcomposer-client"],
     shared_libs: [
-        "android.hardware.graphics.allocator@2.0",
         "android.hardware.graphics.composer@2.1",
         "libbase",
         "libbinder",
diff --git a/graphics/composer/2.1/default/ComposerClient.cpp b/graphics/composer/2.1/default/ComposerClient.cpp
index d599b44..87e4d3b 100644
--- a/graphics/composer/2.1/default/ComposerClient.cpp
+++ b/graphics/composer/2.1/default/ComposerClient.cpp
@@ -16,8 +16,7 @@
 
 #define LOG_TAG "HwcPassthrough"
 
-#include <hardware/gralloc.h>
-#include <hardware/gralloc1.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
 #include <log/log.h>
 
 #include "ComposerClient.h"
@@ -33,10 +32,11 @@
 
 namespace {
 
+using MapperError = android::hardware::graphics::mapper::V2_0::Error;
+using android::hardware::graphics::mapper::V2_0::IMapper;
+
 class HandleImporter {
 public:
-    HandleImporter() : mInitialized(false) {}
-
     bool initialize()
     {
         // allow only one client
@@ -44,9 +44,7 @@
             return false;
         }
 
-        if (!openGralloc()) {
-            return false;
-        }
+        mMapper = IMapper::getService();
 
         mInitialized = true;
         return true;
@@ -54,11 +52,7 @@
 
     void cleanup()
     {
-        if (!mInitialized) {
-            return;
-        }
-
-        closeGralloc();
+        mMapper.clear();
         mInitialized = false;
     }
 
@@ -76,12 +70,20 @@
             return true;
         }
 
-        buffer_handle_t clone = cloneBuffer(handle);
-        if (!clone) {
+        MapperError error;
+        buffer_handle_t importedHandle;
+        mMapper->importBuffer(
+            hidl_handle(handle),
+            [&](const auto& tmpError, const auto& tmpBufferHandle) {
+                error = tmpError;
+                importedHandle = static_cast<buffer_handle_t>(tmpBufferHandle);
+            });
+        if (error != MapperError::NONE) {
             return false;
         }
 
-        handle = clone;
+        handle = importedHandle;
+
         return true;
     }
 
@@ -91,102 +93,12 @@
             return;
         }
 
-        releaseBuffer(handle);
+        mMapper->freeBuffer(const_cast<native_handle_t*>(handle));
     }
 
 private:
-    bool mInitialized;
-
-    // Some existing gralloc drivers do not support retaining more than once,
-    // when we are in passthrough mode.
-    bool openGralloc()
-    {
-        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 false;
-        }
-
-        uint8_t major = (module->module_api_version >> 8) & 0xff;
-        if (major > 1) {
-            ALOGE("unknown gralloc module major version %d", major);
-            return false;
-        }
-
-        if (major == 1) {
-            err = gralloc1_open(module, &mDevice);
-            if (err) {
-                ALOGE("failed to open gralloc1 device");
-                return false;
-            }
-
-            mRetain = reinterpret_cast<GRALLOC1_PFN_RETAIN>(
-                    mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RETAIN));
-            mRelease = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
-                    mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RELEASE));
-            if (!mRetain || !mRelease) {
-                ALOGE("invalid gralloc1 device");
-                gralloc1_close(mDevice);
-                return false;
-            }
-        } else {
-            mModule = reinterpret_cast<const gralloc_module_t*>(module);
-        }
-
-        return true;
-    }
-
-    void closeGralloc()
-    {
-        if (mDevice) {
-            gralloc1_close(mDevice);
-        }
-    }
-
-    buffer_handle_t cloneBuffer(buffer_handle_t handle)
-    {
-        native_handle_t* clone = native_handle_clone(handle);
-        if (!clone) {
-            ALOGE("failed to clone buffer %p", handle);
-            return nullptr;
-        }
-
-        bool err;
-        if (mDevice) {
-            err = (mRetain(mDevice, clone) != GRALLOC1_ERROR_NONE);
-        } else {
-            err = (mModule->registerBuffer(mModule, clone) != 0);
-        }
-
-        if (err) {
-            ALOGE("failed to retain/register buffer %p", clone);
-            native_handle_close(clone);
-            native_handle_delete(clone);
-            return nullptr;
-        }
-
-        return clone;
-    }
-
-    void releaseBuffer(buffer_handle_t handle)
-    {
-        if (mDevice) {
-            mRelease(mDevice, handle);
-        } else {
-            mModule->unregisterBuffer(mModule, handle);
-        }
-        native_handle_close(handle);
-        native_handle_delete(const_cast<native_handle_t*>(handle));
-    }
-
-    // gralloc1
-    gralloc1_device_t* mDevice;
-    GRALLOC1_PFN_RETAIN mRetain;
-    GRALLOC1_PFN_RELEASE mRelease;
-
-    // gralloc0
-    const gralloc_module_t* mModule;
+ bool mInitialized = false;
+ sp<IMapper> mMapper;
 };
 
 HandleImporter sHandleImporter;
diff --git a/graphics/mapper/2.0/IMapper.hal b/graphics/mapper/2.0/IMapper.hal
index 246be24..4ee206b 100644
--- a/graphics/mapper/2.0/IMapper.hal
+++ b/graphics/mapper/2.0/IMapper.hal
@@ -85,10 +85,11 @@
      * Imports a raw buffer handle to create an imported buffer handle for use
      * with the rest of the mapper or with other in-process libraries.
      *
-     * A buffer handle is considered raw when it is cloned or when it is
-     * received from another HAL or another process. A raw buffer handle must
-     * not be used to access the underlying graphics buffer. It must be
-     * imported to create an imported handle first.
+     * A buffer handle is considered raw when it is cloned (e.g., with
+     * native_handle_clone) from another buffer handle locally, or when it is
+     * received from another HAL server/client or another process. A raw
+     * buffer handle must not be used to access the underlying graphics
+     * buffer. It must be imported to create an imported handle first.
      *
      * This function must at least validate the raw handle before creating the
      * imported handle. It must also support importing the same raw handle
@@ -96,6 +97,12 @@
      * must be considered valid everywhere in the process, including in
      * another instance of the mapper.
      *
+     * Because of passthrough HALs, a raw buffer handle received from a HAL
+     * may actually have been imported in the process. importBuffer must treat
+     * such a handle as if it is raw and must not return BAD_BUFFER. The
+     * returned handle is independent from the input handle as usual, and
+     * freeBuffer must be called on it when it is no longer needed.
+     *
      * @param rawHandle is the raw buffer handle to import.
      * @return error is NONE upon success. Otherwise,
      *                  BAD_BUFFER when the raw handle is invalid.
diff --git a/graphics/mapper/2.0/default/GrallocMapper.cpp b/graphics/mapper/2.0/default/GrallocMapper.cpp
index 6441af6..d16143d 100644
--- a/graphics/mapper/2.0/default/GrallocMapper.cpp
+++ b/graphics/mapper/2.0/default/GrallocMapper.cpp
@@ -125,11 +125,8 @@
 
 Return<void> GrallocMapper::importBuffer(const hidl_handle& rawHandle,
                                          importBuffer_cb hidl_cb) {
-    // importing an already imported handle rather than a raw handle
-    if (gRegisteredHandles->get(rawHandle.getNativeHandle())) {
-        hidl_cb(Error::BAD_BUFFER, nullptr);
-        return Void();
-    }
+    // because of passthrough HALs, we must not generate an error when
+    // rawHandle has been imported
 
     if (!rawHandle.getNativeHandle()) {
         hidl_cb(Error::BAD_BUFFER, nullptr);
diff --git a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
index f066a1e..c74013b 100644
--- a/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
+++ b/graphics/mapper/2.0/vts/functional/VtsHalGraphicsMapperV2_0TargetTest.cpp
@@ -216,18 +216,6 @@
             << "importBuffer with invalid handle did not fail with BAD_BUFFER";
     });
     native_handle_delete(invalidHandle);
-
-    const native_handle_t* importedHandle;
-    ASSERT_NO_FATAL_FAILURE(importedHandle =
-                                mGralloc->allocate(mDummyDescriptorInfo, true));
-    mGralloc->getMapper()->importBuffer(
-        importedHandle, [&](const auto& tmpError, const auto&) {
-            EXPECT_EQ(Error::BAD_BUFFER, tmpError)
-                << "importBuffer with an "
-                   "already imported handle did "
-                   "not fail with BAD_BUFFER";
-        });
-    mGralloc->freeBuffer(importedHandle);
 }
 
 /**