mirror of
https://github.com/Evolution-X-Devices/device_oplus_mt6893-common
synced 2026-02-01 09:03:05 +00:00
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
/*
|
|
* Copyright (C) 2022 The Android Open Source 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.
|
|
*/
|
|
|
|
#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, std::string 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::setNodes(std::vector<std::pair<std::string, std::string>> values) {
|
|
for (const auto& [path, value] : values) {
|
|
ndk::ScopedAStatus status = setNode(path, value);
|
|
|
|
if (!status.isOk()) {
|
|
return status;
|
|
}
|
|
}
|
|
|
|
return ndk::ScopedAStatus::ok();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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
|