diff --git a/DeviceSettings/res/drawable/ic_usb_fastcharge.xml b/DeviceSettings/res/drawable/ic_usb_fastcharge.xml
new file mode 100644
index 00000000..8a2f0b73
--- /dev/null
+++ b/DeviceSettings/res/drawable/ic_usb_fastcharge.xml
@@ -0,0 +1,14 @@
+
+
+
diff --git a/DeviceSettings/res/values/strings.xml b/DeviceSettings/res/values/strings.xml
index b53f7470..d5ed6175 100644
--- a/DeviceSettings/res/values/strings.xml
+++ b/DeviceSettings/res/values/strings.xml
@@ -152,4 +152,9 @@
Soft Bass
Soft Treble
+
+ USB Fastcharge
+ Enable USB Fastcharge
+ Charge upto 900mA when connected to a computer via USB 3.0 port
+
diff --git a/DeviceSettings/res/xml/preferences_xiaomi_parts.xml b/DeviceSettings/res/xml/preferences_xiaomi_parts.xml
index 5b023279..f4e32cfe 100644
--- a/DeviceSettings/res/xml/preferences_xiaomi_parts.xml
+++ b/DeviceSettings/res/xml/preferences_xiaomi_parts.xml
@@ -173,6 +173,18 @@
android:targetClass="com.xiaomi.parts.speaker.ClearSpeakerActivity"
android:targetPackage="com.xiaomi.parts.speaker" />
-
+
+
+
+
+
+
diff --git a/DeviceSettings/src/org/lineageos/settings/device/BootReceiver.java b/DeviceSettings/src/org/lineageos/settings/device/BootReceiver.java
index 5914c0d5..18c71ac1 100644
--- a/DeviceSettings/src/org/lineageos/settings/device/BootReceiver.java
+++ b/DeviceSettings/src/org/lineageos/settings/device/BootReceiver.java
@@ -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;
diff --git a/DeviceSettings/src/org/lineageos/settings/device/DeviceSettings.java b/DeviceSettings/src/org/lineageos/settings/device/DeviceSettings.java
index 712f8b44..b60ac1e6 100644
--- a/DeviceSettings/src/org/lineageos/settings/device/DeviceSettings.java
+++ b/DeviceSettings/src/org/lineageos/settings/device/DeviceSettings.java
@@ -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
diff --git a/DeviceSettings/src/org/lineageos/settings/device/Fastcharge.java b/DeviceSettings/src/org/lineageos/settings/device/Fastcharge.java
new file mode 100644
index 00000000..a9ad6141
--- /dev/null
+++ b/DeviceSettings/src/org/lineageos/settings/device/Fastcharge.java
@@ -0,0 +1,65 @@
+/*
+* Copyright (C) 2020 ronaxdevil
+*
+* 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 .
+*
+*/
+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;
+ }
+}
diff --git a/DeviceSettings/src/org/lineageos/settings/device/FileUtils.java b/DeviceSettings/src/org/lineageos/settings/device/FileUtils.java
index 4190a5ac..6dc64533 100644
--- a/DeviceSettings/src/org/lineageos/settings/device/FileUtils.java
+++ b/DeviceSettings/src/org/lineageos/settings/device/FileUtils.java
@@ -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");
diff --git a/rootdir/etc/init.xiaomi_parts.rc b/rootdir/etc/init.xiaomi_parts.rc
index ff476796..3fcd8350 100644
--- a/rootdir/etc/init.xiaomi_parts.rc
+++ b/rootdir/etc/init.xiaomi_parts.rc
@@ -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
diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te
index ff8bc000..a9f3d6b8 100644
--- a/sepolicy/vendor/file.te
+++ b/sepolicy/vendor/file.te
@@ -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;
diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts
index 1623a64c..92722265 100644
--- a/sepolicy/vendor/genfs_contexts
+++ b/sepolicy/vendor/genfs_contexts
@@ -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
diff --git a/sepolicy/vendor/system_app.te b/sepolicy/vendor/system_app.te
index 53f9c45b..b3feeb68 100644
--- a/sepolicy/vendor/system_app.te
+++ b/sepolicy/vendor/system_app.te
@@ -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;