Merge "Update app usage page active time column" into sc-dev

This commit is contained in:
Wesley Wang
2021-04-20 11:58:55 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 The Android Open Source Project
Copyright (C) 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -23,12 +23,10 @@
android:key="header_view"
android:layout="@layout/settings_entity_header"
android:selectable="false"
android:order="-10000"
settings:allowDividerBelow="true"/>
<com.android.settingslib.widget.ActionButtonsPreference
android:key="action_buttons"
android:order="-9999"/>
android:key="action_buttons"/>
<PreferenceCategory
android:title="@string/battery_detail_manage_title"
@@ -72,23 +70,7 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/battery_detail_info_title">
<Preference
android:key="app_usage_foreground"
android:title="@string/battery_detail_foreground"
android:selectable="false"/>
<Preference
android:key="app_usage_background"
android:title="@string/battery_detail_background"
android:selectable="false"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference
android:order="100"
android:key="app_usage_footer_preference"
android:title="@string/manager_battery_usage_footer"
android:selectable="true"

View File

@@ -292,31 +292,29 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
}
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
//TODO(b/178197718) Refine the layout
controller.setSummary(TextUtils.expandTemplate(
getText(R.string.battery_total_and_background_usage),
StringUtil.formatElapsedTime(
getContext(),
totalTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false),
StringUtil.formatElapsedTime(
getContext(),
backgroundTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false)));
controller.done(context, true /* rebindActions */);
}
@VisibleForTesting
void initPreference() {
final Bundle bundle = getArguments();
final Context context = getContext();
final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
mForegroundPreference.setSummary(
TextUtils.expandTemplate(getText(R.string.battery_used_for),
StringUtil.formatElapsedTime(
context,
foregroundTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false)));
mBackgroundPreference.setSummary(
TextUtils.expandTemplate(getText(R.string.battery_active_for),
StringUtil.formatElapsedTime(
context,
backgroundTimeMs,
/* withSeconds */ false,
/* collapseTimeUnit */ false)));
final String stateString;
final String footerString;
//TODO(b/178197718) Update strings

View File

@@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -266,6 +267,17 @@ public class AdvancedPowerUsageDetailTest {
verify(mEntityHeaderController).setIsInstantApp(true);
}
@Test
public void testInitHeader_hasCorrectSummary() {
mFragment.mAppEntry = null;
mFragment.initHeader();
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("0 min total • 0 min background for past 24 hr");
}
@Test
public void testStartBatteryDetailPage_hasBasicData() {
AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment,
@@ -353,26 +365,6 @@ public class AdvancedPowerUsageDetailTest {
assertThat(mBundle.getInt(AdvancedPowerUsageDetail.EXTRA_UID)).isEqualTo(UID);
}
@Test
public void testInitPreference_hasCorrectSummary() {
Bundle bundle = new Bundle(4);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, BACKGROUND_TIME_MS);
bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, FOREGROUND_TIME_MS);
bundle.putString(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT, USAGE_PERCENT);
bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, POWER_MAH);
when(mFragment.getArguments()).thenReturn(bundle);
doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
R.string.battery_used_for);
doReturn(mContext.getText(R.string.battery_active_for)).when(mFragment).getText(
R.string.battery_active_for);
mFragment.initPreference();
assertThat(mForegroundPreference.getSummary().toString()).isEqualTo("Used for 0 min");
assertThat(mBackgroundPreference.getSummary().toString()).isEqualTo("Active for 0 min");
}
@Test
public void testInitPreference_isValidPackageName_hasCorrectString() {
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(false);