forked from PeterGSI/patches
101 lines
4.1 KiB
Diff
101 lines
4.1 KiB
Diff
From 399022e4c7686d24d6738ad6a1c939998c6ac801 Mon Sep 17 00:00:00 2001
|
|
From: Peter Cai <peter@typeblog.net>
|
|
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 <aidl/android/hardware/vibrator/IVibrator.h>
|
|
+#include <android-base/properties.h>
|
|
#include <android/hardware/vibrator/1.3/IVibrator.h>
|
|
#include <hardware/vibrator.h>
|
|
#include <cmath>
|
|
@@ -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>(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<milliseconds>::unsupported(); \
|
|
+ }
|
|
+
|
|
namespace android {
|
|
|
|
namespace vibrator {
|
|
@@ -63,8 +80,18 @@ Info HalWrapper::getInfo() {
|
|
getCapabilities();
|
|
getPrimitiveDurations();
|
|
std::lock_guard<std::mutex> 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<Effect> 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<std::vector<Effect>>::ok(filtered);
|
|
+ }
|
|
}
|
|
if (mInfoCache.mSupportedBraking.isFailed()) {
|
|
mInfoCache.mSupportedBraking = getSupportedBrakingInternal();
|
|
@@ -295,6 +322,8 @@ HalResult<void> AidlHalWrapper::alwaysOnDisable(int32_t id) {
|
|
|
|
HalResult<milliseconds> AidlHalWrapper::performEffect(
|
|
Effect effect, EffectStrength strength, const std::function<void()>& completionCallback) {
|
|
+ RETURN_UNSUPPORTED_IF_IGNORED();
|
|
+
|
|
HalResult<Capabilities> capabilities = getCapabilities();
|
|
bool supportsCallback = capabilities.isOk() &&
|
|
static_cast<int32_t>(capabilities.value() & Capabilities::PERFORM_CALLBACK);
|
|
@@ -563,6 +592,8 @@ template <typename T>
|
|
HalResult<milliseconds> HidlHalWrapper<I>::performInternal(
|
|
perform_fn<T> performFn, sp<I> handle, T effect, EffectStrength strength,
|
|
const std::function<void()>& 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
|
|
|