Skip to content

Commit

Permalink
adds charge_full
Browse files Browse the repository at this point in the history
Signed-off-by: Xuefer <[email protected]>
  • Loading branch information
xuefer committed Oct 3, 2016
1 parent f1db5d0 commit 3f8410c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ForceFastChargePreference extends SwitchPreference {
// copied from android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
private static final String EXTRA_MAX_CHARGING_CURRENT = "max_charging_current";
private static final String BATTERY_CURRENT_PATH = "/sys/class/power_supply/max170xx_battery/current_now";
private static final String CHARGE_FULL_PATH = "/sys/class/power_supply/max170xx_battery/charge_full";
private static final String MAX_CHARGING_CURRENT_PATH1 = "/sys/class/power_supply/ac/current_max";
private static final String MAX_CHARGING_CURRENT_PATH2 = "/sys/class/power_supply/usb/current_max";

Expand Down Expand Up @@ -67,29 +68,28 @@ public void onClick(DialogInterface dialog, int which) {
}

void updateChargingStatus() {
String s = Helper.readOneLine(BATTERY_CURRENT_PATH);
final int batteryCurrent = s == null ? -1 : Integer.parseInt(s);
final int batteryCurrent = Helper.readInt(BATTERY_CURRENT_PATH, -1);
final int chargeFull = Helper.readInt(CHARGE_FULL_PATH, -1);
int maxChargingCurrent = batteryStatus_.maxChargingCurrent;
if (maxChargingCurrent == -1) {
s = Helper.readOneLine(MAX_CHARGING_CURRENT_PATH1);
if (s == null) {
s = Helper.readOneLine(MAX_CHARGING_CURRENT_PATH2);
maxChargingCurrent = Helper.readInt(MAX_CHARGING_CURRENT_PATH1, -1);
if (maxChargingCurrent == -1) {
maxChargingCurrent = Helper.readInt(MAX_CHARGING_CURRENT_PATH2, -1);
}
maxChargingCurrent = s == null ? -1000 : Integer.parseInt(s);
}

String max;
if (batteryStatus_.plugged) {
setSummary(getContext().getString(
R.string.force_fast_charge_charging,
batteryCurrent / 1000, maxChargingCurrent / 1000
));
max = getContext().getString(R.string.force_fast_charge_charging, maxChargingCurrent / 1000);
}
else {
setSummary(getContext().getString(
R.string.force_fast_charge_discharging,
batteryCurrent / 1000
));
max = getContext().getString(R.string.force_fast_charge_discharging);
}

setSummary(getContext().getString(
R.string.force_fast_charge_summary,
batteryCurrent / 1000, max, chargeFull / 1000
));
}

private final Handler handler_ = new Handler() {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/net/tonyliu/mi3setting/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public static String readOneLine(String fileName) {
}
}

public static int readInt(String fileName) {
return readInt(fileName, 0);
}

public static int readInt(String fileName, int defaultValue) {
String s = readOneLine(fileName);
return s == null ? defaultValue : Integer.parseInt(s);
}

public static boolean writeLine(String fileName, String value) {
try (FileOutputStream fos = new FileOutputStream(fileName)) {
fos.write(value.getBytes());
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
<string name="extra_settings">附加设置</string>

<string name="force_fast_charge">强制快充识别</string>
<string name="force_fast_charge_charging">电流:%1$dmA\n最大:%2$dmA</string>
<string name="force_fast_charge_charging">%dmA</string>
<string name="force_fast_charge_confirmmessage">启用本功能将会忽略 USB 充电头识别, 并提高最大充电电流到 2100mA。\n实际充电电流依然受限于您的充电头/充电线能力。\n\n由此造成的损坏后果自负。</string>
<string name="force_fast_charge_discharging">电流:%1$dmA(放电中)</string>
<string name="force_fast_charge_discharging">放电中</string>
<string name="force_fast_charge_summary">电流:%1$dmA\n最大:%2$s\n实测最大容量: %3$dmAh</string>

<string name="gps_workaround_executed">已执行 GPS 修复</string>
<string name="gps_workaround_summary">解决 GPS 冷启动问题</string>
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
<string name="extra_settings">Extra Settings</string>

<string name="force_fast_charge">Force Fast Charge</string>
<string name="force_fast_charge_charging">Current: %1$dmA\nMax: %2$dmA</string>
<string name="force_fast_charge_charging">%dmA</string>
<string name="force_fast_charge_confirmmessage">Enableing this feature will ignore USB Adapter Type Detection and lift max charging current up to 2100mA.\nActual charging current is still limited to your AC adapter.\n\nAny damage cause by this feature is at your own risk.</string>
<string name="force_fast_charge_discharging">Current: %1$dmA (Discharging)</string>
<string name="force_fast_charge_discharging">Discharging</string>
<string name="force_fast_charge_summary">Current: %1$dmA\nMax: %2$s\nMeasured capacity: %3$dmAh</string>

<string name="gps_workaround_executed">GPS workaround kicked in</string>
<string name="gps_workaround_summary">Fix GPS startup issue</string>
Expand Down

0 comments on commit 3f8410c

Please sign in to comment.