Skip to content

Commit

Permalink
ChargingControl: Set a small margin for devices with bypass support
Browse files Browse the repository at this point in the history
Change-Id: I1eddaa85f9dd47283af1fcd43d6fc207bcfd5546
Signed-off-by: Mohammad Hasan Keramat J <ikeramat@protonmail.com>
  • Loading branch information
hellobbn authored and bheatleyyy committed Sep 28, 2023
1 parent 5bda666 commit 87b6af7
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -152,8 +152,6 @@ public ChargingControlController(Context context, Handler handler) {

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);
Expand All @@ -170,6 +168,17 @@ public ChargingControlController(Context context, Handler handler) {
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
Expand Down Expand Up @@ -404,8 +413,7 @@ private boolean shouldSetLimitFlag() {
return false;
}

if (!mIsChargingBypassSupported
&& isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) {
if (isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) {
return mBatteryPct >= mConfigLimit - mChargingLimitMargin;
}

Expand Down

0 comments on commit 87b6af7

Please sign in to comment.