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

Commit e29882bd authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "vibrator: handle aidl HAL dying"

parents d5ef2d61 ee3a5892
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -154,21 +154,29 @@ class VibratorShim : public V1_4::IVibrator {

        sp<aidl::IVibratorCallback> cb = callback ? new CallbackShim(callback) : nullptr;
        int timeoutMs = 0;
        V1_0::Status status = toHidlStatus(
        Return<V1_0::Status> status = toHidlStatus(
            mVib->perform(static_cast<aidl::Effect>(effect),
                          static_cast<aidl::EffectStrength>(strength), cb, &timeoutMs));

        if (status.isOk()) {
            _hidl_cb(status, timeoutMs);
            return android::hardware::Status::ok();
        } else {
            return android::hardware::details::StatusOf<V1_0::Status, void>(status);
        }
    }
  private:
    sp<aidl::IVibrator> mVib;

    V1_0::Status toHidlStatus(const android::binder::Status& status) {
    Return<V1_0::Status> toHidlStatus(const android::binder::Status& status) {
        switch(status.exceptionCode()) {
            using android::hardware::Status;
            case Status::EX_NONE: return V1_0::Status::OK;
            case Status::EX_ILLEGAL_ARGUMENT: return V1_0::Status::BAD_VALUE;
            case Status::EX_UNSUPPORTED_OPERATION: return V1_0::Status::UNSUPPORTED_OPERATION;
            case Status::EX_TRANSACTION_FAILED: {
                return Status::fromStatusT(status.transactionError());
            }
        }
        return V1_0::Status::UNKNOWN_ERROR;
    }
@@ -247,9 +255,15 @@ class HalWrapper {
            }

            ALOGE("Failed to issue command to vibrator HAL. Retrying.");

            // Restoring connection to the HAL.
            sp<aidl::IVibrator> aidlVib = checkVintfService<aidl::IVibrator>();
            if (aidlVib) {
                mHal = new VibratorShim(aidlVib);
            } else {
                mHal = I::tryGetService();
            }
        }
        return ret;
    }