Fix result check of IBinder::pingBinder on vibrator HAl wrapper
The result is a status_t and should be checked agains the const values
listed in include/utils/Error.h.
Also adding error message to vibrator::HalResult to allow
vibrator::HalController to print underlying failure cause.
Bug: b/163027437
Test: atest libvibratorservice_test
Change-Id: Ic1c68246c401cd68a16a1d1f2d8e48d179441576
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp
index 1210110..ee891de 100644
--- a/services/vibratorservice/VibratorHalWrapper.cpp
+++ b/services/vibratorservice/VibratorHalWrapper.cpp
@@ -67,6 +67,10 @@
// -------------------------------------------------------------------------------------------------
+const constexpr char* STATUS_T_ERROR_MESSAGE_PREFIX = "status_t = ";
+const constexpr char* STATUS_V_1_0_ERROR_MESSAGE_PREFIX =
+ "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) {
@@ -75,7 +79,7 @@
if (status.isOk()) {
return HalResult<T>::ok(data);
}
- return HalResult<T>::failed();
+ return HalResult<T>::failed(std::string(status.toString8().c_str()));
}
template <typename T>
@@ -86,24 +90,32 @@
case V1_0::Status::UNSUPPORTED_OPERATION:
return HalResult<T>::unsupported();
default:
- return HalResult<T>::failed();
+ return HalResult<T>::failed(STATUS_V_1_0_ERROR_MESSAGE_PREFIX + toString(status));
}
}
template <typename T>
template <typename R>
HalResult<T> HalResult<T>::fromReturn(hardware::Return<R>& ret, T data) {
- return ret.isOk() ? HalResult<T>::ok(data) : HalResult<T>::failed();
+ return ret.isOk() ? HalResult<T>::ok(data) : HalResult<T>::failed(ret.description());
}
template <typename T>
template <typename R>
HalResult<T> HalResult<T>::fromReturn(hardware::Return<R>& ret, V1_0::Status status, T data) {
- return ret.isOk() ? HalResult<T>::fromStatus(status, data) : HalResult<T>::failed();
+ return ret.isOk() ? HalResult<T>::fromStatus(status, data)
+ : HalResult<T>::failed(ret.description());
}
// -------------------------------------------------------------------------------------------------
+HalResult<void> HalResult<void>::fromStatus(status_t status) {
+ if (status == android::OK) {
+ return HalResult<void>::ok();
+ }
+ return HalResult<void>::failed(STATUS_T_ERROR_MESSAGE_PREFIX + statusToString(status));
+}
+
HalResult<void> HalResult<void>::fromStatus(binder::Status status) {
if (status.exceptionCode() == binder::Status::EX_UNSUPPORTED_OPERATION) {
return HalResult<void>::unsupported();
@@ -111,7 +123,7 @@
if (status.isOk()) {
return HalResult<void>::ok();
}
- return HalResult<void>::failed();
+ return HalResult<void>::failed(std::string(status.toString8().c_str()));
}
HalResult<void> HalResult<void>::fromStatus(V1_0::Status status) {
@@ -121,13 +133,13 @@
case V1_0::Status::UNSUPPORTED_OPERATION:
return HalResult<void>::unsupported();
default:
- return HalResult<void>::failed();
+ return HalResult<void>::failed(STATUS_V_1_0_ERROR_MESSAGE_PREFIX + toString(status));
}
}
template <typename R>
HalResult<void> HalResult<void>::fromReturn(hardware::Return<R>& ret) {
- return ret.isOk() ? HalResult<void>::ok() : HalResult<void>::failed();
+ return ret.isOk() ? HalResult<void>::ok() : HalResult<void>::failed(ret.description());
}
// -------------------------------------------------------------------------------------------------
@@ -149,8 +161,7 @@
// -------------------------------------------------------------------------------------------------
HalResult<void> AidlHalWrapper::ping() {
- // TODO(b/153415251): Investigate why IBinder::pingBinder() is returning false even on success.
- return getCapabilitiesInternal().isFailed() ? HalResult<void>::failed() : HalResult<void>::ok();
+ return HalResult<void>::fromStatus(IInterface::asBinder(getHal())->pingBinder());
}
void AidlHalWrapper::tryReconnect() {
@@ -456,15 +467,15 @@
}
HalResult<Capabilities> HidlHalWrapperV1_3::getCapabilitiesInternal() {
+ Capabilities capabilities = Capabilities::NONE;
+
sp<V1_3::IVibrator> hal = getHal();
auto amplitudeResult = hal->supportsAmplitudeControl();
if (!amplitudeResult.isOk()) {
- return HalResult<Capabilities>::failed();
+ return HalResult<Capabilities>::fromReturn(amplitudeResult, capabilities);
}
auto externalControlResult = hal->supportsExternalControl();
- Capabilities capabilities = Capabilities::NONE;
-
if (amplitudeResult.withDefault(false)) {
capabilities |= Capabilities::AMPLITUDE_CONTROL;
}