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

Commit 9ab25973 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

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

Merge "Call detect anomaly in period job only when there is new battery usage data." into udc-qpr-dev am: a72b00a9

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/24800290



Change-Id: I7a24ea9b18c421a7de2d2752bfc5158e21aa324e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0e850e9d a72b00a9
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();
    }