cherish: Smart Charging (2/4)
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com> Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -679,5 +679,14 @@
|
|||||||
<!-- Power menu and dialogs opacity -->
|
<!-- Power menu and dialogs opacity -->
|
||||||
<string name="power_menu_transparency">Power/reboot menu opacity</string>
|
<string name="power_menu_transparency">Power/reboot menu opacity</string>
|
||||||
<string name="power_menu_dialog_dim">Power/reboot dialog dim background amount</string>
|
<string name="power_menu_dialog_dim">Power/reboot dialog dim background amount</string>
|
||||||
|
|
||||||
|
<!-- Smart charging -->
|
||||||
|
<string name="smart_charging_title">Smart Charging</string>
|
||||||
|
<string name="smart_charging_summary">Set maximum charging level</string>
|
||||||
|
<string name="smart_charging_switch_title">Enable Smart Charging</string>
|
||||||
|
<string name="smart_charging_level_title">Stop trigger level</string>
|
||||||
|
<string name="smart_charging_resume_level_title">Start trigger level</string>
|
||||||
|
<string name="smart_charging_reset_stats_title">Reset battery statistics</string>
|
||||||
|
<string name="smart_charging_reset_stats_summary">Reset battery statistics after reaching user defined charging level</string>
|
||||||
|
<string name="smart_charging_footer">Smart Charging allows you to set maximum charging level to extend the lifespan of your battery. When enabled, battery stops charging at Stop trigger level and resumes charging at Start trigger level. Stop trigger level should be always greater than Start trigger level.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -31,6 +31,13 @@
|
|||||||
android:summary="@string/laboratory_ignore_window_secure_summary"
|
android:summary="@string/laboratory_ignore_window_secure_summary"
|
||||||
android:defaultValue="false"/>
|
android:defaultValue="false"/>
|
||||||
|
|
||||||
|
<!-- Smart Charging -->
|
||||||
|
<Preference
|
||||||
|
android:key="smart_charging"
|
||||||
|
android:title="@string/smart_charging_title"
|
||||||
|
android:summary="@string/smart_charging_summary"
|
||||||
|
android:fragment="com.cherish.settings.fragments.SmartCharging"/>
|
||||||
|
|
||||||
<!-- Unlock FPS for specific games -->
|
<!-- Unlock FPS for specific games -->
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="use_games_spoof"
|
android:key="use_games_spoof"
|
||||||
|
|||||||
57
res/xml/smart_charging.xml
Normal file
57
res/xml/smart_charging.xml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2020-2022 The CherishOS Project
|
||||||
|
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||||
|
android:title="@string/smart_charging_title">
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||||
|
android:key="smart_charging"
|
||||||
|
android:title="@string/smart_charging_switch_title"
|
||||||
|
android:summary="@string/smart_charging_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingSwitchPreference
|
||||||
|
android:key="smart_charging_reset_stats"
|
||||||
|
android:title="@string/smart_charging_reset_stats_title"
|
||||||
|
android:summary="@string/smart_charging_reset_stats_summary"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:dependency="smart_charging" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||||
|
android:key="smart_charging_level"
|
||||||
|
android:title="@string/smart_charging_level_title"
|
||||||
|
android:max="100"
|
||||||
|
settings:min="65"
|
||||||
|
settings:units="%"
|
||||||
|
android:defaultValue="80"
|
||||||
|
android:dependency="smart_charging" />
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SystemSettingSeekBarPreference
|
||||||
|
android:key="smart_charging_resume_level"
|
||||||
|
android:title="@string/smart_charging_resume_level_title"
|
||||||
|
android:max="99"
|
||||||
|
settings:min="15"
|
||||||
|
settings:units="%"
|
||||||
|
android:defaultValue="60"
|
||||||
|
android:dependency="smart_charging" />
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.FooterPreference
|
||||||
|
android:key="smart_charging_footer"
|
||||||
|
android:selectable="false"
|
||||||
|
settings:searchable="false"
|
||||||
|
android:dependency="smart_charging" />
|
||||||
|
</PreferenceScreen>
|
||||||
@@ -39,10 +39,11 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
|||||||
import com.android.settingslib.search.SearchIndexable;
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
|
import com.cherish.settings.fragments.SmartCharging;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
@SearchIndexable
|
||||||
public class MiscSettings extends SettingsPreferenceFragment implements
|
public class MiscSettings extends SettingsPreferenceFragment implements
|
||||||
OnPreferenceChangeListener {
|
OnPreferenceChangeListener {
|
||||||
private static final String KEY_GAMES_SPOOF = "use_games_spoof";
|
private static final String KEY_GAMES_SPOOF = "use_games_spoof";
|
||||||
@@ -50,9 +51,12 @@ public class MiscSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private static final String SYS_GAMES_SPOOF = "persist.sys.pixelprops.games";
|
private static final String SYS_GAMES_SPOOF = "persist.sys.pixelprops.games";
|
||||||
private static final String SYS_PHOTOS_SPOOF = "persist.sys.pixelprops.gphotos";
|
private static final String SYS_PHOTOS_SPOOF = "persist.sys.pixelprops.gphotos";
|
||||||
|
|
||||||
|
private static final String SMART_CHARGING = "smart_charging";
|
||||||
|
|
||||||
private SwitchPreference mGamesSpoof;
|
private SwitchPreference mGamesSpoof;
|
||||||
private SwitchPreference mPhotosSpoof;
|
private SwitchPreference mPhotosSpoof;
|
||||||
|
private Preference mSmartCharging;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -60,16 +64,9 @@ public class MiscSettings extends SettingsPreferenceFragment implements
|
|||||||
ContentResolver resolver = getActivity().getContentResolver();
|
ContentResolver resolver = getActivity().getContentResolver();
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.cherish_settings_misc);
|
addPreferencesFromResource(R.xml.cherish_settings_misc);
|
||||||
|
|
||||||
Resources res = null;
|
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||||
Context ctx = getContext();
|
final Resources res = getResources();
|
||||||
float density = Resources.getSystem().getDisplayMetrics().density;
|
|
||||||
|
|
||||||
try {
|
|
||||||
res = ctx.getPackageManager().getResourcesForApplication("com.android.systemui");
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
mGamesSpoof = (SwitchPreference) findPreference(KEY_GAMES_SPOOF);
|
mGamesSpoof = (SwitchPreference) findPreference(KEY_GAMES_SPOOF);
|
||||||
mGamesSpoof.setChecked(SystemProperties.getBoolean(SYS_GAMES_SPOOF, false));
|
mGamesSpoof.setChecked(SystemProperties.getBoolean(SYS_GAMES_SPOOF, false));
|
||||||
@@ -78,6 +75,12 @@ public class MiscSettings extends SettingsPreferenceFragment implements
|
|||||||
mPhotosSpoof = (SwitchPreference) findPreference(KEY_PHOTOS_SPOOF);
|
mPhotosSpoof = (SwitchPreference) findPreference(KEY_PHOTOS_SPOOF);
|
||||||
mPhotosSpoof.setChecked(SystemProperties.getBoolean(SYS_PHOTOS_SPOOF, true));
|
mPhotosSpoof.setChecked(SystemProperties.getBoolean(SYS_PHOTOS_SPOOF, true));
|
||||||
mPhotosSpoof.setOnPreferenceChangeListener(this);
|
mPhotosSpoof.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
mSmartCharging = (Preference) prefScreen.findPreference(SMART_CHARGING);
|
||||||
|
boolean mSmartChargingSupported = res.getBoolean(
|
||||||
|
com.android.internal.R.bool.config_smartChargingAvailable);
|
||||||
|
if (!mSmartChargingSupported)
|
||||||
|
prefScreen.removePreference(mSmartCharging);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,29 +103,19 @@ public class MiscSettings extends SettingsPreferenceFragment implements
|
|||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For Search.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
|
||||||
boolean enabled) {
|
|
||||||
ArrayList<SearchIndexableResource> result =
|
|
||||||
new ArrayList<SearchIndexableResource>();
|
|
||||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.cherish_settings_misc;
|
|
||||||
result.add(sir);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.cherish_settings_misc) {
|
||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
List<String> keys = super.getNonIndexableKeys(context);
|
List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
|
||||||
|
boolean mSmartChargingSupported = context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_smartChargingAvailable);
|
||||||
|
if (!mSmartChargingSupported)
|
||||||
|
keys.add(SMART_CHARGING);
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
68
src/com/cherish/settings/fragments/SmartCharging.java
Normal file
68
src/com/cherish/settings/fragments/SmartCharging.java
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020-2022 The CherishOS Project
|
||||||
|
*
|
||||||
|
* 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.cherish.settings.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
public class SmartCharging extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
|
private static final String TAG = "SmartCharging";
|
||||||
|
private static final String SMART_CHARGING_FOOTER = "smart_charging_footer";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.smart_charging);
|
||||||
|
|
||||||
|
findPreference(SMART_CHARGING_FOOTER).setTitle(R.string.smart_charging_footer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset(Context mContext) {
|
||||||
|
ContentResolver resolver = mContext.getContentResolver();
|
||||||
|
Settings.System.putIntForUser(resolver,
|
||||||
|
Settings.System.SMART_CHARGING, 0, UserHandle.USER_CURRENT);
|
||||||
|
Settings.System.putIntForUser(resolver,
|
||||||
|
Settings.System.SMART_CHARGING_RESET_STATS, 0, UserHandle.USER_CURRENT);
|
||||||
|
Settings.System.putIntForUser(resolver,
|
||||||
|
Settings.System.SMART_CHARGING_LEVEL, 80, UserHandle.USER_CURRENT);
|
||||||
|
Settings.System.putIntForUser(resolver,
|
||||||
|
Settings.System.SMART_CHARGING_RESUME_LEVEL, 60, UserHandle.USER_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user