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

Commit 906118b6 authored by Jay Wang's avatar Jay Wang
Browse files

Change charging string in keyguard

Charging speed won't be meaningful when the battery is in a bad state,
so only provide the general charging info in this case.

Bug: 406894719
Flag: EXEMPT bugfix
Test: local test
Change-Id: I48f4121bf0cac84cce54cfa32f7ec5b14c0a9a90
parent 19fe5202
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -16,11 +16,14 @@

package com.android.settingslib.fuelgauge;

import static android.os.BatteryManager.BATTERY_HEALTH_DEAD;
import static android.os.BatteryManager.BATTERY_HEALTH_UNKNOWN;
import static android.os.BatteryManager.BATTERY_STATUS_FULL;
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
import static android.os.BatteryManager.CHARGING_POLICY_ADAPTIVE_LONGLIFE;
import static android.os.BatteryManager.CHARGING_POLICY_DEFAULT;
import static android.os.BatteryManager.EXTRA_CHARGING_STATUS;
import static android.os.BatteryManager.EXTRA_HEALTH;
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;
@@ -55,6 +58,7 @@ public class BatteryStatus {
    public final int status;
    public final int level;
    public final int plugged;
    public final int health;
    public final int chargingStatus;
    public final int maxChargingWattage;
    public final boolean present;
@@ -75,6 +79,7 @@ public class BatteryStatus {
        this.maxChargingWattage = maxChargingWattage;
        this.present = present;
        this.incompatibleCharger = Optional.empty();
        this.health = BATTERY_HEALTH_UNKNOWN;
    }


@@ -90,6 +95,7 @@ public class BatteryStatus {
        status = batteryChangedIntent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
        plugged = batteryChangedIntent.getIntExtra(EXTRA_PLUGGED, 0);
        level = getBatteryLevel(batteryChangedIntent);
        health = batteryChangedIntent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN);
        chargingStatus = batteryChangedIntent.getIntExtra(EXTRA_CHARGING_STATUS,
                CHARGING_POLICY_DEFAULT);
        present = batteryChangedIntent.getBooleanExtra(EXTRA_PRESENT, true);
@@ -140,6 +146,15 @@ public class BatteryStatus {
        return isBatteryDefender(chargingStatus);
    }

    /**
     * Whether battery is dead.
     *
     * @return true if battery is dead
     */
    public boolean isDead() {
        return health == BATTERY_HEALTH_DEAD;
    }

    /** Return current charging speed is fast, slow or normal. */
    public final int getChargingSpeed(Context context) {
        final int slowThreshold = context.getResources().getInteger(
+8 −1
Original line number Diff line number Diff line
@@ -219,6 +219,7 @@ public class KeyguardIndicationController {
    private boolean mBatteryDefender;
    /** Whether the battery defender is triggered with the device plugged. */
    private boolean mEnableBatteryDefender;
    private boolean mBatteryDead;
    private boolean mIncompatibleCharger;
    private int mChargingWattage;
    private int mBatteryLevel = -1;
@@ -1162,6 +1163,12 @@ public class KeyguardIndicationController {
        if (mPowerCharged) {
            return mContext.getResources().getString(R.string.keyguard_charged);
        }

        String percentage = NumberFormat.getPercentInstance().format(mBatteryLevel / 100f);
        if (mBatteryDead) {
            return mContext.getResources().getString(R.string.keyguard_plugged_in, percentage);
        }

        final boolean hasChargingTime = mChargingTimeRemaining > 0;
        int chargingId;
        if (mPowerPluggedInWired) {
@@ -1196,7 +1203,6 @@ public class KeyguardIndicationController {
                    : R.string.keyguard_plugged_in;
        }

        String percentage = NumberFormat.getPercentInstance().format(mBatteryLevel / 100f);
        if (hasChargingTime) {
            String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes(
                    mContext, mChargingTimeRemaining);
@@ -1356,6 +1362,7 @@ public class KeyguardIndicationController {
            mBatteryLevel = status.level;
            mBatteryPresent = status.present;
            mBatteryDefender = isBatteryDefender(status);
            mBatteryDead = status.isDead();
            // when the battery is overheated, device doesn't charge so only guard on pluggedIn:
            mEnableBatteryDefender = mBatteryDefender && status.isPluggedIn();
            mIncompatibleCharger = status.incompatibleCharger.orElse(false);