2020package com .grarak .kerneladiutor .utils .kernel .battery ;
2121
2222import android .content .Context ;
23+ import android .text .TextUtils ;
24+
25+ import com .grarak .kerneladiutor .R ;
2326import android .support .annotation .NonNull ;
2427
2528import com .grarak .kerneladiutor .fragments .ApplyOnBootFragment ;
2831
2932import java .lang .reflect .Constructor ;
3033import 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 () {
0 commit comments