Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 0W 0V on charging info lock screen #1

Open
wants to merge 2 commits into
base: 15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public static int getChargingSpeed(Context context, Intent batteryChangedIntent)
*/
public static int calculateChargingSpeed(
Context context, int maxChargingMicroCurrent, int maxChargingMicroVolt) {
final int maxChargingMicroWatt =
final float maxChargingMicroWatt =
calculateMaxChargingMicroWatt(maxChargingMicroCurrent, maxChargingMicroVolt);

if (maxChargingMicroWatt <= 0) {
Expand All @@ -413,23 +413,23 @@ public static int calculateChargingSpeed(
}
}

private static int calculateMaxChargingMicroWatt(Intent batteryChangedIntent) {
private static float calculateMaxChargingMicroWatt(Intent batteryChangedIntent) {
final int maxChargingMicroAmp =
batteryChangedIntent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
int maxChargingMicroVolt = batteryChangedIntent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1);

return calculateMaxChargingMicroWatt(maxChargingMicroAmp, maxChargingMicroVolt);
}

private static int calculateMaxChargingMicroWatt(int maxChargingMicroAmp,
private static float calculateMaxChargingMicroWatt(int maxChargingMicroAmp,
int maxChargingMicroVolt) {
if (maxChargingMicroVolt <= 0) {
maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;
}

if (maxChargingMicroAmp > 0) {
// Calculating µW = mA * mV
return (int) Math.round(maxChargingMicroAmp * 0.001 * maxChargingMicroVolt * 0.001);
return (float)(maxChargingMicroAmp * 0.001 * maxChargingMicroVolt * 0.001);
} else {
return -1;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/SystemUI/res/values/voltage_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<!-- Charging info current divider, if needed -->
<integer name="config_currentInfoDivider" translatable="false">1000</integer>

<!-- Charging info voltage divider, if needed -->
<integer name="config_voltageInfoDivider" translatable="false">1000</integer>

<!-- Update battery info every second when device is charging -->
<bool name="config_alternateFastchargeInfoUpdate">false</bool>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public class KeyguardIndicationController {
private boolean mFaceDetectionRunning;

private int mCurrentDivider;
private int mVoltageDivider;

private boolean mHasDashCharger;
private boolean mHasWarpCharger;
Expand Down Expand Up @@ -436,6 +437,7 @@ public void init() {
mStatusBarStateListener.onDozingChanged(mStatusBarStateController.isDozing());

mCurrentDivider = mContext.getResources().getInteger(R.integer.config_currentInfoDivider);
mVoltageDivider = mContext.getResources().getInteger(R.integer.config_voltageInfoDivider);

mAlternateFastchargeInfoUpdate =
mContext.getResources().getBoolean(R.bool.config_alternateFastchargeInfoUpdate);
Expand Down Expand Up @@ -1401,13 +1403,16 @@ protected String computePowerChargingStringIndication() {
} else if (mChargingCurrent > 0) {
batteryInfo = String.format("%.0f" , (mChargingCurrent / mCurrentDivider)) + "mA";
}
if (mChargingWattage > 0) {
batteryInfo = (batteryInfo == "" ? "" : batteryInfo + " · ") +
String.format("%.1f" , (mChargingWattage / mCurrentDivider / 1000)) + "W";
if (mChargingWattage >= mVoltageDivider) {
batteryInfo = (batteryInfo.isEmpty() ? "" : batteryInfo + " · ") +
String.format("%.2f", (mChargingWattage / mVoltageDivider)) + "W";
} else if (mChargingWattage > 0) {
batteryInfo = (batteryInfo.isEmpty() ? "" : batteryInfo + " · ") +
String.format("%.0f", (mChargingWattage * 1000 / mVoltageDivider)) + "mW";
}
if (mChargingVoltage > 0) {
batteryInfo = (batteryInfo == "" ? "" : batteryInfo + " · ") +
String.format("%.1f", (mChargingVoltage / 1000 / 1000)) + "V";
String.format("%.1f", (mChargingVoltage / mVoltageDivider / 1000)) + "V";
}
if (mTemperature > 0) {
batteryInfo = (batteryInfo == "" ? "" : batteryInfo + " · ") +
Expand Down