eqs: Implement vendor.lineage.powershare@1.0 HAL

Change-Id: I8022ac47411369f3ede969417fd46e08fb984e24
This commit is contained in:
LuK1337
2021-09-16 13:55:07 +02:00
committed by SGCMarkus
parent b2dde636dd
commit 4548ac73de
7 changed files with 185 additions and 0 deletions

View File

@@ -86,6 +86,10 @@ PRODUCT_PACKAGES += \
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.nfc.hcef.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.nfc.hcef.xml
# PowerShare
PRODUCT_PACKAGES += \
vendor.lineage.powershare@1.0-service.eqs
# Sensors
PRODUCT_PACKAGES += \
sensors.eqs

18
powershare/Android.bp Normal file
View File

@@ -0,0 +1,18 @@
cc_binary {
name: "vendor.lineage.powershare@1.0-service.eqs",
defaults: ["hidl_defaults"],
init_rc: ["vendor.lineage.powershare@1.0-service.eqs.rc"],
vintf_fragments: ["vendor.lineage.powershare@1.0-service.eqs.xml"],
vendor: true,
relative_install_path: "hw",
srcs: [
"service.cpp",
"PowerShare.cpp",
],
shared_libs: [
"libbase",
"libhidlbase",
"libutils",
"vendor.lineage.powershare@1.0",
],
}

59
powershare/PowerShare.cpp Normal file
View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2022 The LineageOS 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.
*/
#define LOG_TAG "vendor.lineage.powershare@1.0-service.eqs"
#include "PowerShare.h"
#include <android-base/file.h>
using ::android::base::ReadFileToString;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kWirelessTxEnablePath = "/sys/class/power_supply/wireless/device/tx_mode";
} // anonymous namespace
namespace vendor {
namespace lineage {
namespace powershare {
namespace V1_0 {
namespace implementation {
Return<bool> PowerShare::isEnabled() {
std::string value;
return ReadFileToString(kWirelessTxEnablePath, &value) && value != "0\n";
}
Return<bool> PowerShare::setEnabled(bool enable) {
return WriteStringToFile(enable ? "1" : "0", kWirelessTxEnablePath, 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

45
powershare/PowerShare.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2022 The LineageOS 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.
*/
#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

44
powershare/service.cpp Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 The LineageOS 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.
*/
#define LOG_TAG "vendor.lineage.powershare@1.0-service.eqs"
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include "PowerShare.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
}

View File

@@ -0,0 +1,4 @@
service vendor.powershare-hal-1-0 /vendor/bin/hw/vendor.lineage.powershare@1.0-service.eqs
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>