Fix b/265632782: Battery usage app list changed when entering the app details page and back

This only happens on the first time the Settings package is installed.
Discussed with Chaohui, the old showSystemApp() logic in Settings->Apps has some issues. This cl updates the logic to the new logic Chaohui provided.

Bug: 265632782
Fix: 265632782
Test: manual
Change-Id: I65ca150cc685409f69b8950b131feb198662f055
This commit is contained in:
Zaiyue Xue
2023-01-16 16:43:50 +08:00
parent b427e8f02a
commit 16dfab6b31
6 changed files with 43 additions and 35 deletions

View File

@@ -88,6 +88,7 @@ public final class BatteryChartPreferenceControllerTest {
Locale.setDefault(new Locale("en_US"));
org.robolectric.shadows.ShadowSettings.set24HourTimeFormat(false);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
DataProcessor.sFakeSystemAppsSet = Set.of();
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mContext).getApplicationContext();

View File

@@ -38,6 +38,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.List;
import java.util.Set;
@RunWith(RobolectricTestRunner.class)
public class BatteryDiffDataTest {
@@ -77,7 +78,7 @@ public class BatteryDiffDataTest {
hiddenHistEntry);
boolean needsCombineInSystemApp = BatteryDiffData.needsCombineInSystemApp(
hiddenDiffEntry, List.of(), mApplicationsState);
hiddenDiffEntry, List.of(), Set.of());
assertThat(needsCombineInSystemApp).isTrue();
}
@@ -107,7 +108,7 @@ public class BatteryDiffDataTest {
mApplicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
boolean needsCombineInSystemApp = BatteryDiffData.needsCombineInSystemApp(
batteryDiffEntry, List.of(), mApplicationsState);
batteryDiffEntry, List.of(), Set.of(ConvertUtils.FAKE_PACKAGE_NAME));
assertThat(needsCombineInSystemApp).isTrue();
}
@@ -137,7 +138,7 @@ public class BatteryDiffDataTest {
mApplicationInfo.flags = 0;
boolean needsCombineInSystemApp = BatteryDiffData.needsCombineInSystemApp(
batteryDiffEntry, List.of(), mApplicationsState);
batteryDiffEntry, List.of(), Set.of());
assertThat(needsCombineInSystemApp).isFalse();
}

View File

@@ -105,8 +105,9 @@ public final class BatteryUsageBreakdownControllerTest {
/*cachedUsageConsumePower=*/ 0,
mBatteryHistEntry);
mBatteryDiffEntry = spy(mBatteryDiffEntry);
mBatteryUsageBreakdownController.mBatteryDiffData = new BatteryDiffData(mContext,
Arrays.asList(mBatteryDiffEntry), Arrays.asList(), /* isAccumulated= */ false);
mBatteryUsageBreakdownController.mBatteryDiffData =
new BatteryDiffData(mContext, Arrays.asList(mBatteryDiffEntry), Arrays.asList(),
Set.of(), /* isAccumulated= */ false);
// Adds fake testing data.
BatteryDiffEntry.sResourceCache.put(
"fakeBatteryDiffEntryKey",

View File

@@ -90,6 +90,7 @@ public final class DataProcessorTest {
mFeatureFactory = FakeFeatureFactory.setupForTest();
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
DataProcessor.sFakeSystemAppsSet = Set.of();
DataProcessor.sUsageStatsManager = mUsageStatsManager;
doReturn(mIntent).when(mContext).registerReceiver(any(), any());
doReturn(100).when(mIntent).getIntExtra(eq(BatteryManager.EXTRA_SCALE), anyInt());