Merge "Expanding VTS test coverage" into qt-dev
diff --git a/camera/provider/2.4/ICameraProvider.hal b/camera/provider/2.4/ICameraProvider.hal
index 8773bc0..74c3ff1 100644
--- a/camera/provider/2.4/ICameraProvider.hal
+++ b/camera/provider/2.4/ICameraProvider.hal
@@ -140,7 +140,8 @@
      *         Torch API support cannot be queried. This may be due to
      *         a failure to initialize the camera subsystem, for example.
      * @return support Whether the camera devices known to this provider
-     *     supports setTorchMode API or not.
+     *     supports setTorchMode API or not. Devices launched with SDK
+     *     level 29 or higher must return true.
      *
      */
     isSetTorchModeSupported() generates (Status status, bool support);
diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
index 814b88b..33d23a0 100644
--- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
+++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp
@@ -272,6 +272,16 @@
         ALOGW("Unexpected HAL status code %d", s);
         return Status::OPERATION_NOT_SUPPORTED;
     }
+
+    void getFirstApiLevel(/*out*/int32_t* outApiLevel) {
+        int32_t firstApiLevel = property_get_int32("ro.product.first_api_level", /*default*/-1);
+        if (firstApiLevel < 0) {
+            firstApiLevel = property_get_int32("ro.build.version.sdk", /*default*/-1);
+        }
+        ASSERT_GT(firstApiLevel, 0); // first_api_level must exist
+        *outApiLevel = firstApiLevel;
+        return;
+    }
 }
 
 // Test environment for camera
@@ -1484,11 +1494,8 @@
 // Test devices with first_api_level >= P does not advertise device@1.0
 TEST_F(CameraHidlTest, noHal1AfterP) {
     constexpr int32_t HAL1_PHASE_OUT_API_LEVEL = 28;
-    int32_t firstApiLevel = property_get_int32("ro.product.first_api_level", /*default*/-1);
-    if (firstApiLevel < 0) {
-        firstApiLevel = property_get_int32("ro.build.version.sdk", /*default*/-1);
-    }
-    ASSERT_GT(firstApiLevel, 0); // first_api_level must exist
+    int32_t firstApiLevel = 0;
+    getFirstApiLevel(&firstApiLevel);
 
     // all devices with first API level == 28 and <= 1GB of RAM must set low_ram
     // and thus be allowed to continue using HAL1
@@ -1509,11 +1516,19 @@
 }
 
 // Test if ICameraProvider::isTorchModeSupported returns Status::OK
+// Also if first_api_level >= Q torch API must be supported.
 TEST_F(CameraHidlTest, isTorchModeSupported) {
+    constexpr int32_t API_LEVEL_Q = 29;
+    int32_t firstApiLevel = 0;
+    getFirstApiLevel(&firstApiLevel);
+
     Return<void> ret;
     ret = mProvider->isSetTorchModeSupported([&](auto status, bool support) {
         ALOGI("isSetTorchModeSupported returns status:%d supported:%d", (int)status, support);
         ASSERT_EQ(Status::OK, status);
+        if (firstApiLevel >= API_LEVEL_Q) {
+            ASSERT_EQ(true, support);
+        }
     });
     ASSERT_TRUE(ret.isOk());
 }
diff --git a/current.txt b/current.txt
index a8062d3..875be97 100644
--- a/current.txt
+++ b/current.txt
@@ -391,6 +391,7 @@
 f8a19622cb0cc890913b1ef3e32b675ffb26089a09e02fef4056ebad324d2b5d android.hardware.camera.device@3.4::types
 291638a1b6d4e63283e9e722ab5049d9351717ffa2b66162124f84d1aa7c2835 android.hardware.camera.metadata@3.2::types
 23780340c686ee86986aa5a9755c2d8566224fed177bbb22a5ebf06be574b60c android.hardware.camera.metadata@3.3::types
+05d1ee760d81cdd2dc7a70ce0241af9fa830edae33b4be83d9bf5fffe05ddc6f android.hardware.camera.provider@2.4::ICameraProvider
 da33234403ff5d60f3473711917b9948e6484a4260b5247acdafb111193a9de2 android.hardware.configstore@1.0::ISurfaceFlingerConfigs
 21165b8e30c4b2d52980e4728f661420adc16e38bbe73476c06b2085be908f4c android.hardware.gnss@1.0::IGnssCallback
 d702fb01dc2a0733aa820b7eb65435ee3334f75632ef880bafd2fb8803a20a58 android.hardware.gnss@1.0::IGnssMeasurementCallback
@@ -487,7 +488,7 @@
 7a2d64095252f85781b2d521f4f11d04ce774544feececcec2088c568656e93c android.hardware.graphics.common@1.2::types
 3dff04a36b86660b5807414587e530bb0c294ed56fdff06f8915ba0a9b73f974 android.hardware.graphics.composer@2.3::IComposer
 54bc1dc874f8bc0781767786075dafd33a0796c1eea7d2317231b8929280e946 android.hardware.graphics.composer@2.3::IComposerClient
-5c8bf8e1af9efe225a4661db8c08ff1b7e13fdc8ed49f35291bd0b6c9436b8f2 android.hardware.graphics.mapper@3.0::IMapper
+033e096cb65e5093ee1d0e473892b9a487911d4611dbb65ebecb5cef18338923 android.hardware.graphics.mapper@3.0::IMapper
 7183d9d9acfa41a61a64bdfed548e98299265a7bb1821a3ed204173b5c2cfd4a android.hardware.graphics.mapper@3.0::types
 c3f831a66d5815baf74f5b82fe79cf099542ddae4dfab3f388e1d41828e794fc android.hardware.health.storage@1.0::IGarbageCollectCallback
 dd1ec219f5d2e2b33c6c0bcb92e63bbedb36f7c716413462848f6b6ae74fc864 android.hardware.health.storage@1.0::IStorage
diff --git a/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h
index 1b40795..3792c2e 100644
--- a/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h
+++ b/graphics/composer/2.3/utils/hal/include/composer-hal/2.3/ComposerClient.h
@@ -22,7 +22,6 @@
 
 #include <android/hardware/graphics/composer/2.3/IComposerClient.h>
 #include <composer-hal/2.2/ComposerResources.h>
-#include <composer-hal/2.3/ComposerClient.h>
 #include <composer-hal/2.3/ComposerCommandEngine.h>
 #include <composer-hal/2.3/ComposerHal.h>
 
diff --git a/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h
index e2bed95..4829e24 100644
--- a/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h
+++ b/graphics/composer/2.3/utils/passthrough/include/composer-passthrough/2.3/HwcHal.h
@@ -221,10 +221,6 @@
 
     Error getDisplayCapabilities(
         Display display, hidl_vec<IComposerClient::DisplayCapability>* outCapabilities) override {
-        if (!mDispatch.getDisplayCapabilities) {
-            return Error::UNSUPPORTED;
-        }
-
         uint32_t count = 0;
         int32_t error = mDispatch.getDisplayCapabilities(mDevice, display, &count, nullptr);
         if (error != HWC2_ERROR_NONE) {
diff --git a/graphics/composer/2.3/utils/vts/ComposerVts.cpp b/graphics/composer/2.3/utils/vts/ComposerVts.cpp
index 4de85d6..b763209 100644
--- a/graphics/composer/2.3/utils/vts/ComposerVts.cpp
+++ b/graphics/composer/2.3/utils/vts/ComposerVts.cpp
@@ -177,13 +177,17 @@
     return error;
 }
 
-std::vector<IComposerClient::DisplayCapability> ComposerClient::getDisplayCapabilities(
-    Display display) {
+Error ComposerClient::getDisplayCapabilities(
+        Display display, std::vector<IComposerClient::DisplayCapability>* outCapabilities) {
     std::vector<IComposerClient::DisplayCapability> capabilities;
-    mClient->getDisplayCapabilities(
-        display, [&](const auto&, const auto& tmpCapabilities) { capabilities = tmpCapabilities; });
+    Error error = Error::NONE;
+    mClient->getDisplayCapabilities(display,
+                                    [&](const auto& tmpError, const auto& tmpCapabilities) {
+                                        error = tmpError;
+                                        *outCapabilities = tmpCapabilities;
+                                    });
 
-    return capabilities;
+    return error;
 }
 
 bool ComposerClient::getDisplayBrightnessSupport(Display display) {
diff --git a/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h b/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h
index a0e764d..0d4e5b8 100644
--- a/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h
+++ b/graphics/composer/2.3/utils/vts/include/composer-vts/2.3/ComposerVts.h
@@ -95,7 +95,9 @@
 
     bool getClientTargetSupport_2_3(Display display, uint32_t width, uint32_t height,
                                     PixelFormat format, Dataspace dataspace);
-    std::vector<IComposerClient::DisplayCapability> getDisplayCapabilities(Display display);
+    Error getDisplayCapabilities(
+            Display display,
+            std::vector<IComposerClient::DisplayCapability>* outDisplayCapabilities);
 
     std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys_2_3(Display display);
 
diff --git a/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp b/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp
index b983e42..56b2e33 100644
--- a/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp
+++ b/graphics/composer/2.3/vts/functional/VtsHalGraphicsComposerV2_3TargetTest.cpp
@@ -565,16 +565,19 @@
  * Test some constraints.
  */
 TEST_F(GraphicsComposerHidlTest, getDisplayCapabilitiesBasic) {
-    auto capabilities = mComposerClient->getDisplayCapabilities(mPrimaryDisplay);
-    bool hasDozeSupport = std::find(capabilities.begin(), capabilities.end(),
-                                    IComposerClient::DisplayCapability::DOZE) != capabilities.end();
+    std::vector<IComposerClient::DisplayCapability> capabilities;
+    const auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
+    ASSERT_EQ(Error::NONE, error);
+    const bool hasDozeSupport =
+            std::find(capabilities.begin(), capabilities.end(),
+                      IComposerClient::DisplayCapability::DOZE) != capabilities.end();
     EXPECT_EQ(mComposerClient->getDozeSupport(mPrimaryDisplay), hasDozeSupport);
 }
 
 TEST_F(GraphicsComposerHidlTest, getDisplayCapabilitiesBadDisplay) {
-    mComposerClient->getRaw()->getDisplayCapabilities(
-        mInvalidDisplayId,
-        [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_DISPLAY, tmpError); });
+    std::vector<IComposerClient::DisplayCapability> capabilities;
+    const auto error = mComposerClient->getDisplayCapabilities(mInvalidDisplayId, &capabilities);
+    EXPECT_EQ(Error::BAD_DISPLAY, error);
 }
 
 TEST_F(GraphicsComposerHidlTest, SetLayerPerFrameMetadataBlobs) {
@@ -604,7 +607,9 @@
  * Test that getDisplayBrightnessSupport works as expected.
  */
 TEST_F(GraphicsComposerHidlTest, getDisplayBrightnessSupport) {
-    auto capabilities = mComposerClient->getDisplayCapabilities(mPrimaryDisplay);
+    std::vector<IComposerClient::DisplayCapability> capabilities;
+    const auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
+    ASSERT_EQ(Error::NONE, error);
     bool brightnessSupport =
             std::find(capabilities.begin(), capabilities.end(),
                       IComposerClient::DisplayCapability::BRIGHTNESS) != capabilities.end();
@@ -616,9 +621,9 @@
  */
 TEST_F(GraphicsComposerHidlTest, setDisplayBrightness) {
     if (!mComposerClient->getDisplayBrightnessSupport(mPrimaryDisplay)) {
-        EXPECT_EQ(mComposerClient->getRaw()->setDisplayBrightness(mPrimaryDisplay, 0.5f),
-                  Error::UNSUPPORTED);
+        EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.5f), Error::UNSUPPORTED);
         GTEST_SUCCEED() << "Brightness operations are not supported";
+        return;
     }
 
     EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.0f), Error::NONE);
diff --git a/graphics/mapper/3.0/IMapper.hal b/graphics/mapper/3.0/IMapper.hal
index a0e4d7a..71b56d9 100644
--- a/graphics/mapper/3.0/IMapper.hal
+++ b/graphics/mapper/3.0/IMapper.hal
@@ -16,8 +16,8 @@
 
 package android.hardware.graphics.mapper@3.0;
 
-import android.hardware.graphics.common@1.1::BufferUsage;
-import android.hardware.graphics.common@1.1::PixelFormat;
+import android.hardware.graphics.common@1.2::BufferUsage;
+import android.hardware.graphics.common@1.2::PixelFormat;
 import android.hardware.graphics.common@1.2::Rect;
 
 interface IMapper {
diff --git a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
index cfae635..ff73ecf 100644
--- a/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
+++ b/graphics/mapper/3.0/vts/functional/VtsHalGraphicsMapperV3_0TargetTest.cpp
@@ -32,8 +32,8 @@
 namespace vts {
 namespace {
 
-using android::hardware::graphics::common::V1_0::BufferUsage;
-using android::hardware::graphics::common::V1_1::PixelFormat;
+using android::hardware::graphics::common::V1_2::BufferUsage;
+using android::hardware::graphics::common::V1_2::PixelFormat;
 
 // Test environment for graphics.mapper.
 class GraphicsMapperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
diff --git a/vibrator/1.3/example/Vibrator.cpp b/vibrator/1.3/example/Vibrator.cpp
index 0cb37e6..b529437 100644
--- a/vibrator/1.3/example/Vibrator.cpp
+++ b/vibrator/1.3/example/Vibrator.cpp
@@ -56,27 +56,30 @@
 }
 
 Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
+    if (!amplitude) {
+        return Status::BAD_VALUE;
+    }
     ALOGI("Amplitude: %u -> %u\n", mAmplitude, amplitude);
     mAmplitude = amplitude;
     return Status::OK;
 }
 
 Return<void> Vibrator::perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
-    return perform_1_1(static_cast<V1_1::Effect_1_1>(effect), strength, _hidl_cb);
+    return perform<decltype(effect)>(effect, strength, _hidl_cb);
 }
 
 // Methods from ::android::hardware::vibrator::V1_1::IVibrator follow.
 
 Return<void> Vibrator::perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
                                    perform_cb _hidl_cb) {
-    return perform_1_2(static_cast<V1_2::Effect>(effect), strength, _hidl_cb);
+    return perform<decltype(effect)>(effect, strength, _hidl_cb);
 }
 
 // Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
 
 Return<void> Vibrator::perform_1_2(V1_2::Effect effect, EffectStrength strength,
                                    perform_cb _hidl_cb) {
-    return perform_1_3(static_cast<V1_3::Effect>(effect), strength, _hidl_cb);
+    return perform<decltype(effect)>(effect, strength, _hidl_cb);
 }
 
 // Methods from ::android::hardware::vibrator::V1_3::IVibrator follow.
@@ -98,6 +101,12 @@
 }
 
 Return<void> Vibrator::perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
+    return perform<decltype(effect)>(effect, strength, _hidl_cb);
+}
+
+// Private methods follow.
+
+Return<void> Vibrator::perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
     uint8_t amplitude;
     uint32_t ms;
     Status status = Status::OK;
@@ -123,7 +132,15 @@
     return Void();
 }
 
-// Private methods follow.
+template <typename T>
+Return<void> Vibrator::perform(T effect, EffectStrength strength, perform_cb _hidl_cb) {
+    auto validRange = hidl_enum_range<T>();
+    if (effect < *validRange.begin() || effect > *std::prev(validRange.end())) {
+        _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
+        return Void();
+    }
+    return perform(static_cast<Effect>(effect), strength, _hidl_cb);
+}
 
 Status Vibrator::enable(bool enabled) {
     if (mExternalControl) {
diff --git a/vibrator/1.3/example/Vibrator.h b/vibrator/1.3/example/Vibrator.h
index 64e8e1b..5180774 100644
--- a/vibrator/1.3/example/Vibrator.h
+++ b/vibrator/1.3/example/Vibrator.h
@@ -54,6 +54,9 @@
     Return<void> perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
 
   private:
+    Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
+    template <typename T>
+    Return<void> perform(T effect, EffectStrength strength, perform_cb _hidl_cb);
     Status enable(bool enabled);
     Status activate(uint32_t ms);
     void timeout();