Add test flags for battery tips.
When this flag is true, we will show related battery tip by force. Then we can manually test and verify the UI behavior. Following CL will add test flag for "app restriction" since it is a little tricky. Bug: 77477035 Test: RunSettingsRoboTests Change-Id: Ib12ff4aa8bcc998ea6a73f461c3d5f7fcc39b019
This commit is contained in:
@@ -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_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_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
|
* {@code true} if general battery tip is enabled
|
||||||
*
|
*
|
||||||
@@ -164,6 +168,30 @@ public class BatteryTipPolicy {
|
|||||||
*/
|
*/
|
||||||
public final int excessiveBgDrainPercentage;
|
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;
|
private final KeyValueListParser mParser;
|
||||||
|
|
||||||
public BatteryTipPolicy(Context context) {
|
public BatteryTipPolicy(Context context) {
|
||||||
@@ -197,6 +225,10 @@ public class BatteryTipPolicy {
|
|||||||
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
|
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
|
||||||
dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
|
dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
|
||||||
excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ public class EarlyWarningDetector implements BatteryTipDetector {
|
|||||||
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
||||||
final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
|
final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
|
||||||
final boolean earlyWarning = mPowerUsageFeatureProvider.getEarlyWarningSignal(mContext,
|
final boolean earlyWarning = mPowerUsageFeatureProvider.getEarlyWarningSignal(mContext,
|
||||||
EarlyWarningDetector.class.getName());
|
EarlyWarningDetector.class.getName()) || mPolicy.testBatterySaverTip;
|
||||||
|
|
||||||
final int state = powerSaveModeOn
|
final int state = powerSaveModeOn
|
||||||
? BatteryTip.StateType.HANDLED
|
? BatteryTip.StateType.HANDLED
|
||||||
|
@@ -34,6 +34,7 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detector whether to show summary tip. This detector should be executed as the last
|
* 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);
|
final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
|
||||||
if (mPolicy.highUsageEnabled) {
|
if (mPolicy.highUsageEnabled) {
|
||||||
parseBatteryData();
|
parseBatteryData();
|
||||||
if (mDataParser.isDeviceHeavilyUsed()) {
|
if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
|
||||||
final List<BatterySipper> batterySippers = mBatteryStatsHelper.getUsageList();
|
final List<BatterySipper> batterySippers = mBatteryStatsHelper.getUsageList();
|
||||||
for (int i = 0, size = batterySippers.size(); i < size; i++) {
|
for (int i = 0, size = batterySippers.size(); i < size; i++) {
|
||||||
final BatterySipper batterySipper = batterySippers.get(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());
|
Collections.sort(mHighUsageAppList, Collections.reverseOrder());
|
||||||
mHighUsageAppList = mHighUsageAppList.subList(0,
|
mHighUsageAppList = mHighUsageAppList.subList(0,
|
||||||
Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
|
Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
|
||||||
|
@@ -38,10 +38,10 @@ public class SmartBatteryDetector implements BatteryTipDetector {
|
|||||||
@Override
|
@Override
|
||||||
public BatteryTip detect() {
|
public BatteryTip detect() {
|
||||||
// Show it if there is no other tips shown
|
// Show it if there is no other tips shown
|
||||||
final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
|
final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver,
|
||||||
Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
|
Settings.Global.APP_STANDBY_ENABLED, 1) == 0 || mPolicy.testSmartBatteryTip;
|
||||||
final int state =
|
final int state =
|
||||||
smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
|
smartBatteryOff ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
|
||||||
return new SmartBatteryTip(state);
|
return new SmartBatteryTip(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,10 @@ public class BatteryTipPolicyTest {
|
|||||||
+ ",low_battery_enabled=false"
|
+ ",low_battery_enabled=false"
|
||||||
+ ",low_battery_hour=10"
|
+ ",low_battery_hour=10"
|
||||||
+ ",data_history_retain_day=24"
|
+ ",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;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -74,6 +77,9 @@ public class BatteryTipPolicyTest {
|
|||||||
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
|
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
|
||||||
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(24);
|
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(24);
|
||||||
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(25);
|
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(25);
|
||||||
|
assertThat(batteryTipPolicy.testBatterySaverTip).isTrue();
|
||||||
|
assertThat(batteryTipPolicy.testHighUsageTip).isFalse();
|
||||||
|
assertThat(batteryTipPolicy.testSmartBatteryTip).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,5 +103,8 @@ public class BatteryTipPolicyTest {
|
|||||||
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
|
assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
|
||||||
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
|
assertThat(batteryTipPolicy.dataHistoryRetainDay).isEqualTo(30);
|
||||||
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
|
assertThat(batteryTipPolicy.excessiveBgDrainPercentage).isEqualTo(10);
|
||||||
|
assertThat(batteryTipPolicy.testBatterySaverTip).isFalse();
|
||||||
|
assertThat(batteryTipPolicy.testHighUsageTip).isFalse();
|
||||||
|
assertThat(batteryTipPolicy.testSmartBatteryTip).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -74,6 +74,16 @@ public class EarlyWarningDetectorTest {
|
|||||||
assertThat(mEarlyWarningDetector.detect().isVisible()).isFalse();
|
assertThat(mEarlyWarningDetector.detect().isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetect_testFeatureOn_tipNew() {
|
||||||
|
doReturn(false).when(mFakeFeatureFactory.powerUsageFeatureProvider)
|
||||||
|
.getEarlyWarningSignal(any(), any());
|
||||||
|
ReflectionHelpers.setField(mPolicy, "testBatterySaverTip", true);
|
||||||
|
|
||||||
|
assertThat(mEarlyWarningDetector.detect().getState())
|
||||||
|
.isEqualTo(BatteryTip.StateType.NEW);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetect_batterySaverOn_tipHandled() {
|
public void testDetect_batterySaverOn_tipHandled() {
|
||||||
doReturn(true).when(mPowerManager).isPowerSaveMode();
|
doReturn(true).when(mPowerManager).isPowerSaveMode();
|
||||||
|
@@ -34,6 +34,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
|
|||||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||||
import com.android.settings.fuelgauge.batterytip.HighUsageDataParser;
|
import com.android.settings.fuelgauge.batterytip.HighUsageDataParser;
|
||||||
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
@@ -108,6 +109,14 @@ public class HighUsageDetectorTest {
|
|||||||
assertThat(mHighUsageDetector.detect().isVisible()).isFalse();
|
assertThat(mHighUsageDetector.detect().isVisible()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetect_testFeatureOn_tipNew() {
|
||||||
|
doReturn(false).when(mDataParser).isDeviceHeavilyUsed();
|
||||||
|
ReflectionHelpers.setField(mPolicy, "testHighUsageTip", true);
|
||||||
|
|
||||||
|
assertThat(mHighUsageDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDetect_containsHighUsageApp_tipVisible() {
|
public void testDetect_containsHighUsageApp_tipVisible() {
|
||||||
doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
|
doReturn(true).when(mDataParser).isDeviceHeavilyUsed();
|
||||||
|
@@ -24,6 +24,7 @@ import android.content.Context;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||||
|
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -31,6 +32,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class SmartBatteryDetectorTest {
|
public class SmartBatteryDetectorTest {
|
||||||
@@ -38,6 +40,7 @@ public class SmartBatteryDetectorTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private SmartBatteryDetector mSmartBatteryDetector;
|
private SmartBatteryDetector mSmartBatteryDetector;
|
||||||
|
private BatteryTipPolicy mPolicy;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -45,8 +48,15 @@ public class SmartBatteryDetectorTest {
|
|||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mContentResolver = mContext.getContentResolver();
|
mContentResolver = mContext.getContentResolver();
|
||||||
final BatteryTipPolicy policy = spy(new BatteryTipPolicy(mContext));
|
mPolicy = spy(new BatteryTipPolicy(mContext));
|
||||||
mSmartBatteryDetector = new SmartBatteryDetector(policy, mContentResolver);
|
mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContentResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDetect_testFeatureOn_tipNew() {
|
||||||
|
ReflectionHelpers.setField(mPolicy, "testSmartBatteryTip", true);
|
||||||
|
|
||||||
|
assertThat(mSmartBatteryDetector.detect().getState()).isEqualTo(BatteryTip.StateType.NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user