From 077b413c5c4988b71e0daf2d8167353935008344 Mon Sep 17 00:00:00 2001 From: Soul Spark Date: Sun, 29 Dec 2024 07:18:04 +0000 Subject: [PATCH 1/2] feat: add voltageDivider config for device like Realme --- packages/SystemUI/res/values/voltage_config.xml | 3 +++ .../statusbar/KeyguardIndicationController.java | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/res/values/voltage_config.xml b/packages/SystemUI/res/values/voltage_config.xml index 00ed1fb1d56e1..ecb584a797ecc 100644 --- a/packages/SystemUI/res/values/voltage_config.xml +++ b/packages/SystemUI/res/values/voltage_config.xml @@ -25,6 +25,9 @@ 1000 + + 1000 + false diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 36e0dc51b212a..7d08e4e6c8426 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -241,6 +241,7 @@ public class KeyguardIndicationController { private boolean mFaceDetectionRunning; private int mCurrentDivider; + private int mVoltageDivider; private boolean mHasDashCharger; private boolean mHasWarpCharger; @@ -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); @@ -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 + " · ") + From b25e60e0f96373aefbe3978077d98bfe87c68b72 Mon Sep 17 00:00:00 2001 From: Soul Spark Date: Sun, 29 Dec 2024 10:53:01 +0000 Subject: [PATCH 2/2] feat: allow Wattage to be more significant Since value while calculation is in float and the place where it is used is also float. --- .../com/android/settingslib/fuelgauge/BatteryStatus.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java index 171b5fb34801f..3697c2e98dbcd 100644 --- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java +++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatteryStatus.java @@ -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) { @@ -413,7 +413,7 @@ 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); @@ -421,7 +421,7 @@ private static int calculateMaxChargingMicroWatt(Intent batteryChangedIntent) { 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; @@ -429,7 +429,7 @@ private static int calculateMaxChargingMicroWatt(int maxChargingMicroAmp, 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; }