sdm660-common: DeviceSettings: Add USB fastcharge toggle
Co-authored-by: ronaxdevil <pratabidya.007@gmail.com> Signed-off-by: clarencelol <clarencekuiek@icloud.com> Signed-off-by: pix106 <sbordenave@gmail.com>
This commit is contained in:
parent
7e992f6717
commit
5182be1445
11 changed files with 131 additions and 2 deletions
14
DeviceSettings/res/drawable/ic_usb_fastcharge.xml
Normal file
14
DeviceSettings/res/drawable/ic_usb_fastcharge.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?> <!-- drawable/usb.xml --> <vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal" >
|
||||
<path android:fillColor="#000"
|
||||
android:pathData="M15,7V11H16V13H13V5H15L12,1L9,5H11V13H8V10.93C8.7,10.56
|
||||
9.2,9.85 9.2,9C9.2,7.78 8.21,6.8 7,6.8C5.78,6.8 4.8,7.78 4.8,9C4.8,9.85
|
||||
5.3,10.56 6,10.93V13A2,2 0 0,0 8,15H11V18.05C10.29,18.41 9.8,19.15
|
||||
9.8,20A2.2,2.2 0 0,0 12,22.2A2.2,2.2 0 0,0 14.2,20C14.2,19.15 13.71,18.41
|
||||
13,18.05V15H16A2,2 0 0,0 18,13V11H19V7H15Z" />
|
||||
</vector>
|
|
@ -152,4 +152,9 @@
|
|||
<string name="dirac_preset_soft_bass">Soft Bass</string>
|
||||
<string name="dirac_preset_soft_treble">Soft Treble</string>
|
||||
|
||||
<!-- USB fastcharge -->
|
||||
<string name="usb_fastcharge_title">USB Fastcharge</string>
|
||||
<string name="fastcharge_title">Enable USB Fastcharge</string>
|
||||
<string name="fastcharge_summary">Charge upto 900mA when connected to a computer via USB 3.0 port</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -173,6 +173,18 @@
|
|||
android:targetClass="com.xiaomi.parts.speaker.ClearSpeakerActivity"
|
||||
android:targetPackage="com.xiaomi.parts.speaker" />
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="usb_fastcharge"
|
||||
android:title="@string/usb_fastcharge_title" >
|
||||
|
||||
<org.lineageos.settings.device.preferences.SecureSettingSwitchPreference
|
||||
android:key="fastcharge"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/fastcharge_title"
|
||||
android:icon="@drawable/ic_usb_fastcharge"
|
||||
android:summary="@string/fastcharge_summary" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
@ -85,6 +85,10 @@ public class BootReceiver extends BroadcastReceiver implements Utils {
|
|||
// Dirac
|
||||
context.startService(new Intent(context, DiracService.class));
|
||||
|
||||
// USB Fastcharge
|
||||
FileUtils.setValue(DeviceSettings.USB_FASTCHARGE_PATH, Settings.Secure.getInt(context.getContentResolver(),
|
||||
DeviceSettings.PREF_USB_FASTCHARGE, 0));
|
||||
|
||||
// FPS Info
|
||||
boolean enabled = Settings.Secure.getInt(context.getContentResolver(),
|
||||
DeviceSettings.PREF_KEY_FPS_INFO, 0) == 1;
|
||||
|
|
|
@ -57,6 +57,9 @@ public class DeviceSettings extends PreferenceFragment implements
|
|||
private static final String PREF_PRESET = "dirac_preset_pref";
|
||||
|
||||
public static final String PREF_KEY_FPS_INFO = "fps_info";
|
||||
public static final String CATEGORY_FASTCHARGE = "usb_fastcharge";
|
||||
public static final String PREF_USB_FASTCHARGE = "fastcharge";
|
||||
public static final String USB_FASTCHARGE_PATH = "/sys/kernel/fast_charge/force_fast_charge";
|
||||
|
||||
// value of vtg_min and vtg_max
|
||||
public static final int MIN_VIBRATION = 116;
|
||||
|
@ -86,6 +89,7 @@ public class DeviceSettings extends PreferenceFragment implements
|
|||
private SecureSettingSwitchPreference mEnableDirac;
|
||||
private SecureSettingListPreference mHeadsetType;
|
||||
private SecureSettingListPreference mPreset;
|
||||
private SecureSettingSwitchPreference mFastcharge;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
|
@ -135,7 +139,6 @@ public class DeviceSettings extends PreferenceFragment implements
|
|||
} else {
|
||||
gainCategory.removePreference(findPreference(PREF_MIC_GAIN));
|
||||
}
|
||||
|
||||
// Display Category
|
||||
PreferenceCategory displayCategory = (PreferenceCategory) findPreference(CATEGORY_DISPLAY);
|
||||
// Doze
|
||||
|
@ -190,6 +193,15 @@ public class DeviceSettings extends PreferenceFragment implements
|
|||
} else {
|
||||
getPreferenceScreen().removePreference(findPreference(CATEGORY_HALL_WAKEUP));
|
||||
}
|
||||
|
||||
if (FileUtils.fileWritable(USB_FASTCHARGE_PATH)) {
|
||||
mFastcharge = (SecureSettingSwitchPreference) findPreference(PREF_USB_FASTCHARGE);
|
||||
mFastcharge.setEnabled(Fastcharge.isSupported());
|
||||
mFastcharge.setChecked(Fastcharge.isCurrentlyEnabled(this.getContext()));
|
||||
mFastcharge.setOnPreferenceChangeListener(new Fastcharge(getContext()));
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(findPreference(CATEGORY_FASTCHARGE));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (C) 2020 ronaxdevil <pratabidya.007@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.lineageos.settings.device;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.lineageos.settings.device.DeviceSettings;
|
||||
|
||||
public class Fastcharge implements OnPreferenceChangeListener {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public Fastcharge(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public static String getFile() {
|
||||
if (FileUtils.fileWritable(DeviceSettings.USB_FASTCHARGE_PATH)) {
|
||||
return DeviceSettings.USB_FASTCHARGE_PATH;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return FileUtils.fileWritable(getFile());
|
||||
}
|
||||
|
||||
public static boolean isCurrentlyEnabled(Context context) {
|
||||
return FileUtils.getFileValueAsBoolean(getFile(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
final String key = preference.getKey();
|
||||
switch (key) {
|
||||
case DeviceSettings.PREF_USB_FASTCHARGE:
|
||||
FileUtils.setValue(DeviceSettings.USB_FASTCHARGE_PATH, (boolean) value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -115,6 +115,14 @@ public class FileUtils {
|
|||
return line;
|
||||
}
|
||||
|
||||
static boolean getFileValueAsBoolean(String filename, boolean defValue) {
|
||||
String fileValue = getValue(filename);
|
||||
if (fileValue != null) {
|
||||
return !fileValue.equals("0");
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
static void setProp(String prop, boolean value) {
|
||||
if (value) {
|
||||
SystemProperties.set(prop, "1");
|
||||
|
|
|
@ -41,6 +41,10 @@ on boot
|
|||
chmod 0660 /sys/class/leds/red/brightness
|
||||
chmod 0660 /sys/class/leds/red/max_brightness
|
||||
|
||||
# USB Fastcharge
|
||||
chown system system /sys/kernel/fast_charge/force_fast_charge
|
||||
chmod 0660 /sys/kernel/fast_charge/force_fast_charge
|
||||
|
||||
# KCal
|
||||
chown system system /sys/devices/platform/kcal_ctrl.0/kcal_cont
|
||||
chown system system /sys/devices/platform/kcal_ctrl.0/kcal_enable
|
||||
|
|
3
sepolicy/vendor/file.te
vendored
3
sepolicy/vendor/file.te
vendored
|
@ -17,6 +17,9 @@ type vendor_sysfs_hvdcp, fs_type, sysfs_type;
|
|||
# Hall Switch
|
||||
type hall_dev, sysfs_type, fs_type;
|
||||
|
||||
# Fast Charge
|
||||
type sysfs_fcharge, sysfs_type, fs_type;
|
||||
|
||||
# Kcal
|
||||
type kcal_dev, sysfs_type, fs_type;
|
||||
|
||||
|
|
1
sepolicy/vendor/genfs_contexts
vendored
1
sepolicy/vendor/genfs_contexts
vendored
|
@ -67,3 +67,4 @@ genfscon sysfs /devices/platform/soc/ca0c000.qcom,cci/ca0c000.qcom,cci:qcom,came
|
|||
genfscon sysfs /devices/platform/soc/ca0c000.qcom,cci/ca0c000.qcom,cci:qcom,camera@1/video4linux/video3/wakeup u:object_r:sysfs_wakeup:s0
|
||||
genfscon sysfs /devices/platform/soc/ca0c000.qcom,cci/ca0c000.qcom,cci:qcom,camera@2/video4linux/video4/wakeup u:object_r:sysfs_wakeup:s0
|
||||
genfscon sysfs /devices/virtual/input/input1/wakeup u:object_r:sysfs_wakeup:s0
|
||||
genfscon sysfs /kernel/fast_charge/force_fast_charge u:object_r:sysfs_fcharge:s0
|
||||
|
|
1
sepolicy/vendor/system_app.te
vendored
1
sepolicy/vendor/system_app.te
vendored
|
@ -5,6 +5,7 @@ allow system_app kcal_dev:dir search;
|
|||
allow system_app kcal_dev:file rw_file_perms;
|
||||
allow system_app proc_pagetypeinfo:file r_file_perms;
|
||||
allow system_app proc_vmallocinfo:file read;
|
||||
allow system_app sysfs_fcharge:file rw_file_perms;
|
||||
allow system_app sysfs_vibrator:dir search;
|
||||
allow system_app sysfs_vibrator:file rw_file_perms;
|
||||
allow system_app sysfs_graphics:dir search;
|
||||
|
|
Loading…
Reference in a new issue