ChargingControl: Set a small margin for devices with bypass support
Change-Id: I1eddaa85f9dd47283af1fcd43d6fc207bcfd5546
diff --git a/src/org/omnirom/omnilib/internal/health/ChargingControlController.java b/src/org/omnirom/omnilib/internal/health/ChargingControlController.java
index 6263e56..deb3491 100644
--- a/src/org/omnirom/omnilib/internal/health/ChargingControlController.java
+++ b/src/org/omnirom/omnilib/internal/health/ChargingControlController.java
@@ -153,8 +153,6 @@
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);
@@ -171,6 +169,17 @@
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
@@ -405,8 +414,7 @@
return false;
}
- if (!mIsChargingBypassSupported
- && isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) {
+ if (isChargingReasonSet(ChargingStopReason.REACH_LIMIT)) {
return mBatteryPct >= mConfigLimit - mChargingLimitMargin;
}