From 399022e4c7686d24d6738ad6a1c939998c6ac801 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Mon, 7 Oct 2024 22:07:58 -0400 Subject: [PATCH 3/3] vibratorservice: Support optionally ignoring vibrator effects On Unihertz Jelly Max the preloaded vibrator HAL is utterly broken. Change-Id: I308190a225932fba2a4aa1c830c03ab874d8032e --- services/vibratorservice/Android.bp | 1 + .../vibratorservice/VibratorHalWrapper.cpp | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/services/vibratorservice/Android.bp b/services/vibratorservice/Android.bp index 4735ae5..6263b05 100644 --- a/services/vibratorservice/Android.bp +++ b/services/vibratorservice/Android.bp @@ -41,6 +41,7 @@ cc_library_shared { }, shared_libs: [ + "libbase", "libbinder_ndk", "libhidlbase", "liblog", diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp index 4ac1618..ab027bd 100644 --- a/services/vibratorservice/VibratorHalWrapper.cpp +++ b/services/vibratorservice/VibratorHalWrapper.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "VibratorHalWrapper" #include +#include #include #include #include @@ -44,6 +45,22 @@ namespace V1_2 = android::hardware::vibrator::V1_2; namespace V1_3 = android::hardware::vibrator::V1_3; namespace Aidl = aidl::android::hardware::vibrator; +const Effect EFFECT_WITH_FALLBACK[] = { + Effect::CLICK, + Effect::DOUBLE_CLICK, + Effect::HEAVY_CLICK, + Effect::TICK, +}; + +#define RETURN_UNSUPPORTED_IF_IGNORED() \ + bool shouldIgnoreEffects = android::base::GetBoolProperty("persist.sys.phh.ignore_vibrator_effects", false); \ + auto casted_effect = static_cast(effect); \ + bool isEffectWithFallback = std::find(std::begin(EFFECT_WITH_FALLBACK), std::end(EFFECT_WITH_FALLBACK), casted_effect) \ + != std::end(EFFECT_WITH_FALLBACK); \ + if (shouldIgnoreEffects && isEffectWithFallback) { \ + return HalResult::unsupported(); \ + } + namespace android { namespace vibrator { @@ -63,8 +80,18 @@ Info HalWrapper::getInfo() { getCapabilities(); getPrimitiveDurations(); std::lock_guard lock(mInfoMutex); + bool shouldIgnoreEffects = android::base::GetBoolProperty("persist.sys.phh.ignore_vibrator_effects", false); if (mInfoCache.mSupportedEffects.isFailed()) { mInfoCache.mSupportedEffects = getSupportedEffectsInternal(); + if (mInfoCache.mSupportedEffects.isOk()) { + std::vector filtered; + for (auto& effect : mInfoCache.mSupportedEffects.value()) { + if (std::find(std::begin(EFFECT_WITH_FALLBACK), std::end(EFFECT_WITH_FALLBACK), effect) == std::end(EFFECT_WITH_FALLBACK)) { + filtered.push_back(effect); + } + } + mInfoCache.mSupportedEffects = HalResult>::ok(filtered); + } } if (mInfoCache.mSupportedBraking.isFailed()) { mInfoCache.mSupportedBraking = getSupportedBrakingInternal(); @@ -295,6 +322,8 @@ HalResult AidlHalWrapper::alwaysOnDisable(int32_t id) { HalResult AidlHalWrapper::performEffect( Effect effect, EffectStrength strength, const std::function& completionCallback) { + RETURN_UNSUPPORTED_IF_IGNORED(); + HalResult capabilities = getCapabilities(); bool supportsCallback = capabilities.isOk() && static_cast(capabilities.value() & Capabilities::PERFORM_CALLBACK); @@ -563,6 +592,8 @@ template HalResult HidlHalWrapper::performInternal( perform_fn performFn, sp handle, T effect, EffectStrength strength, const std::function& completionCallback) { + RETURN_UNSUPPORTED_IF_IGNORED(); + V1_0::Status status; int32_t lengthMs; auto effectCallback = [&status, &lengthMs](V1_0::Status retStatus, uint32_t retLengthMs) { -- 2.44.0