hidl: Implement vendor.lineage.powershare@1.0 HAL for Xiaomi

* This feature is present in Xiaomi Mi 10/Pro/Ultra and for the Xiaomi
   family of SM8350, LAHAINA devices.

Change-Id: Icabcee87980611d97a837f86a52d94033de337ef
This commit is contained in:
LuK1337 2021-09-16 13:55:07 +02:00 committed by Sebastiano Barezzi
parent c6a4249c37
commit ac68cfefd7
No known key found for this signature in database
GPG Key ID: 47760583F393BC44
6 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1,26 @@
//
// Copyright (C) 2020 The LineageOS Project
//
// SPDX-License-Identifier: Apache-2.0
//
cc_binary {
name: "vendor.lineage.powershare@1.0-service.xiaomi",
defaults: ["hidl_defaults"],
relative_install_path: "hw",
init_rc: ["vendor.lineage.powershare@1.0-service.xiaomi.rc"],
vintf_fragments: ["vendor.lineage.powershare@1.0-service.xiaomi.xml"],
srcs: [
"service.cpp",
"PowerShare.cpp",
],
shared_libs: [
"libbase",
"libhardware",
"libhidlbase",
"liblog",
"libutils",
"vendor.lineage.powershare@1.0",
],
proprietary: true,
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) 2020 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "PowerShareService"
#include "PowerShare.h"
#include <hidl/HidlTransportSupport.h>
#include <fstream>
namespace vendor {
namespace lineage {
namespace powershare {
namespace V1_0 {
namespace implementation {
#define WIRELESS_TX_ENABLE_PATH "/proc/wireless/enable_tx"
/*
* Write value to path and close file.
*/
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
file << value;
}
template <typename T>
static T get(const std::string& path, const T& def) {
std::ifstream file(path);
T result;
file >> result;
return file.fail() ? def : result;
}
Return<bool> PowerShare::isEnabled() {
return get<std::string>(WIRELESS_TX_ENABLE_PATH, "disable") != "disable";
}
Return<bool> PowerShare::setEnabled(bool enable) {
set(WIRELESS_TX_ENABLE_PATH, enable ? 1 : 0);
return isEnabled();
}
Return<uint32_t> PowerShare::getMinBattery() {
return 0;
}
Return<uint32_t> PowerShare::setMinBattery(uint32_t) {
return getMinBattery();
}
} // namespace implementation
} // namespace V1_0
} // namespace powershare
} // namespace lineage
} // namespace vendor

View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 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
#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

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2020 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "vendor.lineage.powershare@1.0-service.xiaomi"
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include "PowerShare.h"
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using vendor::lineage::powershare::V1_0::IPowerShare;
using vendor::lineage::powershare::V1_0::implementation::PowerShare;
using android::OK;
using android::status_t;
int main() {
android::sp<IPowerShare> service = new PowerShare();
configureRpcThreadpool(1, true);
status_t status = service->registerAsService();
if (status != OK) {
LOG(ERROR) << "Cannot register PowerShare HAL service.";
return 1;
}
LOG(INFO) << "PowerShare HAL service ready.";
joinRpcThreadpool();
LOG(ERROR) << "PowerShare HAL service failed to join thread pool.";
return 1;
}

View File

@ -0,0 +1,4 @@
service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.xiaomi
class hal
user system
group system

View File

@ -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>