Make app usage page active time support time period

- Add time slot into active time text
 Screenshot: https://screenshot.googleplex.com/hzj5cJ3eDJD5iW7.png

Bug: 178197718
Test: make SettingsRoboTests
Change-Id: I0904e78ca9ab0a5b454e093388f667e978e8722f
This commit is contained in:
Wesley.CW Wang
2021-04-26 20:30:03 +08:00
parent db74d13d4f
commit 86a6a0d32c
3 changed files with 168 additions and 32 deletions

View File

@@ -6322,9 +6322,9 @@
<string name ="battery_detail_manage_title">Manage battery usage</string> <string name ="battery_detail_manage_title">Manage battery usage</string>
<!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background for past 24 hr. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background for past 24 hr. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_and_background_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for past 24 hr</string> <string name="battery_total_and_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for past 24 hr</string>
<!-- Description for battery total and background usage time in a time period for an app, i.e. 1 hr 15 min total • 39 min background for 12 am-2 am. Note: ^1, ^2 and ^3 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery total and background usage time in a time period for an app, i.e. 1 hr 15 min total • 39 min background for 12 am-2 am. Note: ^1, ^2 and ^3 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_and_background_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for <xliff:g id="time_period" example="12 am-2 am">^3</xliff:g></string> <string name="battery_total_and_bg_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background for <xliff:g id="time_period" example="12 am-2 am">^3</xliff:g></string>
<!-- Description for battery total usage time is less than a minute for an app [CHAR LIMIT=120] --> <!-- Description for battery total usage time is less than a minute for an app [CHAR LIMIT=120] -->
<string name="battery_total_usage_less_minute">Total less than a minute for past 24 hr</string> <string name="battery_total_usage_less_minute">Total less than a minute for past 24 hr</string>
@@ -6332,9 +6332,9 @@
<string name="battery_total_usage_less_minute_with_period">Total less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string> <string name="battery_total_usage_less_minute_with_period">Total less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string>
<!-- Description for battery background usage time is less than a minute for an app [CHAR LIMIT=120] --> <!-- Description for battery background usage time is less than a minute for an app [CHAR LIMIT=120] -->
<string name="battery_background_usage_less_minute">Background less than a minute for past 24 hr</string> <string name="battery_bg_usage_less_minute">Background less than a minute for past 24 hr</string>
<!-- Description for battery background usage time is less than a minute in a time period for an app, i.e. Background less than a minute for 12 am-2 am. Note: ^1 should be used in all translations[CHAR LIMIT=120] --> <!-- Description for battery background usage time is less than a minute in a time period for an app, i.e. Background less than a minute for 12 am-2 am. Note: ^1 should be used in all translations[CHAR LIMIT=120] -->
<string name="battery_background_usage_less_minute_with_period">Background less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string> <string name="battery_bg_usage_less_minute_with_period">Background less than a minute for <xliff:g id="time_period" example="12 am-2 am">^1</xliff:g></string>
<!-- Description for battery total usage time for an app, i.e. 1 hr 15 min total for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery total usage time for an app, i.e. 1 hr 15 min total for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for past 24 hr</string> <string name="battery_total_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for past 24 hr</string>
@@ -6342,14 +6342,14 @@
<string name="battery_total_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string> <string name="battery_total_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
<!-- Description for battery background usage time for an app, i.e. 1 hr 15 min background for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery background usage time for an app, i.e. 1 hr 15 min background for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_background_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background for past 24 hr</string> <string name="battery_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background for past 24 hr</string>
<!-- Description for battery background usage time in a time period for an app, i.e. 1 hr 15 min background for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery background usage time in a time period for an app, i.e. 1 hr 15 min background for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_background_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string> <string name="battery_bg_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
<!-- Description for battery total usage with background usage time less than a minute for an app, i.e. 1 hr 15 min total • background less than a minute for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery total usage with background usage time less than a minute for an app, i.e. 1 hr 15 min total • background less than a minute for past 24 hr. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_usage_and_background_less_minute_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute for past 24 hr</string> <string name="battery_total_usage_and_bg_less_minute_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute for past 24 hr</string>
<!-- Description for battery total usage with background usage time less than a minute in a time period for an app, i.e. 1 hr 15 min total • background less than a minute for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] --> <!-- Description for battery total usage with background usage time less than a minute in a time period for an app, i.e. 1 hr 15 min total • background less than a minute for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_total_usage_and_background_less_minute_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string> <string name="battery_total_usage_and_bg_less_minute_usage_with_period"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute for <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
<!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] --> <!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] -->
<string name="battery_not_usage">No usage for past 24 hr</string> <string name="battery_not_usage">No usage for past 24 hr</string>

View File

@@ -70,6 +70,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
public static final String EXTRA_PACKAGE_NAME = "extra_package_name"; public static final String EXTRA_PACKAGE_NAME = "extra_package_name";
public static final String EXTRA_FOREGROUND_TIME = "extra_foreground_time"; public static final String EXTRA_FOREGROUND_TIME = "extra_foreground_time";
public static final String EXTRA_BACKGROUND_TIME = "extra_background_time"; public static final String EXTRA_BACKGROUND_TIME = "extra_background_time";
public static final String EXTRA_SLOT_TIME = "extra_slot_time";
public static final String EXTRA_LABEL = "extra_label"; public static final String EXTRA_LABEL = "extra_label";
public static final String EXTRA_ICON_ID = "extra_icon_id"; public static final String EXTRA_ICON_ID = "extra_icon_id";
public static final String EXTRA_POWER_USAGE_PERCENT = "extra_power_usage_percent"; public static final String EXTRA_POWER_USAGE_PERCENT = "extra_power_usage_percent";
@@ -184,6 +185,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
args.putInt(EXTRA_UID, launchArgs.mUid); args.putInt(EXTRA_UID, launchArgs.mUid);
args.putLong(EXTRA_BACKGROUND_TIME, launchArgs.mBackgroundTimeMs); args.putLong(EXTRA_BACKGROUND_TIME, launchArgs.mBackgroundTimeMs);
args.putLong(EXTRA_FOREGROUND_TIME, launchArgs.mForegroundTimeMs); args.putLong(EXTRA_FOREGROUND_TIME, launchArgs.mForegroundTimeMs);
args.putString(EXTRA_SLOT_TIME, launchArgs.mSlotInformation);
args.putString(EXTRA_POWER_USAGE_PERCENT, launchArgs.mUsagePercent); args.putString(EXTRA_POWER_USAGE_PERCENT, launchArgs.mUsagePercent);
args.putInt(EXTRA_POWER_USAGE_AMOUNT, launchArgs.mConsumedPower); args.putInt(EXTRA_POWER_USAGE_AMOUNT, launchArgs.mConsumedPower);
final int userId = launchArgs.mIsUserEntry ? ActivityManager.getCurrentUser() final int userId = launchArgs.mIsUserEntry ? ActivityManager.getCurrentUser()
@@ -294,8 +296,9 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
if (enableTriState) { if (enableTriState) {
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME); final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME); final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
//TODO(b/178197718) Update layout to support multiple lines //TODO(b/178197718) Update layout to support multiple lines
controller.setSummary(getAppActiveTime(foregroundTimeMs, backgroundTimeMs)); controller.setSummary(getAppActiveTime(foregroundTimeMs, backgroundTimeMs, slotTime));
} }
controller.done(context, true /* rebindActions */); controller.done(context, true /* rebindActions */);
@@ -430,18 +433,32 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
getContext(), getArguments().getInt(EXTRA_UID), packageName); getContext(), getArguments().getInt(EXTRA_UID), packageName);
} }
//TODO(b/178197718) Update method to support time period private CharSequence getAppActiveTime(
private CharSequence getAppActiveTime(long foregroundTimeMs, long backgroundTimeMs) { long foregroundTimeMs, long backgroundTimeMs, String slotTime) {
final long totalTimeMs = foregroundTimeMs + backgroundTimeMs; final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
final CharSequence usageTimeSummary; final CharSequence usageTimeSummary;
if (totalTimeMs == 0) { if (totalTimeMs == 0) {
usageTimeSummary = getText(R.string.battery_not_usage); usageTimeSummary = getText(R.string.battery_not_usage);
} else if (slotTime == null) {
// Shows summary text with past 24 hr if slot time is null.
usageTimeSummary =
getAppPast24HrActiveSummary(foregroundTimeMs, backgroundTimeMs, totalTimeMs);
} else {
// Shows summary text with slot time.
usageTimeSummary = getAppActiveSummaryWithSlotTime(
foregroundTimeMs, backgroundTimeMs, totalTimeMs, slotTime);
}
return usageTimeSummary;
}
private CharSequence getAppPast24HrActiveSummary(
long foregroundTimeMs, long backgroundTimeMs, long totalTimeMs) {
// Shows background summary only if we don't have foreground usage time. // Shows background summary only if we don't have foreground usage time.
} else if (foregroundTimeMs == 0 && backgroundTimeMs != 0) { if (foregroundTimeMs == 0 && backgroundTimeMs != 0) {
usageTimeSummary = backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS ? return backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS ?
getText(R.string.battery_background_usage_less_minute) : getText(R.string.battery_bg_usage_less_minute) :
TextUtils.expandTemplate(getText(R.string.battery_background_usage), TextUtils.expandTemplate(getText(R.string.battery_bg_usage),
StringUtil.formatElapsedTime( StringUtil.formatElapsedTime(
getContext(), getContext(),
backgroundTimeMs, backgroundTimeMs,
@@ -449,13 +466,13 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
/* collapseTimeUnit */ false)); /* collapseTimeUnit */ false));
// Shows total usage summary only if total usage time is small. // Shows total usage summary only if total usage time is small.
} else if (totalTimeMs < DateUtils.MINUTE_IN_MILLIS) { } else if (totalTimeMs < DateUtils.MINUTE_IN_MILLIS) {
usageTimeSummary = getText(R.string.battery_total_usage_less_minute); return getText(R.string.battery_total_usage_less_minute);
// Shows different total usage summary when background usage time is small. // Shows different total usage summary when background usage time is small.
} else if (backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS) { } else if (backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS) {
usageTimeSummary = TextUtils.expandTemplate( return TextUtils.expandTemplate(
getText(backgroundTimeMs == 0 ? getText(backgroundTimeMs == 0 ?
R.string.battery_total_usage : R.string.battery_total_usage :
R.string.battery_total_usage_and_background_less_minute_usage), R.string.battery_total_usage_and_bg_less_minute_usage),
StringUtil.formatElapsedTime( StringUtil.formatElapsedTime(
getContext(), getContext(),
totalTimeMs, totalTimeMs,
@@ -463,8 +480,8 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
/* collapseTimeUnit */ false)); /* collapseTimeUnit */ false));
// Shows default summary. // Shows default summary.
} else { } else {
usageTimeSummary = TextUtils.expandTemplate( return TextUtils.expandTemplate(
getText(R.string.battery_total_and_background_usage), getText(R.string.battery_total_and_bg_usage),
StringUtil.formatElapsedTime( StringUtil.formatElapsedTime(
getContext(), getContext(),
totalTimeMs, totalTimeMs,
@@ -476,6 +493,51 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
/* withSeconds */ false, /* withSeconds */ false,
/* collapseTimeUnit */ false)); /* collapseTimeUnit */ false));
} }
return usageTimeSummary; }
private CharSequence getAppActiveSummaryWithSlotTime(
long foregroundTimeMs, long backgroundTimeMs, long totalTimeMs, String slotTime) {
// Shows background summary only if we don't have foreground usage time.
if (foregroundTimeMs == 0 && backgroundTimeMs != 0) {
return backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS ?
TextUtils.expandTemplate(
getText(R.string.battery_bg_usage_less_minute_with_period),
slotTime) :
TextUtils.expandTemplate(getText(R.string.battery_bg_usage_with_period),
StringUtil.formatElapsedTime(
getContext(),
backgroundTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false), slotTime);
// Shows total usage summary only if total usage time is small.
} else if (totalTimeMs < DateUtils.MINUTE_IN_MILLIS) {
return TextUtils.expandTemplate(
getText(R.string.battery_total_usage_less_minute_with_period), slotTime);
// Shows different total usage summary when background usage time is small.
} else if (backgroundTimeMs < DateUtils.MINUTE_IN_MILLIS) {
return TextUtils.expandTemplate(
getText(backgroundTimeMs == 0 ?
R.string.battery_total_usage_with_period :
R.string.battery_total_usage_and_bg_less_minute_usage_with_period),
StringUtil.formatElapsedTime(
getContext(),
totalTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false), slotTime);
// Shows default summary.
} else {
return TextUtils.expandTemplate(
getText(R.string.battery_total_and_bg_usage_with_period),
StringUtil.formatElapsedTime(
getContext(),
totalTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false),
StringUtil.formatElapsedTime(
getContext(),
backgroundTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false), slotTime);
}
} }
} }

View File

@@ -81,6 +81,7 @@ public class AdvancedPowerUsageDetailTest {
private static final String SUMMARY = "summary"; private static final String SUMMARY = "summary";
private static final String[] PACKAGE_NAME = {"com.android.app"}; private static final String[] PACKAGE_NAME = {"com.android.app"};
private static final String USAGE_PERCENT = "16%"; private static final String USAGE_PERCENT = "16%";
private static final String SLOT_TIME = "12 am-2 am";
private static final int ICON_ID = 123; private static final int ICON_ID = 123;
private static final int UID = 1; private static final int UID = 1;
private static final int POWER_MAH = 150; private static final int POWER_MAH = 150;
@@ -284,7 +285,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_backgroundTwoMinutesForegroundZero_hasCorrectSummary() { public void testInitHeader_backgroundTwoMinForegroundZero_hasCorrectSummary() {
final long backgroundTimeTwoMinutes = 120000; final long backgroundTimeTwoMinutes = 120000;
final long foregroundTimeZero = 0; final long foregroundTimeZero = 0;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -301,7 +302,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_backgroundLessThanAMinutesForegroundZero_hasCorrectSummary() { public void testInitHeader_backgroundLessThanAMinForegroundZero_hasCorrectSummary() {
final long backgroundTimeLessThanAMinute = 59999; final long backgroundTimeLessThanAMinute = 59999;
final long foregroundTimeZero = 0; final long foregroundTimeZero = 0;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -319,7 +320,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_totalUsageLessThanAMinutes_hasCorrectSummary() { public void testInitHeader_totalUsageLessThanAMin_hasCorrectSummary() {
final long backgroundTimeLessThanHalfMinute = 20000; final long backgroundTimeLessThanHalfMinute = 20000;
final long foregroundTimeLessThanHalfMinute = 20000; final long foregroundTimeLessThanHalfMinute = 20000;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -338,7 +339,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_TotalAMinutesBackgroundLessThanAMinutes_hasCorrectSummary() { public void testInitHeader_TotalAMinutesBackgroundLessThanAMin_hasCorrectSummary() {
final long backgroundTimeZero = 59999; final long backgroundTimeZero = 59999;
final long foregroundTimeTwoMinutes = 1; final long foregroundTimeTwoMinutes = 1;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -355,7 +356,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_TotalAMinutesBackgroundZero_hasCorrectSummary() { public void testInitHeader_TotalAMinBackgroundZero_hasCorrectSummary() {
final long backgroundTimeZero = 0; final long backgroundTimeZero = 0;
final long foregroundTimeAMinutes = 60000; final long foregroundTimeAMinutes = 60000;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -372,7 +373,7 @@ public class AdvancedPowerUsageDetailTest {
} }
@Test @Test
public void testInitHeader_foregroundTwoMinutesBackgroundFourMinutes_hasCorrectSummary() { public void testInitHeader_foregroundTwoMinBackgroundFourMin_hasCorrectSummary() {
final long backgroundTimeFourMinute = 240000; final long backgroundTimeFourMinute = 240000;
final long foregroundTimeTwoMinutes = 120000; final long foregroundTimeTwoMinutes = 120000;
Bundle bundle = new Bundle(2); Bundle bundle = new Bundle(2);
@@ -387,6 +388,79 @@ public class AdvancedPowerUsageDetailTest {
.isEqualTo("6 min total • 4 min background for past 24 hr"); .isEqualTo("6 min total • 4 min background for past 24 hr");
} }
@Test
public void testInitHeader_totalUsageLessThanAMinWithSlotTime_hasCorrectSummary() {
final long backgroundTimeLessThanHalfMinute = 20000;
final long foregroundTimeLessThanHalfMinute = 20000;
Bundle bundle = new Bundle(2);
bundle.putLong(
AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanHalfMinute);
bundle.putLong(
AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeLessThanHalfMinute);
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
when(mFragment.getArguments()).thenReturn(bundle);
mFragment.initHeader();
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("Total less than a minute for 12 am-2 am");
}
@Test
public void testInitHeader_TotalAMinBackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
final long backgroundTimeZero = 59999;
final long foregroundTimeTwoMinutes = 1;
Bundle bundle = new Bundle(2);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
when(mFragment.getArguments()).thenReturn(bundle);
mFragment.initHeader();
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("1 min total • background less than a minute for 12 am-2 am");
}
@Test
public void testInitHeader_TotalAMinBackgroundZeroWithSlotTime_hasCorrectSummary() {
final long backgroundTimeZero = 0;
final long foregroundTimeAMinutes = 60000;
Bundle bundle = new Bundle(2);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeAMinutes);
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
when(mFragment.getArguments()).thenReturn(bundle);
mFragment.initHeader();
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("1 min total for 12 am-2 am");
}
@Test
public void testInitHeader_foregroundTwoMinBackgroundFourMinWithSlotTime_hasCorrectSummary() {
final long backgroundTimeFourMinute = 240000;
final long foregroundTimeTwoMinutes = 120000;
Bundle bundle = new Bundle(2);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeFourMinute);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
when(mFragment.getArguments()).thenReturn(bundle);
mFragment.initHeader();
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("6 min total • 4 min background for 12 am-2 am");
}
@Test @Test
public void testStartBatteryDetailPage_hasBasicData() { public void testStartBatteryDetailPage_hasBasicData() {
AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment, AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment,