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"
}
}