Revert "S666LN: Import AIDL vibrator services"
This reverts commit 3a67e21718.
Signed-off-by: fjrXTR <fajarslebew31@gmail.com>
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2024 The LineageOS Project
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
soong_config_module_type {
|
||||
name: "mediatek_vibrator_defaults",
|
||||
module_type: "cc_defaults",
|
||||
config_namespace: "mediatek_vibrator",
|
||||
bool_variables: [
|
||||
"supports_effects",
|
||||
],
|
||||
properties: [
|
||||
"cflags",
|
||||
],
|
||||
}
|
||||
|
||||
mediatek_vibrator_defaults {
|
||||
name: "mediatek_vibrator_defaults",
|
||||
soong_config_variables: {
|
||||
supports_effects: {
|
||||
cflags: ["-DVIBRATOR_SUPPORTS_EFFECTS"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cc_binary {
|
||||
name: "android.hardware.vibrator-service.s666ln",
|
||||
defaults: ["mediatek_vibrator_defaults"],
|
||||
vintf_fragments: ["android.hardware.vibrator.s666ln.xml"],
|
||||
init_rc: ["vibrator-s666ln.rc"],
|
||||
vendor: true,
|
||||
relative_install_path: "hw",
|
||||
|
||||
srcs: [
|
||||
"Vibrator.cpp",
|
||||
"VibratorUtils.cpp",
|
||||
"main.cpp",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"android.hardware.vibrator-V2-ndk",
|
||||
],
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Vibrator.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace vibrator {
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
Vibrator::Vibrator() {
|
||||
if (exists(kVibratorStrength)) {
|
||||
mVibratorStrengthSupported = true;
|
||||
mVibratorStrengthMax = getNode(kVibratorStrengthMax, 9);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
|
||||
LOG(VERBOSE) << "Vibrator reporting capabilities";
|
||||
*_aidl_return = IVibrator::CAP_ON_CALLBACK;
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
*_aidl_return |= IVibrator::CAP_PERFORM_CALLBACK;
|
||||
|
||||
if (mVibratorStrengthSupported) *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL;
|
||||
#endif
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::off() {
|
||||
LOG(VERBOSE) << "Vibrator off";
|
||||
return setNode(kVibratorActivate, 0);
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
|
||||
const std::shared_ptr<IVibratorCallback>& callback) {
|
||||
ndk::ScopedAStatus status;
|
||||
|
||||
LOG(VERBOSE) << "Vibrator on for timeoutMs: " << timeoutMs;
|
||||
|
||||
status = activate(timeoutMs);
|
||||
if (!status.isOk()) return status;
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(VERBOSE) << "Starting on on another thread";
|
||||
usleep(timeoutMs * 1000);
|
||||
LOG(VERBOSE) << "Notifying on complete";
|
||||
if (!callback->onComplete().isOk()) {
|
||||
LOG(ERROR) << "Failed to call onComplete";
|
||||
}
|
||||
}).detach();
|
||||
}
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength,
|
||||
const std::shared_ptr<IVibratorCallback>& callback,
|
||||
int32_t* _aidl_return) {
|
||||
ndk::ScopedAStatus status;
|
||||
int32_t timeoutMs;
|
||||
|
||||
if (vibEffects.find(effect) == vibEffects.end())
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
|
||||
if (vibStrengths.find(strength) == vibStrengths.end())
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
setAmplitude(vibStrengths[strength]);
|
||||
#endif
|
||||
|
||||
timeoutMs = vibEffects[effect];
|
||||
|
||||
status = activate(timeoutMs);
|
||||
if (!status.isOk()) return status;
|
||||
|
||||
if (callback != nullptr) {
|
||||
std::thread([=] {
|
||||
LOG(VERBOSE) << "Starting perform on another thread";
|
||||
usleep(timeoutMs * 1000);
|
||||
LOG(VERBOSE) << "Notifying perform complete";
|
||||
callback->onComplete();
|
||||
}).detach();
|
||||
}
|
||||
|
||||
*_aidl_return = timeoutMs;
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
|
||||
for (auto const& pair : vibEffects)
|
||||
_aidl_return->push_back(pair.first);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
int32_t intensity;
|
||||
#endif
|
||||
|
||||
if (amplitude <= 0.0f || amplitude > 1.0f)
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
LOG(VERBOSE) << "Setting amplitude: " << amplitude;
|
||||
|
||||
intensity = amplitude * mVibratorStrengthMax;
|
||||
|
||||
LOG(VERBOSE) << "Setting intensity: " << intensity;
|
||||
|
||||
if (mVibratorStrengthSupported) setNode(kVibratorStrength, intensity);
|
||||
#endif
|
||||
|
||||
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(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
|
||||
}
|
||||
|
||||
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
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/android/hardware/vibrator/BnVibrator.h>
|
||||
#include <map>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace vibrator {
|
||||
|
||||
const std::string kVibratorPropPrefix = "ro.vendor.vibrator.hal.";
|
||||
const std::string kVibratorPropDuration = ".duration";
|
||||
|
||||
const std::string kVibratorState = "/sys/class/leds/vibrator_single/state";
|
||||
const std::string kVibratorDuration = "/sys/class/leds/vibrator_single/duration";
|
||||
const std::string kVibratorActivate = "/sys/class/leds/vibrator_single/activate";
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
const std::string kVibratorStrength = "/sys/class/leds/vibrator_single/vmax";
|
||||
const std::string kVibratorStrengthMax = "/sys/class/leds/vibrator_single/vmax_max";
|
||||
#endif
|
||||
|
||||
static std::map<EffectStrength, float> vibStrengths = {
|
||||
{EffectStrength::LIGHT, 0.25}, {EffectStrength::MEDIUM, 0.5}, {EffectStrength::STRONG, 1}};
|
||||
|
||||
class Vibrator : public BnVibrator {
|
||||
public:
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
Vibrator();
|
||||
#endif
|
||||
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;
|
||||
|
||||
private:
|
||||
static ndk::ScopedAStatus setNode(const std::string path, const int32_t value);
|
||||
static int getIntProperty(const std::string& key, const int fallback);
|
||||
std::map<Effect, int32_t> vibEffects = {
|
||||
{Effect::CLICK, getIntProperty("click" + kVibratorPropDuration, 50)},
|
||||
{Effect::TICK, getIntProperty("tick" + kVibratorPropDuration, 32)},
|
||||
{Effect::TEXTURE_TICK, getIntProperty("texture_tick" + kVibratorPropDuration, 25)},
|
||||
};
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
static bool exists(const std::string path);
|
||||
static int getNode(const std::string path, const int fallback);
|
||||
bool mVibratorStrengthSupported;
|
||||
int mVibratorStrengthMax;
|
||||
#endif
|
||||
ndk::ScopedAStatus activate(const int32_t timeoutMs);
|
||||
};
|
||||
|
||||
} // namespace vibrator
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Vibrator.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace vibrator {
|
||||
|
||||
ndk::ScopedAStatus Vibrator::setNode(const std::string path, const int32_t value) {
|
||||
std::ofstream file(path);
|
||||
|
||||
if (!file.is_open()) {
|
||||
LOG(ERROR) << "Failed to write " << value << " to " << path;
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
|
||||
}
|
||||
|
||||
file << value << std::endl;
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Vibrator::activate(const int32_t timeoutMs) {
|
||||
ndk::ScopedAStatus status;
|
||||
|
||||
/* timeoutMs under 1 = turn off vibrator */
|
||||
if (timeoutMs < 1) {
|
||||
return off();
|
||||
}
|
||||
|
||||
status = setNode(kVibratorState, 1);
|
||||
if (!status.isOk()) return status;
|
||||
|
||||
status = setNode(kVibratorDuration, timeoutMs);
|
||||
if (!status.isOk()) return status;
|
||||
|
||||
status = setNode(kVibratorActivate, 1);
|
||||
if (!status.isOk()) return status;
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
#ifdef VIBRATOR_SUPPORTS_EFFECTS
|
||||
bool Vibrator::exists(const std::string path) {
|
||||
std::ofstream file(path);
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
int Vibrator::getNode(const std::string path, const int fallback) {
|
||||
std::ifstream file(path);
|
||||
int value;
|
||||
|
||||
if (!file.is_open()) {
|
||||
LOG(ERROR) << "failed to read from " << path.c_str();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
file >> value;
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
|
||||
int Vibrator::getIntProperty(const std::string& key, const int fallback) {
|
||||
return ::android::base::GetIntProperty(kVibratorPropPrefix + key, fallback);
|
||||
}
|
||||
|
||||
} // namespace vibrator
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
@@ -1,7 +0,0 @@
|
||||
<manifest version="1.0" type="device">
|
||||
<hal format="aidl">
|
||||
<name>android.hardware.vibrator</name>
|
||||
<version>2</version>
|
||||
<fqname>IVibrator/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "Vibrator.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
using aidl::android::hardware::vibrator::Vibrator;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
|
||||
// make a default vibrator service
|
||||
auto vib = ndk::SharedRefBase::make<Vibrator>();
|
||||
const std::string vibName = std::string() + Vibrator::descriptor + "/default";
|
||||
binder_status_t status = AServiceManager_addService(vib->asBinder().get(), vibName.c_str());
|
||||
CHECK_EQ(status, STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
on init
|
||||
chown system system /sys/class/leds/vibrator_single/vmax
|
||||
chown system system /sys/class/leds/vibrator_single/vmax_max
|
||||
|
||||
service vendor.vibrator /vendor/bin/hw/android.hardware.vibrator-service.s666ln
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
Reference in New Issue
Block a user