powershare: add default implementation
Change-Id: If14d0e2038c604d6da5e383df638fd138e7aea26
This commit is contained in:
parent
7cbd562024
commit
bd66d5bf2e
6 changed files with 158 additions and 0 deletions
21
powershare/1.0/default/Android.bp
Normal file
21
powershare/1.0/default/Android.bp
Normal file
|
@ -0,0 +1,21 @@
|
|||
cc_binary {
|
||||
name: "vendor.lineage.powershare@1.0-service.default",
|
||||
defaults: [
|
||||
"hidl_defaults",
|
||||
"powershare_defaults",
|
||||
],
|
||||
init_rc: ["vendor.lineage.powershare@1.0-service.default.rc"],
|
||||
vintf_fragments: ["vendor.lineage.powershare@1.0-service.default.xml"],
|
||||
vendor: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"service.cpp",
|
||||
"PowerShare.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libhidlbase",
|
||||
"libutils",
|
||||
"vendor.lineage.powershare@1.0",
|
||||
],
|
||||
}
|
51
powershare/1.0/default/PowerShare.cpp
Normal file
51
powershare/1.0/default/PowerShare.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "PowerShare.h"
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
using ::android::base::ReadFileToString;
|
||||
using ::android::base::WriteStringToFile;
|
||||
|
||||
namespace vendor {
|
||||
namespace lineage {
|
||||
namespace powershare {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
Return<bool> PowerShare::isEnabled() {
|
||||
std::string value;
|
||||
|
||||
if (!ReadFileToString(POWERSHARE_PATH, &value)) {
|
||||
LOG(ERROR) << "Failed to read current powershare value";
|
||||
return false;
|
||||
}
|
||||
|
||||
value = android::base::Trim(value);
|
||||
|
||||
return value == POWERSHARE_ENABLED;
|
||||
}
|
||||
|
||||
Return<bool> PowerShare::setEnabled(bool enable) {
|
||||
const auto& value = enable ? POWERSHARE_ENABLED : POWERSHARE_DISABLED;
|
||||
return WriteStringToFile(value, POWERSHARE_PATH, true);
|
||||
}
|
||||
|
||||
Return<uint32_t> PowerShare::getMinBattery() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Return<uint32_t> PowerShare::setMinBattery(uint32_t /*minBattery*/) {
|
||||
return getMinBattery();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace powershare
|
||||
} // namespace lineage
|
||||
} // namespace vendor
|
40
powershare/1.0/default/PowerShare.h
Normal file
40
powershare/1.0/default/PowerShare.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
|
||||
#define VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
|
||||
|
||||
#define LOG_TAG "vendor.lineage.powershare@1.0-service.default"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <vendor/lineage/powershare/1.0/IPowerShare.h>
|
||||
|
||||
namespace vendor {
|
||||
namespace lineage {
|
||||
namespace powershare {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::sp;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
|
||||
class PowerShare : public IPowerShare {
|
||||
public:
|
||||
Return<bool> isEnabled() override;
|
||||
Return<bool> setEnabled(bool enable) override;
|
||||
Return<uint32_t> getMinBattery() override;
|
||||
Return<uint32_t> setMinBattery(uint32_t minBattery) override;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace powershare
|
||||
} // namespace lineage
|
||||
} // namespace vendor
|
||||
|
||||
#endif // VENDOR_LINEAGE_POWERSHARE_V1_0_POWERSHARE_H
|
31
powershare/1.0/default/service.cpp
Normal file
31
powershare/1.0/default/service.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "PowerShare.h"
|
||||
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
using android::sp;
|
||||
|
||||
using vendor::lineage::powershare::V1_0::IPowerShare;
|
||||
using vendor::lineage::powershare::V1_0::implementation::PowerShare;
|
||||
|
||||
int main() {
|
||||
sp<IPowerShare> powerShareService = new PowerShare();
|
||||
|
||||
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||
|
||||
if (powerShareService->registerAsService() != android::OK) {
|
||||
LOG(ERROR) << "Can't register PowerShare HAL service";
|
||||
return 1;
|
||||
}
|
||||
|
||||
joinRpcThreadpool();
|
||||
|
||||
return 0; // should never get here
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.default
|
||||
class hal
|
||||
user system
|
||||
group system
|
|
@ -0,0 +1,11 @@
|
|||
<manifest version="1.0" type="device">
|
||||
<hal format="hidl">
|
||||
<name>vendor.lineage.powershare</name>
|
||||
<transport>hwbinder</transport>
|
||||
<version>1.0</version>
|
||||
<interface>
|
||||
<name>IPowerShare</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
Loading…
Reference in a new issue