Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c5a3af3 authored by Steven Moreland's avatar Steven Moreland
Browse files

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
parent ee3a5892
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -67,8 +67,12 @@ class VibratorShim : public V1_4::IVibrator {
    Return<bool> supportsAmplitudeControl() override {
        int32_t cap = 0;
        if (!mVib->getCapabilities(&cap).isOk()) return false;
        if (mUnderExternalControl) {
           return (cap & aidl::IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL) > 0;
        } else {
           return (cap & aidl::IVibrator::CAP_AMPLITUDE_CONTROL) > 0;
        }
    }

    Return<V1_0::Status> setAmplitude(uint8_t amplitude) override {
        return toHidlStatus(mVib->setAmplitude(amplitude));
@@ -96,7 +100,11 @@ class VibratorShim : public V1_4::IVibrator {
    }

    Return<V1_0::Status> setExternalControl(bool enabled) override {
        return toHidlStatus(mVib->setExternalControl(enabled));
        Return<V1_0::Status> status = toHidlStatus(mVib->setExternalControl(enabled));
        if (status.isOk() && status == V1_0::Status::OK) {
            mUnderExternalControl = enabled;
        }
        return status;
    }

    Return<void> perform_1_3(V1_3::Effect effect, V1_0::EffectStrength strength,
@@ -167,6 +175,7 @@ class VibratorShim : public V1_4::IVibrator {
    }
  private:
    sp<aidl::IVibrator> mVib;
    bool mUnderExternalControl = false;

    Return<V1_0::Status> toHidlStatus(const android::binder::Status& status) {
        switch(status.exceptionCode()) {