universal7885: parts: Implement swap on /data ctrl

This commit is contained in:
roynatech2544 2022-04-18 14:10:29 +09:00
commit f5d3e25c02
20 changed files with 329 additions and 1 deletions

View file

@ -40,6 +40,12 @@
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".swap.SwapActivity" android:exported="true" android:label="@string/swap_title">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<provider android:name=".dolby.DolbySearchIndexablesProvider" android:exported="true" android:authorities="com.eurekateam.samsungextras" android:multiprocess="false" android:grantUriPermissions="true" android:permission="android.permission.READ_SEARCH_INDEXABLES">
<intent-filter>
<action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER"/>

View file

@ -0,0 +1,28 @@
#include "jni.h"
#include <hardware/hardware.h>
#include <hidl/HidlSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/Status.h>
#include <vendor/eureka/hardware/parts/1.0/ISwapOnData.h>
using android::sp;
using vendor::eureka::hardware::parts::V1_0::ISwapOnData;
static sp<ISwapOnData> service = ISwapOnData::getService();
extern "C" JNIEXPORT void JNICALL
Java_com_eurekateam_samsungextras_interfaces_Swap_setSize(JNIEnv *env,
jclass clazz,
jint size) {
service->setSwapSize(size);
}
extern "C" JNIEXPORT void JNICALL
Java_com_eurekateam_samsungextras_interfaces_Swap_setSwapOn(
JNIEnv *env, jclass clazz, jboolean enable) {
if (enable){
service->setSwapOn();
} else {
service->setSwapOff();
}
}

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0 0h24v24H0V0z" />
<path
android:fillColor="#000000"
android:pathData="M15 9H9v6h6V9zm-2 4h-2v-2h2v2zm8-2V9h-2V7c0-1.1-0.9-2-2-2h-2V3h-2v2h-2V3H9v2H7c-1.1 0-2 0.9-2 2v2H3v2h2v2H3v2h2v2c0 1.1 0.9 2 2 2h2v2h2v-2h2v2h2v-2h2c1.1 0 2-0.9 2-2v-2h2v-2h-2v-2h2zm-4 6H7V7h10v10z" />
</vector>

View file

@ -56,6 +56,11 @@
<string name="flashlight_description">Samsung\'s OneUI Has An Option to Adjust
Flashlight Brightness. AOSP doesn\'t have this feature.\n\n
Use this feature to adjust low or high flashlight brightness. Ranges from 0 to 10.</string>
<string name="swap_title">Swap on userdata</string>
<string name="swap_enable_title">Enable swap on EMMC</string>
<string name="swap_size_title">Swap size</string>
<string name="swap_size_summary">Adjust the size of swap</string>
<string name="swap_description">Creates the swap (not zram) on /data partiton. Useful for low memory devices.</string>
<!-- Display Category -->
<string name="misc_category">Misc</string>
<string name="dt2w_mode">Toggle for double tap to wake</string>

View file

@ -22,6 +22,9 @@
</Preference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/misc_category">
<Preference android:key="swap_settings" android:title="@string/swap_title" android:icon="@drawable/ic_memory" android:summary="@string/swap_description" android:persistent="true">
<intent android:action="android.intent.action.MAIN" android:targetClass="com.eurekateam.samsungextras.swap.SwapActivity" android:targetPackage="com.eurekateam.samsungextras"/>
</Preference>
<SwitchPreference android:key="dt2w_settings" android:title="@string/dt2w_mode" android:persistent="true"/>
<SwitchPreference android:key="glove_mode_settings" android:title="@string/glove_mode" android:persistent="true"/>
</PreferenceCategory>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/swap_title">
<com.android.settingslib.widget.MainSwitchPreference android:defaultValue="false" android:key="swap_enable" android:title="@string/swap_enable_title"/>
<SeekBarPreference android:key="swap_size" android:title="@string/swap_size_title" android:icon="@drawable/ic_memory" android:summary="@string/swap_size_summary"/>
<com.android.settingslib.widget.FooterPreference android:title="@string/swap_description" android:selectable="false"/>
</PreferenceScreen>

View file

@ -0,0 +1,22 @@
/*
* Copyright (C) 2022 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 com.eurekateam.samsungextras.interfaces
object Swap{
external fun setSwapOn(mEnabled: Boolean)
external fun setSize(mSize : Int)
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 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 com.eurekateam.samsungextras.swap
import android.os.Bundle
import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
import com.android.settingslib.collapsingtoolbar.R
class SwapActivity : CollapsingToolbarBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportFragmentManager.beginTransaction().replace(
R.id.content_frame,
SwapFragment()
).commit()
}
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (C) 2022 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 com.eurekateam.samsungextras.swap
import android.content.SharedPreferences
import android.os.Build
import android.os.Bundle
import android.widget.Switch
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.preference.SeekBarPreference
import com.android.settingslib.widget.MainSwitchPreference
import com.android.settingslib.widget.OnMainSwitchChangeListener
import com.eurekateam.samsungextras.R
import com.eurekateam.samsungextras.interfaces.Swap
class SwapFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, OnMainSwitchChangeListener {
private lateinit var mSwapSizePref: SeekBarPreference
private lateinit var mSharedPreferences: SharedPreferences
private lateinit var mSwapEnable: MainSwitchPreference
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.swap_settings)
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
mSwapSizePref = findPreference(PREF_SWAP_SIZE)!!
mSwapSizePref.onPreferenceChangeListener = this
mSwapSizePref.setMax(100)
mSwapSizePref.setMin(10)
mSwapSizePref.value = mSharedPreferences.getInt(PREF_SWAP_SIZE, 50)
mSwapEnable = findPreference(PREF_SWAP_ENABLE)!!
mSwapEnable.isChecked = mSharedPreferences.getBoolean(PREF_SWAP_ENABLE, false)
mSwapEnable.addOnSwitchChangeListener(this)
mSwapSizePref.isEnabled = !mSwapEnable.isChecked
}
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
if (preference == mSwapSizePref) {
val value = newValue as Int
Swap.setSize(value)
mSharedPreferences.edit().putInt(PREF_SWAP_SIZE, value).apply()
return true
}
return false
}
override fun onSwitchChanged(switchView: Switch, isChecked: Boolean) {
Swap.setSwapOn(isChecked)
mSharedPreferences.edit().putBoolean(PREF_SWAP_ENABLE, isChecked)
mSwapSizePref.isEnabled = !isChecked
}
companion object {
const val PREF_SWAP_SIZE = "swap_size"
const val PREF_SWAP_ENABLE = "swap_enable"
}
}

View file

@ -6,6 +6,7 @@ hidl_interface {
"IBatteryStats.hal",
"IFlashBrightness.hal",
"IDisplayConfigs.hal",
"ISwapOnData.hal",
],
interfaces: [ "android.hidl.base@1.0" ],
gen_java: false,

View file

@ -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();
};

View file

@ -7,7 +7,8 @@ cc_binary {
"Battery.cpp",
"FlashLight.cpp",
"Display.cpp",
"service.cpp",
"Swap.cpp",
"service.cpp",
],
shared_libs: [
"libhidlbase",

View file

@ -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

View file

@ -0,0 +1,40 @@
// Copyright (C) 2021 Eureka Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <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

View file

@ -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

View file

@ -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

View file

@ -16,5 +16,9 @@
<name>IDisplayConfigs</name>
<instance>default</instance>
</interface>
<interface>
<name>ISwapOnData</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View file

@ -24,6 +24,7 @@
/data/vendor/log(/.*)? u:object_r:log_vendor_data_file:s0
/data/vendor/log/cbd(/.*)? u:object_r:log_cbd_vendor_data_file:s0
/data/vendor/secradio(/.*)? u:object_r:radio_vendor_data_file:s0
/data/swap(/.*)? u:object_r:parts_data_file:s0
### DEV
/dev/block/platform/.+/by-name/boot u:object_r:boot_block_device:s0

View file

@ -24,3 +24,12 @@ allow hal_parts_default sysfs_virtual:dir search;
# Display
allow hal_parts_default sysfs_sec_touchscreen:dir search;
allow hal_parts_default sysfs_touchscreen_writable:file rw_file_perms;
# Swap
type parts_data_file, file_type, data_file_type;
allow hal_parts_default parts_data_file:dir rw_dir_perms;
allow hal_parts_default parts_data_file:file rw_file_perms;
allow hal_parts_default parts_data_file:file create_file_perms;
allow hal_parts_default vendor_shell_exec:file rx_file_perms;
allow hal_parts_default vendor_toolbox_exec:file rx_file_perms;
allow hal_parts_default self:capability sys_admin;

View file

@ -8,6 +8,7 @@ vendor.lineage.power::ILineagePower u:object_r:hal_power_hwservice:s0
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
# FMRadio
vendor.eureka.hardware.fmradio::IFMRadio u:object_r:hal_fmradio_hwservice:s0