sm8250-common: Implement vendor.lineage.powershare@1.0 HAL

This commit is contained in:
LuK1337 2020-07-07 12:47:29 +02:00
parent 89b4f0377f
commit 28e667380b
10 changed files with 226 additions and 0 deletions

View file

@ -168,6 +168,10 @@ PRODUCT_COPY_FILES += \
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
android.hardware.power@1.2-service.oneplus_kona android.hardware.power@1.2-service.oneplus_kona
# PowerShare
PRODUCT_PACKAGES += \
lineage.powershare@1.0-service.oneplus_kona
# Ramdisk # Ramdisk
PRODUCT_COPY_FILES += \ PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/rootdir/etc/fstab.qcom:$(TARGET_COPY_OUT_RAMDISK)/fstab.qcom $(LOCAL_PATH)/rootdir/etc/fstab.qcom:$(TARGET_COPY_OUT_RAMDISK)/fstab.qcom

View file

@ -34,6 +34,15 @@
<instance>default</instance> <instance>default</instance>
</interface> </interface>
</hal> </hal>
<hal format="hidl">
<name>vendor.lineage.powershare</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IPowerShare</name>
<instance>default</instance>
</interface>
</hal>
<hal format="hidl"> <hal format="hidl">
<name>vendor.lineage.trust</name> <name>vendor.lineage.trust</name>
<transport>hwbinder</transport> <transport>hwbinder</transport>

32
powershare/Android.bp Normal file
View file

@ -0,0 +1,32 @@
//
// Copyright (C) 2020 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.
cc_binary {
relative_install_path: "hw",
defaults: ["hidl_defaults"],
name: "lineage.powershare@1.0-service.oneplus_kona",
init_rc: ["lineage.powershare@1.0-service.oneplus_kona.rc"],
srcs: ["service.cpp", "PowerShare.cpp"],
shared_libs: [
"libbase",
"libhardware",
"libhidlbase",
"libhidltransport",
"liblog",
"libhwbinder",
"libutils",
"vendor.lineage.powershare@1.0",
],
}

71
powershare/PowerShare.cpp Normal file
View file

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

45
powershare/PowerShare.h Normal file
View file

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

View file

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

50
powershare/service.cpp Normal file
View file

@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 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 "lineage.powershare@1.0-service.oneplus_kona"
#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

@ -4,6 +4,7 @@ type op2_file, file_type;
# proc # proc
type proc_touchpanel, fs_type, proc_type; type proc_touchpanel, fs_type, proc_type;
type procfs_oem_wireless, fs_type, proc_type;
# sysfs # sysfs
type sysfs_battery_supply, sysfs_type, fs_type; type sysfs_battery_supply, sysfs_type, fs_type;

View file

@ -13,6 +13,7 @@
/(product|system/product)/vendor_overlay/[0-9]+/bin/hw/android\.hardware\.power@1\.2-service u:object_r:hal_power_default_exec:s0 /(product|system/product)/vendor_overlay/[0-9]+/bin/hw/android\.hardware\.power@1\.2-service u:object_r:hal_power_default_exec:s0
/system/bin/hw/lineage\.biometrics\.fingerprint\.inscreen@1.0-service\.oneplus_kona u:object_r:hal_fod_kona_exec:s0 /system/bin/hw/lineage\.biometrics\.fingerprint\.inscreen@1.0-service\.oneplus_kona u:object_r:hal_fod_kona_exec:s0
/system/bin/hw/lineage\.livedisplay@2\.0-service\.oneplus_kona u:object_r:hal_livedisplay_kona_exec:s0 /system/bin/hw/lineage\.livedisplay@2\.0-service\.oneplus_kona u:object_r:hal_livedisplay_kona_exec:s0
/system/bin/hw/lineage\.powershare@1\.0-service\.oneplus_kona u:object_r:hal_powershare_kona_exec:s0
/system/bin/hw/lineage\.touch@1\.0-service\.oneplus_kona u:object_r:hal_touch_kona_exec:s0 /system/bin/hw/lineage\.touch@1\.0-service\.oneplus_kona u:object_r:hal_touch_kona_exec:s0
# DASH # DASH

View file

@ -0,0 +1,9 @@
type hal_powershare_kona, coredomain, domain;
hal_server_domain(hal_powershare_kona, hal_lineage_powershare)
type hal_powershare_kona_exec, system_file_type, exec_type, file_type;
init_daemon_domain(hal_powershare_kona)
# Allow access to wireless rx enable nodes
allow hal_powershare_kona procfs_oem_wireless:dir search;
allow hal_powershare_kona procfs_oem_wireless:file rw_file_perms;