mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-22 12:05:32 -04:00
universal7885: parts: Implement swap on /data ctrl
This commit is contained in:
parent
442aa11e81
commit
f5d3e25c02
20 changed files with 329 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ hidl_interface {
|
|||
"IBatteryStats.hal",
|
||||
"IFlashBrightness.hal",
|
||||
"IDisplayConfigs.hal",
|
||||
"ISwapOnData.hal",
|
||||
],
|
||||
interfaces: [ "android.hidl.base@1.0" ],
|
||||
gen_java: false,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
// 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 ISwapOnData {
|
||||
setSwapSize(int32_t size /* Size in megabytes */);
|
||||
setSwapOn();
|
||||
setSwapOff();
|
||||
};
|
||||
|
|
@ -7,7 +7,8 @@ cc_binary {
|
|||
"Battery.cpp",
|
||||
"FlashLight.cpp",
|
||||
"Display.cpp",
|
||||
"service.cpp",
|
||||
"Swap.cpp",
|
||||
"service.cpp",
|
||||
],
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
// 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>
|
||||
|
||||
static int mSwapSize = 100;
|
||||
|
||||
#define SWAP_PATH "/data/swap/swapfile"
|
||||
using namespace std;
|
||||
namespace vendor::eureka::hardware::parts::V1_0 {
|
||||
|
||||
Return<void> SwapOnData::setSwapSize(int32_t size) {
|
||||
mSwapSize = size;
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> SwapOnData::setSwapOn(){
|
||||
string cmd = string("dd if=/dev/zero of=") + string(SWAP_PATH) + string(" bs=") + std::to_string(mSwapSize)
|
||||
+ " count=10";
|
||||
system(cmd.c_str());
|
||||
cmd = string("mkswap ") + string(SWAP_PATH);
|
||||
system(cmd.c_str());
|
||||
cmd = string("swapon ") + string(SWAP_PATH);
|
||||
system(cmd.c_str());
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> SwapOnData::setSwapOff(){
|
||||
std::string cmd = string("swapoff ") + string(SWAP_PATH);
|
||||
system(cmd.c_str());
|
||||
cmd = string("rm ") + string(SWAP_PATH);
|
||||
system(cmd.c_str());
|
||||
return Void();
|
||||
}
|
||||
|
||||
ISwapOnData *SwapOnData::getInstance(void) {
|
||||
return new SwapOnData();
|
||||
}
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -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 <hidl/MQDescriptor.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
|
||||
|
||||
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 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();
|
||||
// Methods from ::android::hidl::base::V2_0::IBase follow.
|
||||
static ISwapOnData *getInstance(void);
|
||||
};
|
||||
} // namespace vendor::eureka::hardware::parts::V1_0
|
||||
|
|
@ -18,10 +18,12 @@
|
|||
#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/IFlashBrightness.h>
|
||||
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
|
||||
|
||||
#include "Battery.h"
|
||||
#include "Display.h"
|
||||
#include "FlashLight.h"
|
||||
#include "Swap.h"
|
||||
|
||||
using android::sp;
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
|
|
@ -29,9 +31,11 @@ using android::hardware::joinRpcThreadpool;
|
|||
using vendor::eureka::hardware::parts::V1_0::BatteryStats;
|
||||
using vendor::eureka::hardware::parts::V1_0::DisplayConfigs;
|
||||
using vendor::eureka::hardware::parts::V1_0::FlashBrightness;
|
||||
using vendor::eureka::hardware::parts::V1_0::SwapOnData;
|
||||
using vendor::eureka::hardware::parts::V1_0::IBatteryStats;
|
||||
using vendor::eureka::hardware::parts::V1_0::IDisplayConfigs;
|
||||
using vendor::eureka::hardware::parts::V1_0::IFlashBrightness;
|
||||
using vendor::eureka::hardware::parts::V1_0::ISwapOnData;
|
||||
|
||||
int main() {
|
||||
int ret;
|
||||
|
|
@ -39,6 +43,7 @@ int main() {
|
|||
android::sp<IFlashBrightness> mFlashLightService =
|
||||
FlashBrightness::getInstance();
|
||||
android::sp<IDisplayConfigs> mDisplayService = DisplayConfigs::getInstance();
|
||||
android::sp<ISwapOnData> mSwapService = SwapOnData::getInstance();
|
||||
configureRpcThreadpool(4, true /*callerWillJoin*/);
|
||||
|
||||
if (mBatteryService != nullptr) {
|
||||
|
|
@ -71,6 +76,16 @@ int main() {
|
|||
} 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");
|
||||
}
|
||||
joinRpcThreadpool();
|
||||
|
||||
return -1; // should never get here
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ service vendor.parts-hal /vendor/bin/vendor.eureka.hardware.parts@1.0-service
|
|||
interface vendor.eureka.hardware.parts@1.0::IBatteryStats default
|
||||
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
|
||||
class hal
|
||||
user root
|
||||
group root
|
||||
|
|
|
|||
|
|
@ -16,5 +16,9 @@
|
|||
<name>IDisplayConfigs</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
<interface>
|
||||
<name>ISwapOnData</name>
|
||||
<instance>default</instance>
|
||||
</interface>
|
||||
</hal>
|
||||
</manifest>
|
||||
|
|
|
|||
Loading…
Reference in a new issue