Spacewar: implement richtap vibrator service
Change-Id: Ieab0cfca22c0fd8a63c33ce2a6a21e982e57aee8
This commit is contained in:
committed by
Wiktor Rudzki
parent
7988896784
commit
29292fa394
@@ -347,7 +347,7 @@ PRODUCT_PACKAGES += \
|
||||
|
||||
# Vibrator
|
||||
PRODUCT_PACKAGES += \
|
||||
vendor.qti.hardware.vibrator.service
|
||||
android.hardware.vibrator.service.spacewar
|
||||
|
||||
PRODUCT_COPY_FILES += \
|
||||
vendor/qcom/opensource/vibrator/excluded-input-devices.xml:$(TARGET_COPY_OUT_VENDOR)/etc/excluded-input-devices.xml
|
||||
|
||||
5
sepolicy/vendor/file_contexts
vendored
5
sepolicy/vendor/file_contexts
vendored
@@ -18,4 +18,7 @@
|
||||
/vendor/bin/hw/vendor\.lineage\.powershare@1\.0-service\.nothing u:object_r:hal_lineage_powershare_default_exec:s0
|
||||
|
||||
# LEDs
|
||||
/sys/devices/platform/soc/984000.i2c/i2c-0/0-0020/leds/aw210xx_led(/.*)? u:object_r:sysfs_leds:s0
|
||||
/sys/devices/platform/soc/984000.i2c/i2c-0/0-0020/leds/aw210xx_led(/.*)? u:object_r:sysfs_leds:s0
|
||||
|
||||
# Vibrator
|
||||
/vendor/bin/hw/android.hardware.vibrator.service.spacewar u:object_r:hal_vibrator_default_exec:s0
|
||||
11
vibrator/.clang-format
Normal file
11
vibrator/.clang-format
Normal file
@@ -0,0 +1,11 @@
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -2
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
ColumnLimit: 100
|
||||
CommentPragmas: NOLINT:.*
|
||||
DerivePointerAlignment: false
|
||||
IndentWidth: 4
|
||||
PointerAlignment: Left
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
PenaltyExcessCharacter: 32
|
||||
27
vibrator/Android.bp
Normal file
27
vibrator/Android.bp
Normal file
@@ -0,0 +1,27 @@
|
||||
cc_binary {
|
||||
name: "android.hardware.vibrator.service.spacewar",
|
||||
vendor: true,
|
||||
cflags: [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-DLOG_TAG=\"android.hardware.vibrator.service.spacewar\"",
|
||||
],
|
||||
relative_install_path: "hw",
|
||||
init_rc: ["android.hardware.vibrator.service.spacewar.rc"],
|
||||
vintf_fragments: [
|
||||
"android.hardware.vibrator.service.spacewar.xml",
|
||||
],
|
||||
srcs: [
|
||||
"service.cpp",
|
||||
"Vibrator.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libcutils",
|
||||
"libutils",
|
||||
"liblog",
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libaacvibrator",
|
||||
"android.hardware.vibrator-V2-ndk",
|
||||
],
|
||||
}
|
||||
213
vibrator/Vibrator.cpp
Normal file
213
vibrator/Vibrator.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Vibrator.h"
|
||||
|
||||
#include <cutils/properties.h>
|
||||
#include <inttypes.h>
|
||||
#include <log/log.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "aac_vibra_function.h"
|
||||
|
||||
#define RICHTAP_LIGHT_STRENGTH 69
|
||||
#define RICHTAP_MEDIUM_STRENGTH 89
|
||||
#define RICHTAP_STRONG_STRENGTH 99
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace vibrator {
|
||||
|
||||
Vibrator::Vibrator() {
|
||||
uint32_t deviceType = 0;
|
||||
|
||||
int32_t ret = aac_vibra_init(&deviceType);
|
||||
if (ret) {
|
||||
ALOGE("AAC init failed: %d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
aac_vibra_looper_start();
|
||||
|
||||
ALOGI("AAC init success: %u\n", deviceType);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
|
||||
*_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK |
|
||||
IVibrator::CAP_AMPLITUDE_CONTROL;
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::off() {
|
||||
int32_t ret = aac_vibra_off();
|
||||
if (ret) {
|
||||
ALOGE("AAC off failed: %d\n", ret);
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
|
||||
const std::shared_ptr<IVibratorCallback>& callback) {
|
||||
int32_t ret = aac_vibra_looper_on(timeoutMs);
|
||||
if (ret < 0) {
|
||||
ALOGE("AAC on failed: %d\n", ret);
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
}
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
usleep(ret * 1000);
|
||||
callback->onComplete();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es,
|
||||
const std::shared_ptr<IVibratorCallback>& callback,
|
||||
int32_t* _aidl_return) {
|
||||
int32_t strength;
|
||||
|
||||
if (effect < Effect::CLICK || effect > Effect::HEAVY_CLICK)
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
|
||||
switch (es) {
|
||||
case EffectStrength::LIGHT:
|
||||
strength = RICHTAP_LIGHT_STRENGTH;
|
||||
break;
|
||||
case EffectStrength::MEDIUM:
|
||||
strength = RICHTAP_MEDIUM_STRENGTH;
|
||||
break;
|
||||
case EffectStrength::STRONG:
|
||||
strength = RICHTAP_STRONG_STRENGTH;
|
||||
break;
|
||||
default:
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
int32_t ret = aac_vibra_looper_prebaked_effect(static_cast<uint32_t>(effect), strength);
|
||||
if (ret < 0) {
|
||||
ALOGE("AAC perform failed: %d\n", ret);
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
}
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
usleep(ret * 1000);
|
||||
callback->onComplete();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
*_aidl_return = ret;
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
|
||||
*_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK,
|
||||
Effect::THUD, Effect::POP, Effect::HEAVY_CLICK};
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
|
||||
uint8_t tmp = (uint8_t)(amplitude * 0xff);
|
||||
|
||||
int32_t ret = aac_vibra_setAmplitude(tmp);
|
||||
if (ret) {
|
||||
ALOGE("AAC set amplitude failed: %d\n", ret);
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
}
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* maxDelayMs __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* maxSize __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedPrimitives(
|
||||
std::vector<CompositePrimitive>* supported __unused) {
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPrimitiveDuration(CompositePrimitive primitive __unused,
|
||||
int32_t* durationMs __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composite __unused,
|
||||
const std::shared_ptr<IVibratorCallback>& callback __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::alwaysOnEnable(int32_t id __unused, Effect effect __unused,
|
||||
EffectStrength strength __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::alwaysOnDisable(int32_t id __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getResonantFrequency(float* resonantFreqHz __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getQFactor(float* qFactor __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyResolution(float* freqResolutionHz __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getFrequencyMinimum(float* freqMinimumHz __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getBandwidthAmplitudeMap(std::vector<float>* _aidl_return __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPwlePrimitiveDurationMax(int32_t* durationMs __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getPwleCompositionSizeMax(int32_t* maxSize __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedBraking(std::vector<Braking>* supported __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::composePwle(const std::vector<PrimitivePwle>& composite __unused,
|
||||
const std::shared_ptr<IVibratorCallback>& callback __unused) {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
} // namespace vibrator
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
52
vibrator/Vibrator.h
Normal file
52
vibrator/Vibrator.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <aidl/android/hardware/vibrator/BnVibrator.h>
|
||||
|
||||
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* maxDelayMs);
|
||||
ndk::ScopedAStatus getCompositionSizeMax(int32_t* maxSize);
|
||||
ndk::ScopedAStatus getSupportedPrimitives(std::vector<CompositePrimitive>* supported) override;
|
||||
ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive,
|
||||
int32_t* durationMs) 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* resonantFreqHz) override;
|
||||
ndk::ScopedAStatus getQFactor(float* qFactor) override;
|
||||
ndk::ScopedAStatus getFrequencyResolution(float* freqResolutionHz) override;
|
||||
ndk::ScopedAStatus getFrequencyMinimum(float* freqMinimumHz) override;
|
||||
ndk::ScopedAStatus getBandwidthAmplitudeMap(std::vector<float>* _aidl_return) override;
|
||||
ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t* durationMs) override;
|
||||
ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t* maxSize) override;
|
||||
ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* supported) override;
|
||||
ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle>& composite,
|
||||
const std::shared_ptr<IVibratorCallback>& callback) override;
|
||||
};
|
||||
|
||||
} // namespace vibrator
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
56
vibrator/aac_vibra_function.h
Normal file
56
vibrator/aac_vibra_function.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef _AAC_VIBRA_FUNCTION_H_
|
||||
#define _AAC_VIBRA_FUNCTION_H_
|
||||
|
||||
#include <android/log.h>
|
||||
#include <log/log.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <functional>
|
||||
using namespace std;
|
||||
|
||||
enum PATTERN_PERFORM_STATE {
|
||||
PATTERN_PERFORM_START = 1,
|
||||
PATTERN_PERFORM_INTERRUPT, //
|
||||
PATTERN_PERFORM_RESUME,
|
||||
PATTERN_PERFORM_BUSY,
|
||||
PATTERN_PERFORM_END,
|
||||
INVALID_PATTERN_STATUS,
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int aac_vibra_init(uint32_t* deviceType);
|
||||
extern int aac_vibra_on(unsigned int timeout_ms);
|
||||
extern int aac_vibra_off();
|
||||
extern int aac_vibra_setAmplitude(uint8_t amplitude);
|
||||
extern int aac_vibra_perform(uint32_t effect, uint32_t strength, uint32_t* timeout_ms);
|
||||
extern int aac_vibra_performEnvelope(void* vib_info, bool fast_flag);
|
||||
extern int aac_vibra_performRtp(int fd, uint32_t* timeout_ms);
|
||||
extern int aac_vibra_performPattern(void* pattern);
|
||||
extern int aac_vibra_performHe(void* he);
|
||||
extern int aac_vibra_performHe_with_len(void* he, int32_t len);
|
||||
extern int aac_vibra_dynamic_scale(uint8_t scale);
|
||||
extern int aac_vibra_setting_f0(int f0);
|
||||
extern int aac_vibra_stop(int32_t* index);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
extern void aac_vibra_looper_start();
|
||||
extern int32_t aac_vibra_looper_post(const int32_t* pattern, int32_t patternLen, int32_t intervalMs,
|
||||
int32_t loopNum, int32_t amplitude, int32_t freq);
|
||||
|
||||
extern bool aac_vibra_looper_performParam(int32_t intervalMs, int32_t amplitude, int32_t freq);
|
||||
|
||||
extern bool aac_vibra_looper_stopPerformHe(void);
|
||||
|
||||
// new api
|
||||
extern int32_t aac_vibra_looper_on(uint32_t time_out);
|
||||
extern int32_t aac_vibra_looper_prebaked_effect(uint32_t effect_id, int32_t strength);
|
||||
extern int32_t aac_vibra_looper_envelope(const int32_t* envelope_data, uint32_t data_len,
|
||||
bool fastFlag);
|
||||
extern int32_t aac_vibra_looper_rtp(int32_t fd);
|
||||
#endif // _HARDWARE_VIBRATOR_H
|
||||
10
vibrator/android.hardware.vibrator.service.spacewar.rc
Normal file
10
vibrator/android.hardware.vibrator.service.spacewar.rc
Normal file
@@ -0,0 +1,10 @@
|
||||
on late-fs
|
||||
chown system system /dev/aw8697_haptic
|
||||
chmod 0600 /dev/aw8697_haptic
|
||||
|
||||
service vendor.vibrator /vendor/bin/hw/android.hardware.vibrator.service.spacewar
|
||||
class hal
|
||||
user system
|
||||
group system input
|
||||
setenv RICHTAP_DEVICE_PATH /dev/aw8697_haptic
|
||||
setenv ENV_RICHTAP_CONFIG_PATH /odm/etc/aac_richtap.config
|
||||
11
vibrator/android.hardware.vibrator.service.spacewar.xml
Normal file
11
vibrator/android.hardware.vibrator.service.spacewar.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.vibrator</name>
|
||||
<version>2</version>
|
||||
<fqname>IVibrator/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
24
vibrator/service.cpp
Normal file
24
vibrator/service.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
#include "Vibrator.h"
|
||||
|
||||
using aidl::android::hardware::vibrator::Vibrator;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<Vibrator> vib = ndk::SharedRefBase::make<Vibrator>();
|
||||
|
||||
const std::string instance = std::string() + Vibrator::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(vib->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
Reference in New Issue
Block a user