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

Commit 93ff8333 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Add test flags for battery tips." into pi-dev

parents 3ec0e485 21bde3af
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ public class BatteryTipPolicy {
    private static final String KEY_DATA_HISTORY_RETAIN_DAY = "data_history_retain_day";
    private static final String KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE = "excessive_bg_drain_percentage";

    private static final String KEY_TEST_BATTERY_SAVER_TIP = "test_battery_saver_tip";
    private static final String KEY_TEST_HIGH_USAGE_TIP = "test_high_usage_tip";
    private static final String KEY_TEST_SMART_BATTERY_TIP = "test_smart_battery_tip";

    /**
     * {@code true} if general battery tip is enabled
     *
@@ -164,6 +168,30 @@ public class BatteryTipPolicy {
     */
    public final int excessiveBgDrainPercentage;

    /**
     * {@code true} if we want to test battery saver tip.
     *
     * @see Settings.Global#BATTERY_TIP_CONSTANTS
     * @see #KEY_TEST_BATTERY_SAVER_TIP
     */
    public final boolean testBatterySaverTip;

    /**
     * {@code true} if we want to test high usage tip.
     *
     * @see Settings.Global#BATTERY_TIP_CONSTANTS
     * @see #KEY_TEST_HIGH_USAGE_TIP
     */
    public final boolean testHighUsageTip;

    /**
     * {@code true} if we want to test smart battery tip.
     *
     * @see Settings.Global#BATTERY_TIP_CONSTANTS
     * @see #KEY_TEST_SMART_BATTERY_TIP
     */
    public final boolean testSmartBatteryTip;

    private final KeyValueListParser mParser;

    public BatteryTipPolicy(Context context) {
@@ -197,6 +225,10 @@ public class BatteryTipPolicy {
        lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
        dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
        excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);

        testBatterySaverTip = mParser.getBoolean(KEY_TEST_BATTERY_SAVER_TIP, false);
        testHighUsageTip = mParser.getBoolean(KEY_TEST_HIGH_USAGE_TIP, false);
        testSmartBatteryTip = mParser.getBoolean(KEY_TEST_SMART_BATTERY_TIP, false);
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class EarlyWarningDetector implements BatteryTipDetector {
                batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
        final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
        final boolean earlyWarning = mPowerUsageFeatureProvider.getEarlyWarningSignal(mContext,
                EarlyWarningDetector.class.getName());
                EarlyWarningDetector.class.getName()) || mPolicy.testBatterySaverTip;

        final int state = powerSaveModeOn
                ? BatteryTip.StateType.HANDLED
+10 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Detector whether to show summary tip. This detector should be executed as the last
@@ -65,7 +66,7 @@ public class HighUsageDetector implements BatteryTipDetector {
        final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
        if (mPolicy.highUsageEnabled) {
            parseBatteryData();
            if (mDataParser.isDeviceHeavilyUsed()) {
            if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
                final List<BatterySipper> batterySippers = mBatteryStatsHelper.getUsageList();
                for (int i = 0, size = batterySippers.size(); i < size; i++) {
                    final BatterySipper batterySipper = batterySippers.get(i);
@@ -84,6 +85,14 @@ public class HighUsageDetector implements BatteryTipDetector {
                    }
                }

                // When in test mode, add an app if necessary
                if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
                    mHighUsageAppList.add(new AppInfo.Builder()
                            .setPackageName("com.android.settings")
                            .setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3))
                            .build());
                }

                Collections.sort(mHighUsageAppList, Collections.reverseOrder());
                mHighUsageAppList = mHighUsageAppList.subList(0,
                        Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
+3 −3
Original line number Diff line number Diff line
@@ -38,10 +38,10 @@ public class SmartBatteryDetector implements BatteryTipDetector {
    @Override
    public BatteryTip detect() {
        // Show it if there is no other tips shown
        final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
                Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
        final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver,
                Settings.Global.APP_STANDBY_ENABLED, 1) == 0 || mPolicy.testSmartBatteryTip;
        final int state =
                smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
                smartBatteryOff ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
        return new SmartBatteryTip(state);
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -45,7 +45,10 @@ public class BatteryTipPolicyTest {
            + ",low_battery_enabled=false"
            + ",low_battery_hour=10"
            + ",data_history_retain_day=24"
            + ",excessive_bg_drain_percentage=25";
            + ",excessive_bg_drain_percentage=25"
            + ",test_battery_saver_tip=true"
            + ",test_high_usage_tip=false"
            + ",test_smart_battery_tip=true";
    private Context mContext;

    @Before
@@ -74,6 +77,9 @@ public class BatteryTipPolicyTest {
        assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
        assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(24);
        assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(25);
        assertThat(batteryTipPolicy.testBatterySaverTip).isTrue();
        assertThat(batteryTipPolicy.testHighUsageTip).isFalse();
        assertThat(batteryTipPolicy.testSmartBatteryTip).isTrue();
    }

    @Test
@@ -97,5 +103,8 @@ public class BatteryTipPolicyTest {
        assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
        assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
        assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
        assertThat(batteryTipPolicy.testBatterySaverTip).isFalse();
        assertThat(batteryTipPolicy.testHighUsageTip).isFalse();
        assertThat(batteryTipPolicy.testSmartBatteryTip).isFalse();
    }
}
Loading