From: Jan Altensen Date: Wed, 20 May 2020 20:49:05 +0000 (+0200) Subject: exynos9610: add custom vibrator hidl hal X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f9d80587fd0b448f1cb176addeee82dabff2d8f8;p=GitHub%2Fmoto-9609%2Fandroid_device_motorola_exynos9610-common.git exynos9610: add custom vibrator hidl hal Change-Id: Ice6cfcb0f2c98368497f2650f1bd30c5017a5cd8 --- diff --git a/common.mk b/common.mk index 684d29d..913fe29 100644 --- a/common.mk +++ b/common.mk @@ -234,6 +234,10 @@ PRODUCT_COPY_FILES += \ $(COMMON_PATH)/configs/thermal/exynos-thermal-kane-retin.conf:$(TARGET_COPY_OUT_VENDOR)/exynos-thermal-kane-retin.conf \ $(COMMON_PATH)/configs/thermal/exynos-thermal-troika.conf:$(TARGET_COPY_OUT_VENDOR)/exynos-thermal-troika.conf +# Vibrator +PRODUCT_PACKAGES += \ + android.hardware.vibrator@1.0-service.exynos9610 + # WiFi PRODUCT_PACKAGES += \ android.hardware.wifi@1.0-service \ diff --git a/hidl/vibrator/Android.bp b/hidl/vibrator/Android.bp new file mode 100644 index 0000000..6411cf5 --- /dev/null +++ b/hidl/vibrator/Android.bp @@ -0,0 +1,30 @@ +// Copyright (C) 2020 The LineageOS Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_binary { + name: "android.hardware.vibrator@1.0-service.exynos9610", + defaults: ["hidl_defaults"], + vendor: true, + relative_install_path: "hw", + init_rc: ["android.hardware.vibrator@1.0-service.exynos9610.rc"], + srcs: ["service.cpp", "Vibrator.cpp"], + shared_libs: [ + "libbase", + "libhidlbase", + "liblog", + "libutils", + "libhardware", + "android.hardware.vibrator@1.0", + ], +} diff --git a/hidl/vibrator/Vibrator.cpp b/hidl/vibrator/Vibrator.cpp new file mode 100644 index 0000000..aacbc8a --- /dev/null +++ b/hidl/vibrator/Vibrator.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.vibrator@1.0-service.exynos9610" + +#include + +#include + +#include +#include + +#include "Vibrator.h" + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace vibrator { +namespace V1_0 { +namespace implementation { + +/* + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value << std::endl; +} + +Vibrator::Vibrator() {} + +// Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. +Return Vibrator::on(uint32_t timeout_ms) { + set("/sys/class/leds/vibrator/state", 1); + set("/sys/class/leds/vibrator/duration", timeout_ms); + set("/sys/class/leds/vibrator/activate", 1); + + return Status::OK; +} + +Return Vibrator::off() { + set("/sys/class/leds/vibrator/activate", 0); + + return Status::OK; +} + +Return Vibrator::supportsAmplitudeControl() { + return false; +} + +Return Vibrator::setAmplitude(uint8_t) { + return Status::UNSUPPORTED_OPERATION; +} + +Return Vibrator::perform(Effect, EffectStrength, perform_cb _hidl_cb) { + _hidl_cb(Status::UNSUPPORTED_OPERATION, 0); + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace vibrator +} // namespace hardware +} // namespace android diff --git a/hidl/vibrator/Vibrator.h b/hidl/vibrator/Vibrator.h new file mode 100644 index 0000000..01370be --- /dev/null +++ b/hidl/vibrator/Vibrator.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H +#define ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H + +#include +#include + +#include + +namespace android { +namespace hardware { +namespace vibrator { +namespace V1_0 { +namespace implementation { + +class Vibrator : public IVibrator { + public: + Vibrator(); + + // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. + Return on(uint32_t timeoutMs) override; + Return off() override; + Return supportsAmplitudeControl() override; + Return setAmplitude(uint8_t) override; + Return perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace vibrator +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_VIBRATOR_V1_0_VIBRATOR_H diff --git a/hidl/vibrator/android.hardware.vibrator@1.0-service.exynos9610.rc b/hidl/vibrator/android.hardware.vibrator@1.0-service.exynos9610.rc new file mode 100644 index 0000000..1f42b29 --- /dev/null +++ b/hidl/vibrator/android.hardware.vibrator@1.0-service.exynos9610.rc @@ -0,0 +1,4 @@ +service vendor.vibrator-1-0 /vendor/bin/hw/android.hardware.vibrator@1.0-service.exynos9610 + class hal + user system + group system diff --git a/hidl/vibrator/service.cpp b/hidl/vibrator/service.cpp new file mode 100644 index 0000000..e6adb24 --- /dev/null +++ b/hidl/vibrator/service.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.vibrator@1.0-service.exynos9610" + +#include +#include +#include +#include +#include +#include + +#include "Vibrator.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::hardware::vibrator::V1_0::IVibrator; +using android::hardware::vibrator::V1_0::implementation::Vibrator; + +using android::OK; +using android::sp; +using android::status_t; + +int main() { + status_t status; + sp vibrator; + + LOG(INFO) << "Vibrator HAL service is starting."; + + vibrator = new Vibrator(); + if (vibrator == nullptr) { + LOG(ERROR) << "Can not create an instance of Vibrator HAL IVibrator, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true); + + status = vibrator->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for Vibrator HAL"; + goto shutdown; + } + + LOG(INFO) << "Vibrator HAL service is Ready."; + joinRpcThreadpool(); + +shutdown: + // In normal operation, we don't expect the thread pool to shutdown + LOG(ERROR) << "Vibrator HAL failed to join thread pool."; + return 1; +}