Removing Vibrator HIDL HAL support from frameworks
Android Q is now no longer supported for launching or
upgrading devices in Android V so the vibrator HIDL HAL
versions no longer needs to be supported by the platform.
Bug: 308452413
Test: manually using the command line
Flag: EXEMPT updating Android.bp and removing dependencies
Change-Id: I6ba36f7c153f39afa9cf1a3c6dd679885da49ce7
diff --git a/services/vibratorservice/Android.bp b/services/vibratorservice/Android.bp
index 4735ae5..ed03cfc 100644
--- a/services/vibratorservice/Android.bp
+++ b/services/vibratorservice/Android.bp
@@ -42,14 +42,9 @@
shared_libs: [
"libbinder_ndk",
- "libhidlbase",
"liblog",
"libutils",
"android.hardware.vibrator-V3-ndk",
- "android.hardware.vibrator@1.0",
- "android.hardware.vibrator@1.1",
- "android.hardware.vibrator@1.2",
- "android.hardware.vibrator@1.3",
],
cflags: [
diff --git a/services/vibratorservice/VibratorHalController.cpp b/services/vibratorservice/VibratorHalController.cpp
index 283a5f0..302e3e1 100644
--- a/services/vibratorservice/VibratorHalController.cpp
+++ b/services/vibratorservice/VibratorHalController.cpp
@@ -18,8 +18,6 @@
#include <aidl/android/hardware/vibrator/IVibrator.h>
#include <android/binder_manager.h>
-#include <android/hardware/vibrator/1.3/IVibrator.h>
-#include <hardware/vibrator.h>
#include <utils/Log.h>
@@ -31,15 +29,10 @@
using aidl::android::hardware::vibrator::CompositePrimitive;
using aidl::android::hardware::vibrator::Effect;
using aidl::android::hardware::vibrator::EffectStrength;
+using aidl::android::hardware::vibrator::IVibrator;
using std::chrono::milliseconds;
-namespace V1_0 = android::hardware::vibrator::V1_0;
-namespace V1_1 = android::hardware::vibrator::V1_1;
-namespace V1_2 = android::hardware::vibrator::V1_2;
-namespace V1_3 = android::hardware::vibrator::V1_3;
-namespace Aidl = aidl::android::hardware::vibrator;
-
namespace android {
namespace vibrator {
@@ -53,9 +46,9 @@
return nullptr;
}
- auto serviceName = std::string(Aidl::IVibrator::descriptor) + "/default";
+ auto serviceName = std::string(IVibrator::descriptor) + "/default";
if (AServiceManager_isDeclared(serviceName.c_str())) {
- std::shared_ptr<Aidl::IVibrator> hal = Aidl::IVibrator::fromBinder(
+ std::shared_ptr<IVibrator> hal = IVibrator::fromBinder(
ndk::SpAIBinder(AServiceManager_waitForService(serviceName.c_str())));
if (hal) {
ALOGV("Successfully connected to Vibrator HAL AIDL service.");
@@ -63,30 +56,9 @@
}
}
- sp<V1_0::IVibrator> halV1_0 = V1_0::IVibrator::getService();
- if (halV1_0 == nullptr) {
- ALOGV("Vibrator HAL service not available.");
- gHalExists = false;
- return nullptr;
- }
-
- sp<V1_3::IVibrator> halV1_3 = V1_3::IVibrator::castFrom(halV1_0);
- if (halV1_3) {
- ALOGV("Successfully connected to Vibrator HAL v1.3 service.");
- return std::make_shared<HidlHalWrapperV1_3>(std::move(scheduler), halV1_3);
- }
- sp<V1_2::IVibrator> halV1_2 = V1_2::IVibrator::castFrom(halV1_0);
- if (halV1_2) {
- ALOGV("Successfully connected to Vibrator HAL v1.2 service.");
- return std::make_shared<HidlHalWrapperV1_2>(std::move(scheduler), halV1_2);
- }
- sp<V1_1::IVibrator> halV1_1 = V1_1::IVibrator::castFrom(halV1_0);
- if (halV1_1) {
- ALOGV("Successfully connected to Vibrator HAL v1.1 service.");
- return std::make_shared<HidlHalWrapperV1_1>(std::move(scheduler), halV1_1);
- }
- ALOGV("Successfully connected to Vibrator HAL v1.0 service.");
- return std::make_shared<HidlHalWrapperV1_0>(std::move(scheduler), halV1_0);
+ ALOGV("Vibrator HAL service not available.");
+ gHalExists = false;
+ return nullptr;
}
// -------------------------------------------------------------------------------------------------
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp
index 536a6b3..5d4c17d 100644
--- a/services/vibratorservice/VibratorHalWrapper.cpp
+++ b/services/vibratorservice/VibratorHalWrapper.cpp
@@ -17,7 +17,6 @@
#define LOG_TAG "VibratorHalWrapper"
#include <aidl/android/hardware/vibrator/IVibrator.h>
-#include <android/hardware/vibrator/1.3/IVibrator.h>
#include <hardware/vibrator.h>
#include <cmath>
@@ -33,32 +32,18 @@
using aidl::android::hardware::vibrator::Effect;
using aidl::android::hardware::vibrator::EffectStrength;
using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry;
+using aidl::android::hardware::vibrator::IVibrator;
using aidl::android::hardware::vibrator::PrimitivePwle;
using aidl::android::hardware::vibrator::VendorEffect;
using std::chrono::milliseconds;
-namespace V1_0 = android::hardware::vibrator::V1_0;
-namespace V1_1 = android::hardware::vibrator::V1_1;
-namespace V1_2 = android::hardware::vibrator::V1_2;
-namespace V1_3 = android::hardware::vibrator::V1_3;
-namespace Aidl = aidl::android::hardware::vibrator;
-
namespace android {
namespace vibrator {
// -------------------------------------------------------------------------------------------------
-template <class T>
-bool isStaticCastValid(Effect effect) {
- T castEffect = static_cast<T>(effect);
- auto iter = hardware::hidl_enum_range<T>();
- return castEffect >= *iter.begin() && castEffect <= *std::prev(iter.end());
-}
-
-// -------------------------------------------------------------------------------------------------
-
Info HalWrapper::getInfo() {
getCapabilities();
getPrimitiveDurations();
@@ -261,7 +246,7 @@
if (!result.isOk()) {
return;
}
- std::shared_ptr<Aidl::IVibrator> newHandle = result.value();
+ std::shared_ptr<IVibrator> newHandle = result.value();
if (newHandle) {
std::lock_guard<std::mutex> lock(mHandleMutex);
mHandle = std::move(newHandle);
@@ -514,219 +499,13 @@
frequencyToOutputAccelerationMap);
}
-std::shared_ptr<Aidl::IVibrator> AidlHalWrapper::getHal() {
+std::shared_ptr<IVibrator> AidlHalWrapper::getHal() {
std::lock_guard<std::mutex> lock(mHandleMutex);
return mHandle;
}
// -------------------------------------------------------------------------------------------------
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::ping() {
- return HalResultFactory::fromReturn(getHal()->ping());
-}
-
-template <typename I>
-void HidlHalWrapper<I>::tryReconnect() {
- sp<I> newHandle = I::tryGetService();
- if (newHandle) {
- std::lock_guard<std::mutex> lock(mHandleMutex);
- mHandle = std::move(newHandle);
- }
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::on(milliseconds timeout,
- const std::function<void()>& completionCallback) {
- auto status = getHal()->on(timeout.count());
- auto ret = HalResultFactory::fromStatus(status.withDefault(V1_0::Status::UNKNOWN_ERROR));
- if (ret.isOk()) {
- mCallbackScheduler->schedule(completionCallback, timeout);
- }
- return ret;
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::off() {
- auto status = getHal()->off();
- return HalResultFactory::fromStatus(status.withDefault(V1_0::Status::UNKNOWN_ERROR));
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::setAmplitude(float amplitude) {
- uint8_t amp = static_cast<uint8_t>(amplitude * std::numeric_limits<uint8_t>::max());
- auto status = getHal()->setAmplitude(amp);
- return HalResultFactory::fromStatus(status.withDefault(V1_0::Status::UNKNOWN_ERROR));
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::setExternalControl(bool) {
- ALOGV("Skipped setExternalControl because Vibrator HAL does not support it");
- return HalResult<void>::unsupported();
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::alwaysOnEnable(int32_t, Effect, EffectStrength) {
- ALOGV("Skipped alwaysOnEnable because Vibrator HAL AIDL is not available");
- return HalResult<void>::unsupported();
-}
-
-template <typename I>
-HalResult<void> HidlHalWrapper<I>::alwaysOnDisable(int32_t) {
- ALOGV("Skipped alwaysOnDisable because Vibrator HAL AIDL is not available");
- return HalResult<void>::unsupported();
-}
-
-template <typename I>
-HalResult<Capabilities> HidlHalWrapper<I>::getCapabilitiesInternal() {
- hardware::Return<bool> result = getHal()->supportsAmplitudeControl();
- Capabilities capabilities =
- result.withDefault(false) ? Capabilities::AMPLITUDE_CONTROL : Capabilities::NONE;
- return HalResultFactory::fromReturn<Capabilities>(std::move(result), capabilities);
-}
-
-template <typename I>
-template <typename T>
-HalResult<milliseconds> HidlHalWrapper<I>::performInternal(
- perform_fn<T> performFn, sp<I> handle, T effect, EffectStrength strength,
- const std::function<void()>& completionCallback) {
- V1_0::Status status;
- int32_t lengthMs;
- auto effectCallback = [&status, &lengthMs](V1_0::Status retStatus, uint32_t retLengthMs) {
- status = retStatus;
- lengthMs = retLengthMs;
- };
-
- V1_0::EffectStrength effectStrength = static_cast<V1_0::EffectStrength>(strength);
- auto result = std::invoke(performFn, handle, effect, effectStrength, effectCallback);
- milliseconds length = milliseconds(lengthMs);
-
- auto ret = HalResultFactory::fromReturn<milliseconds>(std::move(result), status, length);
- if (ret.isOk()) {
- mCallbackScheduler->schedule(completionCallback, length);
- }
-
- return ret;
-}
-
-template <typename I>
-sp<I> HidlHalWrapper<I>::getHal() {
- std::lock_guard<std::mutex> lock(mHandleMutex);
- return mHandle;
-}
-
-// -------------------------------------------------------------------------------------------------
-
-HalResult<milliseconds> HidlHalWrapperV1_0::performEffect(
- Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
- if (isStaticCastValid<V1_0::Effect>(effect)) {
- return performInternal(&V1_0::IVibrator::perform, getHal(),
- static_cast<V1_0::Effect>(effect), strength, completionCallback);
- }
-
- ALOGV("Skipped performEffect because Vibrator HAL does not support effect %s",
- Aidl::toString(effect).c_str());
- return HalResult<milliseconds>::unsupported();
-}
-
-// -------------------------------------------------------------------------------------------------
-
-HalResult<milliseconds> HidlHalWrapperV1_1::performEffect(
- Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
- if (isStaticCastValid<V1_0::Effect>(effect)) {
- return performInternal(&V1_1::IVibrator::perform, getHal(),
- static_cast<V1_0::Effect>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_1::Effect_1_1>(effect)) {
- return performInternal(&V1_1::IVibrator::perform_1_1, getHal(),
- static_cast<V1_1::Effect_1_1>(effect), strength, completionCallback);
- }
-
- ALOGV("Skipped performEffect because Vibrator HAL does not support effect %s",
- Aidl::toString(effect).c_str());
- return HalResult<milliseconds>::unsupported();
-}
-
-// -------------------------------------------------------------------------------------------------
-
-HalResult<milliseconds> HidlHalWrapperV1_2::performEffect(
- Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
- if (isStaticCastValid<V1_0::Effect>(effect)) {
- return performInternal(&V1_2::IVibrator::perform, getHal(),
- static_cast<V1_0::Effect>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_1::Effect_1_1>(effect)) {
- return performInternal(&V1_2::IVibrator::perform_1_1, getHal(),
- static_cast<V1_1::Effect_1_1>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_2::Effect>(effect)) {
- return performInternal(&V1_2::IVibrator::perform_1_2, getHal(),
- static_cast<V1_2::Effect>(effect), strength, completionCallback);
- }
-
- ALOGV("Skipped performEffect because Vibrator HAL does not support effect %s",
- Aidl::toString(effect).c_str());
- return HalResult<milliseconds>::unsupported();
-}
-
-// -------------------------------------------------------------------------------------------------
-
-HalResult<void> HidlHalWrapperV1_3::setExternalControl(bool enabled) {
- auto result = getHal()->setExternalControl(static_cast<uint32_t>(enabled));
- return HalResultFactory::fromStatus(result.withDefault(V1_0::Status::UNKNOWN_ERROR));
-}
-
-HalResult<milliseconds> HidlHalWrapperV1_3::performEffect(
- Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
- if (isStaticCastValid<V1_0::Effect>(effect)) {
- return performInternal(&V1_3::IVibrator::perform, getHal(),
- static_cast<V1_0::Effect>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_1::Effect_1_1>(effect)) {
- return performInternal(&V1_3::IVibrator::perform_1_1, getHal(),
- static_cast<V1_1::Effect_1_1>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_2::Effect>(effect)) {
- return performInternal(&V1_3::IVibrator::perform_1_2, getHal(),
- static_cast<V1_2::Effect>(effect), strength, completionCallback);
- }
- if (isStaticCastValid<V1_3::Effect>(effect)) {
- return performInternal(&V1_3::IVibrator::perform_1_3, getHal(),
- static_cast<V1_3::Effect>(effect), strength, completionCallback);
- }
-
- ALOGV("Skipped performEffect because Vibrator HAL does not support effect %s",
- Aidl::toString(effect).c_str());
- return HalResult<milliseconds>::unsupported();
-}
-
-HalResult<Capabilities> HidlHalWrapperV1_3::getCapabilitiesInternal() {
- Capabilities capabilities = Capabilities::NONE;
-
- sp<V1_3::IVibrator> hal = getHal();
- auto amplitudeResult = hal->supportsAmplitudeControl();
- if (!amplitudeResult.isOk()) {
- return HalResultFactory::fromReturn<Capabilities>(std::move(amplitudeResult), capabilities);
- }
-
- auto externalControlResult = hal->supportsExternalControl();
- if (amplitudeResult.withDefault(false)) {
- capabilities |= Capabilities::AMPLITUDE_CONTROL;
- }
- if (externalControlResult.withDefault(false)) {
- capabilities |= Capabilities::EXTERNAL_CONTROL;
-
- if (amplitudeResult.withDefault(false)) {
- capabilities |= Capabilities::EXTERNAL_AMPLITUDE_CONTROL;
- }
- }
-
- return HalResultFactory::fromReturn<Capabilities>(std::move(externalControlResult),
- capabilities);
-}
-
-// -------------------------------------------------------------------------------------------------
-
}; // namespace vibrator
}; // namespace android
diff --git a/services/vibratorservice/VibratorManagerHalController.cpp b/services/vibratorservice/VibratorManagerHalController.cpp
index 494f88f..31b6ed0 100644
--- a/services/vibratorservice/VibratorManagerHalController.cpp
+++ b/services/vibratorservice/VibratorManagerHalController.cpp
@@ -20,7 +20,10 @@
#include <vibratorservice/VibratorManagerHalController.h>
-namespace Aidl = aidl::android::hardware::vibrator;
+using aidl::android::hardware::vibrator::IVibrationSession;
+using aidl::android::hardware::vibrator::IVibrator;
+using aidl::android::hardware::vibrator::IVibratorManager;
+using aidl::android::hardware::vibrator::VibrationSessionConfig;
namespace android {
@@ -29,9 +32,9 @@
std::shared_ptr<ManagerHalWrapper> connectManagerHal(std::shared_ptr<CallbackScheduler> scheduler) {
static bool gHalExists = true;
if (gHalExists) {
- auto serviceName = std::string(Aidl::IVibratorManager::descriptor) + "/default";
+ auto serviceName = std::string(IVibratorManager::descriptor) + "/default";
if (AServiceManager_isDeclared(serviceName.c_str())) {
- std::shared_ptr<Aidl::IVibratorManager> hal = Aidl::IVibratorManager::fromBinder(
+ std::shared_ptr<IVibratorManager> hal = IVibratorManager::fromBinder(
ndk::SpAIBinder(AServiceManager_checkService(serviceName.c_str())));
if (hal) {
ALOGV("Successfully connected to VibratorManager HAL AIDL service.");
@@ -41,6 +44,7 @@
}
}
+ ALOGV("VibratorManager HAL service not available.");
gHalExists = false;
return std::make_shared<LegacyManagerHalWrapper>();
}
@@ -150,10 +154,10 @@
return apply(cancelSyncedFn, "cancelSynced");
}
-HalResult<std::shared_ptr<Aidl::IVibrationSession>> ManagerHalController::startSession(
- const std::vector<int32_t>& ids, const Aidl::VibrationSessionConfig& config,
+HalResult<std::shared_ptr<IVibrationSession>> ManagerHalController::startSession(
+ const std::vector<int32_t>& ids, const VibrationSessionConfig& config,
const std::function<void()>& completionCallback) {
- hal_fn<std::shared_ptr<Aidl::IVibrationSession>> startSessionFn =
+ hal_fn<std::shared_ptr<IVibrationSession>> startSessionFn =
[&](std::shared_ptr<ManagerHalWrapper> hal) {
return hal->startSession(ids, config, completionCallback);
};
diff --git a/services/vibratorservice/VibratorManagerHalWrapper.cpp b/services/vibratorservice/VibratorManagerHalWrapper.cpp
index 3db8ff8..bab3f58 100644
--- a/services/vibratorservice/VibratorManagerHalWrapper.cpp
+++ b/services/vibratorservice/VibratorManagerHalWrapper.cpp
@@ -20,7 +20,10 @@
#include <vibratorservice/VibratorManagerHalWrapper.h>
-namespace Aidl = aidl::android::hardware::vibrator;
+using aidl::android::hardware::vibrator::IVibrationSession;
+using aidl::android::hardware::vibrator::IVibrator;
+using aidl::android::hardware::vibrator::IVibratorManager;
+using aidl::android::hardware::vibrator::VibrationSessionConfig;
namespace android {
@@ -41,10 +44,9 @@
return HalResult<void>::unsupported();
}
-HalResult<std::shared_ptr<Aidl::IVibrationSession>> ManagerHalWrapper::startSession(
- const std::vector<int32_t>&, const Aidl::VibrationSessionConfig&,
- const std::function<void()>&) {
- return HalResult<std::shared_ptr<Aidl::IVibrationSession>>::unsupported();
+HalResult<std::shared_ptr<IVibrationSession>> ManagerHalWrapper::startSession(
+ const std::vector<int32_t>&, const VibrationSessionConfig&, const std::function<void()>&) {
+ return HalResult<std::shared_ptr<IVibrationSession>>::unsupported();
}
HalResult<void> ManagerHalWrapper::clearSessions() {
@@ -87,11 +89,11 @@
std::shared_ptr<HalWrapper> AidlManagerHalWrapper::connectToVibrator(
int32_t vibratorId, std::shared_ptr<CallbackScheduler> callbackScheduler) {
- std::function<HalResult<std::shared_ptr<Aidl::IVibrator>>()> reconnectFn = [=, this]() {
- std::shared_ptr<Aidl::IVibrator> vibrator;
+ std::function<HalResult<std::shared_ptr<IVibrator>>()> reconnectFn = [=, this]() {
+ std::shared_ptr<IVibrator> vibrator;
auto status = this->getHal()->getVibrator(vibratorId, &vibrator);
- return HalResultFactory::fromStatus<std::shared_ptr<Aidl::IVibrator>>(std::move(status),
- vibrator);
+ return HalResultFactory::fromStatus<std::shared_ptr<IVibrator>>(std::move(status),
+ vibrator);
};
auto result = reconnectFn();
if (!result.isOk()) {
@@ -110,8 +112,8 @@
}
void AidlManagerHalWrapper::tryReconnect() {
- auto aidlServiceName = std::string(Aidl::IVibratorManager::descriptor) + "/default";
- std::shared_ptr<Aidl::IVibratorManager> newHandle = Aidl::IVibratorManager::fromBinder(
+ auto aidlServiceName = std::string(IVibratorManager::descriptor) + "/default";
+ std::shared_ptr<IVibratorManager> newHandle = IVibratorManager::fromBinder(
ndk::SpAIBinder(AServiceManager_checkService(aidlServiceName.c_str())));
if (newHandle) {
std::lock_guard<std::mutex> lock(mHandleMutex);
@@ -198,15 +200,14 @@
return HalResultFactory::fromStatus(getHal()->triggerSynced(cb));
}
-HalResult<std::shared_ptr<Aidl::IVibrationSession>> AidlManagerHalWrapper::startSession(
- const std::vector<int32_t>& ids, const Aidl::VibrationSessionConfig& config,
+HalResult<std::shared_ptr<IVibrationSession>> AidlManagerHalWrapper::startSession(
+ const std::vector<int32_t>& ids, const VibrationSessionConfig& config,
const std::function<void()>& completionCallback) {
auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback);
- std::shared_ptr<Aidl::IVibrationSession> session;
+ std::shared_ptr<IVibrationSession> session;
auto status = getHal()->startSession(ids, config, cb, &session);
- return HalResultFactory::fromStatus<std::shared_ptr<Aidl::IVibrationSession>>(std::move(status),
- std::move(
- session));
+ return HalResultFactory::fromStatus<std::shared_ptr<IVibrationSession>>(std::move(status),
+ std::move(session));
}
HalResult<void> AidlManagerHalWrapper::cancelSynced() {
@@ -227,7 +228,7 @@
return HalResultFactory::fromStatus(getHal()->clearSessions());
}
-std::shared_ptr<Aidl::IVibratorManager> AidlManagerHalWrapper::getHal() {
+std::shared_ptr<IVibratorManager> AidlManagerHalWrapper::getHal() {
std::lock_guard<std::mutex> lock(mHandleMutex);
return mHandle;
}
diff --git a/services/vibratorservice/benchmarks/Android.bp b/services/vibratorservice/benchmarks/Android.bp
index 915d6c7..6fc5cf3 100644
--- a/services/vibratorservice/benchmarks/Android.bp
+++ b/services/vibratorservice/benchmarks/Android.bp
@@ -29,15 +29,10 @@
],
shared_libs: [
"libbinder_ndk",
- "libhidlbase",
"liblog",
"libutils",
"libvibratorservice",
"android.hardware.vibrator-V3-ndk",
- "android.hardware.vibrator@1.0",
- "android.hardware.vibrator@1.1",
- "android.hardware.vibrator@1.2",
- "android.hardware.vibrator@1.3",
],
cflags: [
"-Wall",
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
index 9a39ad4..0652278 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
@@ -22,7 +22,6 @@
#include <android-base/thread_annotations.h>
#include <android/binder_manager.h>
-#include <android/hardware/vibrator/1.3/IVibrator.h>
#include <binder/IServiceManager.h>
#include <vibratorservice/VibratorCallbackScheduler.h>
@@ -105,26 +104,6 @@
: fromFailedStatus<T>(std::move(status));
}
- template <typename T>
- static HalResult<T> fromStatus(hardware::vibrator::V1_0::Status&& status, T data) {
- return (status == hardware::vibrator::V1_0::Status::OK)
- ? HalResult<T>::ok(std::move(data))
- : fromFailedStatus<T>(std::move(status));
- }
-
- template <typename T, typename R>
- static HalResult<T> fromReturn(hardware::Return<R>&& ret, T data) {
- return ret.isOk() ? HalResult<T>::ok(std::move(data))
- : fromFailedReturn<T, R>(std::move(ret));
- }
-
- template <typename T, typename R>
- static HalResult<T> fromReturn(hardware::Return<R>&& ret,
- hardware::vibrator::V1_0::Status status, T data) {
- return ret.isOk() ? fromStatus<T>(std::move(status), std::move(data))
- : fromFailedReturn<T, R>(std::move(ret));
- }
-
static HalResult<void> fromStatus(status_t status) {
return (status == android::OK) ? HalResult<void>::ok()
: fromFailedStatus<void>(std::move(status));
@@ -134,17 +113,6 @@
return status.isOk() ? HalResult<void>::ok() : fromFailedStatus<void>(std::move(status));
}
- static HalResult<void> fromStatus(hardware::vibrator::V1_0::Status&& status) {
- return (status == hardware::vibrator::V1_0::Status::OK)
- ? HalResult<void>::ok()
- : fromFailedStatus<void>(std::move(status));
- }
-
- template <typename R>
- static HalResult<void> fromReturn(hardware::Return<R>&& ret) {
- return ret.isOk() ? HalResult<void>::ok() : fromFailedReturn<void, R>(std::move(ret));
- }
-
private:
template <typename T>
static HalResult<T> fromFailedStatus(status_t status) {
@@ -166,23 +134,6 @@
}
return HalResult<T>::failed(status.getMessage());
}
-
- template <typename T>
- static HalResult<T> fromFailedStatus(hardware::vibrator::V1_0::Status&& status) {
- switch (status) {
- case hardware::vibrator::V1_0::Status::UNSUPPORTED_OPERATION:
- return HalResult<T>::unsupported();
- default:
- auto msg = "android::hardware::vibrator::V1_0::Status = " + toString(status);
- return HalResult<T>::failed(msg.c_str());
- }
- }
-
- template <typename T, typename R>
- static HalResult<T> fromFailedReturn(hardware::Return<R>&& ret) {
- return ret.isDeadObject() ? HalResult<T>::transactionFailed(ret.description().c_str())
- : HalResult<T>::failed(ret.description().c_str());
- }
};
// -------------------------------------------------------------------------------------------------
@@ -548,108 +499,6 @@
std::shared_ptr<IVibrator> getHal();
};
-// Wrapper for the HDIL Vibrator HALs.
-template <typename I>
-class HidlHalWrapper : public HalWrapper {
-public:
- HidlHalWrapper(std::shared_ptr<CallbackScheduler> scheduler, sp<I> handle)
- : HalWrapper(std::move(scheduler)), mHandle(std::move(handle)) {}
- virtual ~HidlHalWrapper() = default;
-
- HalResult<void> ping() override final;
- void tryReconnect() override final;
-
- HalResult<void> on(std::chrono::milliseconds timeout,
- const std::function<void()>& completionCallback) override final;
- HalResult<void> off() override final;
-
- HalResult<void> setAmplitude(float amplitude) override final;
- virtual HalResult<void> setExternalControl(bool enabled) override;
-
- HalResult<void> alwaysOnEnable(int32_t id, HalWrapper::Effect effect,
- HalWrapper::EffectStrength strength) override final;
- HalResult<void> alwaysOnDisable(int32_t id) override final;
-
-protected:
- std::mutex mHandleMutex;
- sp<I> mHandle GUARDED_BY(mHandleMutex);
-
- virtual HalResult<Capabilities> getCapabilitiesInternal() override;
-
- template <class T>
- using perform_fn =
- hardware::Return<void> (I::*)(T, hardware::vibrator::V1_0::EffectStrength,
- hardware::vibrator::V1_0::IVibrator::perform_cb);
-
- template <class T>
- HalResult<std::chrono::milliseconds> performInternal(
- perform_fn<T> performFn, sp<I> handle, T effect, HalWrapper::EffectStrength strength,
- const std::function<void()>& completionCallback);
-
- sp<I> getHal();
-};
-
-// Wrapper for the HDIL Vibrator HAL v1.0.
-class HidlHalWrapperV1_0 : public HidlHalWrapper<hardware::vibrator::V1_0::IVibrator> {
-public:
- HidlHalWrapperV1_0(std::shared_ptr<CallbackScheduler> scheduler,
- sp<hardware::vibrator::V1_0::IVibrator> handle)
- : HidlHalWrapper<hardware::vibrator::V1_0::IVibrator>(std::move(scheduler),
- std::move(handle)) {}
- virtual ~HidlHalWrapperV1_0() = default;
-
- HalResult<std::chrono::milliseconds> performEffect(
- HalWrapper::Effect effect, HalWrapper::EffectStrength strength,
- const std::function<void()>& completionCallback) override final;
-};
-
-// Wrapper for the HDIL Vibrator HAL v1.1.
-class HidlHalWrapperV1_1 : public HidlHalWrapper<hardware::vibrator::V1_1::IVibrator> {
-public:
- HidlHalWrapperV1_1(std::shared_ptr<CallbackScheduler> scheduler,
- sp<hardware::vibrator::V1_1::IVibrator> handle)
- : HidlHalWrapper<hardware::vibrator::V1_1::IVibrator>(std::move(scheduler),
- std::move(handle)) {}
- virtual ~HidlHalWrapperV1_1() = default;
-
- HalResult<std::chrono::milliseconds> performEffect(
- HalWrapper::Effect effect, HalWrapper::EffectStrength strength,
- const std::function<void()>& completionCallback) override final;
-};
-
-// Wrapper for the HDIL Vibrator HAL v1.2.
-class HidlHalWrapperV1_2 : public HidlHalWrapper<hardware::vibrator::V1_2::IVibrator> {
-public:
- HidlHalWrapperV1_2(std::shared_ptr<CallbackScheduler> scheduler,
- sp<hardware::vibrator::V1_2::IVibrator> handle)
- : HidlHalWrapper<hardware::vibrator::V1_2::IVibrator>(std::move(scheduler),
- std::move(handle)) {}
- virtual ~HidlHalWrapperV1_2() = default;
-
- HalResult<std::chrono::milliseconds> performEffect(
- HalWrapper::Effect effect, HalWrapper::EffectStrength strength,
- const std::function<void()>& completionCallback) override final;
-};
-
-// Wrapper for the HDIL Vibrator HAL v1.3.
-class HidlHalWrapperV1_3 : public HidlHalWrapper<hardware::vibrator::V1_3::IVibrator> {
-public:
- HidlHalWrapperV1_3(std::shared_ptr<CallbackScheduler> scheduler,
- sp<hardware::vibrator::V1_3::IVibrator> handle)
- : HidlHalWrapper<hardware::vibrator::V1_3::IVibrator>(std::move(scheduler),
- std::move(handle)) {}
- virtual ~HidlHalWrapperV1_3() = default;
-
- HalResult<void> setExternalControl(bool enabled) override final;
-
- HalResult<std::chrono::milliseconds> performEffect(
- HalWrapper::Effect effect, HalWrapper::EffectStrength strength,
- const std::function<void()>& completionCallback) override final;
-
-protected:
- HalResult<Capabilities> getCapabilitiesInternal() override final;
-};
-
// -------------------------------------------------------------------------------------------------
}; // namespace vibrator
diff --git a/services/vibratorservice/test/Android.bp b/services/vibratorservice/test/Android.bp
index 92527eb..038248e 100644
--- a/services/vibratorservice/test/Android.bp
+++ b/services/vibratorservice/test/Android.bp
@@ -29,10 +29,6 @@
"VibratorCallbackSchedulerTest.cpp",
"VibratorHalControllerTest.cpp",
"VibratorHalWrapperAidlTest.cpp",
- "VibratorHalWrapperHidlV1_0Test.cpp",
- "VibratorHalWrapperHidlV1_1Test.cpp",
- "VibratorHalWrapperHidlV1_2Test.cpp",
- "VibratorHalWrapperHidlV1_3Test.cpp",
"VibratorManagerHalControllerTest.cpp",
"VibratorManagerHalWrapperAidlTest.cpp",
"VibratorManagerHalWrapperLegacyTest.cpp",
@@ -45,15 +41,10 @@
shared_libs: [
"libbase",
"libbinder_ndk",
- "libhidlbase",
"liblog",
"libvibratorservice",
"libutils",
"android.hardware.vibrator-V3-ndk",
- "android.hardware.vibrator@1.0",
- "android.hardware.vibrator@1.1",
- "android.hardware.vibrator@1.2",
- "android.hardware.vibrator@1.3",
],
static_libs: [
"libgmock",
diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp
deleted file mode 100644
index 04dbe4e..0000000
--- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "VibratorHalWrapperHidlV1_0Test"
-
-#include <aidl/android/hardware/vibrator/IVibrator.h>
-#include <android/persistable_bundle_aidl.h>
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include <utils/Log.h>
-#include <thread>
-
-#include <vibratorservice/VibratorCallbackScheduler.h>
-#include <vibratorservice/VibratorHalWrapper.h>
-
-#include "test_mocks.h"
-#include "test_utils.h"
-
-namespace V1_0 = android::hardware::vibrator::V1_0;
-
-using aidl::android::hardware::vibrator::Braking;
-using aidl::android::hardware::vibrator::CompositeEffect;
-using aidl::android::hardware::vibrator::CompositePrimitive;
-using aidl::android::hardware::vibrator::CompositePwleV2;
-using aidl::android::hardware::vibrator::Effect;
-using aidl::android::hardware::vibrator::EffectStrength;
-using aidl::android::hardware::vibrator::IVibrator;
-using aidl::android::hardware::vibrator::PrimitivePwle;
-using aidl::android::hardware::vibrator::PwleV2Primitive;
-using aidl::android::hardware::vibrator::VendorEffect;
-using aidl::android::os::PersistableBundle;
-
-using namespace android;
-using namespace std::chrono_literals;
-using namespace testing;
-
-// -------------------------------------------------------------------------------------------------
-
-class MockIVibratorV1_0 : public V1_0::IVibrator {
-public:
- MOCK_METHOD(hardware::Return<void>, ping, (), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, on, (uint32_t timeoutMs), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, off, (), (override));
- MOCK_METHOD(hardware::Return<bool>, supportsAmplitudeControl, (), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, setAmplitude, (uint8_t amplitude), (override));
- MOCK_METHOD(hardware::Return<void>, perform,
- (V1_0::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
-};
-
-// -------------------------------------------------------------------------------------------------
-
-class VibratorHalWrapperHidlV1_0Test : public Test {
-public:
- void SetUp() override {
- mMockHal = new StrictMock<MockIVibratorV1_0>();
- mMockScheduler = std::make_shared<StrictMock<vibrator::MockCallbackScheduler>>();
- mWrapper = std::make_unique<vibrator::HidlHalWrapperV1_0>(mMockScheduler, mMockHal);
- ASSERT_NE(mWrapper, nullptr);
- }
-
-protected:
- std::shared_ptr<StrictMock<vibrator::MockCallbackScheduler>> mMockScheduler = nullptr;
- std::unique_ptr<vibrator::HalWrapper> mWrapper = nullptr;
- sp<StrictMock<MockIVibratorV1_0>> mMockHal = nullptr;
-};
-
-// -------------------------------------------------------------------------------------------------
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPing) {
- EXPECT_CALL(*mMockHal.get(), ping())
- .Times(Exactly(2))
- .WillOnce([]() { return hardware::Return<void>(); })
- .WillRepeatedly([]() {
- return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
- });
-
- ASSERT_TRUE(mWrapper->ping().isOk());
- ASSERT_TRUE(mWrapper->ping().isFailed());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestOn) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), on(Eq(static_cast<uint32_t>(1))))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](uint32_t) { return hardware::Return<V1_0::Status>(V1_0::Status::OK); });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(1ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- EXPECT_CALL(*mMockHal.get(), on(Eq(static_cast<uint32_t>(10))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint32_t) {
- return hardware::Return<V1_0::Status>(V1_0::Status::UNSUPPORTED_OPERATION);
- });
- EXPECT_CALL(*mMockHal.get(), on(Eq(static_cast<uint32_t>(11))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint32_t) {
- return hardware::Return<V1_0::Status>(V1_0::Status::BAD_VALUE);
- });
- EXPECT_CALL(*mMockHal.get(), on(Eq(static_cast<uint32_t>(12))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint32_t) {
- return hardware::Return<V1_0::Status>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->on(1ms, callback).isOk());
- ASSERT_EQ(1, *callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->on(10ms, callback).isUnsupported());
- ASSERT_TRUE(mWrapper->on(11ms, callback).isFailed());
- ASSERT_TRUE(mWrapper->on(12ms, callback).isFailed());
-
- // Callback not triggered for unsupported and on failure
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestOff) {
- EXPECT_CALL(*mMockHal.get(), off())
- .Times(Exactly(4))
- .WillOnce([]() { return hardware::Return<V1_0::Status>(V1_0::Status::OK); })
- .WillOnce([]() {
- return hardware::Return<V1_0::Status>(V1_0::Status::UNSUPPORTED_OPERATION);
- })
- .WillOnce([]() { return hardware::Return<V1_0::Status>(V1_0::Status::BAD_VALUE); })
- .WillRepeatedly([]() {
- return hardware::Return<V1_0::Status>(hardware::Status::fromExceptionCode(-1));
- });
-
- ASSERT_TRUE(mWrapper->off().isOk());
- ASSERT_TRUE(mWrapper->off().isUnsupported());
- ASSERT_TRUE(mWrapper->off().isFailed());
- ASSERT_TRUE(mWrapper->off().isFailed());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestSetAmplitude) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(static_cast<uint8_t>(1))))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](uint8_t) { return hardware::Return<V1_0::Status>(V1_0::Status::OK); });
- EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(static_cast<uint8_t>(2))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint8_t) {
- return hardware::Return<V1_0::Status>(V1_0::Status::UNSUPPORTED_OPERATION);
- });
- EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(static_cast<uint8_t>(3))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint8_t) {
- return hardware::Return<V1_0::Status>(V1_0::Status::BAD_VALUE);
- });
- EXPECT_CALL(*mMockHal.get(), setAmplitude(Eq(static_cast<uint8_t>(4))))
- .Times(Exactly(1))
- .WillRepeatedly([](uint8_t) {
- return hardware::Return<V1_0::Status>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- auto maxAmplitude = std::numeric_limits<uint8_t>::max();
- ASSERT_TRUE(mWrapper->setAmplitude(1.0f / maxAmplitude).isOk());
- ASSERT_TRUE(mWrapper->setAmplitude(2.0f / maxAmplitude).isUnsupported());
- ASSERT_TRUE(mWrapper->setAmplitude(3.0f / maxAmplitude).isFailed());
- ASSERT_TRUE(mWrapper->setAmplitude(4.0f / maxAmplitude).isFailed());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestSetExternalControlUnsupported) {
- ASSERT_TRUE(mWrapper->setExternalControl(true).isUnsupported());
- ASSERT_TRUE(mWrapper->setExternalControl(false).isUnsupported());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestAlwaysOnEnableUnsupported) {
- ASSERT_TRUE(mWrapper->alwaysOnEnable(1, Effect::CLICK, EffectStrength::LIGHT).isUnsupported());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestAlwaysOnDisableUnsupported) {
- ASSERT_TRUE(mWrapper->alwaysOnDisable(1).isUnsupported());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestGetInfoDoesNotCacheFailedResult) {
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(2))
- .WillOnce([]() {
- return hardware::Return<bool>(hardware::Status::fromExceptionCode(-1));
- })
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
-
- ASSERT_TRUE(mWrapper->getInfo().capabilities.isFailed());
-
- vibrator::Info info = mWrapper->getInfo();
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, info.capabilities.value());
- ASSERT_TRUE(info.supportedEffects.isUnsupported());
- ASSERT_TRUE(info.supportedBraking.isUnsupported());
- ASSERT_TRUE(info.supportedPrimitives.isUnsupported());
- ASSERT_TRUE(info.primitiveDurations.isUnsupported());
- ASSERT_TRUE(info.primitiveDelayMax.isUnsupported());
- ASSERT_TRUE(info.pwlePrimitiveDurationMax.isUnsupported());
- ASSERT_TRUE(info.compositionSizeMax.isUnsupported());
- ASSERT_TRUE(info.pwleSizeMax.isUnsupported());
- ASSERT_TRUE(info.minFrequency.isUnsupported());
- ASSERT_TRUE(info.resonantFrequency.isUnsupported());
- ASSERT_TRUE(info.frequencyResolution.isUnsupported());
- ASSERT_TRUE(info.qFactor.isUnsupported());
- ASSERT_TRUE(info.maxAmplitudes.isUnsupported());
- ASSERT_TRUE(info.maxEnvelopeEffectSize.isUnsupported());
- ASSERT_TRUE(info.minEnvelopeEffectControlPointDuration.isUnsupported());
- ASSERT_TRUE(info.maxEnvelopeEffectControlPointDuration.isUnsupported());
- ASSERT_TRUE(info.frequencyToOutputAccelerationMap.isUnsupported());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestGetInfoWithoutAmplitudeControl) {
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl()).Times(Exactly(1)).WillRepeatedly([]() {
- return hardware::Return<bool>(false);
- });
-
- ASSERT_EQ(vibrator::Capabilities::NONE, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestGetInfoCachesResult) {
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl()).Times(Exactly(1)).WillRepeatedly([]() {
- return hardware::Return<bool>(true);
- });
-
- std::vector<std::thread> threads;
- for (int i = 0; i < 10; i++) {
- threads.push_back(
- std::thread([&]() { ASSERT_TRUE(mWrapper->getInfo().capabilities.isOk()); }));
- }
- std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
-
- vibrator::Info info = mWrapper->getInfo();
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, info.capabilities.value());
- ASSERT_TRUE(info.supportedEffects.isUnsupported());
- ASSERT_TRUE(info.supportedBraking.isUnsupported());
- ASSERT_TRUE(info.supportedPrimitives.isUnsupported());
- ASSERT_TRUE(info.primitiveDurations.isUnsupported());
- ASSERT_TRUE(info.minFrequency.isUnsupported());
- ASSERT_TRUE(info.resonantFrequency.isUnsupported());
- ASSERT_TRUE(info.frequencyResolution.isUnsupported());
- ASSERT_TRUE(info.qFactor.isUnsupported());
- ASSERT_TRUE(info.maxAmplitudes.isUnsupported());
- ASSERT_TRUE(info.maxEnvelopeEffectSize.isUnsupported());
- ASSERT_TRUE(info.minEnvelopeEffectControlPointDuration.isUnsupported());
- ASSERT_TRUE(info.maxEnvelopeEffectControlPointDuration.isUnsupported());
- ASSERT_TRUE(info.frequencyToOutputAccelerationMap.isUnsupported());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformEffect) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_0::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::MEDIUM), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_0::perform_cb cb) {
- cb(V1_0::Status::UNSUPPORTED_OPERATION, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::STRONG), _))
- .Times(Exactly(2))
- .WillOnce([](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_0::perform_cb cb) {
- cb(V1_0::Status::BAD_VALUE, 10);
- return hardware::Return<void>();
- })
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_0::perform_cb) {
- return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- auto result = mWrapper->performEffect(Effect::CLICK, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-
- result = mWrapper->performEffect(Effect::CLICK, EffectStrength::MEDIUM, callback);
- ASSERT_TRUE(result.isUnsupported());
-
- result = mWrapper->performEffect(Effect::CLICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- result = mWrapper->performEffect(Effect::CLICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- // Callback not triggered for unsupported and on failure
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformEffectUnsupported) {
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- // Using TICK that is only available in v1.1
- auto result = mWrapper->performEffect(Effect::TICK, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isUnsupported());
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformVendorEffectUnsupported) {
- PersistableBundle vendorData; // empty
- VendorEffect vendorEffect;
- vendorEffect.vendorData = vendorData;
- vendorEffect.strength = EffectStrength::LIGHT;
- vendorEffect.scale = 1.0f;
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->performVendorEffect(vendorEffect, callback).isUnsupported());
-
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformComposedEffectUnsupported) {
- std::vector<CompositeEffect> emptyEffects, singleEffect, multipleEffects;
- singleEffect.push_back(
- vibrator::TestFactory::createCompositeEffect(CompositePrimitive::CLICK, 10ms, 0.0f));
- multipleEffects.push_back(
- vibrator::TestFactory::createCompositeEffect(CompositePrimitive::SPIN, 100ms, 0.5f));
- multipleEffects.push_back(
- vibrator::TestFactory::createCompositeEffect(CompositePrimitive::THUD, 1000ms, 1.0f));
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->performComposedEffect(singleEffect, callback).isUnsupported());
- ASSERT_TRUE(mWrapper->performComposedEffect(multipleEffects, callback).isUnsupported());
-
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformPwleEffectUnsupported) {
- std::vector<PrimitivePwle> emptyPrimitives, multiplePrimitives;
- multiplePrimitives.push_back(vibrator::TestFactory::createActivePwle(0, 1, 0, 1, 10ms));
- multiplePrimitives.push_back(vibrator::TestFactory::createBrakingPwle(Braking::NONE, 100ms));
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->performPwleEffect(emptyPrimitives, callback).isUnsupported());
- ASSERT_TRUE(mWrapper->performPwleEffect(multiplePrimitives, callback).isUnsupported());
-
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_0Test, TestComposePwleV2Unsupported) {
- CompositePwleV2 composite;
- composite.pwlePrimitives = {
- PwleV2Primitive(/*amplitude=*/0.2, /*frequency=*/50, /*time=*/100),
- PwleV2Primitive(/*amplitude=*/0.5, /*frequency=*/150, /*time=*/100),
- PwleV2Primitive(/*amplitude=*/0.8, /*frequency=*/250, /*time=*/100),
- };
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- ASSERT_TRUE(mWrapper->composePwleV2(composite, callback).isUnsupported());
-
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_1Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_1Test.cpp
deleted file mode 100644
index b0a6537..0000000
--- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_1Test.cpp
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "VibratorHalWrapperHidlV1_1Test"
-
-#include <aidl/android/hardware/vibrator/IVibrator.h>
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include <utils/Log.h>
-
-#include <vibratorservice/VibratorCallbackScheduler.h>
-#include <vibratorservice/VibratorHalWrapper.h>
-
-#include "test_mocks.h"
-#include "test_utils.h"
-
-namespace V1_0 = android::hardware::vibrator::V1_0;
-namespace V1_1 = android::hardware::vibrator::V1_1;
-
-using aidl::android::hardware::vibrator::Effect;
-using aidl::android::hardware::vibrator::EffectStrength;
-
-using namespace android;
-using namespace std::chrono_literals;
-using namespace testing;
-
-// -------------------------------------------------------------------------------------------------
-
-class MockIVibratorV1_1 : public V1_1::IVibrator {
-public:
- MOCK_METHOD(hardware::Return<V1_0::Status>, on, (uint32_t timeoutMs), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, off, (), (override));
- MOCK_METHOD(hardware::Return<bool>, supportsAmplitudeControl, (), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, setAmplitude, (uint8_t amplitude), (override));
- MOCK_METHOD(hardware::Return<void>, perform,
- (V1_0::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_1,
- (V1_1::Effect_1_1 effect, V1_0::EffectStrength strength, perform_cb cb),
- (override));
-};
-
-// -------------------------------------------------------------------------------------------------
-
-class VibratorHalWrapperHidlV1_1Test : public Test {
-public:
- void SetUp() override {
- mMockHal = new StrictMock<MockIVibratorV1_1>();
- mMockScheduler = std::make_shared<StrictMock<vibrator::MockCallbackScheduler>>();
- mWrapper = std::make_unique<vibrator::HidlHalWrapperV1_1>(mMockScheduler, mMockHal);
- ASSERT_NE(mWrapper, nullptr);
- }
-
-protected:
- std::shared_ptr<StrictMock<vibrator::MockCallbackScheduler>> mMockScheduler = nullptr;
- std::unique_ptr<vibrator::HalWrapper> mWrapper = nullptr;
- sp<StrictMock<MockIVibratorV1_1>> mMockHal = nullptr;
-};
-
-// -------------------------------------------------------------------------------------------------
-
-TEST_F(VibratorHalWrapperHidlV1_1Test, TestPerformEffectV1_0) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_1::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::CLICK, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_1Test, TestPerformEffectV1_1) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_1(Eq(V1_1::Effect_1_1::TICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly([](V1_1::Effect_1_1, V1_0::EffectStrength,
- MockIVibratorV1_1::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- EXPECT_CALL(*mMockHal.get(),
- perform_1_1(Eq(V1_1::Effect_1_1::TICK), Eq(V1_0::EffectStrength::MEDIUM), _))
- .Times(Exactly(1))
- .WillRepeatedly([](V1_1::Effect_1_1, V1_0::EffectStrength,
- MockIVibratorV1_1::perform_cb cb) {
- cb(V1_0::Status::UNSUPPORTED_OPERATION, 0);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockHal.get(),
- perform_1_1(Eq(V1_1::Effect_1_1::TICK), Eq(V1_0::EffectStrength::STRONG), _))
- .Times(Exactly(2))
- .WillOnce([](V1_1::Effect_1_1, V1_0::EffectStrength,
- MockIVibratorV1_1::perform_cb cb) {
- cb(V1_0::Status::BAD_VALUE, 0);
- return hardware::Return<void>();
- })
- .WillRepeatedly(
- [](V1_1::Effect_1_1, V1_0::EffectStrength, MockIVibratorV1_1::perform_cb) {
- return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- auto result = mWrapper->performEffect(Effect::TICK, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-
- result = mWrapper->performEffect(Effect::TICK, EffectStrength::MEDIUM, callback);
- ASSERT_TRUE(result.isUnsupported());
-
- result = mWrapper->performEffect(Effect::TICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- result = mWrapper->performEffect(Effect::TICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- // Callback not triggered for unsupported and on failure
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_1Test, TestPerformEffectUnsupported) {
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- // Using THUD that is only available in v1.2
- auto result = mWrapper->performEffect(Effect::THUD, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isUnsupported());
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_2Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_2Test.cpp
deleted file mode 100644
index dfe3fa0..0000000
--- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_2Test.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "VibratorHalWrapperHidlV1_2Test"
-
-#include <aidl/android/hardware/vibrator/IVibrator.h>
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include <utils/Log.h>
-
-#include <vibratorservice/VibratorCallbackScheduler.h>
-#include <vibratorservice/VibratorHalWrapper.h>
-
-#include "test_mocks.h"
-#include "test_utils.h"
-
-namespace V1_0 = android::hardware::vibrator::V1_0;
-namespace V1_1 = android::hardware::vibrator::V1_1;
-namespace V1_2 = android::hardware::vibrator::V1_2;
-
-using aidl::android::hardware::vibrator::Effect;
-using aidl::android::hardware::vibrator::EffectStrength;
-
-using namespace android;
-using namespace std::chrono_literals;
-using namespace testing;
-
-// -------------------------------------------------------------------------------------------------
-
-class MockIVibratorV1_2 : public V1_2::IVibrator {
-public:
- MOCK_METHOD(hardware::Return<V1_0::Status>, on, (uint32_t timeoutMs), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, off, (), (override));
- MOCK_METHOD(hardware::Return<bool>, supportsAmplitudeControl, (), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, setAmplitude, (uint8_t amplitude), (override));
- MOCK_METHOD(hardware::Return<void>, perform,
- (V1_0::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_1,
- (V1_1::Effect_1_1 effect, V1_0::EffectStrength strength, perform_cb cb),
- (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_2,
- (V1_2::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
-};
-
-// -------------------------------------------------------------------------------------------------
-
-class VibratorHalWrapperHidlV1_2Test : public Test {
-public:
- void SetUp() override {
- mMockHal = new StrictMock<MockIVibratorV1_2>();
- mMockScheduler = std::make_shared<StrictMock<vibrator::MockCallbackScheduler>>();
- mWrapper = std::make_unique<vibrator::HidlHalWrapperV1_2>(mMockScheduler, mMockHal);
- ASSERT_NE(mWrapper, nullptr);
- }
-
-protected:
- std::shared_ptr<StrictMock<vibrator::MockCallbackScheduler>> mMockScheduler = nullptr;
- std::unique_ptr<vibrator::HalWrapper> mWrapper = nullptr;
- sp<StrictMock<MockIVibratorV1_2>> mMockHal = nullptr;
-};
-
-// -------------------------------------------------------------------------------------------------
-
-TEST_F(VibratorHalWrapperHidlV1_2Test, TestPerformEffectV1_0) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_2::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::CLICK, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_2Test, TestPerformEffectV1_1) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_1(Eq(V1_1::Effect_1_1::TICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly([](V1_1::Effect_1_1, V1_0::EffectStrength,
- MockIVibratorV1_2::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::TICK, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_2Test, TestPerformEffectV1_2) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_2(Eq(V1_2::Effect::THUD), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_2::Effect, V1_0::EffectStrength, MockIVibratorV1_2::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- EXPECT_CALL(*mMockHal.get(),
- perform_1_2(Eq(V1_2::Effect::THUD), Eq(V1_0::EffectStrength::MEDIUM), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_2::Effect, V1_0::EffectStrength, MockIVibratorV1_2::perform_cb cb) {
- cb(V1_0::Status::UNSUPPORTED_OPERATION, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockHal.get(),
- perform_1_2(Eq(V1_2::Effect::THUD), Eq(V1_0::EffectStrength::STRONG), _))
- .Times(Exactly(2))
- .WillOnce([](V1_2::Effect, V1_0::EffectStrength, MockIVibratorV1_2::perform_cb cb) {
- cb(V1_0::Status::BAD_VALUE, 10);
- return hardware::Return<void>();
- })
- .WillRepeatedly(
- [](V1_2::Effect, V1_0::EffectStrength, MockIVibratorV1_2::perform_cb) {
- return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- auto result = mWrapper->performEffect(Effect::THUD, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-
- result = mWrapper->performEffect(Effect::THUD, EffectStrength::MEDIUM, callback);
- ASSERT_TRUE(result.isUnsupported());
-
- result = mWrapper->performEffect(Effect::THUD, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- result = mWrapper->performEffect(Effect::THUD, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- // Callback not triggered for unsupported and on failure
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_2Test, TestPerformEffectUnsupported) {
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- // Using TEXTURE_TICK that is only available in v1.3
- auto result = mWrapper->performEffect(Effect::TEXTURE_TICK, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isUnsupported());
- // No callback is triggered.
- ASSERT_EQ(0, *callbackCounter.get());
-}
diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_3Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_3Test.cpp
deleted file mode 100644
index 8624332..0000000
--- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_3Test.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "VibratorHalWrapperHidlV1_3Test"
-
-#include <aidl/android/hardware/vibrator/IVibrator.h>
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include <utils/Log.h>
-#include <thread>
-
-#include <vibratorservice/VibratorCallbackScheduler.h>
-#include <vibratorservice/VibratorHalWrapper.h>
-
-#include "test_mocks.h"
-#include "test_utils.h"
-
-namespace V1_0 = android::hardware::vibrator::V1_0;
-namespace V1_1 = android::hardware::vibrator::V1_1;
-namespace V1_2 = android::hardware::vibrator::V1_2;
-namespace V1_3 = android::hardware::vibrator::V1_3;
-
-using aidl::android::hardware::vibrator::Effect;
-using aidl::android::hardware::vibrator::EffectStrength;
-using aidl::android::hardware::vibrator::IVibrator;
-
-using namespace android;
-using namespace std::chrono_literals;
-using namespace testing;
-
-// -------------------------------------------------------------------------------------------------
-
-class MockIVibratorV1_3 : public V1_3::IVibrator {
-public:
- MOCK_METHOD(hardware::Return<V1_0::Status>, on, (uint32_t timeoutMs), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, off, (), (override));
- MOCK_METHOD(hardware::Return<bool>, supportsAmplitudeControl, (), (override));
- MOCK_METHOD(hardware::Return<bool>, supportsExternalControl, (), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, setAmplitude, (uint8_t amplitude), (override));
- MOCK_METHOD(hardware::Return<V1_0::Status>, setExternalControl, (bool enabled), (override));
- MOCK_METHOD(hardware::Return<void>, perform,
- (V1_0::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_1,
- (V1_1::Effect_1_1 effect, V1_0::EffectStrength strength, perform_cb cb),
- (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_2,
- (V1_2::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
- MOCK_METHOD(hardware::Return<void>, perform_1_3,
- (V1_3::Effect effect, V1_0::EffectStrength strength, perform_cb cb), (override));
-};
-
-// -------------------------------------------------------------------------------------------------
-
-class VibratorHalWrapperHidlV1_3Test : public Test {
-public:
- void SetUp() override {
- mMockHal = new StrictMock<MockIVibratorV1_3>();
- mMockScheduler = std::make_shared<StrictMock<vibrator::MockCallbackScheduler>>();
- mWrapper = std::make_unique<vibrator::HidlHalWrapperV1_3>(mMockScheduler, mMockHal);
- ASSERT_NE(mWrapper, nullptr);
- }
-
-protected:
- std::shared_ptr<StrictMock<vibrator::MockCallbackScheduler>> mMockScheduler = nullptr;
- std::unique_ptr<vibrator::HalWrapper> mWrapper = nullptr;
- sp<StrictMock<MockIVibratorV1_3>> mMockHal = nullptr;
-};
-
-// -------------------------------------------------------------------------------------------------
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestSetExternalControl) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), setExternalControl(Eq(true)))
- .Times(Exactly(2))
- .WillOnce([]() { return hardware::Return<V1_0::Status>(V1_0::Status::OK); })
- .WillRepeatedly([]() {
- return hardware::Return<V1_0::Status>(V1_0::Status::UNSUPPORTED_OPERATION);
- });
- EXPECT_CALL(*mMockHal.get(), setExternalControl(Eq(false)))
- .Times(Exactly(2))
- .WillOnce([]() { return hardware::Return<V1_0::Status>(V1_0::Status::BAD_VALUE); })
- .WillRepeatedly([]() {
- return hardware::Return<V1_0::Status>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- ASSERT_TRUE(mWrapper->setExternalControl(true).isOk());
- ASSERT_TRUE(mWrapper->setExternalControl(true).isUnsupported());
- ASSERT_TRUE(mWrapper->setExternalControl(false).isFailed());
- ASSERT_TRUE(mWrapper->setExternalControl(false).isFailed());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoSuccessful) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(true);
- });
- }
-
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL | vibrator::Capabilities::EXTERNAL_CONTROL |
- vibrator::Capabilities::EXTERNAL_AMPLITUDE_CONTROL,
- mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoOnlyAmplitudeControl) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(true);
- });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(false);
- });
- }
-
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoOnlyExternalControl) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(false);
- });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(true);
- });
- }
-
- ASSERT_EQ(vibrator::Capabilities::EXTERNAL_CONTROL, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoNoCapabilities) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(false); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(false);
- });
- }
-
- ASSERT_EQ(vibrator::Capabilities::NONE, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoFailed) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() {
- return hardware::Return<bool>(hardware::Status::fromExceptionCode(-1));
- });
-
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() {
- return hardware::Return<bool>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- ASSERT_TRUE(mWrapper->getInfo().capabilities.isFailed());
- ASSERT_TRUE(mWrapper->getInfo().capabilities.isFailed());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoCachesResult) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl()).Times(Exactly(1)).WillOnce([]() {
- return hardware::Return<bool>(false);
- });
- }
-
- std::vector<std::thread> threads;
- for (int i = 0; i < 10; i++) {
- threads.push_back(
- std::thread([&]() { ASSERT_TRUE(mWrapper->getInfo().capabilities.isOk()); }));
- }
- std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
-
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestGetInfoDoesNotCacheFailedResult) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() {
- return hardware::Return<bool>(hardware::Status::fromExceptionCode(-1));
- });
-
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() {
- return hardware::Return<bool>(hardware::Status::fromExceptionCode(-1));
- });
-
- EXPECT_CALL(*mMockHal.get(), supportsAmplitudeControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(true); });
- EXPECT_CALL(*mMockHal.get(), supportsExternalControl())
- .Times(Exactly(1))
- .WillRepeatedly([]() { return hardware::Return<bool>(false); });
- }
-
- // Call to supportsAmplitudeControl failed.
- ASSERT_TRUE(mWrapper->getInfo().capabilities.isFailed());
-
- // Call to supportsExternalControl failed.
- ASSERT_TRUE(mWrapper->getInfo().capabilities.isFailed());
-
- // Returns successful result from third call.
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, mWrapper->getInfo().capabilities.value());
-
- // Returns cached successful result.
- ASSERT_EQ(vibrator::Capabilities::AMPLITUDE_CONTROL, mWrapper->getInfo().capabilities.value());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestPerformEffectV1_0) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform(Eq(V1_0::Effect::CLICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_0::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::CLICK, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestPerformEffectV1_1) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_1(Eq(V1_1::Effect_1_1::TICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly([](V1_1::Effect_1_1, V1_0::EffectStrength,
- MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::TICK, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestPerformEffectV1_2) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_2(Eq(V1_2::Effect::THUD), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_2::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
- auto result = mWrapper->performEffect(Effect::THUD, EffectStrength::LIGHT, callback);
-
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-}
-
-TEST_F(VibratorHalWrapperHidlV1_3Test, TestPerformEffectV1_3) {
- {
- InSequence seq;
- EXPECT_CALL(*mMockHal.get(),
- perform_1_3(Eq(V1_3::Effect::TEXTURE_TICK), Eq(V1_0::EffectStrength::LIGHT), _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_3::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::OK, 10);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockScheduler.get(), schedule(_, Eq(10ms)))
- .Times(Exactly(1))
- .WillRepeatedly(vibrator::TriggerSchedulerCallback());
- EXPECT_CALL(*mMockHal.get(),
- perform_1_3(Eq(V1_3::Effect::TEXTURE_TICK), Eq(V1_0::EffectStrength::MEDIUM),
- _))
- .Times(Exactly(1))
- .WillRepeatedly(
- [](V1_3::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::UNSUPPORTED_OPERATION, 0);
- return hardware::Return<void>();
- });
- EXPECT_CALL(*mMockHal.get(),
- perform_1_3(Eq(V1_3::Effect::TEXTURE_TICK), Eq(V1_0::EffectStrength::STRONG),
- _))
- .Times(Exactly(2))
- .WillOnce([](V1_3::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb cb) {
- cb(V1_0::Status::BAD_VALUE, 0);
- return hardware::Return<void>();
- })
- .WillRepeatedly(
- [](V1_3::Effect, V1_0::EffectStrength, MockIVibratorV1_3::perform_cb) {
- return hardware::Return<void>(hardware::Status::fromExceptionCode(-1));
- });
- }
-
- std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
- auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
-
- auto result = mWrapper->performEffect(Effect::TEXTURE_TICK, EffectStrength::LIGHT, callback);
- ASSERT_TRUE(result.isOk());
- ASSERT_EQ(10ms, result.value());
- ASSERT_EQ(1, *callbackCounter.get());
-
- result = mWrapper->performEffect(Effect::TEXTURE_TICK, EffectStrength::MEDIUM, callback);
- ASSERT_TRUE(result.isUnsupported());
-
- result = mWrapper->performEffect(Effect::TEXTURE_TICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- result = mWrapper->performEffect(Effect::TEXTURE_TICK, EffectStrength::STRONG, callback);
- ASSERT_TRUE(result.isFailed());
-
- // Callback not triggered for unsupported and on failure
- ASSERT_EQ(1, *callbackCounter.get());
-}