mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 19:55:33 -04:00
universal7885: parts-hidl: Refactor code and impl smartcharge
This commit is contained in:
parent
5f6bde3d2b
commit
2e0da038da
27 changed files with 407 additions and 200 deletions
|
|
@ -7,6 +7,7 @@ hidl_interface {
|
|||
"IFlashBrightness.hal",
|
||||
"IDisplayConfigs.hal",
|
||||
"ISwapOnData.hal",
|
||||
"ISmartCharge.hal"
|
||||
],
|
||||
interfaces: ["android.hidl.base@1.0"],
|
||||
gen_java: false,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@
|
|||
package vendor.eureka.hardware.parts@1.0;
|
||||
|
||||
interface IBatteryStats {
|
||||
getBatteryStats(SysfsType stats) generates (int32_t result);
|
||||
setBatteryWritable(SysfsType stats, Number value);
|
||||
getBatteryStats(BatterySys stats) generates (int32_t result);
|
||||
setBatteryWritable(BatterySys stats, Status value);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,5 +15,5 @@
|
|||
package vendor.eureka.hardware.parts@1.0;
|
||||
|
||||
interface IDisplayConfigs {
|
||||
writeDisplay(Number enable, Display type);
|
||||
writeDisplay(Status enable, DisplaySys type);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
package vendor.eureka.hardware.parts@1.0;
|
||||
|
||||
interface IFlashBrightness {
|
||||
setFlashlightWritable(Value value);
|
||||
setFlashlightEnable(Number enable);
|
||||
readFlashlightstats(Device device) generates (int32_t value);
|
||||
setFlashlightWritable(int32_t value);
|
||||
setFlashlightEnable(Status enable);
|
||||
readFlashlightstats(bool s2mu106) generates (int32_t value);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// 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.parts@1.0;
|
||||
|
||||
interface ISmartCharge {
|
||||
start();
|
||||
stop();
|
||||
setConfig(int32_t limit, int32_t restart);
|
||||
getLimitCnt() generates (int32_t cnt);
|
||||
getRestartCnt() generates (int32_t cnt);
|
||||
};
|
||||
|
|
@ -18,4 +18,7 @@ interface ISwapOnData {
|
|||
setSwapSize(int32_t size /* Size in megabytes */);
|
||||
setSwapOn();
|
||||
setSwapOff();
|
||||
removeSwapFile();
|
||||
getSwapOnResult() generates (bool result);
|
||||
isMutexLocked() generates (bool islocked);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,8 +9,11 @@ cc_binary {
|
|||
"Display.cpp",
|
||||
"Swap.cpp",
|
||||
"SwapHelpers.cpp",
|
||||
"SmartChargingImpl.cpp",
|
||||
"SmartCharge.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
cflags: ["-Wno-thread-safety-negative"],
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libutils",
|
||||
|
|
|
|||
|
|
@ -17,95 +17,58 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
#include "CachedClass.h"
|
||||
#include "BatteryConstants.h"
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
static BatteryStats *kCached = nullptr;
|
||||
|
||||
static inline const char* BatterySysToPath (parts::V1_0::BatterySys type) {
|
||||
switch (type) {
|
||||
case BatterySys::CAPACITY_MAX:
|
||||
return BATTERY_CAPACITY_MAX;
|
||||
case BatterySys::TEMP:
|
||||
return BATTERY_TEMP;
|
||||
case BatterySys::CAPACITY_CURRENT:
|
||||
return BATTERY_CAPACITY_CURRENT;
|
||||
case BatterySys::CURRENT:
|
||||
return BATTERY_CURRENT;
|
||||
case BatterySys::FASTCHARGE:
|
||||
return BATTERY_FASTCHARGE;
|
||||
case BatterySys::CHARGE:
|
||||
return BATTERY_CHARGE;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::battery::V1_0::IBattery follow.
|
||||
Return<int32_t> BatteryStats::getBatteryStats(parts::V1_0::SysfsType stats) {
|
||||
Return<int32_t> BatteryStats::getBatteryStats(parts::V1_0::BatterySys 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);
|
||||
file.open(BatterySysToPath(stats));
|
||||
if (file.is_open()) {
|
||||
getline(file, value);
|
||||
file.close();
|
||||
std::stringstream val(value);
|
||||
val >> intvalue;
|
||||
return intvalue;
|
||||
return stoi(value);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Return<void> BatteryStats::setBatteryWritable(parts::V1_0::SysfsType stats,
|
||||
parts::V1_0::Number value) {
|
||||
Return<void> BatteryStats::setBatteryWritable(parts::V1_0::BatterySys stats,
|
||||
parts::V1_0::Status value) {
|
||||
std::ofstream file;
|
||||
std::string filename;
|
||||
bool FastCharge = false;
|
||||
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";
|
||||
FastCharge = true;
|
||||
break;
|
||||
case SysfsType::CHARGE:
|
||||
filename =
|
||||
"/sys/devices/platform/battery/power_supply/battery/batt_slate_mode";
|
||||
break;
|
||||
default:
|
||||
filename = "";
|
||||
break;
|
||||
}
|
||||
if (FastCharge)
|
||||
seteuid(ANDROID_SYSTEM_UID);
|
||||
file.open(filename);
|
||||
int write;
|
||||
if (value == Number::ENABLE) {
|
||||
write = 1;
|
||||
} else {
|
||||
write = 0;
|
||||
}
|
||||
file << write;
|
||||
file.open(BatterySysToPath(stats));
|
||||
file << static_cast<int32_t>(value);
|
||||
file.close();
|
||||
if (FastCharge)
|
||||
seteuid(ANDROID_ROOT_UID);
|
||||
return Void();
|
||||
}
|
||||
|
||||
IBatteryStats *BatteryStats::getInstance(void) { return new BatteryStats(); }
|
||||
IBatteryStats *BatteryStats::getInstance(void) { USE_CACHED(kCached); }
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
|
|||
|
|
@ -24,17 +24,13 @@
|
|||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
using ::android::sp;
|
||||
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;
|
||||
|
||||
struct BatteryStats : public IBatteryStats {
|
||||
// Methods from ::vendor::eureka::hardware::parts::V1_0::IBatteryStats follow.
|
||||
Return<int32_t> getBatteryStats(SysfsType stats) override;
|
||||
Return<void> setBatteryWritable(SysfsType stats, Number value) override;
|
||||
Return<int32_t> getBatteryStats(BatterySys stats) override;
|
||||
Return<void> setBatteryWritable(BatterySys stats, Status value) override;
|
||||
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
static IBatteryStats *getInstance(void);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
constexpr const char* BATTERY_CAPACITY_MAX = "/sys/devices/platform/battery/power_supply/battery/charge_full";
|
||||
constexpr const char* BATTERY_TEMP = "/sys/devices/platform/battery/power_supply/battery/batt_temp";
|
||||
constexpr const char* BATTERY_CAPACITY_CURRENT = "/sys/devices/platform/battery/power_supply/battery/capacity";
|
||||
constexpr const char* BATTERY_CURRENT = "/sys/devices/platform/battery/power_supply/battery/current_now";
|
||||
constexpr const char* BATTERY_FASTCHARGE = "/sys/class/sec/switch/afc_disable";
|
||||
constexpr const char* BATTERY_CHARGE = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode";
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
template <class C>
|
||||
static inline C *cachedClass(C* cached) {
|
||||
if (cached != nullptr) {
|
||||
return cached;
|
||||
}
|
||||
cached = new C();
|
||||
return cached;
|
||||
}
|
||||
|
||||
#define USE_CACHED(cache) \
|
||||
({ \
|
||||
return cachedClass((cache)); \
|
||||
})
|
||||
|
||||
|
|
@ -16,19 +16,23 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "CachedClass.h"
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Number enable,
|
||||
parts::V1_0::Display type) {
|
||||
static DisplayConfigs *kCached;
|
||||
|
||||
Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Status enable,
|
||||
parts::V1_0::DisplaySys type) {
|
||||
std::ofstream file;
|
||||
std::string writevalue;
|
||||
if (type == Display::DOUBLE_TAP) {
|
||||
if (type == DisplaySys::DOUBLE_TAP) {
|
||||
writevalue = "aot_enable";
|
||||
} else if (type == Display::GLOVE_MODE) {
|
||||
} else if (type == DisplaySys::GLOVE_MODE) {
|
||||
writevalue = "glove_mode";
|
||||
}
|
||||
writevalue += ",";
|
||||
if (enable == Number::ENABLE) {
|
||||
if (enable == Status::ENABLE) {
|
||||
writevalue += "1";
|
||||
} else {
|
||||
writevalue += "0";
|
||||
|
|
@ -40,6 +44,6 @@ Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Number enable,
|
|||
}
|
||||
|
||||
IDisplayConfigs *DisplayConfigs::getInstance(void) {
|
||||
return new DisplayConfigs();
|
||||
USE_CACHED(kCached);
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
|
|||
|
|
@ -21,17 +21,13 @@
|
|||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
using ::android::sp;
|
||||
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;
|
||||
|
||||
struct DisplayConfigs : public IDisplayConfigs {
|
||||
// Methods from ::vendor::eureka::hardware::parts::V1_0::IDisplayConfigs
|
||||
// follow.
|
||||
Return<void> writeDisplay(Number enable, Display type);
|
||||
Return<void> writeDisplay(Status enable, DisplaySys type);
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
static IDisplayConfigs *getInstance(void);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,17 +16,21 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "CachedClass.h"
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
static FlashBrightness *kCached;
|
||||
|
||||
// Methods from ::android::hardware::parts::V1_0::IFlashLight follow.
|
||||
Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Number enable) {
|
||||
Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Status enable) {
|
||||
std::ofstream file;
|
||||
std::string writevalue;
|
||||
switch (enable) {
|
||||
case Number::ENABLE:
|
||||
case Status::ENABLE:
|
||||
writevalue = "1";
|
||||
break;
|
||||
case Number::DISABLE:
|
||||
case Status::DISABLE:
|
||||
writevalue = "0";
|
||||
break;
|
||||
default:
|
||||
|
|
@ -39,38 +43,32 @@ Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Number enable) {
|
|||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FlashBrightness::setFlashlightWritable(parts::V1_0::Value value) {
|
||||
Return<void> FlashBrightness::setFlashlightWritable(int32_t value) {
|
||||
std::ofstream file;
|
||||
std::string writevalue = std::to_string((int)value);
|
||||
std::string writevalue = std::to_string(value);
|
||||
file.open("/sys/class/camera/flash/torch_brightness_lvl");
|
||||
file << writevalue;
|
||||
file.close();
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<int32_t>
|
||||
FlashBrightness::readFlashlightstats(parts::V1_0::Device device) {
|
||||
Return<int32_t> FlashBrightness::readFlashlightstats(bool s2mu106) {
|
||||
std::ifstream file;
|
||||
std::string value;
|
||||
int32_t intvalue;
|
||||
file.open("/sys/class/camera/flash/torch_brightness_lvl");
|
||||
if (file.is_open()) {
|
||||
getline(file, value);
|
||||
file.close();
|
||||
std::stringstream val(value);
|
||||
val >> intvalue;
|
||||
if (device == Device::A10) {
|
||||
return intvalue;
|
||||
} else if (device == Device::NOTA10) {
|
||||
return intvalue / 21;
|
||||
if (s2mu106) {
|
||||
return stoi(value);
|
||||
} else {
|
||||
return stoi(value) / 21;
|
||||
}
|
||||
// Never Here
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
IFlashBrightness *FlashBrightness::getInstance(void) {
|
||||
return new FlashBrightness();
|
||||
USE_CACHED(kCached);
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
|
|||
|
|
@ -21,19 +21,15 @@
|
|||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
using ::android::sp;
|
||||
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;
|
||||
|
||||
struct FlashBrightness : public IFlashBrightness {
|
||||
// Methods from ::vendor::eureka::hardware::parts::V1_0::IFlashBrightness
|
||||
// follow.
|
||||
Return<void> setFlashlightEnable(Number enable);
|
||||
Return<void> setFlashlightWritable(Value value);
|
||||
Return<int32_t> readFlashlightstats(Device device);
|
||||
Return<void> setFlashlightEnable(Status enable);
|
||||
Return<void> setFlashlightWritable(int32_t value);
|
||||
Return<int32_t> readFlashlightstats(bool s2mu106);
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
static IFlashBrightness *getInstance(void);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
// 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 "SmartCharge.h"
|
||||
#include "SmartChargingImpl.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "CachedClass.h"
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
static SmartCharge *kCached;
|
||||
static SmartChargeImpl *kInst = nullptr;
|
||||
|
||||
static int limit = 0;
|
||||
static int restart = 0;
|
||||
|
||||
static int limit_stat = 0;
|
||||
static int restart_stat = 0;
|
||||
|
||||
Return<void> SmartCharge::start(void) {
|
||||
if (limit == 0 || restart == 0)
|
||||
return Void();
|
||||
kInst = new SmartChargeImpl(limit, restart);
|
||||
kInst->start();
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> SmartCharge::stop(void) {
|
||||
if (kInst != nullptr) {
|
||||
kInst->stop();
|
||||
limit_stat += kInst->charge_limit_cnt;
|
||||
restart_stat += kInst->restart_cnt;
|
||||
delete kInst;
|
||||
kInst = nullptr;
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> SmartCharge::setConfig(int32_t limit_user, int32_t restart_user) {
|
||||
limit = limit_user;
|
||||
restart = restart_user;
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<int32_t> SmartCharge::getLimitCnt(void) {
|
||||
return limit_stat;
|
||||
}
|
||||
|
||||
Return<int32_t> SmartCharge::getRestartCnt(void) {
|
||||
return restart_stat;
|
||||
}
|
||||
|
||||
ISmartCharge *SmartCharge::getInstance(void) {
|
||||
USE_CACHED(kCached);
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
// 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 <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/ISmartCharge.h>
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
using ::android::sp;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
|
||||
struct SmartCharge : public ISmartCharge {
|
||||
// Methods from ::vendor::eureka::hardware::parts::V1_0::ISmartCharge
|
||||
// follow.
|
||||
Return<void> start(void);
|
||||
Return<void> stop(void);
|
||||
Return<void> setConfig(int32_t limit, int32_t restart);
|
||||
Return<int32_t> getLimitCnt(void);
|
||||
Return<int32_t> getRestartCnt(void);
|
||||
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||
static ISmartCharge *getInstance(void);
|
||||
};
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#include "SmartChargingImpl.h"
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
static std::thread *monitor;
|
||||
static bool shouldRun = false;
|
||||
|
||||
SmartChargeImpl::SmartChargeImpl(int limit, int restart) : limit_percent(limit), restart_percent(restart) {
|
||||
charge_limit_cnt = 0;
|
||||
restart_cnt = 0;
|
||||
}
|
||||
|
||||
static void battery_monitor(const int limit_percent, const int restart_percent,
|
||||
int *charge_limit_cnt, int *restart_cnt) {
|
||||
while (shouldRun) {
|
||||
auto batt = stoi(readFile(BATTERY_CAPACITY_CURRENT));
|
||||
if (batt >= limit_percent) {
|
||||
disableSysfs(BATTERY_CHARGE);
|
||||
*charge_limit_cnt += 1;
|
||||
} else if (batt <= restart_percent) {
|
||||
enableSysfs(BATTERY_CHARGE);
|
||||
*restart_cnt += 1;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
void SmartChargeImpl::start(void) {
|
||||
shouldRun = true;
|
||||
monitor = new std::thread(battery_monitor, limit_percent,
|
||||
restart_percent, &charge_limit_cnt, &restart_cnt);
|
||||
monitor->join();
|
||||
}
|
||||
|
||||
void SmartChargeImpl::stop(void) {
|
||||
shouldRun = false;
|
||||
monitor = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#include "BatteryConstants.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
class SmartChargeImpl {
|
||||
public:
|
||||
SmartChargeImpl(int limit, int restart);
|
||||
void start(void);
|
||||
void stop(void);
|
||||
|
||||
int charge_limit_cnt;
|
||||
int restart_cnt;
|
||||
private:
|
||||
const int limit_percent;
|
||||
const int restart_percent;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
static inline void disableSysfs(const char* path) {
|
||||
const std::string pathcpp = std::string(path);
|
||||
std::ofstream file;
|
||||
file.open(pathcpp);
|
||||
if (file.is_open()) {
|
||||
file << 0;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void enableSysfs(const char* path) {
|
||||
const std::string pathcpp = std::string(path);
|
||||
std::ofstream file;
|
||||
file.open(pathcpp);
|
||||
if (file.is_open()) {
|
||||
file << 1;
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
static inline std::string readFile(const char* path) {
|
||||
const std::string pathcpp = std::string(path);
|
||||
std::ifstream file;
|
||||
file.open(pathcpp);
|
||||
std::string result;
|
||||
if (file.is_open()) {
|
||||
getline(file, result);
|
||||
file.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -16,33 +16,69 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sys/swap.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "CachedClass.h"
|
||||
|
||||
static int mSwapSize = 100;
|
||||
extern int mkswap (std::string filename);
|
||||
extern void mkfile(int filesize, std::string name);
|
||||
extern int mkswap (const char *filename);
|
||||
extern void mkfile(int filesize, const char *name);
|
||||
|
||||
static std::string SWAP_PATH = "/data/swap/swapfile";
|
||||
constexpr const char* SWAP_PATH = "/data/swap/swapfile";
|
||||
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
static SwapOnData *kCached = nullptr;
|
||||
|
||||
static std::mutex thread_lock;
|
||||
|
||||
static bool swapOnRes = false;
|
||||
|
||||
Return<void> SwapOnData::setSwapSize(int32_t size) {
|
||||
mSwapSize = size;
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> SwapOnData::setSwapOn() {
|
||||
mkfile(mSwapSize * 10, SWAP_PATH);
|
||||
mkswap(SWAP_PATH);
|
||||
swapon(SWAP_PATH.c_str(), (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
|
||||
Return<void> SwapOnData::removeSwapFile(void) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
std::remove(SWAP_PATH);
|
||||
return Void();
|
||||
}
|
||||
|
||||
static void mkfile_swapon_thread(void) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
if (access(SWAP_PATH, F_OK) == 0) {
|
||||
mkfile(mSwapSize * 10, SWAP_PATH);
|
||||
mkswap(SWAP_PATH);
|
||||
}
|
||||
int res = swapon(SWAP_PATH, (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
|
||||
swapOnRes = res == 0;
|
||||
}
|
||||
|
||||
Return<void> SwapOnData::setSwapOn() {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
std::thread mkswapfile(mkfile_swapon_thread);
|
||||
mkswapfile.join();
|
||||
return Void();
|
||||
}
|
||||
|
||||
static void swapoff_thread(void) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
swapoff(SWAP_PATH);
|
||||
}
|
||||
|
||||
Return<void> SwapOnData::setSwapOff() {
|
||||
swapoff(SWAP_PATH.c_str());
|
||||
remove(SWAP_PATH.c_str());
|
||||
std::thread swapoff(swapoff_thread);
|
||||
swapoff.join();
|
||||
return Void();
|
||||
}
|
||||
Return<bool> SwapOnData::getSwapOnResult(void) { return swapOnRes; }
|
||||
|
||||
Return<bool> SwapOnData::isMutexLocked() { return !thread_lock.try_lock(); }
|
||||
|
||||
ISwapOnData *SwapOnData::getInstance(void) {
|
||||
USE_CACHED(kCached);
|
||||
}
|
||||
|
||||
ISwapOnData *SwapOnData::getInstance(void) { return new SwapOnData(); }
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@
|
|||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
using ::android::sp;
|
||||
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;
|
||||
|
||||
|
|
@ -32,8 +28,11 @@ struct SwapOnData : public ISwapOnData {
|
|||
// Methods from ::vendor::eureka::hardware::parts::V1_0::ISwapOnData
|
||||
// follow.
|
||||
Return<void> setSwapSize(int32_t size);
|
||||
Return<void> setSwapOn();
|
||||
Return<void> setSwapOff();
|
||||
Return<void> setSwapOn(void);
|
||||
Return<void> removeSwapFile(void);
|
||||
Return<void> setSwapOff(void);
|
||||
Return<bool> getSwapOnResult(void);
|
||||
Return<bool> isMutexLocked(void);
|
||||
// Methods from ::android::hidl::base::V2_0::IBase follow.
|
||||
static ISwapOnData *getInstance(void);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ struct linux_swap_header {
|
|||
u_int32_t padding[117];
|
||||
u_int32_t badpages[1];
|
||||
};
|
||||
void mkfile(int filesize, std::string name){
|
||||
void mkfile(int filesize, const char* path){
|
||||
std::vector<char> empty(1024, 0);
|
||||
std::ofstream ofs(name, std::ios::binary | std::ios::out);
|
||||
std::ofstream ofs(std::string(path), std::ios::binary | std::ios::out);
|
||||
|
||||
for(int i = 0; i < 1024 * filesize; i++)
|
||||
{
|
||||
|
|
@ -32,14 +32,14 @@ void mkfile(int filesize, std::string name){
|
|||
#define MAGIC_SWAP_HEADER "SWAPSPACE2"
|
||||
#define MAGIC_SWAP_HEADER_LEN 10
|
||||
#define MIN_PAGES 10
|
||||
int mkswap(std::string filename) {
|
||||
int mkswap(const char* filename) {
|
||||
int err = 0;
|
||||
int fd;
|
||||
ssize_t len;
|
||||
off_t swap_size;
|
||||
int pagesize;
|
||||
struct linux_swap_header sw_hdr;
|
||||
fd = open(filename.c_str(), O_WRONLY | O_CLOEXEC);
|
||||
fd = open(filename, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
err = errno;
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@
|
|||
#include <vendor/eureka/hardware/parts/1.0/IDisplayConfigs.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/IFlashBrightness.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/ISmartCharge.h>
|
||||
|
||||
#include "Battery.h"
|
||||
#include "Display.h"
|
||||
#include "FlashLight.h"
|
||||
#include "Swap.h"
|
||||
#include "SmartCharge.h"
|
||||
|
||||
using android::sp;
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
|
|
@ -36,56 +38,33 @@ using vendor::eureka::hardware::parts::V1_0::IDisplayConfigs;
|
|||
using vendor::eureka::hardware::parts::V1_0::IFlashBrightness;
|
||||
using vendor::eureka::hardware::parts::V1_0::ISwapOnData;
|
||||
using vendor::eureka::hardware::parts::V1_0::SwapOnData;
|
||||
using vendor::eureka::hardware::parts::V1_0::ISmartCharge;
|
||||
using vendor::eureka::hardware::parts::V1_0::SmartCharge;
|
||||
|
||||
template <class C>
|
||||
static inline int registerAsService(C kClass) {
|
||||
int ret = -1;
|
||||
if (kClass != nullptr) {
|
||||
ret = kClass->registerAsService();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int ret;
|
||||
android::sp<IBatteryStats> mBatteryService = BatteryStats::getInstance();
|
||||
android::sp<IFlashBrightness> mFlashLightService =
|
||||
FlashBrightness::getInstance();
|
||||
android::sp<IFlashBrightness> mFlashLightService = FlashBrightness::getInstance();
|
||||
android::sp<IDisplayConfigs> mDisplayService = DisplayConfigs::getInstance();
|
||||
android::sp<ISwapOnData> mSwapService = SwapOnData::getInstance();
|
||||
android::sp<ISmartCharge> mSmartChargeService = SmartCharge::getInstance();
|
||||
|
||||
configureRpcThreadpool(4, true /*callerWillJoin*/);
|
||||
|
||||
if (mBatteryService != nullptr) {
|
||||
ret = mBatteryService->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");
|
||||
}
|
||||
if (mFlashLightService != nullptr) {
|
||||
ret = mFlashLightService->registerAsService();
|
||||
if (ret != 0) {
|
||||
ALOGE("Can't register instance of FlashLight HAL, nullptr");
|
||||
} else {
|
||||
ALOGI("registered FlashLight HAL");
|
||||
}
|
||||
} else {
|
||||
ALOGE("Can't create instance of FlashLight HAL, nullptr");
|
||||
}
|
||||
if (mDisplayService != nullptr) {
|
||||
ret = mDisplayService->registerAsService();
|
||||
if (ret != 0) {
|
||||
ALOGE("Can't register instance of Display HAL, nullptr");
|
||||
} else {
|
||||
ALOGI("registered Display HAL");
|
||||
}
|
||||
} else {
|
||||
ALOGE("Can't create instance of Display HAL, nullptr");
|
||||
}
|
||||
if (mSwapService != nullptr) {
|
||||
ret = mSwapService->registerAsService();
|
||||
if (ret != 0) {
|
||||
ALOGE("Can't register instance of Swap HAL, nullptr");
|
||||
} else {
|
||||
ALOGI("registered Swap HAL");
|
||||
}
|
||||
} else {
|
||||
ALOGE("Can't create instance of Swap HAL, nullptr");
|
||||
}
|
||||
registerAsService(mBatteryService);
|
||||
registerAsService(mFlashLightService);
|
||||
registerAsService(mDisplayService);
|
||||
registerAsService(mSwapService);
|
||||
registerAsService(mSmartChargeService);
|
||||
|
||||
joinRpcThreadpool();
|
||||
|
||||
return -1; // should never get here
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ service parts-hal /system/bin/vendor.eureka.hardware.parts@1.0-service
|
|||
interface vendor.eureka.hardware.parts@1.0::IDisplayConfigs default
|
||||
interface vendor.eureka.hardware.parts@1.0::IFlashBrightness default
|
||||
interface vendor.eureka.hardware.parts@1.0::ISwapOnData default
|
||||
interface vendor.eureka.hardware.parts@1.0::ISmartCharge default
|
||||
class hal
|
||||
user root
|
||||
group root
|
||||
|
|
|
|||
|
|
@ -19,5 +19,9 @@
|
|||
<name>ISwapOnData</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>ISmartCharge</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
package vendor.eureka.hardware.parts@1.0;
|
||||
|
||||
enum SysfsType : int32_t {
|
||||
enum BatterySys : int32_t {
|
||||
CAPACITY_MAX,
|
||||
TEMP,
|
||||
CAPACITY_CURRENT,
|
||||
|
|
@ -23,30 +23,12 @@ enum SysfsType : int32_t {
|
|||
CHARGE,
|
||||
};
|
||||
|
||||
enum Display : int32_t {
|
||||
enum DisplaySys : int32_t {
|
||||
DOUBLE_TAP,
|
||||
GLOVE_MODE,
|
||||
};
|
||||
|
||||
enum Number : int32_t {
|
||||
enum Status : int32_t {
|
||||
ENABLE = 1,
|
||||
DISABLE = 0,
|
||||
};
|
||||
|
||||
enum Device : int32_t {
|
||||
A10,
|
||||
NOTA10,
|
||||
};
|
||||
|
||||
enum Value : int32_t {
|
||||
ONEUI = 1,
|
||||
TWOUI,
|
||||
THREEUI,
|
||||
FOURUI,
|
||||
FIVEUI,
|
||||
SIXUI,
|
||||
SEVENUI,
|
||||
EIGHTUI,
|
||||
NINEUI,
|
||||
TENUI = 10,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ vendor.eureka.hardware.parts::IBatteryStats u:object_r:hal_parts_hwservice:s0
|
|||
vendor.eureka.hardware.parts::IFlashBrightness u:object_r:hal_parts_hwservice:s0
|
||||
vendor.eureka.hardware.parts::IDisplayConfigs u:object_r:hal_parts_hwservice:s0
|
||||
vendor.eureka.hardware.parts::ISwapOnData u:object_r:hal_parts_hwservice:s0
|
||||
|
||||
vendor.eureka.hardware.parts::ISmartCharge u:object_r:hal_parts_hwservice:s0
|
||||
# FMRadio
|
||||
vendor.eureka.hardware.fmradio::IFMRadio u:object_r:hal_fmradio_hwservice:s0
|
||||
|
|
|
|||
Loading…
Reference in a new issue