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

Commit 79755bc5 authored by Harpreet "Eli" Sangha's avatar Harpreet "Eli" Sangha
Browse files

vibrator: example: Fix New Test Failures



Bug: 129091875
Test: VTS
Change-Id: Ib57457095c8ff30aff45a5909f2408d144980976
Signed-off-by: default avatarHarpreet "Eli" Sangha <eliptus@google.com>
parent a244321f
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -100,14 +100,22 @@ Return<Status> Vibrator::setExternalControl(bool enabled) {
Return<void> Vibrator::perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
    uint8_t amplitude;
    uint32_t ms;
    Status status;
    Status status = Status::OK;

    ALOGI("Perform: Effect %s\n", effectToName(effect).c_str());

    amplitude = strengthToAmplitude(strength);
    amplitude = strengthToAmplitude(strength, &status);
    if (status != Status::OK) {
        _hidl_cb(status, 0);
        return Void();
    }
    setAmplitude(amplitude);

    ms = effectToMs(effect);
    ms = effectToMs(effect, &status);
    if (status != Status::OK) {
        _hidl_cb(status, 0);
        return Void();
    }
    status = activate(ms);

    _hidl_cb(status, ms);
@@ -182,7 +190,7 @@ const std::string Vibrator::effectToName(Effect effect) {
    return toString(effect);
}

uint32_t Vibrator::effectToMs(Effect effect) {
uint32_t Vibrator::effectToMs(Effect effect, Status* status) {
    switch (effect) {
        case Effect::CLICK:
            return 10;
@@ -228,9 +236,11 @@ uint32_t Vibrator::effectToMs(Effect effect) {
        case Effect::RINGTONE_15:
            return 30000;
    }
    *status = Status::UNSUPPORTED_OPERATION;
    return 0;
}

uint8_t Vibrator::strengthToAmplitude(EffectStrength strength) {
uint8_t Vibrator::strengthToAmplitude(EffectStrength strength, Status* status) {
    switch (strength) {
        case EffectStrength::LIGHT:
            return 128;
@@ -239,6 +249,8 @@ uint8_t Vibrator::strengthToAmplitude(EffectStrength strength) {
        case EffectStrength::STRONG:
            return 255;
    }
    *status = Status::UNSUPPORTED_OPERATION;
    return 0;
}

}  // namespace implementation
+2 −2
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ class Vibrator : public IVibrator {

    static void timerCallback(union sigval sigval);
    static const std::string effectToName(Effect effect);
    static uint32_t effectToMs(Effect effect);
    static uint8_t strengthToAmplitude(EffectStrength strength);
    static uint32_t effectToMs(Effect effect, Status* status);
    static uint8_t strengthToAmplitude(EffectStrength strength, Status* status);

  private:
    bool mEnabled{false};