Merge changes from topic "screentime" into main

* changes:
  Fix summary for system components which 30 sec <= usage time < 1 min.
  Fix purge condition for system component in BatteryDiffData.
This commit is contained in:
Xinyi Mao
2024-04-02 10:59:14 +00:00
committed by Android (Google) Code Review
3 changed files with 10 additions and 6 deletions

View File

@@ -670,7 +670,7 @@ public class BatteryUtils {
long timeInMs, long timeInMs,
final int lessThanOneMinuteResId, final int lessThanOneMinuteResId,
final int normalResId) { final int normalResId) {
if (timeInMs < DateUtils.MINUTE_IN_MILLIS) { if (timeInMs <= DateUtils.MINUTE_IN_MILLIS / 2) {
return context.getString(lessThanOneMinuteResId); return context.getString(lessThanOneMinuteResId);
} }
final CharSequence timeSequence = final CharSequence timeSequence =

View File

@@ -150,7 +150,10 @@ public class BatteryDiffData {
final Iterator<BatteryDiffEntry> iterator = entries.iterator(); final Iterator<BatteryDiffEntry> iterator = entries.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final BatteryDiffEntry entry = iterator.next(); final BatteryDiffEntry entry = iterator.next();
final long screenOnTimeInMs = entry.mScreenOnTimeInMs; final long screenOnTimeInMs =
entry.isSystemEntry()
? entry.mForegroundUsageTimeInMs
: entry.mScreenOnTimeInMs;
final double comsumePower = entry.mConsumePower; final double comsumePower = entry.mConsumePower;
final String packageName = entry.getPackageName(); final String packageName = entry.getPackageName();
final Integer componentId = entry.mComponentId; final Integer componentId = entry.mComponentId;

View File

@@ -57,6 +57,7 @@ public final class BatteryUsageBreakdownControllerTest {
private static final String PREF_KEY = "pref_key"; private static final String PREF_KEY = "pref_key";
private static final String PREF_KEY2 = "pref_key2"; private static final String PREF_KEY2 = "pref_key2";
private static final String PREF_SUMMARY = "fake preference summary"; private static final String PREF_SUMMARY = "fake preference summary";
private static final long TIME_LESS_THAN_HALF_MINUTE = DateUtils.MINUTE_IN_MILLIS / 2 - 1;
@Mock private InstrumentedPreferenceFragment mFragment; @Mock private InstrumentedPreferenceFragment mFragment;
@Mock private SettingsActivity mSettingsActivity; @Mock private SettingsActivity mSettingsActivity;
@@ -332,7 +333,7 @@ public final class BatteryUsageBreakdownControllerTest {
createBatteryDiffEntry( createBatteryDiffEntry(
/* isSystem= */ true, /* isSystem= */ true,
/* screenOnTimeInMs= */ 0, /* screenOnTimeInMs= */ 0,
/* foregroundUsageTimeInMs= */ DateUtils.MINUTE_IN_MILLIS - 1, /* foregroundUsageTimeInMs= */ TIME_LESS_THAN_HALF_MINUTE,
/* foregroundServiceUsageTimeInMs= */ 0, /* foregroundServiceUsageTimeInMs= */ 0,
/* backgroundUsageTimeInMs= */ 0)); /* backgroundUsageTimeInMs= */ 0));
assertThat(pref.getSummary().toString()).isEqualTo("Total: less than a minute"); assertThat(pref.getSummary().toString()).isEqualTo("Total: less than a minute");
@@ -427,10 +428,10 @@ public final class BatteryUsageBreakdownControllerTest {
pref, pref,
createBatteryDiffEntry( createBatteryDiffEntry(
/* isSystem= */ false, /* isSystem= */ false,
/* screenOnTimeInMs= */ DateUtils.MINUTE_IN_MILLIS - 1, /* screenOnTimeInMs= */ TIME_LESS_THAN_HALF_MINUTE,
/* foregroundUsageTimeInMs= */ DateUtils.MINUTE_IN_MILLIS - 1, /* foregroundUsageTimeInMs= */ TIME_LESS_THAN_HALF_MINUTE,
/* foregroundServiceUsageTimeInMs= */ 0, /* foregroundServiceUsageTimeInMs= */ 0,
/* backgroundUsageTimeInMs= */ DateUtils.MINUTE_IN_MILLIS - 1)); /* backgroundUsageTimeInMs= */ TIME_LESS_THAN_HALF_MINUTE));
assertThat(pref.getSummary().toString()) assertThat(pref.getSummary().toString())
.isEqualTo("Screen time: less than a minute\nBackground: less than a minute"); .isEqualTo("Screen time: less than a minute\nBackground: less than a minute");
} }