Merge "IBootControl: Use new defaultPassthroughServiceImplementation signature."
diff --git a/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp b/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp
index 3d138f7..5a75ae1 100644
--- a/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp
+++ b/graphics/composer/2.1/utils/hwc2on1adapter/HWC2On1Adapter.cpp
@@ -1389,7 +1389,7 @@
 }
 
 static std::string approximateFloatString(float f) {
-    if (static_cast<int32_t>(f) == f) {
+    if (static_cast<float>(static_cast<int32_t>(f)) == f) {
         return std::to_string(static_cast<int32_t>(f));
     }
     int32_t truncated = static_cast<int32_t>(f * 10);
@@ -1680,10 +1680,10 @@
     if (mAttributes.count(HWC2::Attribute::DpiX) != 0 &&
             mAttributes.at(HWC2::Attribute::DpiX) != -1) {
         std::memset(buffer, 0, BUFFER_SIZE);
-        writtenBytes = snprintf(buffer, BUFFER_SIZE,
-                ", DPI: %.1f x %.1f",
-                mAttributes.at(HWC2::Attribute::DpiX) / 1000.0f,
-                mAttributes.at(HWC2::Attribute::DpiY) / 1000.0f);
+        writtenBytes =
+                snprintf(buffer, BUFFER_SIZE, ", DPI: %.1f x %.1f",
+                         static_cast<float>(mAttributes.at(HWC2::Attribute::DpiX)) / 1000.0f,
+                         static_cast<float>(mAttributes.at(HWC2::Attribute::DpiY)) / 1000.0f);
         output.append(buffer, writtenBytes);
     }
 
diff --git a/sensors/1.0/default/convert.cpp b/sensors/1.0/default/convert.cpp
index 52f5e4f..53ceb0d 100644
--- a/sensors/1.0/default/convert.cpp
+++ b/sensors/1.0/default/convert.cpp
@@ -68,9 +68,9 @@
     typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;
 
     *dst = {
-        .sensorHandle = src.sensor,
-        .sensorType = (SensorType)src.type,
-        .timestamp = src.timestamp
+            .timestamp = src.timestamp,
+            .sensorHandle = src.sensor,
+            .sensorType = (SensorType)src.type,
     };
 
     switch (dst->sensorType) {
diff --git a/sensors/common/vts/utils/GrallocWrapper.cpp b/sensors/common/vts/utils/GrallocWrapper.cpp
index 1cad913..e63faa2 100644
--- a/sensors/common/vts/utils/GrallocWrapper.cpp
+++ b/sensors/common/vts/utils/GrallocWrapper.cpp
@@ -147,8 +147,8 @@
             .width = size,
             .height = 1,
             .layerCount = 1,
-            .usage = kBufferUsage,
             .format = static_cast<decltype(descriptorInfo.format)>(PixelFormat::BLOB),
+            .usage = kBufferUsage,
     };
 
     BufferDescriptor descriptor;
diff --git a/vibrator/staidl/Android.bp b/vibrator/aidl/Android.bp
similarity index 100%
rename from vibrator/staidl/Android.bp
rename to vibrator/aidl/Android.bp
diff --git a/vibrator/staidl/android/hardware/vibrator/Effect.aidl b/vibrator/aidl/android/hardware/vibrator/Effect.aidl
similarity index 100%
rename from vibrator/staidl/android/hardware/vibrator/Effect.aidl
rename to vibrator/aidl/android/hardware/vibrator/Effect.aidl
diff --git a/vibrator/staidl/android/hardware/vibrator/EffectStrength.aidl b/vibrator/aidl/android/hardware/vibrator/EffectStrength.aidl
similarity index 100%
rename from vibrator/staidl/android/hardware/vibrator/EffectStrength.aidl
rename to vibrator/aidl/android/hardware/vibrator/EffectStrength.aidl
diff --git a/vibrator/staidl/android/hardware/vibrator/IVibrator.aidl b/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
similarity index 94%
rename from vibrator/staidl/android/hardware/vibrator/IVibrator.aidl
rename to vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
index b2008f4..d21274b 100644
--- a/vibrator/staidl/android/hardware/vibrator/IVibrator.aidl
+++ b/vibrator/aidl/android/hardware/vibrator/IVibrator.aidl
@@ -74,6 +74,14 @@
     int perform(in Effect effect, in EffectStrength strength, in IVibratorCallback callback);
 
     /**
+     * List supported effects.
+     *
+     * Return the effects which are supported (an effect is expected to be supported at every
+     * strength level.
+     */
+    Effect[] getSupportedEffects();
+
+    /**
      * Sets the motor's vibrational amplitude.
      *
      * Changes the force being produced by the underlying motor.
diff --git a/vibrator/staidl/android/hardware/vibrator/IVibratorCallback.aidl b/vibrator/aidl/android/hardware/vibrator/IVibratorCallback.aidl
similarity index 100%
rename from vibrator/staidl/android/hardware/vibrator/IVibratorCallback.aidl
rename to vibrator/aidl/android/hardware/vibrator/IVibratorCallback.aidl
diff --git a/vibrator/staidl/default/Android.bp b/vibrator/aidl/default/Android.bp
similarity index 100%
rename from vibrator/staidl/default/Android.bp
rename to vibrator/aidl/default/Android.bp
diff --git a/vibrator/staidl/default/Vibrator.cpp b/vibrator/aidl/default/Vibrator.cpp
similarity index 94%
rename from vibrator/staidl/default/Vibrator.cpp
rename to vibrator/aidl/default/Vibrator.cpp
index cdf8e09..2aec8c5 100644
--- a/vibrator/staidl/default/Vibrator.cpp
+++ b/vibrator/aidl/default/Vibrator.cpp
@@ -78,6 +78,11 @@
     return ndk::ScopedAStatus::ok();
 }
 
+ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
+    *_aidl_return = {Effect::CLICK, Effect::TICK};
+    return ndk::ScopedAStatus::ok();
+}
+
 ndk::ScopedAStatus Vibrator::setAmplitude(int32_t amplitude) {
     LOG(INFO) << "Vibrator set amplitude: " << amplitude;
     if (amplitude <= 0 || amplitude > 255) {
diff --git a/vibrator/staidl/default/Vibrator.h b/vibrator/aidl/default/Vibrator.h
similarity index 94%
rename from vibrator/staidl/default/Vibrator.h
rename to vibrator/aidl/default/Vibrator.h
index 77e96e3..14e7292 100644
--- a/vibrator/staidl/default/Vibrator.h
+++ b/vibrator/aidl/default/Vibrator.h
@@ -31,6 +31,7 @@
     ndk::ScopedAStatus perform(Effect effect, EffectStrength strength,
                                const std::shared_ptr<IVibratorCallback>& callback,
                                int32_t* _aidl_return) override;
+    ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override;
     ndk::ScopedAStatus setAmplitude(int32_t amplitude) override;
     ndk::ScopedAStatus setExternalControl(bool enabled) override;
 };
diff --git a/vibrator/staidl/default/main.cpp b/vibrator/aidl/default/main.cpp
similarity index 100%
rename from vibrator/staidl/default/main.cpp
rename to vibrator/aidl/default/main.cpp
diff --git a/vibrator/staidl/default/vibrator-default.rc b/vibrator/aidl/default/vibrator-default.rc
similarity index 100%
rename from vibrator/staidl/default/vibrator-default.rc
rename to vibrator/aidl/default/vibrator-default.rc
diff --git a/vibrator/staidl/default/vibrator-default.xml b/vibrator/aidl/default/vibrator-default.xml
similarity index 100%
rename from vibrator/staidl/default/vibrator-default.xml
rename to vibrator/aidl/default/vibrator-default.xml
diff --git a/vibrator/staidl/vts/Android.bp b/vibrator/aidl/vts/Android.bp
similarity index 100%
rename from vibrator/staidl/vts/Android.bp
rename to vibrator/aidl/vts/Android.bp
diff --git a/vibrator/staidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
similarity index 89%
rename from vibrator/staidl/vts/VtsHalVibratorTargetTest.cpp
rename to vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
index 33bcaf5..b0e6c72 100644
--- a/vibrator/staidl/vts/VtsHalVibratorTargetTest.cpp
+++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
@@ -32,6 +32,7 @@
 using android::hardware::vibrator::EffectStrength;
 using android::hardware::vibrator::IVibrator;
 
+// TODO(b/143992652): autogenerate
 const std::vector<Effect> kEffects = {
         Effect::CLICK,       Effect::DOUBLE_CLICK, Effect::TICK,        Effect::THUD,
         Effect::POP,         Effect::HEAVY_CLICK,  Effect::RINGTONE_1,  Effect::RINGTONE_2,
@@ -40,6 +41,7 @@
         Effect::RINGTONE_11, Effect::RINGTONE_12,  Effect::RINGTONE_13, Effect::RINGTONE_14,
         Effect::RINGTONE_15, Effect::TEXTURE_TICK};
 
+// TODO(b/143992652): autogenerate
 const std::vector<EffectStrength> kEffectStrengths = {EffectStrength::LIGHT, EffectStrength::MEDIUM,
                                                       EffectStrength::STRONG};
 
@@ -105,15 +107,22 @@
 }
 
 TEST_P(VibratorAidl, ValidateEffect) {
+    std::vector<Effect> supported;
+    ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk());
+
     for (Effect effect : kEffects) {
+        bool isEffectSupported =
+                std::find(supported.begin(), supported.end(), effect) != supported.end();
+
         for (EffectStrength strength : kEffectStrengths) {
             int32_t lengthMs = 0;
             Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs);
-            EXPECT_TRUE(status.isOk() ||
-                        status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION);
-            if (status.isOk()) {
+
+            if (isEffectSupported) {
+                EXPECT_TRUE(status.isOk());
                 EXPECT_GT(lengthMs, 0);
             } else {
+                EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
                 EXPECT_EQ(lengthMs, 0);
             }
         }
@@ -123,16 +132,29 @@
 TEST_P(VibratorAidl, ValidateEffectWithCallback) {
     if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) return;
 
+    std::vector<Effect> supported;
+    ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk());
+
     for (Effect effect : kEffects) {
+        bool isEffectSupported =
+                std::find(supported.begin(), supported.end(), effect) != supported.end();
+
         for (EffectStrength strength : kEffectStrengths) {
             std::promise<void> completionPromise;
             std::future<void> completionFuture{completionPromise.get_future()};
             sp<CompletionCallback> callback =
                     new CompletionCallback([&completionPromise] { completionPromise.set_value(); });
-            int lengthMs;
+            int lengthMs = 0;
             Status status = vibrator->perform(effect, strength, callback, &lengthMs);
-            EXPECT_TRUE(status.isOk() ||
-                        status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION);
+
+            if (isEffectSupported) {
+                EXPECT_TRUE(status.isOk());
+                EXPECT_GT(lengthMs, 0);
+            } else {
+                EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION);
+                EXPECT_EQ(lengthMs, 0);
+            }
+
             if (!status.isOk()) continue;
 
             std::chrono::milliseconds timeout{lengthMs * 2};