From fd486e2e50f370a6a5df3cd6e4f74dcb018d5d81 Mon Sep 17 00:00:00 2001 From: sunilpaulmathew Date: Wed, 21 Mar 2018 14:34:25 +0900 Subject: [PATCH] Advanced charge control interface: simplifying a bit Signed-off-by: sunilpaulmathew --- .../fragments/kernel/BatteryFragment.java | 148 +++--------------- .../utils/kernel/battery/Battery.java | 75 ++------- app/src/main/res/values/strings.xml | 25 ++- 3 files changed, 42 insertions(+), 206 deletions(-) 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 4ce0006be..efa99429e 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 @@ -65,31 +65,12 @@ protected void init() { protected void addItems(List items) { levelInit(items); voltageInit(items); - fastChargeControlInit(items); chargeRateInit(items); if (mBattery.hasBlx()) { blxInit(items); } if (mBattery.hasForceFastCharge()) { - ForceFastChargeInit(items); - } - if (mBattery.hasFastChargeControlAC()) { - FastChargeControlACinit(items); - } - if (mBattery.hasFastChargeControlUSB()) { - FastChargeControlUSBinit(items); - } - if (mBattery.hasFastChargeControlWIRELESS()) { - FastChargeControlWirelessinit(items); - } - if (mBattery.hasMtpForceFastCharge()) { - MtpFastChargeInit(items); - } - if (mBattery.hasScreenCurrentLimit()) { - ScreenCurrentLimitInit(items); - } - if (mBattery.hasChargeCustomAC()) { - WarningChargingInit(items); + fastChargeInit(items); } } @@ -118,14 +99,11 @@ private void voltageInit(List items) { items.add(mVoltage); } - private void fastChargeControlInit(List items) { - CardView FastChargeCard = new CardView(getActivity()); - FastChargeCard.setTitle(getString(R.string.charge_levels)); - - items.add(FastChargeCard); - } + private void fastChargeInit(List items) { + CardView fastChargeCard = new CardView(getActivity()); + fastChargeCard.setTitle(getString(R.string.acci)); - private void ForceFastChargeInit(List items) { + if (mBattery.hasForceFastCharge()) { SelectView forceFastCharge = new SelectView(); forceFastCharge.setTitle(getString(R.string.fast_charge)); forceFastCharge.setSummary(getString(R.string.fast_charge_summary)); @@ -138,10 +116,11 @@ public void onItemSelected(SelectView selectView, int position, String item) { } }); - items.add(forceFastCharge); + fastChargeCard.addItem(forceFastCharge); + } - private void FastChargeControlACinit(List items) { + if (mBattery.hasFastChargeControlAC()) { SelectView ACLevelCard = new SelectView(); ACLevelCard.setTitle(getString(R.string.charge_level_ac)); ACLevelCard.setSummary(getString(R.string.charge_level_ac_summary)); @@ -153,10 +132,11 @@ public void onItemSelected(SelectView selectView, int position, String item) { mBattery.setFastChargeControlAC(item, getActivity()); } }); - items.add(ACLevelCard); + fastChargeCard.addItem(ACLevelCard); + } - private void FastChargeControlUSBinit(List items) { + if (mBattery.hasFastChargeControlUSB()) { SelectView USBLevelCard = new SelectView(); USBLevelCard.setTitle(getString(R.string.charge_level_usb)); USBLevelCard.setSummary(getString(R.string.charge_level_usb_summary)); @@ -168,10 +148,10 @@ public void onItemSelected(SelectView selectView, int position, String item) { mBattery.setFastChargeControlUSB(item, getActivity()); } }); - items.add(USBLevelCard); + fastChargeCard.addItem(USBLevelCard); } - private void FastChargeControlWirelessinit(List items) { + if (mBattery.hasFastChargeControlWIRELESS()) { SelectView WirelessLevelCard = new SelectView(); WirelessLevelCard.setTitle(getString(R.string.charge_level_wireless)); WirelessLevelCard.setSummary(getString(R.string.charge_level_wireless_summary)); @@ -183,10 +163,10 @@ public void onItemSelected(SelectView selectView, int position, String item) { mBattery.setFastChargeControlWIRELESS(item, getActivity()); } }); - items.add(WirelessLevelCard); + fastChargeCard.addItem(WirelessLevelCard); } - private void MtpFastChargeInit(List items) { + if (mBattery.hasMtpForceFastCharge()) { SwitchView MtpFastCharge = new SwitchView(); MtpFastCharge.setTitle(getString(R.string.mtp_fast_charge)); MtpFastCharge.setSummary(getString(R.string.mtp_fast_charge_summary)); @@ -198,10 +178,10 @@ public void onChanged(SwitchView switchView, boolean isChecked) { } }); - items.add(MtpFastCharge); + fastChargeCard.addItem(MtpFastCharge); } - private void ScreenCurrentLimitInit(List items) { + if (mBattery.hasScreenCurrentLimit()) { SwitchView ScreenLimit = new SwitchView(); ScreenLimit.setTitle(getString(R.string.screen_limit)); ScreenLimit.setSummary(getString(R.string.screen_limit_summary)); @@ -213,99 +193,11 @@ public void onChanged(SwitchView switchView, boolean isChecked) { } }); - items.add(ScreenLimit); - } - - private void WarningChargingInit(List items) { - CardView WarningChargeCard = new CardView(getActivity()); - WarningChargeCard.setTitle(getString(R.string.warning_charge)); - - if (mBattery.hasFailsafe()) { - SwitchView Failsafe = new SwitchView(); - Failsafe.setTitle(getString(R.string.failsafe)); - Failsafe.setSummary(getString(R.string.failsafe_summary)); - Failsafe.setChecked(mBattery.isFailsafe()); - Failsafe.addOnSwitchListener(new SwitchView.OnSwitchListener() { - @Override - public void onChanged(SwitchView switchView, boolean isChecked) { - mBattery.enableFailsafe(isChecked, getActivity()); - } - }); - - WarningChargeCard.addItem(Failsafe); - } - - if (mBattery.hasFastChargeCustomAC()) { - SeekBarView chargingCustomAC = new SeekBarView(); - chargingCustomAC.setTitle(getString(R.string.charging_custom_ac)); - chargingCustomAC.setSummary(getString(R.string.charging_current_ac_summary)); - chargingCustomAC.setUnit(getString(R.string.ma)); - chargingCustomAC.setMax(2200); - chargingCustomAC.setMin(100); - chargingCustomAC.setOffset(10); - chargingCustomAC.setProgress(mBattery.getChargeCustomAC() / 10 - 10 ); - chargingCustomAC.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { - @Override - public void onMove(SeekBarView seekBarView, int position, String value) { - } - - @Override - public void onStop(SeekBarView seekBarView, int position, String value) { - mBattery.setChargeControlAC((position + 10) * 10, getActivity()); - } - }); - - WarningChargeCard.addItem(chargingCustomAC); - } - - if (mBattery.hasFastChargeCustomUSB()) { - SeekBarView chargingCustomUSB = new SeekBarView(); - chargingCustomUSB.setTitle(getString(R.string.charging_custom_usb)); - chargingCustomUSB.setSummary(getString(R.string.charging_current_usb_summary)); - chargingCustomUSB.setUnit(getString(R.string.ma)); - chargingCustomUSB.setMax(1200); - chargingCustomUSB.setMin(100); - chargingCustomUSB.setOffset(10); - chargingCustomUSB.setProgress(mBattery.getChargeCustomUSB() / 10 - 10); - chargingCustomUSB.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { - @Override - public void onStop(SeekBarView seekBarView, int position, String value) { - mBattery.setChargeControlUSB((position + 10) * 10, getActivity()); - } - - @Override - public void onMove(SeekBarView seekBarView, int position, String value) { - } - }); - - WarningChargeCard.addItem(chargingCustomUSB); - } - - if (mBattery.hasFastChargeCustomWireless()) { - SeekBarView chargingCustomWireless = new SeekBarView(); - chargingCustomWireless.setTitle(getString(R.string.charging_custom_wireless)); - chargingCustomWireless.setSummary(getString(R.string.charging_current_wireless_summary)); - chargingCustomWireless.setUnit(getString(R.string.ma)); - chargingCustomWireless.setMax(1400); - chargingCustomWireless.setMin(100); - chargingCustomWireless.setOffset(10); - chargingCustomWireless.setProgress(mBattery.getChargeCustomWireless() / 10 - 10 ); - chargingCustomWireless.setOnSeekBarListener(new SeekBarView.OnSeekBarListener() { - @Override - public void onMove(SeekBarView seekBarView, int position, String value) { - } - - @Override - public void onStop(SeekBarView seekBarView, int position, String value) { - mBattery.setChargeControlWireless((position + 10) * 10, getActivity()); - } - }); - - WarningChargeCard.addItem(chargingCustomWireless); + fastChargeCard.addItem(ScreenLimit); } - if (WarningChargeCard.size() > 0) { - items.add(WarningChargeCard); + if (fastChargeCard.size() > 0) { + items.add(fastChargeCard); } } 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 69b3f83d2..87811d080 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 @@ -49,19 +49,22 @@ 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 MTP_FORCE_FAST_CHARGE = "/sys/kernel/fast_charge/use_mtp_during_fast_charge"; - private static final String SCREEN_ON_CURRENT_LIMT = "/sys/kernel/fast_charge/screen_on_current_limit"; - private static final String BLX = "/sys/devices/virtual/misc/batterylifeextender/charging_limit"; - private static final String AC_CHARGE_LEVEL = "/sys/kernel/fast_charge/ac_levels"; - private static final String USB_CHARGE_LEVEL = "/sys/kernel/fast_charge/usb_levels"; - private static final String WIRELESS_CHARGE_LEVEL = "/sys/kernel/fast_charge/wireless_levels"; - private static final String FAILSAFE_CONTROL = "/sys/kernel/fast_charge/failsafe"; 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"; private static final String CHARGE_RATE_ENABLE = CHARGE_RATE + "/enabled"; private static final String CUSTOM_CURRENT = CHARGE_RATE + "/custom_current"; @@ -145,32 +148,16 @@ public void setForceFastCharge(int value, Context context) { public static boolean hasFastChargeControlAC() { return Utils.existFile(AC_CHARGE_LEVEL); - } - - public static boolean hasFastChargeCustomAC() { - return Utils.existFile(CUSTOM_AC_CHARGE_LEVEL); - } - - public static boolean hasChargeCustomAC() { - return Utils.existFile(CUSTOM_AC_CHARGE_LEVEL); - } - + } + public static String getFastChargeCustomAC() { return Utils.readFile(CUSTOM_AC_CHARGE_LEVEL); } - - public static int getChargeCustomAC() { - return Utils.strToInt(Utils.readFile(CUSTOM_AC_CHARGE_LEVEL)); - } public void setFastChargeControlAC (String value, Context context) { run(Control.write(String.valueOf(value), CUSTOM_AC_CHARGE_LEVEL), CUSTOM_AC_CHARGE_LEVEL, context); } - public void setChargeControlAC(int 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(" "); @@ -181,19 +168,11 @@ public static List getFastChargeControlAC() { public static boolean hasFastChargeControlUSB() { return Utils.existFile(USB_CHARGE_LEVEL); } - - public static boolean hasFastChargeCustomUSB() { - return Utils.existFile(CUSTOM_USB_CHARGE_LEVEL); - } public static String getFastChargeCustomUSB() { return Utils.readFile(CUSTOM_USB_CHARGE_LEVEL); } - public static int getChargeCustomUSB() { - return Utils.strToInt(Utils.readFile(CUSTOM_USB_CHARGE_LEVEL)); - } - public static List getFastChargeControlUSB() { if (sBatteryUSBAvailable == null) { sBatteryUSBAvailable = Utils.readFile(USB_CHARGE_LEVEL).split(" "); @@ -205,10 +184,6 @@ public void setFastChargeControlUSB (String value, Context context) { run(Control.write(String.valueOf(value), CUSTOM_USB_CHARGE_LEVEL), CUSTOM_USB_CHARGE_LEVEL, context); } - public void setChargeControlUSB(int 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); } @@ -228,18 +203,6 @@ public void setFastChargeControlWIRELESS (String value, Context context) { run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context); } - public static boolean hasFastChargeCustomWireless() { - return Utils.existFile(CUSTOM_WIRELESS_CHARGE_LEVEL); - } - - public int getChargeCustomWireless() { - return Utils.strToInt(Utils.readFile(CUSTOM_WIRELESS_CHARGE_LEVEL)); - } - - public void setChargeControlWireless(int value, Context context) { - run(Control.write(String.valueOf(value), CUSTOM_WIRELESS_CHARGE_LEVEL), CUSTOM_WIRELESS_CHARGE_LEVEL, context); - } - public void enableMtpForceFastCharge(boolean enable, Context context) { run(Control.write(enable ? "1" : "0", MTP_FORCE_FAST_CHARGE), MTP_FORCE_FAST_CHARGE, context); } @@ -263,18 +226,6 @@ public boolean isScreenCurrentLimit() { public boolean hasScreenCurrentLimit() { return Utils.existFile(SCREEN_ON_CURRENT_LIMT); } - - public void enableFailsafe(boolean enable, Context context) { - run(Control.write(enable ? "1" : "0", FAILSAFE_CONTROL), FAILSAFE_CONTROL, context); - } - - public boolean isFailsafe() { - return Utils.readFile(FAILSAFE_CONTROL).equals("1"); - } - - public boolean hasFailsafe() { - return Utils.existFile(FAILSAFE_CONTROL); - } public int getCapacity() { return mCapacity; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 61cf4664e..d5cfa4fb0 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -567,29 +567,22 @@ Charge Rate Charging Current Set charging current. Caution: Exceeding 1250mA may damage your charging driver. - Fast Charge Advanced Control Interface + + + Advanced Charge Control Interface Fast Charge In Custom Mode, the device will charge as per the selected level. Replug your charger when changing this option. Custom Mode - AC Charge mA + AC Charge Level (mA) Choose your Level - USB Charge mA + USB Charge Level (mA) Choose your Level - WIRELESS Charge mA + WIRELESS Charge Level (mA) Choose your Level - MTP During Fast Charge - You can choose if you want MTP during fast charge or not. + MTP while Fast Charge + Enable MTP while fast charge Screen On Current Limit - Our device majorly reduces the amount of power it draws from the power supply when the screen is on. This happens with and without fast charging capable adapters. - WARNING CHARGE AREA - Charging Current AC - Set charging current. Caution: Exceeding 2100mA may damage your equipment. - Charging Current USB - Set charging current. Caution: Exceeding 1000mA may damage your USB driver. - Charging Current WIRELESS - Set charging current. Caution: Exceeding 1200mA may damage your equipment. - Failsafe - If disabled, you can choose your charging current that is not supported by your equipment (i have limited for secure...) + Enable Screen On Current Limit Fade