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

Commit a4ac0361 authored by Yiling Chuang's avatar Yiling Chuang
Browse files

Add isBatteryDefenderMode method for flexibility

Add this method so its subclass can extend from it for different conditions.

Bug: 355567710
Test: atest SystemUITests
Flag: EXEMPT bugfix
Change-Id: Iab9c398404a1eedab59fec07d214cdb08e8cf846
parent 60ce6e15
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -174,15 +174,24 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
        IndentingPrintWriter ipw = asIndenting(pw);
        ipw.println("BatteryController state:");
        ipw.increaseIndent();
        ipw.print("mHasReceivedBattery="); ipw.println(mHasReceivedBattery);
        ipw.print("mLevel="); ipw.println(mLevel);
        ipw.print("mPluggedIn="); ipw.println(mPluggedIn);
        ipw.print("mCharging="); ipw.println(mCharging);
        ipw.print("mCharged="); ipw.println(mCharged);
        ipw.print("mIsBatteryDefender="); ipw.println(mIsBatteryDefender);
        ipw.print("mIsIncompatibleCharging="); ipw.println(mIsIncompatibleCharging);
        ipw.print("mPowerSave="); ipw.println(mPowerSave);
        ipw.print("mStateUnknown="); ipw.println(mStateUnknown);
        ipw.print("mHasReceivedBattery=");
        ipw.println(mHasReceivedBattery);
        ipw.print("mLevel=");
        ipw.println(mLevel);
        ipw.print("mPluggedIn=");
        ipw.println(mPluggedIn);
        ipw.print("mCharging=");
        ipw.println(mCharging);
        ipw.print("mCharged=");
        ipw.println(mCharged);
        ipw.print("mIsBatteryDefender=");
        ipw.println(mIsBatteryDefender);
        ipw.print("mIsIncompatibleCharging=");
        ipw.println(mIsIncompatibleCharging);
        ipw.print("mPowerSave=");
        ipw.println(mPowerSave);
        ipw.print("mStateUnknown=");
        ipw.println(mStateUnknown);
        ipw.println("Callbacks:------------------");
        // Since the above lines are already indented, we need to indent twice for the callbacks.
        ipw.increaseIndent();
@@ -272,7 +281,7 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
            }

            int chargingStatus = intent.getIntExtra(EXTRA_CHARGING_STATUS, CHARGING_POLICY_DEFAULT);
            boolean isBatteryDefender = chargingStatus == CHARGING_POLICY_ADAPTIVE_LONGLIFE;
            boolean isBatteryDefender = isBatteryDefenderMode(chargingStatus);
            if (isBatteryDefender != mIsBatteryDefender) {
                mIsBatteryDefender = isBatteryDefender;
                fireIsBatteryDefenderChanged();
@@ -359,10 +368,23 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC
        return mPluggedChargingSource == BatteryManager.BATTERY_PLUGGED_WIRELESS;
    }

    public boolean isBatteryDefender() {
    /**
     * This method is used for tests only. Returns whether the device is in battery defender
     * mode.
     */
    @VisibleForTesting
    protected boolean isBatteryDefender() {
        return mIsBatteryDefender;
    }

    /**
     * Checks whether the device is in battery defender mode based on the current charging
     * status. This method can be overridden to have a different definition for its subclasses.
     */
    protected boolean isBatteryDefenderMode(int chargingStatus) {
        return chargingStatus == CHARGING_POLICY_ADAPTIVE_LONGLIFE;
    }

    /**
     * Returns whether the charging adapter is incompatible.
     */