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

Commit 1bed4824 authored by YK Hung's avatar YK Hung Committed by Automerger Merge Worker
Browse files

Merge "Fix threshold for fastCharging" into 24D1-dev am: e80119b9

parents 01fbb1fc e80119b9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
    <!-- Threshold in micro watts above which a charger is rated as "fast"; 1.5A @ 5V  -->
    <integer name="config_chargingFastThreshold">7500000</integer>

    <!-- Threshold in micro watts above which a charger is rated as "fast"; 20W  -->
    <integer name="config_chargingFastThreshold_v2">20000000</integer>

    <!-- When true, show 1/2G networks as 3G. -->
    <bool name="config_showMin3G">false</bool>

+9 −2
Original line number Diff line number Diff line
@@ -145,7 +145,8 @@ public class BatteryStatus {
        final int slowThreshold = context.getResources().getInteger(
                R.integer.config_chargingSlowlyThreshold);
        final int fastThreshold = context.getResources().getInteger(
                R.integer.config_chargingFastThreshold);
                getFastChargingThresholdResId());

        return maxChargingWattage <= 0 ? CHARGING_UNKNOWN :
                maxChargingWattage < slowThreshold ? CHARGING_SLOWLY :
                        maxChargingWattage > fastThreshold ? CHARGING_FAST :
@@ -382,7 +383,7 @@ public class BatteryStatus {
                < context.getResources().getInteger(R.integer.config_chargingSlowlyThreshold)) {
            return CHARGING_SLOWLY;
        } else if (maxChargingMicroWatt
                > context.getResources().getInteger(R.integer.config_chargingFastThreshold)) {
                > context.getResources().getInteger(getFastChargingThresholdResId())) {
            return CHARGING_FAST;
        } else {
            return CHARGING_REGULAR;
@@ -410,4 +411,10 @@ public class BatteryStatus {
            return -1;
        }
    }

    private static int getFastChargingThresholdResId() {
        return BatteryUtils.isChargingStringV2Enabled()
                        ? R.integer.config_chargingFastThreshold_v2
                        : R.integer.config_chargingFastThreshold;
    }
}
+13 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.provider.Settings;
import android.util.ArraySet;
import android.view.accessibility.AccessibilityManager;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import java.util.List;
@@ -97,9 +98,18 @@ public final class BatteryUtils {
    /** Used to override the system property to enable or reset for charging string V2. */
    @VisibleForTesting
    public static void setChargingStringV2Enabled(Boolean enabled) {
        setChargingStringV2Enabled(enabled, true /* updateProperty */);
    }

    /** Used to override the system property to enable or reset for charging string V2. */
    @VisibleForTesting
    public static void setChargingStringV2Enabled(
            @Nullable Boolean enabled, boolean updateProperty) {
        if (updateProperty) {
            SystemProperties.set(
                    BatteryUtils.PROPERTY_CHARGING_STRING_V2_KEY,
                    enabled == null ? "" : String.valueOf(enabled));
        }
        BatteryUtils.sChargingStringV2Enabled = enabled;
    }
}
+32 −6
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.settingslib.fuelgauge.BatteryStatus.CHARGING_REGULAR
import com.android.settingslib.fuelgauge.BatteryStatus.CHARGING_SLOWLY
import com.android.settingslib.fuelgauge.BatteryStatus.CHARGING_UNKNOWN
import com.android.settingslib.fuelgauge.BatteryStatus.isBatteryDefender
import com.android.settingslib.fuelgauge.BatteryUtils
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import java.util.Optional
@@ -253,12 +254,17 @@ open class BatteryStatusTest {
        private val maxChargingCurrent: Optional<Int>,
        private val maxChargingVoltage: Optional<Int>,
        private val expectedChargingSpeed: Int,
        private val chargingStringV2Enabled: Boolean,
    ) {

        val context: Context = ApplicationProvider.getApplicationContext()

        @Test
        fun getChargingSpeed_() {
            BatteryUtils.setChargingStringV2Enabled(
                chargingStringV2Enabled,
                false /* updateProperty */
            )
            val batteryChangedIntent =
                Intent(Intent.ACTION_BATTERY_CHANGED).apply {
                    maxChargingCurrent.ifPresent { putExtra(EXTRA_MAX_CHARGING_CURRENT, it) }
@@ -278,37 +284,57 @@ open class BatteryStatusTest {
                        "maxCurrent=n/a, maxVoltage=n/a -> UNKNOWN",
                        Optional.empty<Int>(),
                        Optional.empty<Int>(),
                        CHARGING_UNKNOWN
                        CHARGING_UNKNOWN,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=0, maxVoltage=9000000 -> UNKNOWN",
                        Optional.of(0),
                        Optional.of(0),
                        CHARGING_UNKNOWN
                        CHARGING_UNKNOWN,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=1500000, maxVoltage=5000000 -> CHARGING_REGULAR",
                        Optional.of(1500000),
                        Optional.of(5000000),
                        CHARGING_REGULAR
                        CHARGING_REGULAR,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=1000000, maxVoltage=5000000 -> CHARGING_REGULAR",
                        Optional.of(1000000),
                        Optional.of(5000000),
                        CHARGING_REGULAR
                        CHARGING_REGULAR,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=1500001, maxVoltage=5000000 -> CHARGING_FAST",
                        Optional.of(1501000),
                        Optional.of(5000000),
                        CHARGING_FAST
                        CHARGING_FAST,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=999999, maxVoltage=5000000 -> CHARGING_SLOWLY",
                        Optional.of(999999),
                        Optional.of(5000000),
                        CHARGING_SLOWLY
                        CHARGING_SLOWLY,
                        false /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=3000000, maxVoltage=9000000 -> CHARGING_FAST",
                        Optional.of(3000000),
                        Optional.of(9000000),
                        CHARGING_FAST,
                        true /* chargingStringV2Enabled */
                    ),
                    arrayOf(
                        "maxCurrent=2200000, maxVoltage=9000000 -> CHARGING_REGULAR",
                        Optional.of(2200000),
                        Optional.of(9000000),
                        CHARGING_REGULAR,
                        true /* chargingStringV2Enabled */
                    ),
                )
        }