[Bug Fix] "Dock defend string and tips in settings are incorrectly" issue

Symptom: After the dock defend was triggered, the battery tips still
show "Future-Bypass" dock defend mode. It should be the "Active" dock
defend mode.

Root Cause: The original `BatteryInfo.isBatteryDefender` was implemented
by using `longlife`, due to the charging limit also reuse `longlife`
issue, we replace the implementation of `BatteryInfo.isBatteryDefender`
with HAL API call `isTempDefend` and `isDwellDefend`. However, the
dock defend also needs `longlife`, the original
`BatteryInfo.isBatteryDefender`. So the dock defend checking failed
after replacing the implementation of `BatteryInfo.isBatteryDefender`

Solution:
- Add new property isLonglife in BatteryInfo
- Replace all isBatteryDefender reference that needs isLonglife

Bug: 348563863
Test: Manual Test and robotest
Test: http://ab/I08300010291126076 (unit test)
Test: http://ab/I67800010291096764 (robo test)
Flag: EXEMPT bugfix
Change-Id: I58424927522acc29dc49261a2c24829a5b34ef85
This commit is contained in:
pajacechen
2024-06-26 14:56:58 +08:00
parent af053aa3cc
commit daeb06c3b0
7 changed files with 59 additions and 26 deletions

View File

@@ -53,7 +53,8 @@ public class BatteryInfo {
public int batteryStatus;
public int pluggedStatus;
public boolean discharging = true;
public boolean isBatteryDefender;
public boolean isBatteryDefender = false;
public boolean isLongLife = false;
public boolean isFastCharging;
public long remainingTimeUs = 0;
public long averageTimeToDischarge = EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
@@ -306,7 +307,7 @@ public class BatteryInfo {
info.pluggedStatus = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
info.mCharging = info.pluggedStatus != 0;
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
info.isBatteryDefender =
info.isLongLife =
batteryBroadcast.getIntExtra(
BatteryManager.EXTRA_CHARGING_STATUS,
BatteryManager.CHARGING_POLICY_DEFAULT)
@@ -319,7 +320,7 @@ public class BatteryInfo {
info.isFastCharging =
BatteryStatus.getChargingSpeed(context, batteryBroadcast)
== BatteryStatus.CHARGING_FAST;
if (info.isBatteryDefender) {
if (info.isLongLife) {
info.isBatteryDefender =
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()

View File

@@ -600,12 +600,12 @@ public class BatteryUtils {
context.getContentResolver(), SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS, 0)
== 1) {
return DockDefenderMode.TEMPORARILY_BYPASSED;
} else if (batteryInfo.isBatteryDefender
} else if (batteryInfo.isLongLife
&& FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()
.isExtraDefend()) {
return DockDefenderMode.ACTIVE;
} else if (!batteryInfo.isBatteryDefender) {
} else if (!batteryInfo.isLongLife) {
return DockDefenderMode.FUTURE_BYPASS;
}
}

View File

@@ -247,7 +247,7 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
@Override
public boolean isBatteryDefend(BatteryInfo info) {
return info.isBatteryDefender && !isExtraDefend();
return info.isLongLife && !isExtraDefend();
}
@Override

View File

@@ -21,7 +21,6 @@ import android.content.Context;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory;
/** Detect whether the battery is overheated */
public class BatteryDefenderDetector implements BatteryTipDetector {
@@ -35,12 +34,10 @@ public class BatteryDefenderDetector implements BatteryTipDetector {
@Override
public BatteryTip detect() {
final boolean isBasicBatteryDefend =
FeatureFactory.getFeatureFactory()
.getPowerUsageFeatureProvider()
.isBatteryDefend(mBatteryInfo);
final int state =
isBasicBatteryDefend ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
mBatteryInfo.isBatteryDefender
? BatteryTip.StateType.NEW
: BatteryTip.StateType.INVISIBLE;
final boolean isPluggedIn = mBatteryInfo.pluggedStatus != 0;
return new BatteryDefenderTip(state, isPluggedIn);
}