universal7885: Add custom HAL for SamsungParts

* No need to chown system sysfs nodes, HIDL can run as root
This commit is contained in:
roynatech2544 2021-10-23 22:27:29 +09:00
commit 00fb011c7c
No known key found for this signature in database
GPG key ID: 9675C32163D88D30
10 changed files with 283 additions and 0 deletions

View file

@ -0,0 +1,3 @@
hidl_package_root{
name: "vendor.eureka",
}

View file

@ -0,0 +1,10 @@
hidl_interface {
name: "vendor.eureka.hardware.battery@1.0",
root: "vendor.eureka",
srcs: [
"types.hal",
"IBattery.hal",
],
interfaces: [ "android.hidl.base@1.0" ],
gen_java: true,
}

View file

@ -0,0 +1,20 @@
// Copyright (C) 2021 Eureka Team
//
// 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.
package vendor.eureka.hardware.battery@1.0;
interface IBattery {
getBatteryStats(SysfsType stats) generates (int32_t result);
setBatteryWritable(SysfsType stats, Number value) generates (int32_t result);
};

View file

@ -0,0 +1,17 @@
// FIXME: your file license if you have one
cc_binary {
name: "vendor.eureka.hardware.battery@1.0-service",
relative_install_path: "hw",
proprietary: true,
srcs: [
"Battery.cpp",
"service.cpp",
],
shared_libs: [
"libhidlbase",
"libutils",
"liblog",
"vendor.eureka.hardware.battery@1.0",
],
}

View file

@ -0,0 +1,102 @@
// Copyright (C) 2021 Eureka Team
//
// 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 "Battery.h"
#include <iostream>
#include <fstream>
#include <sstream>
namespace vendor::eureka::hardware::battery::V1_0 {
// Methods from ::android::hardware::battery::V1_0::IBattery follow.
Return<int32_t> Battery::getBatteryStats(battery::V1_0::SysfsType stats) {
std::ifstream file;
std::string filename;
switch (stats){
case SysfsType::CAPACITY_MAX:
filename = "/sys/devices/platform/battery/power_supply/battery/charge_full";
break;
case SysfsType::TEMP:
filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp";
break;
case SysfsType::CAPACITY_CURRENT:
filename = "/sys/devices/platform/battery/power_supply/battery/capacity";
break;
case SysfsType::CURRENT:
filename = "/sys/devices/platform/battery/power_supply/battery/current_now";
break;
case SysfsType::FASTCHARGE:
filename = "/sys/class/sec/switch/afc_disable";
break;
case SysfsType::CHARGE:
filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode";
break;
default:
filename = "";
break;
}
std::string value;
int32_t intvalue;
file.open(filename);
if (file.is_open()) {
getline(file, value);
file.close();
std::stringstream val(value);
val >> intvalue;
return intvalue;
}
return -1;
}
Return<int32_t> Battery::setBatteryWritable(battery::V1_0::SysfsType stats, battery::V1_0::Number value) {
std::ofstream file;
std::string filename;
switch (stats){
case SysfsType::CAPACITY_MAX:
filename = "/sys/devices/platform/battery/power_supply/battery/charge_full";
break;
case SysfsType::TEMP:
filename = "/sys/devices/platform/battery/power_supply/battery/batt_temp";
break;
case SysfsType::CAPACITY_CURRENT:
filename = "/sys/devices/platform/battery/power_supply/battery/capacity";
break;
case SysfsType::CURRENT:
filename = "/sys/devices/platform/battery/power_supply/battery/current_now";
break;
case SysfsType::FASTCHARGE:
filename = "/sys/class/sec/switch/afc_disable";
break;
case SysfsType::CHARGE:
filename = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode";
break;
default:
filename = "";
break;
}
file.open(filename);
int write;
if (value == Number::ENABLE){
write = 1;
}else{
write = 0;
}
file << write;
file.close();
return 0;
}
IBattery *Battery::getInstance(void){
return new Battery();
}
} // namespace android::hardware::battery::implementation

View file

@ -0,0 +1,40 @@
// Copyright (C) 2021 Eureka Team
//
// 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.
#pragma once
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
namespace vendor::eureka::hardware::battery::V1_0 {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
struct Battery : public IBattery {
// Methods from ::vendor::eureka::hardware::battery::V1_0::IBattery follow.
Return<int32_t> getBatteryStats(SysfsType stats) override;
Return<int32_t> setBatteryWritable(SysfsType stats, Number value) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
static IBattery* getInstance(void);
};
} // namespace android::hardware::battery::implementation

View file

@ -0,0 +1,49 @@
// Copyright (C) 2021 Eureka Team
//
// 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.eureka.hardware.battery@1.0-service"
#include <vendor/eureka/hardware/battery/1.0/IBattery.h>
#include <hidl/LegacySupport.h>
#include "Battery.h"
using vendor::eureka::hardware::battery::V1_0::IBattery;
using vendor::eureka::hardware::battery::V1_0::Battery;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;
int main() {
int ret;
android::sp<IBattery> service = Battery::getInstance();
configureRpcThreadpool(1, true /*callerWillJoin*/);
if (service != nullptr) {
ret = service->registerAsService();
if(ret != 0) {
ALOGE("Can't register instance of Battery HAL, nullptr");
}else{
ALOGI("registered Battery HAL");
}
} else {
ALOGE("Can't create instance of Battery HAL, nullptr");
}
joinRpcThreadpool();
return -1; // should never get here
}

View file

@ -0,0 +1,5 @@
service vendor.battery-hal /vendor/bin/hw/vendor.eureka.hardware.battery@1.0-service
interface vendor.eureka.hardware.battery@1.0::IBattery default
class hal
user system
group system

View file

@ -0,0 +1,28 @@
// Copyright (C) 2021 Eureka Team
//
// 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.
package vendor.eureka.hardware.battery@1.0;
enum SysfsType : int32_t {
CAPACITY_MAX,
TEMP,
CAPACITY_CURRENT,
CURRENT,
FASTCHARGE,
CHARGE,
};
enum Number : int32_t {
ENABLE = 1,
DISABLE = 0,
};

View file

@ -241,4 +241,13 @@
<instance>imsd2</instance>
</interface>
</hal>
<hal format="hidl">
<name>vendor.eureka.hardware.battery</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IBattery</name>
<instance>default</instance>
</interface>
</hal>
</manifest>