From c2dbc740320132fc0b1895bf9d684d9fb5399e4d Mon Sep 17 00:00:00 2001 From: Luofan Chen Date: Tue, 13 Jun 2023 10:52:26 +0800 Subject: [PATCH] ChargingControl: Set a small margin for devices with bypass support Change-Id: I1eddaa85f9dd47283af1fcd43d6fc207bcfd5546 --- .../health/ChargingControlController.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java b/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java index bf758da7..21c399f9 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/health/ChargingControlController.java @@ -152,8 +152,6 @@ public class ChargingControlController extends LineageHealthFeature { mChargingTimeMargin = mContext.getResources().getInteger( R.integer.config_chargingControlTimeMargin) * 60 * 1000; - mChargingLimitMargin = mContext.getResources().getInteger( - R.integer.config_chargingControlBatteryRechargeMargin); mDefaultEnabled = mContext.getResources().getBoolean( R.bool.config_chargingControlEnabled); @@ -170,6 +168,17 @@ public class ChargingControlController extends LineageHealthFeature { mIsChargingBypassSupported = isChargingModeSupported(ChargingControlSupportedMode.BYPASS); mIsChargingDeadlineSupported = isChargingModeSupported( ChargingControlSupportedMode.DEADLINE); + + if (mIsChargingBypassSupported) { + // This is a workaround for devices that support charging bypass, but is not able to + // hold the charging current to 0mA, which causes battery to lose power very slowly. + // This will become a problem in limit mode because it will stop charge at limit and + // immediately resume charging at (limit - 1). So we add a small margin here. + mChargingLimitMargin = 1; + } else { + mChargingLimitMargin = mContext.getResources().getInteger( + R.integer.config_chargingControlBatteryRechargeMargin); + } } @Override @@ -404,8 +413,7 @@ public class ChargingControlController extends LineageHealthFeature { return false; } - if (!mIsChargingBypassSupported - && isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) { + if (isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) { return mBatteryPct >= mConfigLimit - mChargingLimitMargin; }