vibrator: port default HIDL service to AIDL

Change-Id: I714c28f4cc046cf1671baa748119a69a021ee9cc
This commit is contained in:
Han Sol Jin 2024-06-23 13:18:49 -07:00 committed by Bruno Martins
parent 9ed3b03032
commit 239c3734f1
6 changed files with 272 additions and 0 deletions

View file

@ -0,0 +1,24 @@
//
// Copyright (C) 2024 The LineageOS Project
//
// SPDX-License-Identifier: Apache-2.0
//
cc_binary {
name: "android.hardware.vibrator-service.legacy",
relative_install_path: "hw",
init_rc: ["android.hardware.vibrator-service.legacy.rc"],
vintf_fragments: ["android.hardware.vibrator-service.legacy.xml"],
srcs: [
"Vibrator.cpp",
"service.cpp",
],
shared_libs: [
"libbase",
"libbinder_ndk",
"libhardware",
"liblog",
"android.hardware.vibrator-V2-ndk",
],
vendor: true,
}

View file

@ -0,0 +1,150 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <log/log.h>
#include <hardware/hardware.h>
#include <hardware/vibrator.h>
#include "Vibrator.h"
namespace aidl {
namespace android {
namespace hardware {
namespace vibrator {
Vibrator::Vibrator() {
vibrator_device_t *vib_device;
const hw_module_t *hw_module = nullptr;
int ret = hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, &hw_module);
if (ret == 0) {
ret = vibrator_open(hw_module, &vib_device);
if (ret != 0) {
ALOGE("vibrator_open failed: %d", ret);
return;
}
} else {
ALOGE("hw_get_module %s failed: %d", VIBRATOR_HARDWARE_MODULE_ID, ret);
return;
}
mDevice = vib_device;
}
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
ALOGV("Vibrator reporting capabilities");
*_aidl_return = IVibrator::CAP_ON_CALLBACK;
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Vibrator::off() {
int32_t ret = mDevice->vibrator_off(mDevice);
if (ret != 0) {
ALOGE("off command failed : %s", strerror(-ret));
return ndk::ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED);
}
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& /*callback*/) {
int32_t ret = mDevice->vibrator_on(mDevice, timeoutMs);
if (ret != 0) {
ALOGE("on command failed : %s", strerror(-ret));
return ndk::ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED);
}
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus Vibrator::perform(Effect /*effect*/, EffectStrength /*strength*/, const std::shared_ptr<IVibratorCallback>& /*callback*/, int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::setAmplitude(float /*amplitude*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::setExternalControl(bool /*enabled*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getSupportedPrimitives(std::vector<CompositePrimitive>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive /*primitive*/, int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t /*id*/, Effect /*effect*/, EffectStrength /*strength*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t /*id*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getResonantFrequency(float* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getQFactor(float* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getFrequencyResolution(float* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getBandwidthAmplitudeMap(std::vector<float>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getPwlePrimitiveDurationMax(int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getPwleCompositionSizeMax(int32_t* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector<Braking>* /*_aidl_return*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& /*composite*/, const std::shared_ptr<IVibratorCallback>& /*callback*/) {
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
} // namespace vibrator
} // namespace hardware
} // namespace android
} // namespace aidl

View file

@ -0,0 +1,63 @@
/*
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <aidl/android/hardware/vibrator/BnVibrator.h>
#include <hardware/hardware.h>
#include <hardware/vibrator.h>
using ::aidl::android::hardware::vibrator::IVibratorCallback;
using ::aidl::android::hardware::vibrator::Braking;
using ::aidl::android::hardware::vibrator::Effect;
using ::aidl::android::hardware::vibrator::EffectStrength;
using ::aidl::android::hardware::vibrator::CompositeEffect;
using ::aidl::android::hardware::vibrator::CompositePrimitive;
using ::aidl::android::hardware::vibrator::PrimitivePwle;
namespace aidl {
namespace android {
namespace hardware {
namespace vibrator {
class Vibrator : public BnVibrator {
public:
Vibrator();
ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override;
ndk::ScopedAStatus off() override;
ndk::ScopedAStatus on(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback) override;
ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override;
ndk::ScopedAStatus setAmplitude(float amplitude) override;
ndk::ScopedAStatus setExternalControl(bool enabled) override;
ndk::ScopedAStatus getCompositionDelayMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getCompositionSizeMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedPrimitives(std::vector<CompositePrimitive>* _aidl_return) override;
ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, int32_t* _aidl_return) override;
ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite, const std::shared_ptr<IVibratorCallback>& callback) override;
ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override;
ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override;
ndk::ScopedAStatus alwaysOnDisable(int32_t id) override;
ndk::ScopedAStatus getResonantFrequency(float* _aidl_return) override;
ndk::ScopedAStatus getQFactor(float* _aidl_return) override;
ndk::ScopedAStatus getFrequencyResolution(float* _aidl_return) override;
ndk::ScopedAStatus getFrequencyMinimum(float* _aidl_return) override;
ndk::ScopedAStatus getBandwidthAmplitudeMap(std::vector<float>* _aidl_return) override;
ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* _aidl_return) override;
ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* _aidl_return) override;
ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle> &composite, const std::shared_ptr<IVibratorCallback> &callback) override;
private:
vibrator_device_t *mDevice;
};
} // namespace vibrator
} // namespace hardware
} // namespace android
} // namespace aidl

View file

@ -0,0 +1,4 @@
service vendor.vibrator-legacy /vendor/bin/hw/android.hardware.vibrator-service.legacy
class hal
user system
group system

View file

@ -0,0 +1,6 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.vibrator</name>
<fqname>IVibrator/default</fqname>
</hal>
</manifest>

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "Vibrator.h"
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <android-base/logging.h>
using ::aidl::android::hardware::vibrator::Vibrator;
int main() {
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<Vibrator> vibrator = ndk::SharedRefBase::make<Vibrator>();
const std::string instance = std::string() + Vibrator::descriptor + "/default";
binder_status_t status = AServiceManager_addService(vibrator->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
ABinderProcess_joinThreadPool();
return EXIT_FAILURE; // should not reach
}