From 3c5a3af3deb5f3c39f127bd9b474216d74b91e48 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 6 Nov 2019 15:57:36 -0800 Subject: [PATCH] vibrator: reflect CAP_EXTERNAL_AMPLITUDE_CONTROL For HIDL, vibrator may change the value of supportsAmplitudeControl based on context. Since the interface is being redone in AIDL, we're avoiding this changing value and providing capabilities for amplitudes we expect to be available in different states. Bug: 141828236 Test: boot Change-Id: If1e38cffa3fd93f2a658c476637db2dd7ce9f91d --- .../core/jni/com_android_server_VibratorService.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp index 51bea1f068ad8..372622801aa05 100644 --- a/services/core/jni/com_android_server_VibratorService.cpp +++ b/services/core/jni/com_android_server_VibratorService.cpp @@ -67,7 +67,11 @@ class VibratorShim : public V1_4::IVibrator { Return supportsAmplitudeControl() override { int32_t cap = 0; if (!mVib->getCapabilities(&cap).isOk()) return false; - return (cap & aidl::IVibrator::CAP_AMPLITUDE_CONTROL) > 0; + if (mUnderExternalControl) { + return (cap & aidl::IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL) > 0; + } else { + return (cap & aidl::IVibrator::CAP_AMPLITUDE_CONTROL) > 0; + } } Return setAmplitude(uint8_t amplitude) override { @@ -96,7 +100,11 @@ class VibratorShim : public V1_4::IVibrator { } Return setExternalControl(bool enabled) override { - return toHidlStatus(mVib->setExternalControl(enabled)); + Return status = toHidlStatus(mVib->setExternalControl(enabled)); + if (status.isOk() && status == V1_0::Status::OK) { + mUnderExternalControl = enabled; + } + return status; } Return perform_1_3(V1_3::Effect effect, V1_0::EffectStrength strength, @@ -167,6 +175,7 @@ class VibratorShim : public V1_4::IVibrator { } private: sp mVib; + bool mUnderExternalControl = false; Return toHidlStatus(const android::binder::Status& status) { switch(status.exceptionCode()) {