Add wrapper for IVibratorManager.aidl to native vibrator service
Add a new implementation of vibrator::ManagerHalWrapper that interacts
with the default IVibratorManager.aidl service.
Add getCapabilities() method to the wrapper, mapping to the constant
values from IVibratorManager.aidl.
This reuses the HalWrapper and HalController to ensure each individual
vibrator will be loaded and reloaded correctly from IVibratorManager.
Bug: 167946816
Test: atest libvibratorservice_test
Change-Id: I5311b4118a3bec5920317aa392a30d171fd80c81
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp
index 9672644..7fee82f 100644
--- a/services/vibratorservice/VibratorHalWrapper.cpp
+++ b/services/vibratorservice/VibratorHalWrapper.cpp
@@ -17,7 +17,6 @@
#define LOG_TAG "VibratorHalWrapper"
#include <android/hardware/vibrator/1.3/IVibrator.h>
-#include <android/hardware/vibrator/BnVibratorCallback.h>
#include <android/hardware/vibrator/IVibrator.h>
#include <hardware/vibrator.h>
@@ -73,17 +72,6 @@
"android::hardware::vibrator::V1_0::Status = ";
template <typename T>
-HalResult<T> HalResult<T>::fromStatus(binder::Status status, T data) {
- if (status.exceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
- return HalResult<T>::unsupported();
- }
- if (status.isOk()) {
- return HalResult<T>::ok(data);
- }
- return HalResult<T>::failed(std::string(status.toString8().c_str()));
-}
-
-template <typename T>
HalResult<T> HalResult<T>::fromStatus(V1_0::Status status, T data) {
switch (status) {
case V1_0::Status::OK:
@@ -145,28 +133,16 @@
// -------------------------------------------------------------------------------------------------
-class HalCallbackWrapper : public Aidl::BnVibratorCallback {
-public:
- HalCallbackWrapper(std::function<void()> completionCallback)
- : mCompletionCallback(completionCallback) {}
-
- binder::Status onComplete() override {
- mCompletionCallback();
- return binder::Status::ok();
- }
-
-private:
- const std::function<void()> mCompletionCallback;
-};
-
-// -------------------------------------------------------------------------------------------------
-
HalResult<void> AidlHalWrapper::ping() {
return HalResult<void>::fromStatus(IInterface::asBinder(getHal())->pingBinder());
}
void AidlHalWrapper::tryReconnect() {
- sp<Aidl::IVibrator> newHandle = checkVintfService<Aidl::IVibrator>();
+ auto result = mReconnectFn();
+ if (!result.isOk()) {
+ return;
+ }
+ sp<Aidl::IVibrator> newHandle = result.value();
if (newHandle) {
std::lock_guard<std::mutex> lock(mHandleMutex);
mHandle = std::move(newHandle);