Refactor PowerUsageFeatureProvider: Cache the config set to avoid generating the set again.
Bug: 262802531 Test: manual Change-Id: I61b36e4e057c432d814aa104a37f0e0d552720cb
This commit is contained in:
@@ -33,12 +33,12 @@ public interface PowerUsageFeatureProvider {
|
||||
/**
|
||||
* Check whether the battery usage button is enabled in the battery page
|
||||
*/
|
||||
boolean isBatteryUsageEnabled(Context context);
|
||||
boolean isBatteryUsageEnabled();
|
||||
|
||||
/**
|
||||
* Returns an allowlist of app names combined into the system-apps item
|
||||
*/
|
||||
List<String> getSystemAppsAllowlist(Context context);
|
||||
List<String> getSystemAppsAllowlist();
|
||||
|
||||
/**
|
||||
* Check whether location setting is enabled
|
||||
@@ -135,25 +135,25 @@ public interface PowerUsageFeatureProvider {
|
||||
/**
|
||||
* Returns {@link Set} for the system component ids which are combined into others.
|
||||
*/
|
||||
Set<Integer> getOthersSystemComponentSet(Context context);
|
||||
Set<Integer> getOthersSystemComponentSet();
|
||||
|
||||
/**
|
||||
* Returns {@link Set} for hiding system component ids in the usage screen.
|
||||
*/
|
||||
Set<Integer> getHideSystemComponentSet(Context context);
|
||||
Set<Integer> getHideSystemComponentSet();
|
||||
|
||||
/**
|
||||
* Returns {@link Set} for hiding application package names in the usage screen.
|
||||
*/
|
||||
Set<CharSequence> getHideApplicationSet(Context context);
|
||||
Set<String> getHideApplicationSet();
|
||||
|
||||
/**
|
||||
* Returns {@link Set} for hiding applications background usage time.
|
||||
*/
|
||||
Set<CharSequence> getHideBackgroundUsageTimeSet(Context context);
|
||||
Set<String> getHideBackgroundUsageTimeSet();
|
||||
|
||||
/**
|
||||
* Returns {@link Set} for ignoring task root class names for screen on time.
|
||||
*/
|
||||
Set<CharSequence> getIgnoreScreenOnTimeTaskRootSet(Context context);
|
||||
Set<String> getIgnoreScreenOnTimeTaskRootSet();
|
||||
}
|
||||
|
@@ -67,12 +67,12 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBatteryUsageEnabled(Context context) {
|
||||
public boolean isBatteryUsageEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSystemAppsAllowlist(Context context) {
|
||||
public List<String> getSystemAppsAllowlist() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -153,27 +153,27 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getOthersSystemComponentSet(Context context) {
|
||||
public Set<Integer> getOthersSystemComponentSet() {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getHideSystemComponentSet(Context context) {
|
||||
public Set<Integer> getHideSystemComponentSet() {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CharSequence> getHideApplicationSet(Context context) {
|
||||
public Set<String> getHideApplicationSet() {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CharSequence> getHideBackgroundUsageTimeSet(Context context) {
|
||||
public Set<String> getHideBackgroundUsageTimeSet() {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CharSequence> getIgnoreScreenOnTimeTaskRootSet(Context context) {
|
||||
public Set<String> getIgnoreScreenOnTimeTaskRootSet() {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
}
|
||||
|
@@ -323,10 +323,10 @@ public final class DataProcessor {
|
||||
final List<AppUsageEvent> appUsageEventList = new ArrayList<>();
|
||||
long numEventsFetched = 0;
|
||||
long numAllEventsFetched = 0;
|
||||
final Set<CharSequence> ignoreScreenOnTimeTaskRootSet =
|
||||
final Set<String> ignoreScreenOnTimeTaskRootSet =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getIgnoreScreenOnTimeTaskRootSet(context);
|
||||
.getIgnoreScreenOnTimeTaskRootSet();
|
||||
for (final long userId : usageEventsMap.keySet()) {
|
||||
final UsageEvents usageEvents = usageEventsMap.get(userId);
|
||||
while (usageEvents.hasNextEvent()) {
|
||||
@@ -1691,15 +1691,15 @@ public final class DataProcessor {
|
||||
final Set<Integer> hideSystemComponentSet =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getHideSystemComponentSet(context);
|
||||
final Set<CharSequence> hideBackgroundUsageTimeSet =
|
||||
.getHideSystemComponentSet();
|
||||
final Set<String> hideBackgroundUsageTimeSet =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getHideBackgroundUsageTimeSet(context);
|
||||
final Set<CharSequence> hideApplicationSet =
|
||||
.getHideBackgroundUsageTimeSet();
|
||||
final Set<String> hideApplicationSet =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getHideApplicationSet(context);
|
||||
.getHideApplicationSet();
|
||||
resultMap.keySet().forEach(dailyKey -> {
|
||||
final Map<Integer, BatteryDiffData> dailyUsageMap = resultMap.get(dailyKey);
|
||||
dailyUsageMap.values().forEach(batteryDiffData -> {
|
||||
@@ -1727,8 +1727,8 @@ public final class DataProcessor {
|
||||
private static void purgeFakeAndHiddenPackages(
|
||||
final List<BatteryDiffEntry> entries,
|
||||
final Set<Integer> hideSystemComponentSet,
|
||||
final Set<CharSequence> hideApplicationSet,
|
||||
final Set<CharSequence> hideBackgroundUsageTimeSet) {
|
||||
final Set<String> hideApplicationSet,
|
||||
final Set<String> hideBackgroundUsageTimeSet) {
|
||||
final Iterator<BatteryDiffEntry> iterator = entries.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final BatteryDiffEntry entry = iterator.next();
|
||||
@@ -1750,7 +1750,7 @@ public final class DataProcessor {
|
||||
final Set<Integer> othersSystemComponentSet =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getOthersSystemComponentSet(context);
|
||||
.getOthersSystemComponentSet();
|
||||
|
||||
BatteryDiffEntry.OthersBatteryDiffEntry othersDiffEntry = null;
|
||||
final Iterator<BatteryDiffEntry> systemListIterator =
|
||||
@@ -1777,7 +1777,7 @@ public final class DataProcessor {
|
||||
final List<String> systemAppsAllowlist =
|
||||
FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context)
|
||||
.getSystemAppsAllowlist(context);
|
||||
.getSystemAppsAllowlist();
|
||||
final Application application = (Application) context.getApplicationContext();
|
||||
final ApplicationsState applicationsState =
|
||||
application == null ? null : ApplicationsState.getInstance(application);
|
||||
|
@@ -256,7 +256,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
mBatteryUsagePreference = findPreference(KEY_BATTERY_USAGE);
|
||||
mBatteryUsagePreference.setSummary(getString(R.string.advanced_battery_preference_summary));
|
||||
mBatteryUsagePreference.setVisible(
|
||||
mPowerFeatureProvider.isBatteryUsageEnabled(getContext()));
|
||||
mPowerFeatureProvider.isBatteryUsageEnabled());
|
||||
|
||||
mHelpPreference = findPreference(KEY_BATTERY_ERROR);
|
||||
mHelpPreference.setVisible(false);
|
||||
|
Reference in New Issue
Block a user