diff --git a/app/src/main/java/com/grarak/kerneladiutor/fragments/kernel/BatteryFragment.java b/app/src/main/java/com/grarak/kerneladiutor/fragments/kernel/BatteryFragment.java index 8ed3dda3d..d8fc3dd42 100755 --- a/app/src/main/java/com/grarak/kerneladiutor/fragments/kernel/BatteryFragment.java +++ b/app/src/main/java/com/grarak/kerneladiutor/fragments/kernel/BatteryFragment.java @@ -33,6 +33,7 @@ import com.grarak.kerneladiutor.views.recyclerview.CardView; import com.grarak.kerneladiutor.views.recyclerview.RecyclerViewItem; import com.grarak.kerneladiutor.views.recyclerview.SeekBarView; +import com.grarak.kerneladiutor.views.recyclerview.SelectView; import com.grarak.kerneladiutor.views.recyclerview.StatsView; import com.grarak.kerneladiutor.views.recyclerview.SwitchView; @@ -66,6 +67,15 @@ protected void addItems(List items) { if (mBattery.hasForceFastCharge()) { forceFastChargeInit(items); } + if (mBattery.hasFastChargeControlAC()) { + FastChargeControlACinit(items); + } + if (mBattery.hasFastChargeControlUSB()) { + FastChargeControlUSBinit(items); + } + if (mBattery.hasFastChargeControlWIRELESS()) { + FastChargeControlWirelessinit(items); + } if (mBattery.hasBlx()) { blxInit(items); } @@ -98,14 +108,65 @@ private void voltageInit(List items) { } private void forceFastChargeInit(List items) { - SwitchView forceFastCharge = new SwitchView(); - forceFastCharge.setTitle(getString(R.string.usb_fast_charge)); - forceFastCharge.setSummary(getString(R.string.usb_fast_charge_summary)); - forceFastCharge.setChecked(mBattery.isForceFastChargeEnabled()); - forceFastCharge.addOnSwitchListener((switchView, isChecked) - -> mBattery.enableForceFastCharge(isChecked, getActivity())); - - items.add(forceFastCharge); + SelectView forceFastCharge = new SelectView(); + forceFastCharge.setTitle(getString(R.string.usb_fast_charge)); + forceFastCharge.setSummary(getString(R.string.usb_fast_charge_summary)); + forceFastCharge.setItems(mBattery.enableForceFastCharge(getActivity())); + forceFastCharge.setItem(mBattery.getForceFastCharge()); + forceFastCharge.setOnItemSelected(new SelectView.OnItemSelected() { + @Override + public void onItemSelected(SelectView selectView, int position, String item) { + mBattery.setForceFastCharge(position, getActivity()); + } + }); + + items.add(forceFastCharge); + + } + + private void FastChargeControlACinit(List items) { + SelectView FastChargeControl = new SelectView(); + FastChargeControl.setTitle(getString(R.string.charge_level_ac)); + FastChargeControl.setSummary(getString(R.string.charge_level_ac_summary)); + FastChargeControl.setItems(mBattery.getFastChargeControlAC()); + FastChargeControl.setItem(mBattery.getFastChargeCustomAC()); + FastChargeControl.setOnItemSelected(new SelectView.OnItemSelected() { + @Override + public void onItemSelected(SelectView selectView, int position, String item) { + mBattery.setFastChargeControlAC(item, getActivity()); + } + }); + items.add(FastChargeControl); + } + + private void FastChargeControlUSBinit(List items) { + SelectView FastChargeControl = new SelectView(); + FastChargeControl.setTitle(getString(R.string.charge_level_usb)); + FastChargeControl.setSummary(getString(R.string.charge_level_usb_summary)); + FastChargeControl.setItems(mBattery.getFastChargeControlUSB()); + FastChargeControl.setItem(mBattery.getFastChargeCustomUSB()); + FastChargeControl.setOnItemSelected(new SelectView.OnItemSelected() { + @Override + public void onItemSelected(SelectView selectView, int position, String item) { + mBattery.setFastChargeControlUSB(item, getActivity()); + } + }); + items.add(FastChargeControl); + } + + private void FastChargeControlWirelessinit(List items) { + SelectView FastChargeControlWireless = new SelectView(); + FastChargeControlWireless.setTitle(getString(R.string.charge_level_wireless)); + FastChargeControlWireless.setSummary(getString(R.string.charge_level_wireless_summary)); + FastChargeControlWireless.setItems(mBattery.getFastChargeControlWIRELESS()); + FastChargeControlWireless.setItem(mBattery.getFastChargeCustomWIRELESS()); + FastChargeControlWireless.setOnItemSelected(new SelectView.OnItemSelected() { + @Override + public void onItemSelected(SelectView selectView, int position, String item) { + mBattery.setFastChargeControlWIRELESS(item, getActivity()); + } + }); + items.add(FastChargeControlWireless); } private void blxInit(List items) { diff --git a/app/src/main/java/com/grarak/kerneladiutor/utils/kernel/battery/Battery.java b/app/src/main/java/com/grarak/kerneladiutor/utils/kernel/battery/Battery.java index 2fe9e71fe..46234b280 100755 --- a/app/src/main/java/com/grarak/kerneladiutor/utils/kernel/battery/Battery.java +++ b/app/src/main/java/com/grarak/kerneladiutor/utils/kernel/battery/Battery.java @@ -20,6 +20,9 @@ package com.grarak.kerneladiutor.utils.kernel.battery; import android.content.Context; +import android.text.TextUtils; + +import com.grarak.kerneladiutor.R; import android.support.annotation.NonNull; import com.grarak.kerneladiutor.fragments.ApplyOnBootFragment; @@ -28,6 +31,9 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * Created by willi on 26.06.16. @@ -43,7 +49,20 @@ public static Battery getInstance(@NonNull Context context) { return sInstance; } - private static final String FORCE_FAST_CHARGE = "/sys/kernel/fast_charge/force_fast_charge"; + private static final String FAST_CHARGE = "/sys/kernel/fast_charge"; + private static final String FORCE_FAST_CHARGE = FAST_CHARGE + "/force_fast_charge"; + private static final String CUSTOM_AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_charge_level"; + private static final String CUSTOM_USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_charge_level"; + private static final String CUSTOM_WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_charge_level"; + + private static final String MTP_FORCE_FAST_CHARGE = FAST_CHARGE + "/use_mtp_during_fast_charge"; + private static final String SCREEN_ON_CURRENT_LIMT = FAST_CHARGE + "/screen_on_current_limit"; + + private static final String AC_CHARGE_LEVEL = FAST_CHARGE + "/ac_levels"; + private static final String USB_CHARGE_LEVEL = FAST_CHARGE + "/usb_levels"; + private static final String WIRELESS_CHARGE_LEVEL = FAST_CHARGE + "/wireless_levels"; + private static final String FAILSAFE_CONTROL = FAST_CHARGE + "/failsafe"; + private static final String BLX = "/sys/devices/virtual/misc/batterylifeextender/charging_limit"; private static final String CHARGE_RATE = "/sys/kernel/thundercharge_control"; @@ -51,6 +70,9 @@ public static Battery getInstance(@NonNull Context context) { private static final String CUSTOM_CURRENT = CHARGE_RATE + "/custom_current"; private int mCapacity; + private static String[] sBatteryAvailable; + private static String[] sBatteryUSBAvailable; + private static String[] sBatteryWIRELESSAvailable; private Battery(Context context) { if (mCapacity == 0) { @@ -104,16 +126,81 @@ public boolean hasBlx() { return Utils.existFile(BLX); } - public void enableForceFastCharge(boolean enable, Context context) { - run(Control.write(enable ? "1" : "0", FORCE_FAST_CHARGE), FORCE_FAST_CHARGE, context); + public static List enableForceFastCharge(Context context) { + List list = new ArrayList<>(); + list.add(context.getString(R.string.disabled)); + list.add(context.getString(R.string.enabled)); + list.add(context.getString(R.string.custom_ma)); + return list; + } + + public static boolean hasForceFastCharge() { + return Utils.existFile(FORCE_FAST_CHARGE); + } + + public static int getForceFastCharge() { + return Utils.strToInt(Utils.readFile(FORCE_FAST_CHARGE)); + } + + public void setForceFastCharge(int value, Context context) { + run(Control.write(String.valueOf(value), FORCE_FAST_CHARGE), FORCE_FAST_CHARGE, context); } - public boolean isForceFastChargeEnabled() { - return Utils.readFile(FORCE_FAST_CHARGE).equals("1"); + public static boolean hasFastChargeControlAC() { + return Utils.existFile(AC_CHARGE_LEVEL); + } + + public static String getFastChargeCustomAC() { + return Utils.readFile(CUSTOM_AC_CHARGE_LEVEL); } - public boolean hasForceFastCharge() { - return Utils.existFile(FORCE_FAST_CHARGE); + public void setFastChargeControlAC (String value, Context context) { + run(Control.write(String.valueOf(value), CUSTOM_AC_CHARGE_LEVEL), CUSTOM_AC_CHARGE_LEVEL, context); + } + + public static List getFastChargeControlAC() { + if (sBatteryAvailable == null) { + sBatteryAvailable = Utils.readFile(AC_CHARGE_LEVEL).split(" "); + } + return new ArrayList<>(Arrays.asList(sBatteryAvailable)); + } + + public static boolean hasFastChargeControlUSB() { + return Utils.existFile(USB_CHARGE_LEVEL); + } + + public static String getFastChargeCustomUSB() { + return Utils.readFile(CUSTOM_USB_CHARGE_LEVEL); + } + + public static List getFastChargeControlUSB() { + if (sBatteryUSBAvailable == null) { + sBatteryUSBAvailable = Utils.readFile(USB_CHARGE_LEVEL).split(" "); + } + return new ArrayList<>(Arrays.asList(sBatteryUSBAvailable)); + } + + public void setFastChargeControlUSB (String value, Context context) { + run(Control.write(String.valueOf(value), CUSTOM_USB_CHARGE_LEVEL), CUSTOM_USB_CHARGE_LEVEL, context); + } + + public boolean hasFastChargeControlWIRELESS() { + return Utils.existFile(WIRELESS_CHARGE_LEVEL); + } + + public static String getFastChargeCustomWIRELESS() { + return Utils.readFile(CUSTOM_WIRELESS_CHARGE_LEVEL); + } + + public static List getFastChargeControlWIRELESS() { + if (sBatteryWIRELESSAvailable == null) { + sBatteryWIRELESSAvailable = Utils.readFile(WIRELESS_CHARGE_LEVEL).split(" "); + } + return new ArrayList<>(Arrays.asList(sBatteryWIRELESSAvailable)); + } + + public void setFastChargeControlWIRELESS (String value, Context context) { + run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context); } public int getCapacity() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a331fbcb4..d87bfc096 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -560,8 +560,15 @@ Level Voltage Capacity - USB Fast Charge - Device will charge faster when connected with USB. Replug your charger when changing this option. + Force Fast Charge + 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. + Custom Mode + AC Charge Level (mA) + Choose your Level + USB Charge Level (mA) + Choose your Level + WIRELESS Charge Level (mA) + Choose your Level Battery Life eXtender Set a limit for the capacity to which the battery will be charged by passing a value between 0 and 100. Charge Rate