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

Commit b00140b7 authored by Pajace Chen's avatar Pajace Chen
Browse files

Reduce the calling times for isExtraDefend

Only calling this HAL API when BatteryDefenderTips card need to be shown

Bug: 243465597
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.fuelgauge.*
Change-Id: Iae3c03d946ec29fe78a826ce62b6bebd893704ef
parent bf23a06e
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.fuelgauge.EstimateKt;
import com.android.settingslib.utils.AsyncLoaderCompat;

@@ -67,16 +66,14 @@ public class BatteryTipLoader extends AsyncLoaderCompat<List<BatteryTip>> {
        final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
        final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(TAG);
        final Context context = getContext();
        final boolean extraDefend = FeatureFactory.getFactory(context)
                .getPowerUsageFeatureProvider(context)
                .isExtraDefend();

        tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
        tips.add(new HighUsageDetector(context, policy, mBatteryUsageStats, batteryInfo).detect());
        tips.add(new SmartBatteryDetector(
                context, policy, batteryInfo, context.getContentResolver()).detect());
        tips.add(new EarlyWarningDetector(policy, context).detect());
        tips.add(new BatteryDefenderDetector(batteryInfo, extraDefend).detect());
        tips.add(new BatteryDefenderDetector(
                batteryInfo, context.getApplicationContext()).detect());
        Collections.sort(tips);
        return tips;
    }
+13 −8
Original line number Diff line number Diff line
@@ -16,28 +16,33 @@

package com.android.settings.fuelgauge.batterytip.detectors;

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 {
    private final BatteryInfo mBatteryInfo;
    private final boolean mExtraDefend;
    private final Context mContext;

    public BatteryDefenderDetector(BatteryInfo batteryInfo, boolean extraDefend) {
    public BatteryDefenderDetector(BatteryInfo batteryInfo, Context context) {
        mBatteryInfo = batteryInfo;
        mExtraDefend = extraDefend;
        mContext = context;
    }

    @Override
    public BatteryTip detect() {
        final int state =
                mBatteryInfo.isOverheated
                    ? BatteryTip.StateType.NEW
                    : BatteryTip.StateType.INVISIBLE;
        return new BatteryDefenderTip(state, mExtraDefend);
        if (mBatteryInfo.isOverheated) {
            final boolean extraDefend = FeatureFactory.getFactory(mContext)
                    .getPowerUsageFeatureProvider(mContext)
                    .isExtraDefend();
            return new BatteryDefenderTip(BatteryTip.StateType.NEW, extraDefend);
        }
        return new BatteryDefenderTip(BatteryTip.StateType.INVISIBLE);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.fuelgauge.batterytip.detectors;

import static com.google.common.truth.Truth.assertThat;

import androidx.test.core.app.ApplicationProvider;

import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;

@@ -42,7 +44,7 @@ public class BatteryDefenderDetectorTest {
        mBatteryInfo.discharging = false;

        mBatteryDefenderDetector = new BatteryDefenderDetector(
            mBatteryInfo, /* extraDefend= */ false);
            mBatteryInfo, ApplicationProvider.getApplicationContext());
    }

    @Test