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

Commit ed7101cd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add action for low battery tip" into pi-dev

parents faa5c228 8d538ef1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ public class BatteryTipPolicy {
        appRestrictionEnabled = mParser.getBoolean(KEY_APP_RESTRICTION_ENABLED, true);
        reducedBatteryEnabled = mParser.getBoolean(KEY_REDUCED_BATTERY_ENABLED, false);
        reducedBatteryPercent = mParser.getInt(KEY_REDUCED_BATTERY_PERCENT, 50);
        lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, false);
        lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, true);
        lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 3);
        dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
        excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class BatteryTipUtils {
            case BatteryTip.TipType.SMART_BATTERY_MANAGER:
                return new SmartBatteryAction(settingsActivity, fragment);
            case BatteryTip.TipType.BATTERY_SAVER:
            case BatteryTip.TipType.LOW_BATTERY:
                if (batteryTip.getState() == BatteryTip.StateType.HANDLED) {
                    return new OpenBatterySaverAction(settingsActivity);
                } else {
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class BatteryTipPolicyTest {
        assertThat(batteryTipPolicy.appRestrictionEnabled).isTrue();
        assertThat(batteryTipPolicy.reducedBatteryEnabled).isFalse();
        assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(50);
        assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
        assertThat(batteryTipPolicy.lowBatteryEnabled).isTrue();
        assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(3);
        assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
        assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
+23 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.settings.fuelgauge.batterytip.actions.OpenRestrictAppFragment
import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip;
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -51,6 +52,7 @@ public class BatteryTipUtilsTest {
    private InstrumentedPreferenceFragment mFragment;
    private RestrictAppTip mRestrictAppTip;
    private EarlyWarningTip mEarlyWarningTip;
    private LowBatteryTip mLowBatteryTip;

    @Before
    public void setUp() {
@@ -59,7 +61,11 @@ public class BatteryTipUtilsTest {
        FakeFeatureFactory.setupForTest();
        doReturn(RuntimeEnvironment.application).when(mFragment).getContext();
        mRestrictAppTip = spy(new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>()));
        mEarlyWarningTip = spy(new EarlyWarningTip(BatteryTip.StateType.NEW, true));
        mEarlyWarningTip = spy(
                new EarlyWarningTip(BatteryTip.StateType.NEW, true /* powerSaveModeOn */));
        mLowBatteryTip = spy(
                new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */,
                        "" /* summary */));
    }

    @Test
@@ -93,4 +99,20 @@ public class BatteryTipUtilsTest {
        assertThat(BatteryTipUtils.getActionForBatteryTip(mEarlyWarningTip, mSettingsActivity,
                mFragment)).isInstanceOf(OpenBatterySaverAction.class);
    }

    @Test
    public void testGetActionForBatteryTip_typeLowBatteryStateNew_returnActionBatterySaver() {
        when(mLowBatteryTip.getState()).thenReturn(BatteryTip.StateType.NEW);

        assertThat(BatteryTipUtils.getActionForBatteryTip(mLowBatteryTip, mSettingsActivity,
                mFragment)).isInstanceOf(BatterySaverAction.class);
    }

    @Test
    public void testGetActionForBatteryTip_typeLowBatteryStateHandled_returnActionOpen() {
        when(mLowBatteryTip.getState()).thenReturn(BatteryTip.StateType.HANDLED);

        assertThat(BatteryTipUtils.getActionForBatteryTip(mLowBatteryTip, mSettingsActivity,
                mFragment)).isInstanceOf(OpenBatterySaverAction.class);
    }
}