Snap for 9279354 from 57cb76428e to tm-qpr2-release

Change-Id: Ic33bba42ea577bcb5d934f1250242599100b69cd
This commit is contained in:
Android Build Coastguard Worker
2022-11-11 00:29:55 +00:00
5 changed files with 117 additions and 29 deletions

View File

@@ -6372,8 +6372,8 @@
<string name="advanced_battery_preference_title">Battery usage</string>
<!-- Preference summary for advanced battery usage, for past 24 hours [CHAR LIMIT=40] -->
<string name="advanced_battery_preference_summary_with_hours">View usage for past 24 hours</string>
<!-- Preference summary for advanced battery usage, from last full charge [CHAR LIMIT=40] -->
<string name="advanced_battery_preference_summary">View usage from last full charge</string>
<!-- Preference summary for advanced battery usage, since last full charge [CHAR LIMIT=40] -->
<string name="advanced_battery_preference_summary">View usage since last full charge</string>
<!-- Activity title for battery usage details for an app. or power consumer -->
<string name="battery_details_title">App battery usage</string>
@@ -6748,50 +6748,50 @@
<!-- Title for the battery management group [CHAR LIMIT=40] -->
<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 from last full charge. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<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\nfrom last full charge</string>
<!-- Description for battery total and background usage time for an app, i.e. 1 hr 15 min total • 39 min background since last full charge. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<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\nsince last full charge</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] -->
<string name="battery_total_and_bg_usage_24hr"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • <xliff:g id="time" example="39 min">^2</xliff:g> background\nfor 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] -->
<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\nfor <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 from last full charge [CHAR LIMIT=120] -->
<string name="battery_total_usage_less_minute">Total less than a minute from last full charge</string>
<!-- Description for battery total usage time is less than a minute for an app since last full charge [CHAR LIMIT=120] -->
<string name="battery_total_usage_less_minute">Total less than a minute since last full charge</string>
<!-- Description for battery total usage time is less than a minute for an app for past 24 hr [CHAR LIMIT=120] -->
<string name="battery_total_usage_less_minute_24hr">Total less than a minute for past 24 hr</string>
<!-- Description for battery total usage time is less than a minute in a time period for an app, i.e. Total less than a minute for 12 am-2 am. Note: ^1 should be used in all translations[CHAR LIMIT=120] -->
<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 from last full charge [CHAR LIMIT=120] -->
<string name="battery_bg_usage_less_minute">Background less than a minute from last full charge</string>
<!-- Description for battery background usage time is less than a minute for an app since last full charge [CHAR LIMIT=120] -->
<string name="battery_bg_usage_less_minute">Background less than a minute since last full charge</string>
<!-- Description for battery background usage time is less than a minute for an app for past 24 hr [CHAR LIMIT=120] -->
<string name="battery_bg_usage_less_minute_24hr">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] -->
<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 from last full charge. 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 from last full charge</string>
<!-- Description for battery total usage time for an app, i.e. 1 hr 15 min total since last full charge. 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 since last full charge</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] -->
<string name="battery_total_usage_24hr"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total for past 24 hr</string>
<!-- Description for battery total usage time in a time period for an app, i.e. 1 hr 15 min total for 12 am-2 am. Note: ^1 and ^2 should be used in all translations [CHAR LIMIT=120] -->
<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 from last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background from last full charge</string>
<!-- Description for battery background usage time for an app, i.e. 1 hr 15 min background since last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<string name="battery_bg_usage"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> background since last full charge</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] -->
<string name="battery_bg_usage_24hr"><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] -->
<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 from last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<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\nfrom last full charge</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 since last full charge. Note: ^1 should be used in all translations [CHAR LIMIT=120] -->
<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\nsince last full charge</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] -->
<string name="battery_total_usage_and_bg_less_minute_usage_24hr"><xliff:g id="time" example="1 hr 15 min">^1</xliff:g> total • background less than a minute\nfor 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] -->
<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\nfor <xliff:g id="time_period" example="12 am-2 am">^2</xliff:g></string>
<!-- Description for no any battery usage from last full charge [CHAR LIMIT=120] -->
<string name="battery_not_usage">No usage from last full charge</string>
<!-- Description for no any battery usage since last full charge [CHAR LIMIT=120] -->
<string name="battery_not_usage">No usage since last full charge</string>
<!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] -->
<string name="battery_not_usage_24hr">No usage for past 24 hr</string>
<!-- Description for no usage time but have battery usage [CHAR LIMIT=120] -->

View File

@@ -67,6 +67,7 @@ public final class DataProcessor {
private static final int MAX_DIFF_SECONDS_OF_UPPER_TIMESTAMP = 5;
// Maximum total time value for each hourly slot cumulative data at most 2 hours.
private static final float TOTAL_HOURLY_TIME_THRESHOLD = DateUtils.HOUR_IN_MILLIS * 2;
private static final long MIN_TIME_SLOT = DateUtils.HOUR_IN_MILLIS * 2;
private static final Map<String, BatteryHistEntry> EMPTY_BATTERY_MAP = new HashMap<>();
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
new BatteryHistEntry(new ContentValues());
@@ -270,13 +271,31 @@ public final class DataProcessor {
}
final long startTime = timestampList.get(0);
final long endTime = timestampList.get(timestampList.size() - 1);
// If the timestamp diff is smaller than MIN_TIME_SLOT, returns the empty list directly.
if (endTime - startTime < MIN_TIME_SLOT) {
return dailyTimestampList;
}
long nextDay = getTimestampOfNextDay(startTime);
dailyTimestampList.add(startTime);
// Only if the timestamp diff in the first day is bigger than MIN_TIME_SLOT, start from the
// first day. Otherwise, start from the second day.
if (nextDay - startTime >= MIN_TIME_SLOT) {
dailyTimestampList.add(startTime);
}
while (nextDay < endTime) {
dailyTimestampList.add(nextDay);
nextDay += DateUtils.DAY_IN_MILLIS;
}
dailyTimestampList.add(endTime);
final long lastDailyTimestamp = dailyTimestampList.get(dailyTimestampList.size() - 1);
// Only if the timestamp diff in the last day is bigger than MIN_TIME_SLOT, add the
// last day.
if (endTime - lastDailyTimestamp >= MIN_TIME_SLOT) {
dailyTimestampList.add(endTime);
}
// The dailyTimestampList must have the start and end timestamp, otherwise, return an empty
// list.
if (dailyTimestampList.size() < MIN_TIMESTAMP_DATA_SIZE) {
return new ArrayList<>();
}
return dailyTimestampList;
}
@@ -721,7 +740,7 @@ public final class DataProcessor {
final List<Long> hourlyTimestampsPerDay = new ArrayList<>();
while (currentTimestamp <= dailyEndTimestamp) {
hourlyTimestampsPerDay.add(currentTimestamp);
currentTimestamp += 2 * DateUtils.HOUR_IN_MILLIS;
currentTimestamp += MIN_TIME_SLOT;
}
hourlyTimestamps.add(hourlyTimestampsPerDay);
}

View File

@@ -467,7 +467,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("2 min background from last full charge");
.isEqualTo("2 min background since last full charge");
}
@Test
@@ -485,7 +485,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("Background less than a minute from last full charge");
.isEqualTo("Background less than a minute since last full charge");
}
@Test
@@ -504,7 +504,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("Total less than a minute from last full charge");
.isEqualTo("Total less than a minute since last full charge");
}
@Test
@@ -520,8 +520,8 @@ public class AdvancedPowerUsageDetailTest {
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\nfrom last full charge");
assertThat(captor.getValue().toString()).isEqualTo(
"1 min total • background less than a minute\nsince last full charge");
}
@Test
@@ -538,7 +538,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("1 min total from last full charge");
.isEqualTo("1 min total since last full charge");
}
@Test
@@ -555,7 +555,7 @@ public class AdvancedPowerUsageDetailTest {
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
verify(mEntityHeaderController).setSummary(captor.capture());
assertThat(captor.getValue().toString())
.isEqualTo("6 min total • 4 min background\nfrom last full charge");
.isEqualTo("6 min total • 4 min background\nsince last full charge");
}
@Test

View File

@@ -329,6 +329,18 @@ public class DataProcessorTest {
public void getDailyTimestamps_notEnoughData_returnEmptyList() {
assertThat(DataProcessor.getDailyTimestamps(new ArrayList<>())).isEmpty();
assertThat(DataProcessor.getDailyTimestamps(List.of(100L))).isEmpty();
assertThat(DataProcessor.getDailyTimestamps(List.of(100L, 5400000L))).isEmpty();
}
@Test
public void getDailyTimestamps_OneHourDataPerDay_returnEmptyList() {
// Timezone GMT+8
final List<Long> timestamps = List.of(
1641049200000L, // 2022-01-01 23:00:00
1641052800000L, // 2022-01-02 00:00:00
1641056400000L // 2022-01-02 01:00:00
);
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEmpty();
}
@Test
@@ -353,14 +365,33 @@ public class DataProcessorTest {
public void getDailyTimestamps_MultipleDaysData_returnExpectedList() {
// Timezone GMT+8
final List<Long> timestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641045600000L, // 2022-01-01 22:00:00
1641060000000L, // 2022-01-02 02:00:00
1641160800000L, // 2022-01-03 06:00:00
1641232800000L // 2022-01-04 02:00:00
);
final List<Long> expectedTimestamps = List.of(
1641045600000L, // 2022-01-01 22:00:00
1641052800000L, // 2022-01-02 00:00:00
1641139200000L, // 2022-01-03 00:00:00
1641225600000L, // 2022-01-04 00:00:00
1641232800000L // 2022-01-04 02:00:00
);
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
}
@Test
public void getDailyTimestamps_FirstDayOneHourData_returnExpectedList() {
// Timezone GMT+8
final List<Long> timestamps = List.of(
1641049200000L, // 2022-01-01 23:00:00
1641060000000L, // 2022-01-02 02:00:00
1641160800000L, // 2022-01-03 06:00:00
1641254400000L // 2022-01-04 08:00:00
);
final List<Long> expectedTimestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641052800000L, // 2022-01-02 00:00:00
1641139200000L, // 2022-01-03 00:00:00
1641225600000L, // 2022-01-04 00:00:00
@@ -369,6 +400,44 @@ public class DataProcessorTest {
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
}
@Test
public void getDailyTimestamps_LastDayNoData_returnExpectedList() {
// Timezone GMT+8
final List<Long> timestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641060000000L, // 2022-01-02 02:00:00
1641160800000L, // 2022-01-03 06:00:00
1641225600000L // 2022-01-04 00:00:00
);
final List<Long> expectedTimestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641052800000L, // 2022-01-02 00:00:00
1641139200000L, // 2022-01-03 00:00:00
1641225600000L // 2022-01-04 00:00:00
);
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
}
@Test
public void getDailyTimestamps_LastDayOneHourData_returnExpectedList() {
// Timezone GMT+8
final List<Long> timestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641060000000L, // 2022-01-02 02:00:00
1641160800000L, // 2022-01-03 06:00:00
1641229200000L // 2022-01-04 01:00:00
);
final List<Long> expectedTimestamps = List.of(
1640988000000L, // 2022-01-01 06:00:00
1641052800000L, // 2022-01-02 00:00:00
1641139200000L, // 2022-01-03 00:00:00
1641225600000L // 2022-01-04 00:00:00
);
assertThat(DataProcessor.getDailyTimestamps(timestamps)).isEqualTo(expectedTimestamps);
}
@Test
public void isFromFullCharge_emptyData_returnFalse() {
assertThat(DataProcessor.isFromFullCharge(null)).isFalse();

View File

@@ -142,7 +142,7 @@ public class PowerUsageSummaryTest {
public void initPreference_hasCorrectSummary() {
mFragment.initPreference();
verify(mBatteryUsagePreference).setSummary("View usage from last full charge");
verify(mBatteryUsagePreference).setSummary("View usage since last full charge");
}
@Test