mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-23 12:35:33 -04:00
universal7885: parts-hidl: Use libFileIO
- Also fix compile errors
This commit is contained in:
parent
840e252b72
commit
3e5e571267
15 changed files with 150 additions and 210 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libfileio",
|
name: "libfileio",
|
||||||
srcs: ["FileIO.cpp"],
|
srcs: ["FileIO.cpp"],
|
||||||
include_dirs: ["include"],
|
cppflags: ["-fexceptions"],
|
||||||
|
local_include_dirs: ["include"],
|
||||||
export_include_dirs: ["include"],
|
export_include_dirs: ["include"],
|
||||||
|
shared_libs: ["liblog"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,14 @@ int readline(const char *path) {
|
||||||
try {
|
try {
|
||||||
return stoi(value);
|
return stoi(value);
|
||||||
} catch (std::invalid_argument const &ex) {
|
} catch (std::invalid_argument const &ex) {
|
||||||
ALOGE("%s: stoi(): invalid argument: for %s", __func__, value);
|
ALOGE("%s: stoi(): invalid argument: for %s", __func__, value.c_str());
|
||||||
} catch (std::out_of_range const &ex) {
|
} catch (std::out_of_range const &ex) {
|
||||||
ALOGE("%s: stoi(): out of range: for %s", __func__, value);
|
ALOGE("%s: stoi(): out of range: for %s", __func__, value.c_str());
|
||||||
}
|
}
|
||||||
return EXIT_ERR;
|
return EXIT_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
void writeline(const char *path, const std::string& data) {
|
||||||
void writeline(const char *path, const T data) {
|
|
||||||
std::ofstream file;
|
std::ofstream file;
|
||||||
file.open(path);
|
file.open(path);
|
||||||
ALOGD("%s: Opening %s", __func__, path);
|
ALOGD("%s: Opening %s", __func__, path);
|
||||||
|
|
@ -45,4 +44,8 @@ void writeline(const char *path, const T data) {
|
||||||
ALOGE("%s: Failed to open %s", __func__, path);
|
ALOGE("%s: Failed to open %s", __func__, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeline(const char *path, const int data) {
|
||||||
|
writeline(path, std::to_string(data));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace FileIO
|
} // namespace FileIO
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
namespace FileIO {
|
namespace FileIO {
|
||||||
int readline(const char *path);
|
int readline(const char *path);
|
||||||
|
|
||||||
template <typename T>
|
void writeline(const char *path, const std::string& data);
|
||||||
void writeline(const char *path, const T data);
|
void writeline(const char *path, const int data);
|
||||||
} // namespace FileIO
|
} // namespace FileIO
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ cc_binary {
|
||||||
"libhidlbase",
|
"libhidlbase",
|
||||||
"libutils",
|
"libutils",
|
||||||
"liblog",
|
"liblog",
|
||||||
|
"libfileio",
|
||||||
"vendor.eureka.hardware.parts@1.0",
|
"vendor.eureka.hardware.parts@1.0",
|
||||||
],
|
],
|
||||||
init_rc: ["vendor.eureka.hardware.parts@1.0-service.rc"],
|
init_rc: ["vendor.eureka.hardware.parts@1.0-service.rc"],
|
||||||
|
|
|
||||||
|
|
@ -12,61 +12,53 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "Battery.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "CachedClass.h"
|
|
||||||
|
#include "Battery.h"
|
||||||
#include "BatteryConstants.h"
|
#include "BatteryConstants.h"
|
||||||
|
#include "CachedClass.h"
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
static BatteryStats *kCached = nullptr;
|
static BatteryStats *kCached = nullptr;
|
||||||
|
|
||||||
static inline const char* BatterySysToPath (parts::V1_0::BatterySys type) {
|
static inline const char *BatterySysToPath(parts::V1_0::BatterySys type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BatterySys::CAPACITY_MAX:
|
case BatterySys::CAPACITY_MAX:
|
||||||
return BATTERY_CAPACITY_MAX;
|
return BATTERY_CAPACITY_MAX;
|
||||||
case BatterySys::TEMP:
|
case BatterySys::TEMP:
|
||||||
return BATTERY_TEMP;
|
return BATTERY_TEMP;
|
||||||
case BatterySys::CAPACITY_CURRENT:
|
case BatterySys::CAPACITY_CURRENT:
|
||||||
return BATTERY_CAPACITY_CURRENT;
|
return BATTERY_CAPACITY_CURRENT;
|
||||||
case BatterySys::CURRENT:
|
case BatterySys::CURRENT:
|
||||||
return BATTERY_CURRENT;
|
return BATTERY_CURRENT;
|
||||||
case BatterySys::FASTCHARGE:
|
case BatterySys::FASTCHARGE:
|
||||||
return BATTERY_FASTCHARGE;
|
return BATTERY_FASTCHARGE;
|
||||||
case BatterySys::CHARGE:
|
case BatterySys::CHARGE:
|
||||||
return BATTERY_CHARGE;
|
return BATTERY_CHARGE;
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods from ::android::hardware::battery::V1_0::IBattery follow.
|
// Methods from ::android::hardware::battery::V1_0::IBattery follow.
|
||||||
Return<int32_t> BatteryStats::getBatteryStats(parts::V1_0::BatterySys stats) {
|
Return<int32_t> BatteryStats::getBatteryStats(parts::V1_0::BatterySys stats) {
|
||||||
std::ifstream file;
|
return FileIO::readline(BatterySysToPath(stats));
|
||||||
std::string value;
|
|
||||||
file.open(BatterySysToPath(stats));
|
|
||||||
if (file.is_open()) {
|
|
||||||
getline(file, value);
|
|
||||||
file.close();
|
|
||||||
return stoi(value);
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> BatteryStats::setBatteryWritable(parts::V1_0::BatterySys stats,
|
Return<void> BatteryStats::setBatteryWritable(parts::V1_0::BatterySys stats,
|
||||||
parts::V1_0::Status value) {
|
parts::V1_0::Status value) {
|
||||||
std::ofstream file;
|
|
||||||
bool FastCharge = false;
|
bool FastCharge = false;
|
||||||
if (FastCharge)
|
if (FastCharge)
|
||||||
seteuid(ANDROID_SYSTEM_UID);
|
seteuid(ANDROID_SYSTEM_UID);
|
||||||
file.open(BatterySysToPath(stats));
|
|
||||||
file << static_cast<int32_t>(value);
|
FileIO::writeline(BatterySysToPath(stats), static_cast<int32_t>(value));
|
||||||
file.close();
|
|
||||||
if (FastCharge)
|
if (FastCharge)
|
||||||
seteuid(ANDROID_ROOT_UID);
|
seteuid(ANDROID_ROOT_UID);
|
||||||
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
constexpr const char* BATTERY_CAPACITY_MAX = "/sys/devices/platform/battery/power_supply/battery/charge_full";
|
constexpr const char *BATTERY_CAPACITY_MAX =
|
||||||
constexpr const char* BATTERY_TEMP = "/sys/devices/platform/battery/power_supply/battery/batt_temp";
|
"/sys/devices/platform/battery/power_supply/battery/charge_full";
|
||||||
constexpr const char* BATTERY_CAPACITY_CURRENT = "/sys/devices/platform/battery/power_supply/battery/capacity";
|
constexpr const char *BATTERY_TEMP =
|
||||||
constexpr const char* BATTERY_CURRENT = "/sys/devices/platform/battery/power_supply/battery/current_now";
|
"/sys/devices/platform/battery/power_supply/battery/batt_temp";
|
||||||
constexpr const char* BATTERY_FASTCHARGE = "/sys/class/sec/switch/afc_disable";
|
constexpr const char *BATTERY_CAPACITY_CURRENT =
|
||||||
constexpr const char* BATTERY_CHARGE = "/sys/devices/platform/battery/power_supply/battery/batt_slate_mode";
|
"/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";
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
template <class C>
|
template <class C> static inline C *cachedClass(C *cached) {
|
||||||
static inline C *cachedClass(C* cached) {
|
if (cached != nullptr) {
|
||||||
if (cached != nullptr) {
|
return cached;
|
||||||
return cached;
|
}
|
||||||
}
|
cached = new C();
|
||||||
cached = new C();
|
return cached;
|
||||||
return cached;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define USE_CACHED(cache) \
|
#define USE_CACHED(cache) ({ return cachedClass((cache)); })
|
||||||
({ \
|
|
||||||
return cachedClass((cache)); \
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,20 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include "CachedClass.h"
|
#include "CachedClass.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
static DisplayConfigs *kCached;
|
static DisplayConfigs *kCached;
|
||||||
|
|
||||||
|
constexpr const char *SEC_TSP_CMD = "/sys/class/sec/tsp/cmd";
|
||||||
|
|
||||||
Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Status enable,
|
Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Status enable,
|
||||||
parts::V1_0::DisplaySys type) {
|
parts::V1_0::DisplaySys type) {
|
||||||
std::ofstream file;
|
|
||||||
std::string writevalue;
|
std::string writevalue;
|
||||||
if (type == DisplaySys::DOUBLE_TAP) {
|
if (type == DisplaySys::DOUBLE_TAP) {
|
||||||
writevalue = "aot_enable";
|
writevalue = "aot_enable";
|
||||||
|
|
@ -37,13 +39,9 @@ Return<void> DisplayConfigs::writeDisplay(parts::V1_0::Status enable,
|
||||||
} else {
|
} else {
|
||||||
writevalue += "0";
|
writevalue += "0";
|
||||||
}
|
}
|
||||||
file.open("/sys/class/sec/tsp/cmd");
|
FileIO::writeline(SEC_TSP_CMD, writevalue);
|
||||||
file << writevalue;
|
|
||||||
file.close();
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
IDisplayConfigs *DisplayConfigs::getInstance(void) {
|
IDisplayConfigs *DisplayConfigs::getInstance(void) { USE_CACHED(kCached); }
|
||||||
USE_CACHED(kCached);
|
|
||||||
}
|
|
||||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
|
||||||
|
|
@ -13,62 +13,35 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "FlashLight.h"
|
#include "FlashLight.h"
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include "CachedClass.h"
|
#include "CachedClass.h"
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
static FlashBrightness *kCached;
|
static FlashBrightness *kCached;
|
||||||
|
|
||||||
|
constexpr const char *TORCH_ENABLE =
|
||||||
|
"/sys/class/camera/flash/torch_brightness_lvl_enable";
|
||||||
|
constexpr const char *TORCH_LVL =
|
||||||
|
"/sys/class/camera/flash/torch_brightness_lvl";
|
||||||
|
|
||||||
// Methods from ::android::hardware::parts::V1_0::IFlashLight follow.
|
// Methods from ::android::hardware::parts::V1_0::IFlashLight follow.
|
||||||
Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Status enable) {
|
Return<void> FlashBrightness::setFlashlightEnable(parts::V1_0::Status enable) {
|
||||||
std::ofstream file;
|
FileIO::writeline(TORCH_ENABLE, static_cast<int32_t>(enable));
|
||||||
std::string writevalue;
|
|
||||||
switch (enable) {
|
|
||||||
case Status::ENABLE:
|
|
||||||
writevalue = "1";
|
|
||||||
break;
|
|
||||||
case Status::DISABLE:
|
|
||||||
writevalue = "0";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
writevalue = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
file.open("/sys/class/camera/flash/torch_brightness_lvl_enable");
|
|
||||||
file << writevalue;
|
|
||||||
file.close();
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> FlashBrightness::setFlashlightWritable(int32_t value) {
|
Return<void> FlashBrightness::setFlashlightWritable(int32_t value) {
|
||||||
std::ofstream file;
|
FileIO::writeline(TORCH_LVL, value);
|
||||||
std::string writevalue = std::to_string(value);
|
|
||||||
file.open("/sys/class/camera/flash/torch_brightness_lvl");
|
|
||||||
file << writevalue;
|
|
||||||
file.close();
|
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<int32_t> FlashBrightness::readFlashlightstats(bool s2mu106) {
|
Return<int32_t> FlashBrightness::readFlashlightstats(bool s2mu106) {
|
||||||
std::ifstream file;
|
return s2mu106 ? FileIO::readline(TORCH_LVL) / 21
|
||||||
std::string value;
|
: FileIO::readline(TORCH_LVL);
|
||||||
file.open("/sys/class/camera/flash/torch_brightness_lvl");
|
|
||||||
if (file.is_open()) {
|
|
||||||
getline(file, value);
|
|
||||||
file.close();
|
|
||||||
if (s2mu106) {
|
|
||||||
return stoi(value);
|
|
||||||
} else {
|
|
||||||
return stoi(value) / 21;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IFlashBrightness *FlashBrightness::getInstance(void) {
|
IFlashBrightness *FlashBrightness::getInstance(void) { USE_CACHED(kCached); }
|
||||||
USE_CACHED(kCached);
|
|
||||||
}
|
|
||||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "SmartCharge.h"
|
#include "SmartCharge.h"
|
||||||
|
#include "CachedClass.h"
|
||||||
#include "SmartChargingImpl.h"
|
#include "SmartChargingImpl.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "CachedClass.h"
|
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
|
|
@ -55,15 +55,9 @@ Return<void> SmartCharge::setConfig(int32_t limit_user, int32_t restart_user) {
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<int32_t> SmartCharge::getLimitCnt(void) {
|
Return<int32_t> SmartCharge::getLimitCnt(void) { return limit_stat; }
|
||||||
return limit_stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
Return<int32_t> SmartCharge::getRestartCnt(void) {
|
Return<int32_t> SmartCharge::getRestartCnt(void) { return restart_stat; }
|
||||||
return restart_stat;
|
|
||||||
}
|
|
||||||
|
|
||||||
ISmartCharge *SmartCharge::getInstance(void) {
|
ISmartCharge *SmartCharge::getInstance(void) { USE_CACHED(kCached); }
|
||||||
USE_CACHED(kCached);
|
|
||||||
}
|
|
||||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,43 @@
|
||||||
#include "SmartChargingImpl.h"
|
#include "SmartChargingImpl.h"
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
static std::thread *monitor;
|
static std::thread *monitor;
|
||||||
static bool shouldRun = false;
|
static bool shouldRun = false;
|
||||||
|
|
||||||
SmartChargeImpl::SmartChargeImpl(int limit, int restart) : limit_percent(limit), restart_percent(restart) {
|
SmartChargeImpl::SmartChargeImpl(int limit, int restart)
|
||||||
charge_limit_cnt = 0;
|
: limit_percent(limit), restart_percent(restart) {
|
||||||
restart_cnt = 0;
|
charge_limit_cnt = 0;
|
||||||
|
restart_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void battery_monitor(const int limit_percent, const int restart_percent,
|
static void battery_monitor(const int limit_percent, const int restart_percent,
|
||||||
int *charge_limit_cnt, int *restart_cnt) {
|
int *charge_limit_cnt, int *restart_cnt) {
|
||||||
while (shouldRun) {
|
while (shouldRun) {
|
||||||
auto batt = stoi(readFile(BATTERY_CAPACITY_CURRENT));
|
auto batt = FileIO::readline(BATTERY_CAPACITY_CURRENT);
|
||||||
if (batt >= limit_percent) {
|
if (batt >= limit_percent) {
|
||||||
disableSysfs(BATTERY_CHARGE);
|
disableSysfs(BATTERY_CHARGE);
|
||||||
*charge_limit_cnt += 1;
|
*charge_limit_cnt += 1;
|
||||||
} else if (batt <= restart_percent) {
|
} else if (batt <= restart_percent) {
|
||||||
enableSysfs(BATTERY_CHARGE);
|
enableSysfs(BATTERY_CHARGE);
|
||||||
*restart_cnt += 1;
|
*restart_cnt += 1;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartChargeImpl::start(void) {
|
void SmartChargeImpl::start(void) {
|
||||||
shouldRun = true;
|
shouldRun = true;
|
||||||
monitor = new std::thread(battery_monitor, limit_percent,
|
monitor = new std::thread(battery_monitor, limit_percent, restart_percent,
|
||||||
restart_percent, &charge_limit_cnt, &restart_cnt);
|
&charge_limit_cnt, &restart_cnt);
|
||||||
monitor->join();
|
monitor->join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartChargeImpl::stop(void) {
|
void SmartChargeImpl::stop(void) {
|
||||||
shouldRun = false;
|
shouldRun = false;
|
||||||
monitor = nullptr;
|
monitor = nullptr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,30 @@
|
||||||
#include "BatteryConstants.h"
|
#include "BatteryConstants.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <FileIO.h>
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
class SmartChargeImpl {
|
class SmartChargeImpl {
|
||||||
public:
|
public:
|
||||||
SmartChargeImpl(int limit, int restart);
|
SmartChargeImpl(int limit, int restart);
|
||||||
void start(void);
|
void start(void);
|
||||||
void stop(void);
|
void stop(void);
|
||||||
|
|
||||||
|
int charge_limit_cnt;
|
||||||
|
int restart_cnt;
|
||||||
|
|
||||||
int charge_limit_cnt;
|
|
||||||
int restart_cnt;
|
|
||||||
private:
|
private:
|
||||||
const int limit_percent;
|
const int limit_percent;
|
||||||
const int restart_percent;
|
const int restart_percent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
||||||
|
static inline void disableSysfs(const char *path) {
|
||||||
|
FileIO::writeline(path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void disableSysfs(const char* path) {
|
static inline void enableSysfs(const char *path) { FileIO::writeline(path, 1); }
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,19 +13,19 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "Swap.h"
|
#include "Swap.h"
|
||||||
|
#include "CachedClass.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/swap.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <sys/swap.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "CachedClass.h"
|
#include <unistd.h>
|
||||||
|
|
||||||
static int mSwapSize = 100;
|
static int mSwapSize = 100;
|
||||||
extern int mkswap (const char *filename);
|
extern int mkswap(const char *filename);
|
||||||
extern void mkfile(int filesize, const char *name);
|
extern void mkfile(int filesize, const char *name);
|
||||||
|
|
||||||
constexpr const char* SWAP_PATH = "/data/swap/swapfile";
|
constexpr const char *SWAP_PATH = "/data/swap/swapfile";
|
||||||
|
|
||||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||||
|
|
||||||
|
|
@ -52,7 +52,8 @@ static void mkfile_swapon_thread(void) {
|
||||||
mkfile(mSwapSize * 10, SWAP_PATH);
|
mkfile(mSwapSize * 10, SWAP_PATH);
|
||||||
mkswap(SWAP_PATH);
|
mkswap(SWAP_PATH);
|
||||||
}
|
}
|
||||||
int res = swapon(SWAP_PATH, (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
|
int res =
|
||||||
|
swapon(SWAP_PATH, (10 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK);
|
||||||
swapOnRes = res == 0;
|
swapOnRes = res == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,8 +78,6 @@ Return<bool> SwapOnData::getSwapOnResult(void) { return swapOnRes; }
|
||||||
|
|
||||||
Return<bool> SwapOnData::isMutexLocked() { return !thread_lock.try_lock(); }
|
Return<bool> SwapOnData::isMutexLocked() { return !thread_lock.try_lock(); }
|
||||||
|
|
||||||
ISwapOnData *SwapOnData::getInstance(void) {
|
ISwapOnData *SwapOnData::getInstance(void) { USE_CACHED(kCached); }
|
||||||
USE_CACHED(kCached);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
#include <cstring>
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/swap.h>
|
#include <sys/swap.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
/* XXX This needs to be obtained from kernel headers. See b/9336527 */
|
/* XXX This needs to be obtained from kernel headers. See b/9336527 */
|
||||||
struct linux_swap_header {
|
struct linux_swap_header {
|
||||||
|
|
@ -20,19 +20,18 @@ struct linux_swap_header {
|
||||||
u_int32_t padding[117];
|
u_int32_t padding[117];
|
||||||
u_int32_t badpages[1];
|
u_int32_t badpages[1];
|
||||||
};
|
};
|
||||||
void mkfile(int filesize, const char* path){
|
void mkfile(int filesize, const char *path) {
|
||||||
std::vector<char> empty(1024, 0);
|
std::vector<char> empty(1024, 0);
|
||||||
std::ofstream ofs(std::string(path), 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++)
|
for (int i = 0; i < 1024 * filesize; i++) {
|
||||||
{
|
ofs.write(&empty[0], empty.size());
|
||||||
ofs.write(&empty[0], empty.size());
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#define MAGIC_SWAP_HEADER "SWAPSPACE2"
|
#define MAGIC_SWAP_HEADER "SWAPSPACE2"
|
||||||
#define MAGIC_SWAP_HEADER_LEN 10
|
#define MAGIC_SWAP_HEADER_LEN 10
|
||||||
#define MIN_PAGES 10
|
#define MIN_PAGES 10
|
||||||
int mkswap(const char* filename) {
|
int mkswap(const char *filename) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int fd;
|
int fd;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@
|
||||||
#include <vendor/eureka/hardware/parts/1.0/IBatteryStats.h>
|
#include <vendor/eureka/hardware/parts/1.0/IBatteryStats.h>
|
||||||
#include <vendor/eureka/hardware/parts/1.0/IDisplayConfigs.h>
|
#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/IFlashBrightness.h>
|
||||||
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
|
|
||||||
#include <vendor/eureka/hardware/parts/1.0/ISmartCharge.h>
|
#include <vendor/eureka/hardware/parts/1.0/ISmartCharge.h>
|
||||||
|
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
|
||||||
|
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
#include "Display.h"
|
#include "Display.h"
|
||||||
#include "FlashLight.h"
|
#include "FlashLight.h"
|
||||||
#include "Swap.h"
|
|
||||||
#include "SmartCharge.h"
|
#include "SmartCharge.h"
|
||||||
|
#include "Swap.h"
|
||||||
|
|
||||||
using android::sp;
|
using android::sp;
|
||||||
using android::hardware::configureRpcThreadpool;
|
using android::hardware::configureRpcThreadpool;
|
||||||
|
|
@ -36,13 +36,12 @@ using vendor::eureka::hardware::parts::V1_0::FlashBrightness;
|
||||||
using vendor::eureka::hardware::parts::V1_0::IBatteryStats;
|
using vendor::eureka::hardware::parts::V1_0::IBatteryStats;
|
||||||
using vendor::eureka::hardware::parts::V1_0::IDisplayConfigs;
|
using vendor::eureka::hardware::parts::V1_0::IDisplayConfigs;
|
||||||
using vendor::eureka::hardware::parts::V1_0::IFlashBrightness;
|
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::ISmartCharge;
|
||||||
|
using vendor::eureka::hardware::parts::V1_0::ISwapOnData;
|
||||||
using vendor::eureka::hardware::parts::V1_0::SmartCharge;
|
using vendor::eureka::hardware::parts::V1_0::SmartCharge;
|
||||||
|
using vendor::eureka::hardware::parts::V1_0::SwapOnData;
|
||||||
|
|
||||||
template <class C>
|
template <class C> static inline int registerAsService(C kClass) {
|
||||||
static inline int registerAsService(C kClass) {
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
if (kClass != nullptr) {
|
if (kClass != nullptr) {
|
||||||
ret = kClass->registerAsService();
|
ret = kClass->registerAsService();
|
||||||
|
|
@ -52,7 +51,8 @@ static inline int registerAsService(C kClass) {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
android::sp<IBatteryStats> mBatteryService = BatteryStats::getInstance();
|
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<IDisplayConfigs> mDisplayService = DisplayConfigs::getInstance();
|
||||||
android::sp<ISwapOnData> mSwapService = SwapOnData::getInstance();
|
android::sp<ISwapOnData> mSwapService = SwapOnData::getInstance();
|
||||||
android::sp<ISmartCharge> mSmartChargeService = SmartCharge::getInstance();
|
android::sp<ISmartCharge> mSmartChargeService = SmartCharge::getInstance();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue