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

Commit 8371d085 authored by Zaiyue Xue's avatar Zaiyue Xue
Browse files

Call detect anomaly in period job only when there is new battery usage data.

 - Reduce the memory usage of call anomaly detection
 - Remove redundant condition for low battery banner

Bug: 300446490
Bug: 284893240
Fix: 300446490
Test: presubmit
Change-Id: I11c1b41a45e129bcec57b9d18c4affe0de7f1d38
Merged-In: I11c1b41a45e129bcec57b9d18c4affe0de7f1d38
parent 821ed070
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;

import java.util.concurrent.TimeUnit;

/**
 * Detect whether the battery is too low
 */
@@ -46,9 +44,7 @@ public class LowBatteryDetector implements BatteryTipDetector {

    @Override
    public BatteryTip detect() {
        final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel
                || (mBatteryInfo.discharging && mBatteryInfo.remainingTimeUs != 0
                && mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour));
        final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel;
        final boolean lowBatteryEnabled = mPolicy.lowBatteryEnabled && !mIsPowerSaveMode;
        final boolean dischargingLowBatteryState =
                mPolicy.testLowBatteryTip || (mBatteryInfo.discharging && lowBattery);
+10 −4
Original line number Diff line number Diff line
@@ -116,8 +116,16 @@ public final class BatteryUsageDataLoader {
        final Handler handler = new Handler(Looper.getMainLooper());
        final BatteryLevelData batteryLevelData = DataProcessManager.getBatteryLevelData(
                context, handler, /*isFromPeriodJob=*/ true,
                batteryDiffDataMap -> DatabaseUtils.sendBatteryUsageSlotData(context,
                        ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap)));
                batteryDiffDataMap -> {
                    DatabaseUtils.sendBatteryUsageSlotData(context,
                            ConvertUtils.convertToBatteryUsageSlotList(batteryDiffDataMap));
                    if (batteryDiffDataMap.values().stream().anyMatch(data ->
                            (!data.getAppDiffEntryList().isEmpty()
                                    || !data.getSystemDiffEntryList().isEmpty()))) {
                        FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context)
                                .detectSettingsAnomaly(context, /* displayDrain= */ 0);
                    }
                });
        if (batteryLevelData == null) {
            Log.d(TAG, "preprocessBatteryUsageSlots() no new battery usage data.");
            return;
@@ -139,8 +147,6 @@ public final class BatteryUsageDataLoader {
                // No app usage data or battery diff data at this time.
                loadAppUsageData(context);
                preprocessBatteryUsageSlots(context);
                FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context)
                        .detectSettingsAnomaly(context, /* displayDrain= */ 0);
            }
            Log.d(TAG, String.format(
                    "loadUsageDataSafely() in %d/ms", System.currentTimeMillis() - start));
+3 −8
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ public class LowBatteryDetectorTest {
        mPolicy = spy(new BatteryTipPolicy(RuntimeEnvironment.application));
        mContext = RuntimeEnvironment.application;
        ReflectionHelpers.setField(mPolicy, "lowBatteryEnabled", true);
        ReflectionHelpers.setField(mPolicy, "lowBatteryHour", 3);
        mBatteryInfo.discharging = true;

        mLowBatteryDetector = new LowBatteryDetector(mContext, mPolicy, mBatteryInfo,
@@ -78,13 +77,9 @@ public class LowBatteryDetectorTest {

    @Test
    public void testDetect_lowBattery_tipNew() {
        mBatteryInfo.batteryLevel = 3;
        mBatteryInfo.batteryLevel = 20;
        mBatteryInfo.remainingTimeUs = TimeUnit.DAYS.toMillis(1);
        assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);

        mBatteryInfo.batteryLevel = 50;
        mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1);
        assertThat(mLowBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);
    }

    @Test
@@ -104,9 +99,9 @@ public class LowBatteryDetectorTest {
    }

    @Test
    public void testDetect_timeEstimationZero_tipInvisible() {
    public void testDetect_lowTimeEstimation_tipInvisible() {
        mBatteryInfo.batteryLevel = 50;
        mBatteryInfo.remainingTimeUs = 0;
        mBatteryInfo.remainingTimeUs = TimeUnit.MINUTES.toMillis(1);
        assertThat(mLowBatteryDetector.detect().isVisible()).isFalse();
    }