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

Commit 1253aadb authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/33062870',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/33062870', 'googleplex-android-review.googlesource.com/33113932'] into sparse-13392877-L45400030011494577.
SPARSE_CHANGE: I48f4121bf0cac84cce54cfa32f7ec5b14c0a9a90
SPARSE_CHANGE: Iead9c06835a227ae870ba71d70a9e9461ef64be9

Change-Id: I8ddb9c2c8a815f0268bf6a05f45732a2e077827a
parents 94612df6 7c7e355d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1849,4 +1849,7 @@

    <!-- The name of the screen for seeing and installing system updates. [CHAR LIMIT=40]-->
    <string name="system_update_settings_list_item_title">System Updates</string>

    <!-- The exclamation symbol defined for the batterymeter. [CHAR LIMIT=NONE]-->
    <string name="config_batterymeterExclamationPath" translatable="false">M7 12.5h.5V12 6 5.5H7 5 4.5V6v6 .5H5 7ZM4.9064 16.0629l.0147.016.016.0147c.2966.2719.6605.4064 1.0629.4064.4024 0 .7673-.1352 1.0536-.4214.294-.294.4464-.6629.4464-1.0786 0-.4092-.1485-.7731-.4462-1.0538C6.7731 13.6485 6.4092 13.5 6 13.5c-.4157 0-.7846.1525-1.0785.4464L5.275 14.3l-.3536-.3536C4.6352 14.2327 4.5 14.5976 4.5 15c0 .4023.1345.7663.4064 1.0629Z</string>
</resources>
+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(
+28 −0
Original line number Diff line number Diff line
@@ -68,6 +68,10 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
    private val plusPath = Path()
    private val scaledPlus = Path()

    // Exclamation sign (used for battery alert)
    private val exclamationPath = Path()
    private val scaledExclamation = Path()

    private var intrinsicHeight: Int
    private var intrinsicWidth: Int

@@ -106,6 +110,12 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
            postInvalidate()
        }

    var alertEnabled = false
        set(value) {
            field = value
            postInvalidate()
        }

    private val fillColorStrokePaint = Paint(Paint.ANTI_ALIAS_FLAG).also { p ->
        p.color = frameColor
        p.alpha = 255
@@ -208,6 +218,12 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
            if (!invertFillIcon) {
                c.drawPath(scaledBolt, fillPaint)
            }
        } else if (alertEnabled) {
            // Clip out the exclamation shape
            unifiedPath.op(scaledExclamation, Path.Op.DIFFERENCE)
            if (!invertFillIcon) {
                c.drawPath(scaledExclamation, fillPaint)
            }
        }

        if (dualTone) {
@@ -243,6 +259,13 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
            } else {
                c.drawPath(scaledBolt, fillColorStrokeProtection)
            }
        } else if (alertEnabled) {
            c.clipOutPath(scaledExclamation)
            if (invertFillIcon) {
                c.drawPath(scaledExclamation, fillColorStrokePaint)
            } else {
                c.drawPath(scaledExclamation, fillColorStrokeProtection)
            }
        } else if (powerSaveEnabled) {
            // If power save is enabled draw the level path with colorError
            c.drawPath(levelPath, errorPaint)
@@ -373,6 +396,7 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
        scaledFill.computeBounds(fillRect, true)
        boltPath.transform(scaleMatrix, scaledBolt)
        plusPath.transform(scaleMatrix, scaledPlus)
        exclamationPath.transform(scaleMatrix, scaledExclamation)

        // It is expected that this view only ever scale by the same factor in each dimension, so
        // just pick one to scale the strokeWidths
@@ -408,6 +432,10 @@ open class ThemedBatteryDrawable(private val context: Context, frameColor: Int)
                com.android.internal.R.string.config_batterymeterPowersavePath)
        plusPath.set(PathParser.createPathFromPathData(plusPathString))

        val exclamationPathString = context.resources.getString(
            R.string.config_batterymeterExclamationPath)
        exclamationPath.set(PathParser.createPathFromPathData(exclamationPathString))

        dualTone = context.resources.getBoolean(
                com.android.internal.R.bool.config_batterymeterDualTone)
    }
+14 −6
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.graphics.Rect
import android.graphics.drawable.DrawableWrapper
import android.util.PathParser
import com.android.settingslib.graph.ThemedBatteryDrawable
import com.android.systemui.res.R
import com.android.systemui.battery.BatterySpecs.BATTERY_HEIGHT
import com.android.systemui.battery.BatterySpecs.BATTERY_HEIGHT_WITH_SHIELD
import com.android.systemui.battery.BatterySpecs.BATTERY_WIDTH
@@ -36,6 +35,7 @@ import com.android.systemui.battery.BatterySpecs.BATTERY_WIDTH_WITH_SHIELD
import com.android.systemui.battery.BatterySpecs.SHIELD_LEFT_OFFSET
import com.android.systemui.battery.BatterySpecs.SHIELD_STROKE
import com.android.systemui.battery.BatterySpecs.SHIELD_TOP_OFFSET
import com.android.systemui.res.R

/**
 * A battery drawable that accessorizes [ThemedBatteryDrawable] with additional information if
@@ -43,10 +43,8 @@ import com.android.systemui.battery.BatterySpecs.SHIELD_TOP_OFFSET
 *
 * For now, it adds a shield in the bottom-right corner when [displayShield] is true.
 */
class AccessorizedBatteryDrawable(
    private val context: Context,
    frameColor: Int,
) : DrawableWrapper(ThemedBatteryDrawable(context, frameColor)) {
class AccessorizedBatteryDrawable(private val context: Context, frameColor: Int) :
    DrawableWrapper(ThemedBatteryDrawable(context, frameColor)) {
    private val mainBatteryDrawable: ThemedBatteryDrawable
        get() = drawable as ThemedBatteryDrawable

@@ -105,7 +103,7 @@ class AccessorizedBatteryDrawable(
            b.left,
            b.top,
            /* right= */ b.left + mainWidth.toInt(),
            /* bottom= */ b.top + mainHeight.toInt()
            /* bottom= */ b.top + mainHeight.toInt(),
        )

        if (displayShield) {
@@ -198,6 +196,16 @@ class AccessorizedBatteryDrawable(
        return mainBatteryDrawable.powerSaveEnabled
    }

    /** Sets whether battery alert is enabled. */
    fun setAlertEnabled(alertEnabled: Boolean) {
        mainBatteryDrawable.alertEnabled = alertEnabled
    }

    /** Returns whether battery alert is currently enabled. */
    fun getAlertEnabled(): Boolean {
        return mainBatteryDrawable.alertEnabled
    }

    /** Sets the colors to use for the icon. */
    fun setColors(fgColor: Int, bgColor: Int, singleToneColor: Int) {
        shieldPaint.color = if (dualTone) fgColor else singleToneColor
+13 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
    private boolean mIsIncompatibleCharging;
    // Error state where we know nothing about the current battery state
    private boolean mBatteryStateUnknown;
    private boolean mBatteryStateAlert;
    // Lazily-loaded since this is expected to be a rare-if-ever state
    private Drawable mUnknownStateDrawable;

@@ -610,6 +611,17 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
        updateShowPercent();
    }

    void onBatteryAlertStateChanged(boolean isAlert) {
        if (mBatteryStateAlert == isAlert) {
            return;
        }

        mBatteryStateAlert = isAlert;
        if (!newStatusBarIcons()) {
            mDrawable.setAlertEnabled(isAlert);
        }
    }

    void scaleBatteryMeterViews() {
        if (!newStatusBarIcons()) {
            scaleBatteryMeterViewsLegacy();
@@ -775,6 +787,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
        pw.println("    mBatteryStateUnknown: " + mBatteryStateUnknown);
        pw.println("    mIsIncompatibleCharging: " + mIsIncompatibleCharging);
        pw.println("    mPluggedIn: " + mPluggedIn);
        pw.println("    mBatteryStateAlert: " + mBatteryStateAlert);
        pw.println("    mLevel: " + mLevel);
        pw.println("    mMode: " + mShowPercentMode);
        if (newStatusBarIcons()) {
Loading