Skip to content
This repository was archived by the owner on Oct 5, 2019. It is now read-only.

Commit 6d7f5b6

Browse files
Battery: add custom AC, USB, and Wireless charge control to yank555.lu's Force Fast Charge
This commit will add access to Force Fast Charge Custom Mode Signed-off-by: sunilpaulmathew <[email protected]>
1 parent 9468630 commit 6d7f5b6

File tree

3 files changed

+172
-17
lines changed

3 files changed

+172
-17
lines changed

app/src/main/java/com/grarak/kerneladiutor/fragments/kernel/BatteryFragment.java

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.grarak.kerneladiutor.views.recyclerview.CardView;
3434
import com.grarak.kerneladiutor.views.recyclerview.RecyclerViewItem;
3535
import com.grarak.kerneladiutor.views.recyclerview.SeekBarView;
36+
import com.grarak.kerneladiutor.views.recyclerview.SelectView;
3637
import com.grarak.kerneladiutor.views.recyclerview.StatsView;
3738
import com.grarak.kerneladiutor.views.recyclerview.SwitchView;
3839

@@ -66,6 +67,15 @@ protected void addItems(List<RecyclerViewItem> items) {
6667
if (mBattery.hasForceFastCharge()) {
6768
forceFastChargeInit(items);
6869
}
70+
if (mBattery.hasFastChargeControlAC()) {
71+
FastChargeControlACinit(items);
72+
}
73+
if (mBattery.hasFastChargeControlUSB()) {
74+
FastChargeControlUSBinit(items);
75+
}
76+
if (mBattery.hasFastChargeControlWIRELESS()) {
77+
FastChargeControlWirelessinit(items);
78+
}
6979
if (mBattery.hasBlx()) {
7080
blxInit(items);
7181
}
@@ -98,14 +108,65 @@ private void voltageInit(List<RecyclerViewItem> items) {
98108
}
99109

100110
private void forceFastChargeInit(List<RecyclerViewItem> items) {
101-
SwitchView forceFastCharge = new SwitchView();
102-
forceFastCharge.setTitle(getString(R.string.usb_fast_charge));
103-
forceFastCharge.setSummary(getString(R.string.usb_fast_charge_summary));
104-
forceFastCharge.setChecked(mBattery.isForceFastChargeEnabled());
105-
forceFastCharge.addOnSwitchListener((switchView, isChecked)
106-
-> mBattery.enableForceFastCharge(isChecked, getActivity()));
107-
108-
items.add(forceFastCharge);
111+
SelectView forceFastCharge = new SelectView();
112+
forceFastCharge.setTitle(getString(R.string.usb_fast_charge));
113+
forceFastCharge.setSummary(getString(R.string.usb_fast_charge_summary));
114+
forceFastCharge.setItems(mBattery.enableForceFastCharge(getActivity()));
115+
forceFastCharge.setItem(mBattery.getForceFastCharge());
116+
forceFastCharge.setOnItemSelected(new SelectView.OnItemSelected() {
117+
@Override
118+
public void onItemSelected(SelectView selectView, int position, String item) {
119+
mBattery.setForceFastCharge(position, getActivity());
120+
}
121+
});
122+
123+
items.add(forceFastCharge);
124+
125+
}
126+
127+
private void FastChargeControlACinit(List<RecyclerViewItem> items) {
128+
SelectView FastChargeControl = new SelectView();
129+
FastChargeControl.setTitle(getString(R.string.charge_level_ac));
130+
FastChargeControl.setSummary(getString(R.string.charge_level_ac_summary));
131+
FastChargeControl.setItems(mBattery.getFastChargeControlAC());
132+
FastChargeControl.setItem(mBattery.getFastChargeCustomAC());
133+
FastChargeControl.setOnItemSelected(new SelectView.OnItemSelected() {
134+
@Override
135+
public void onItemSelected(SelectView selectView, int position, String item) {
136+
mBattery.setFastChargeControlAC(item, getActivity());
137+
}
138+
});
139+
items.add(FastChargeControl);
140+
}
141+
142+
private void FastChargeControlUSBinit(List<RecyclerViewItem> items) {
143+
SelectView FastChargeControl = new SelectView();
144+
FastChargeControl.setTitle(getString(R.string.charge_level_usb));
145+
FastChargeControl.setSummary(getString(R.string.charge_level_usb_summary));
146+
FastChargeControl.setItems(mBattery.getFastChargeControlUSB());
147+
FastChargeControl.setItem(mBattery.getFastChargeCustomUSB());
148+
FastChargeControl.setOnItemSelected(new SelectView.OnItemSelected() {
149+
@Override
150+
public void onItemSelected(SelectView selectView, int position, String item) {
151+
mBattery.setFastChargeControlUSB(item, getActivity());
152+
}
153+
});
154+
items.add(FastChargeControl);
155+
}
156+
157+
private void FastChargeControlWirelessinit(List<RecyclerViewItem> items) {
158+
SelectView FastChargeControlWireless = new SelectView();
159+
FastChargeControlWireless.setTitle(getString(R.string.charge_level_wireless));
160+
FastChargeControlWireless.setSummary(getString(R.string.charge_level_wireless_summary));
161+
FastChargeControlWireless.setItems(mBattery.getFastChargeControlWIRELESS());
162+
FastChargeControlWireless.setItem(mBattery.getFastChargeCustomWIRELESS());
163+
FastChargeControlWireless.setOnItemSelected(new SelectView.OnItemSelected() {
164+
@Override
165+
public void onItemSelected(SelectView selectView, int position, String item) {
166+
mBattery.setFastChargeControlWIRELESS(item, getActivity());
167+
}
168+
});
169+
items.add(FastChargeControlWireless);
109170
}
110171

111172
private void blxInit(List<RecyclerViewItem> items) {

app/src/main/java/com/grarak/kerneladiutor/utils/kernel/battery/Battery.java

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
package com.grarak.kerneladiutor.utils.kernel.battery;
2121

2222
import android.content.Context;
23+
import android.text.TextUtils;
24+
25+
import com.grarak.kerneladiutor.R;
2326
import android.support.annotation.NonNull;
2427

2528
import com.grarak.kerneladiutor.fragments.ApplyOnBootFragment;
@@ -28,6 +31,9 @@
2831

2932
import java.lang.reflect.Constructor;
3033
import java.lang.reflect.Method;
34+
import java.util.ArrayList;
35+
import java.util.Arrays;
36+
import java.util.List;
3137

3238
/**
3339
* Created by willi on 26.06.16.
@@ -43,14 +49,30 @@ public static Battery getInstance(@NonNull Context context) {
4349
return sInstance;
4450
}
4551

46-
private static final String FORCE_FAST_CHARGE = "/sys/kernel/fast_charge/force_fast_charge";
52+
private static final String FAST_CHARGE = "/sys/kernel/fast_charge";
53+
private static final String FORCE_FAST_CHARGE = FAST_CHARGE + "/force_fast_charge";
54+
private static final String CUSTOM_AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_charge_level";
55+
private static final String CUSTOM_USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_charge_level";
56+
private static final String CUSTOM_WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_charge_level";
57+
58+
private static final String MTP_FORCE_FAST_CHARGE = FAST_CHARGE + "/use_mtp_during_fast_charge";
59+
private static final String SCREEN_ON_CURRENT_LIMT = FAST_CHARGE + "/screen_on_current_limit";
60+
61+
private static final String AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_levels";
62+
private static final String USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_levels";
63+
private static final String WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_levels";
64+
private static final String FAILSAFE_CONTROL = FAST_CHARGE + "/failsafe";
65+
4766
private static final String BLX = "/sys/devices/virtual/misc/batterylifeextender/charging_limit";
4867

4968
private static final String CHARGE_RATE = "/sys/kernel/thundercharge_control";
5069
private static final String CHARGE_RATE_ENABLE = CHARGE_RATE + "/enabled";
5170
private static final String CUSTOM_CURRENT = CHARGE_RATE + "/custom_current";
5271

5372
private int mCapacity;
73+
private static String[] sBatteryAvailable;
74+
private static String[] sBatteryUSBAvailable;
75+
private static String[] sBatteryWIRELESSAvailable;
5476

5577
private Battery(Context context) {
5678
if (mCapacity == 0) {
@@ -104,16 +126,81 @@ public boolean hasBlx() {
104126
return Utils.existFile(BLX);
105127
}
106128

107-
public void enableForceFastCharge(boolean enable, Context context) {
108-
run(Control.write(enable ? "1" : "0", FORCE_FAST_CHARGE), FORCE_FAST_CHARGE, context);
129+
public static List<String> enableForceFastCharge(Context context) {
130+
List<String> list = new ArrayList<>();
131+
list.add(context.getString(R.string.disabled));
132+
list.add(context.getString(R.string.enabled));
133+
list.add(context.getString(R.string.custom_ma));
134+
return list;
135+
}
136+
137+
public static boolean hasForceFastCharge() {
138+
return Utils.existFile(FORCE_FAST_CHARGE);
139+
}
140+
141+
public static int getForceFastCharge() {
142+
return Utils.strToInt(Utils.readFile(FORCE_FAST_CHARGE));
143+
}
144+
145+
public void setForceFastCharge(int value, Context context) {
146+
run(Control.write(String.valueOf(value), FORCE_FAST_CHARGE), FORCE_FAST_CHARGE, context);
109147
}
110148

111-
public boolean isForceFastChargeEnabled() {
112-
return Utils.readFile(FORCE_FAST_CHARGE).equals("1");
149+
public static boolean hasFastChargeControlAC() {
150+
return Utils.existFile(AC_CHARGE_LEVEL);
151+
}
152+
153+
public static String getFastChargeCustomAC() {
154+
return Utils.readFile(CUSTOM_AC_CHARGE_LEVEL);
113155
}
114156

115-
public boolean hasForceFastCharge() {
116-
return Utils.existFile(FORCE_FAST_CHARGE);
157+
public void setFastChargeControlAC (String value, Context context) {
158+
run(Control.write(String.valueOf(value), CUSTOM_AC_CHARGE_LEVEL), CUSTOM_AC_CHARGE_LEVEL, context);
159+
}
160+
161+
public static List<String> getFastChargeControlAC() {
162+
if (sBatteryAvailable == null) {
163+
sBatteryAvailable = Utils.readFile(AC_CHARGE_LEVEL).split(" ");
164+
}
165+
return new ArrayList<>(Arrays.asList(sBatteryAvailable));
166+
}
167+
168+
public static boolean hasFastChargeControlUSB() {
169+
return Utils.existFile(USB_CHARGE_LEVEL);
170+
}
171+
172+
public static String getFastChargeCustomUSB() {
173+
return Utils.readFile(CUSTOM_USB_CHARGE_LEVEL);
174+
}
175+
176+
public static List<String> getFastChargeControlUSB() {
177+
if (sBatteryUSBAvailable == null) {
178+
sBatteryUSBAvailable = Utils.readFile(USB_CHARGE_LEVEL).split(" ");
179+
}
180+
return new ArrayList<>(Arrays.asList(sBatteryUSBAvailable));
181+
}
182+
183+
public void setFastChargeControlUSB (String value, Context context) {
184+
run(Control.write(String.valueOf(value), CUSTOM_USB_CHARGE_LEVEL), CUSTOM_USB_CHARGE_LEVEL, context);
185+
}
186+
187+
public boolean hasFastChargeControlWIRELESS() {
188+
return Utils.existFile(WIRELESS_CHARGE_LEVEL);
189+
}
190+
191+
public static String getFastChargeCustomWIRELESS() {
192+
return Utils.readFile(CUSTOM_WIRELESS_CHARGE_LEVEL);
193+
}
194+
195+
public static List<String> getFastChargeControlWIRELESS() {
196+
if (sBatteryWIRELESSAvailable == null) {
197+
sBatteryWIRELESSAvailable = Utils.readFile(WIRELESS_CHARGE_LEVEL).split(" ");
198+
}
199+
return new ArrayList<>(Arrays.asList(sBatteryWIRELESSAvailable));
200+
}
201+
202+
public void setFastChargeControlWIRELESS (String value, Context context) {
203+
run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context);
117204
}
118205

119206
public int getCapacity() {

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,15 @@
560560
<string name="level">Level</string>
561561
<string name="voltage">Voltage</string>
562562
<string name="capacity">Capacity</string>
563-
<string name="usb_fast_charge">USB Fast Charge</string>
564-
<string name="usb_fast_charge_summary">Device will charge faster when connected with USB. Replug your charger when changing this option.</string>
563+
<string name="usb_fast_charge">Force Fast Charge</string>
564+
<string name="usb_fast_charge_summary">If enabled, the device will charge faster when connected to USB. Select custom mode to charge your device in a custom level. Replug your charger when changing these options.</string>
565+
<string name="custom_ma">Custom Mode</string>
566+
<string name="charge_level_ac">AC Charge Level (mA)</string>
567+
<string name="charge_level_ac_summary">Choose your Level</string>
568+
<string name="charge_level_usb">USB Charge Level (mA)</string>
569+
<string name="charge_level_usb_summary">Choose your Level</string>
570+
<string name="charge_level_wireless">WIRELESS Charge Level (mA)</string>
571+
<string name="charge_level_wireless_summary">Choose your Level</string>
565572
<string name="blx">Battery Life eXtender</string>
566573
<string name="blx_summary">Set a limit for the capacity to which the battery will be charged by passing a value between 0 and 100.</string>
567574
<string name="charge_rate">Charge Rate</string>

0 commit comments

Comments
 (0)