Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c859ae9 authored by Adrian Roos's avatar Adrian Roos
Browse files

Charging speed based on voltage

Also takes into account the voltage
at which we charge to make speeds
at different voltages comparable.

Bug: 25229483
Change-Id: I62a192932a013036585cd9fc870808debceac0d3
parent d273c053
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@
    <!-- Allow the menu hard key to be disabled in LockScreen on some devices [DO NOT TRANSLATE] -->
    <bool name="config_disableMenuKeyInLockScreen">false</bool>

    <!-- Threshold in micro amperes below which a charger is rated as "slow" -->
    <integer name="config_chargingSlowlyThreshold">1000000</integer>
    <!-- Threshold in micro watts below which a charger is rated as "slow"; 1A @ 5V -->
    <integer name="config_chargingSlowlyThreshold">5000000</integer>

    <!-- Threshold in micro amperes above which a charger is rated as "fast" -->
    <integer name="config_chargingFastThreshold">1500000</integer>
    <!-- Threshold in micro watts above which a charger is rated as "fast"; 1.5A @ 5V  -->
    <integer name="config_chargingFastThreshold">7500000</integer>
</resources>
+28 −9
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
import static android.os.BatteryManager.EXTRA_HEALTH;
import static android.os.BatteryManager.EXTRA_LEVEL;
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_CURRENT;
import static android.os.BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE;
import static android.os.BatteryManager.EXTRA_PLUGGED;
import static android.os.BatteryManager.EXTRA_STATUS;

@@ -155,6 +156,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
     */
    private static final int FINGERPRINT_STATE_CANCELLING_RESTARTING = 3;

    private static final int DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT = 5000000;

    private static KeyguardUpdateMonitor sInstance;

    private final Context mContext;
@@ -616,10 +619,25 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
                final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0);
                final int level = intent.getIntExtra(EXTRA_LEVEL, 0);
                final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
                final int maxChargingCurrent = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);

                final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1);
                int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1);
                final int maxChargingMicroWatt;

                if (maxChargingMicroVolt <= 0) {
                    maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT;
                }
                if (maxChargingMicroAmp > 0) {
                    // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor
                    // to maintain precision equally on both factors.
                    maxChargingMicroWatt = (maxChargingMicroAmp / 1000)
                            * (maxChargingMicroVolt / 1000);
                } else {
                    maxChargingMicroWatt = -1;
                }
                final Message msg = mHandler.obtainMessage(
                        MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health,
                        maxChargingCurrent));
                                maxChargingMicroWatt));
                mHandler.sendMessage(msg);
            } else if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
                SimData args = SimData.fromIntent(intent);
@@ -803,13 +821,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        public final int level;
        public final int plugged;
        public final int health;
        public final int maxChargingCurrent;
        public BatteryStatus(int status, int level, int plugged, int health, int maxChargingCurrent) {
        public final int maxChargingWattage;
        public BatteryStatus(int status, int level, int plugged, int health,
                int maxChargingWattage) {
            this.status = status;
            this.level = level;
            this.plugged = plugged;
            this.health = health;
            this.maxChargingCurrent = maxChargingCurrent;
            this.maxChargingWattage = maxChargingWattage;
        }

        /**
@@ -841,9 +860,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        }

        public final int getChargingSpeed(int slowThreshold, int fastThreshold) {
            return maxChargingCurrent <= 0 ? CHARGING_UNKNOWN :
                    maxChargingCurrent < slowThreshold ? CHARGING_SLOWLY :
                    maxChargingCurrent > fastThreshold ? CHARGING_FAST :
            return maxChargingWattage <= 0 ? CHARGING_UNKNOWN :
                    maxChargingWattage < slowThreshold ? CHARGING_SLOWLY :
                    maxChargingWattage > fastThreshold ? CHARGING_FAST :
                    CHARGING_REGULAR;
        }
    }
@@ -1419,7 +1438,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
        }

        // change in charging current while plugged in
        if (nowPluggedIn && current.maxChargingCurrent != old.maxChargingCurrent) {
        if (nowPluggedIn && current.maxChargingWattage != old.maxChargingWattage) {
            return true;
        }

+6 −6
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
 */
public class KeyguardIndicationController {

    private static final String TAG = "KeyguardIndicationController";
    private static final boolean DEBUG_CHARGING_CURRENT = false;
    private static final String TAG = "KeyguardIndication";
    private static final boolean DEBUG_CHARGING_SPEED = false;

    private static final int MSG_HIDE_TRANSIENT = 1;
    private static final int MSG_CLEAR_FP_MSG = 2;
@@ -72,7 +72,7 @@ public class KeyguardIndicationController {
    private boolean mPowerPluggedIn;
    private boolean mPowerCharged;
    private int mChargingSpeed;
    private int mChargingCurrent;
    private int mChargingWattage;
    private String mMessageToShowOnScreenOn;

    public KeyguardIndicationController(Context context, KeyguardIndicationTextView textView,
@@ -173,8 +173,8 @@ public class KeyguardIndicationController {
        }
        if (mPowerPluggedIn) {
            String indication = computePowerIndication();
            if (DEBUG_CHARGING_CURRENT) {
                indication += ",  " + (mChargingCurrent / 1000) + " mA";
            if (DEBUG_CHARGING_SPEED) {
                indication += ",  " + (mChargingWattage / 1000) + " mW";
            }
            return indication;
        }
@@ -231,7 +231,7 @@ public class KeyguardIndicationController {
                    || status.status == BatteryManager.BATTERY_STATUS_FULL;
            mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull;
            mPowerCharged = status.isCharged();
            mChargingCurrent = status.maxChargingCurrent;
            mChargingWattage = status.maxChargingWattage;
            mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold);
            updateIndication();
        }