mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 19:55:33 -04:00
universal7885: Move parts HAL to AIDL impl
This commit is contained in:
parent
7beedaa4e4
commit
ba51d9197f
18 changed files with 707 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
cc_binary {
|
||||
name: "vendor.eureka.hardware.parts-service",
|
||||
defaults: ["eureka_defaults"],
|
||||
srcs: [
|
||||
"Battery.cpp",
|
||||
"FlashLight.cpp",
|
||||
"Display.cpp",
|
||||
"Swap.cpp",
|
||||
"SwapHelpers.cpp",
|
||||
"SmartChargingImpl.cpp",
|
||||
"SmartCharge.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libbase",
|
||||
"libbinder_ndk",
|
||||
"libfileio",
|
||||
"vendor.eureka.hardware.parts-ndk",
|
||||
],
|
||||
init_rc: ["vendor.eureka.hardware.parts-service.rc"],
|
||||
vintf_fragments: ["vendor.eureka.hardware.parts.xml"],
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// 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 <unistd.h>
|
||||
|
||||
#include "Battery.h"
|
||||
#include "BatteryConstants.h"
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static inline const char *BatterySysToPath(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.
|
||||
::ndk::ScopedAStatus BatteryStats::getBatteryStats(BatterySys stats,
|
||||
int32_t *_aidl_return) {
|
||||
*_aidl_return = FileIO::readline(BatterySysToPath(stats));
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus BatteryStats::setBatteryWritable(BatterySys stats,
|
||||
bool value) {
|
||||
bool FastCharge = false;
|
||||
if (FastCharge)
|
||||
seteuid(ANDROID_SYSTEM_UID);
|
||||
|
||||
FileIO::writeline(BatterySysToPath(stats), value ? 1 : 0);
|
||||
|
||||
if (FastCharge)
|
||||
seteuid(ANDROID_ROOT_UID);
|
||||
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// 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 <aidl/vendor/eureka/hardware/parts/BnBatteryStats.h>
|
||||
|
||||
#define ANDROID_SYSTEM_UID 1000
|
||||
#define ANDROID_ROOT_UID 0
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct BatteryStats : public BnBatteryStats {
|
||||
// Methods from ::aidl::::vendor::eureka::hardware::parts::IBatteryStats
|
||||
// follow.
|
||||
::ndk::ScopedAStatus getBatteryStats(BatterySys stats,
|
||||
int32_t *_aidl_return) override;
|
||||
::ndk::ScopedAStatus setBatteryWritable(BatterySys stats,
|
||||
bool value) override;
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#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,42 @@
|
|||
// 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 "Display.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
constexpr const char *SEC_TSP_CMD = "/sys/class/sec/tsp/cmd";
|
||||
|
||||
::ndk::ScopedAStatus DisplayConfigs::writeDisplay(bool enable,
|
||||
DisplaySys type) {
|
||||
std::string writevalue;
|
||||
if (type == DisplaySys::DOUBLE_TAP) {
|
||||
writevalue = "aot_enable";
|
||||
} else if (type == DisplaySys::GLOVE_MODE) {
|
||||
writevalue = "glove_mode";
|
||||
}
|
||||
writevalue += ",";
|
||||
if (enable) {
|
||||
writevalue += "1";
|
||||
} else {
|
||||
writevalue += "0";
|
||||
}
|
||||
FileIO::writeline(SEC_TSP_CMD, writevalue);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// 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 <aidl/vendor/eureka/hardware/parts/BnDisplayConfigs.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct DisplayConfigs : public BnDisplayConfigs {
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::IDisplayConfigs
|
||||
// follow.
|
||||
::ndk::ScopedAStatus writeDisplay(bool enable, DisplaySys type);
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
// 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 "FlashLight.h"
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
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.
|
||||
::ndk::ScopedAStatus FlashBrightness::setFlashlightEnable(bool enable) {
|
||||
FileIO::writeline(TORCH_ENABLE, enable ? 1 : 0);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus FlashBrightness::setFlashlightWritable(int32_t value) {
|
||||
FileIO::writeline(TORCH_LVL, value);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus
|
||||
FlashBrightness::readFlashlightstats(bool s2mu106, int32_t *_aidl_return) {
|
||||
*_aidl_return =
|
||||
s2mu106 ? FileIO::readline(TORCH_LVL) / 21 : FileIO::readline(TORCH_LVL);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/vendor/eureka/hardware/parts/BnFlashBrightness.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct FlashBrightness : public BnFlashBrightness {
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::IFlashBrightness
|
||||
// follow.
|
||||
::ndk::ScopedAStatus setFlashlightEnable(bool enable);
|
||||
::ndk::ScopedAStatus setFlashlightWritable(int32_t value);
|
||||
::ndk::ScopedAStatus readFlashlightstats(bool s2mu106, int32_t *_aidl_return);
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// 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 <memory>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static std::unique_ptr<SmartChargeImpl> kInst;
|
||||
|
||||
static int limit = 0;
|
||||
static int restart = 0;
|
||||
|
||||
static int limit_stat = 0;
|
||||
static int restart_stat = 0;
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::start(void) {
|
||||
if (limit == 0 || restart == 0)
|
||||
return ::ndk::ScopedAStatus::fromExceptionCodeWithMessage(
|
||||
EX_ILLEGAL_ARGUMENT, "Start called without configuring.");
|
||||
kInst = std::make_unique<SmartChargeImpl>(limit, restart);
|
||||
kInst->start();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::stop(void) {
|
||||
if (kInst != nullptr) {
|
||||
kInst->stop();
|
||||
limit_stat += kInst->charge_limit_cnt;
|
||||
restart_stat += kInst->restart_cnt;
|
||||
kInst.reset();
|
||||
}
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::setConfig(int32_t limit_user,
|
||||
int32_t restart_user) {
|
||||
limit = limit_user;
|
||||
restart = restart_user;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::getLimitCnt(int32_t *_aidl_return) {
|
||||
*_aidl_return = limit_stat;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SmartCharge::getRestartCnt(int32_t *_aidl_return) {
|
||||
*_aidl_return = restart_stat;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// 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 <aidl/vendor/eureka/hardware/parts/BnSmartCharge.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct SmartCharge : public BnSmartCharge {
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::ISmartCharge
|
||||
// follow.
|
||||
::ndk::ScopedAStatus start(void);
|
||||
::ndk::ScopedAStatus stop(void);
|
||||
::ndk::ScopedAStatus setConfig(int32_t limit, int32_t restart);
|
||||
::ndk::ScopedAStatus getLimitCnt(int32_t *_aidl_return);
|
||||
::ndk::ScopedAStatus getRestartCnt(int32_t *_aidl_return);
|
||||
};
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#include "SmartChargingImpl.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
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 = FileIO::readline(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;
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include "BatteryConstants.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
||||
static inline void disableSysfs(const char *path) {
|
||||
FileIO::writeline(path, 0);
|
||||
}
|
||||
|
||||
static inline void enableSysfs(const char *path) { FileIO::writeline(path, 1); }
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
// 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 "Swap.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <sys/swap.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
static int mSwapSize = 100;
|
||||
extern int mkswap(const char *filename);
|
||||
extern void mkfile(int filesize, const char *name);
|
||||
|
||||
constexpr const char *SWAP_PATH = "/data/swap/swapfile";
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
static std::mutex thread_lock;
|
||||
|
||||
static bool swapOnRes = false;
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapSize(int32_t size) {
|
||||
mSwapSize = size;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::removeSwapFile(void) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
std::remove(SWAP_PATH);
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapOn() {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
std::thread mkswapfile(mkfile_swapon_thread);
|
||||
mkswapfile.join();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
static void swapoff_thread(void) {
|
||||
const std::lock_guard<std::mutex> lock(thread_lock);
|
||||
swapoff(SWAP_PATH);
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::setSwapOff() {
|
||||
std::thread swapoff(swapoff_thread);
|
||||
swapoff.join();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::getSwapOnResult(bool *_aidl_return) {
|
||||
*_aidl_return = swapOnRes;
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus SwapOnData::isMutexLocked(bool *_aidl_return) {
|
||||
*_aidl_return = !thread_lock.try_lock();
|
||||
return ::ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
} // namespace aidl::vendor::eureka::hardware::parts
|
||||
31
universal7885-common/apps/aidl-support/parts/default/Swap.h
Normal file
31
universal7885-common/apps/aidl-support/parts/default/Swap.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// 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 <aidl/vendor/eureka/hardware/parts/BnSwapOnData.h>
|
||||
|
||||
namespace aidl::vendor::eureka::hardware::parts {
|
||||
|
||||
struct SwapOnData : public BnSwapOnData {
|
||||
// Methods from ::aidl::vendor::eureka::hardware::parts::ISwapOnData
|
||||
// follow.
|
||||
::ndk::ScopedAStatus setSwapSize(int32_t size);
|
||||
::ndk::ScopedAStatus setSwapOn(void);
|
||||
::ndk::ScopedAStatus removeSwapFile(void);
|
||||
::ndk::ScopedAStatus setSwapOff(void);
|
||||
::ndk::ScopedAStatus getSwapOnResult(bool *_aidl_return);
|
||||
::ndk::ScopedAStatus isMutexLocked(bool *_aidl_return);
|
||||
};
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/swap.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
/* XXX This needs to be obtained from kernel headers. See b/9336527 */
|
||||
struct linux_swap_header {
|
||||
char bootbits[1024]; /* Space for disklabel etc. */
|
||||
u_int32_t version;
|
||||
u_int32_t last_page;
|
||||
u_int32_t nr_badpages;
|
||||
unsigned char sws_uuid[16];
|
||||
unsigned char sws_volume[16];
|
||||
u_int32_t padding[117];
|
||||
u_int32_t badpages[1];
|
||||
};
|
||||
void mkfile(int filesize, const char *path) {
|
||||
std::vector<char> empty(1024, 0);
|
||||
std::ofstream ofs(std::string(path), std::ios::binary | std::ios::out);
|
||||
|
||||
for (int i = 0; i < 1024 * filesize; i++) {
|
||||
ofs.write(&empty[0], empty.size());
|
||||
}
|
||||
}
|
||||
#define MAGIC_SWAP_HEADER "SWAPSPACE2"
|
||||
#define MAGIC_SWAP_HEADER_LEN 10
|
||||
#define MIN_PAGES 10
|
||||
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, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
err = errno;
|
||||
return err;
|
||||
}
|
||||
pagesize = getpagesize();
|
||||
/* Determine the length of the swap file */
|
||||
swap_size = lseek(fd, 0, SEEK_END);
|
||||
if (swap_size < MIN_PAGES * pagesize) {
|
||||
err = -ENOSPC;
|
||||
goto err;
|
||||
}
|
||||
if (lseek(fd, 0, SEEK_SET)) {
|
||||
err = errno;
|
||||
goto err;
|
||||
}
|
||||
memset(&sw_hdr, 0, sizeof(sw_hdr));
|
||||
sw_hdr.version = 1;
|
||||
sw_hdr.last_page = (swap_size / pagesize) - 1;
|
||||
len = write(fd, &sw_hdr, sizeof(sw_hdr));
|
||||
if (len != sizeof(sw_hdr)) {
|
||||
err = errno;
|
||||
goto err;
|
||||
}
|
||||
/* Write the magic header */
|
||||
if (lseek(fd, pagesize - MAGIC_SWAP_HEADER_LEN, SEEK_SET) < 0) {
|
||||
err = errno;
|
||||
goto err;
|
||||
}
|
||||
len = write(fd, MAGIC_SWAP_HEADER, MAGIC_SWAP_HEADER_LEN);
|
||||
if (len != MAGIC_SWAP_HEADER_LEN) {
|
||||
err = errno;
|
||||
goto err;
|
||||
}
|
||||
if (fsync(fd) < 0) {
|
||||
err = errno;
|
||||
goto err;
|
||||
}
|
||||
err:
|
||||
close(fd);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
// 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 <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
#include "Battery.h"
|
||||
#include "Display.h"
|
||||
#include "FlashLight.h"
|
||||
#include "SmartCharge.h"
|
||||
#include "Swap.h"
|
||||
|
||||
using ::aidl::vendor::eureka::hardware::parts::BatteryStats;
|
||||
using ::aidl::vendor::eureka::hardware::parts::DisplayConfigs;
|
||||
using ::aidl::vendor::eureka::hardware::parts::FlashBrightness;
|
||||
using ::aidl::vendor::eureka::hardware::parts::SmartCharge;
|
||||
using ::aidl::vendor::eureka::hardware::parts::SwapOnData;
|
||||
|
||||
template <class C> static void registerAsService(std::shared_ptr<C> service) {
|
||||
const std::string instance = std::string() + C::descriptor + "/default";
|
||||
binder_status_t status =
|
||||
AServiceManager_addService(service->asBinder().get(), instance.c_str());
|
||||
CHECK(status == STATUS_OK);
|
||||
LOG(INFO) << "Register done for " << C::descriptor;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
|
||||
registerAsService(ndk::SharedRefBase::make<BatteryStats>());
|
||||
registerAsService(ndk::SharedRefBase::make<DisplayConfigs>());
|
||||
registerAsService(ndk::SharedRefBase::make<FlashBrightness>());
|
||||
registerAsService(ndk::SharedRefBase::make<SmartCharge>());
|
||||
registerAsService(ndk::SharedRefBase::make<SwapOnData>());
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return -1; // should never get here
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
service parts-hal-aidl /system/bin/vendor.eureka.hardware.parts-service
|
||||
class hal
|
||||
user root
|
||||
group root
|
||||
|
||||
on post-fs-data
|
||||
mkdir /data/swap 0755 root root encryption=None
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<manifest version="1.0" type="framework">
|
||||
<hal format="aidl">
|
||||
<name>vendor.eureka.hardware.fmradio</name>
|
||||
<fqname>IBatteryStats/default</fqname>
|
||||
<fqname>IDisplayConfigs/default</fqname>
|
||||
<fqname>IFlashBrightness/default</fqname>
|
||||
<fqname>ISwapOnData/default</fqname>
|
||||
<fqname>ISmartCharge/default</fqname>
|
||||
</hal>
|
||||
</manifest>
|
||||
Loading…
Reference in a new issue