Merge "Should not show internal package entry in the usage list" into sc-dev
This commit is contained in:
@@ -1512,12 +1512,20 @@
|
||||
<item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
|
||||
</string-array>
|
||||
|
||||
<!-- An allowlist which packages won't show summary in battery usage screen. [CHAR LIMIT=NONE] -->
|
||||
<!-- An allowlist which packages won't show summary in battery usage screen.
|
||||
[CHAR LIMIT=NONE] -->
|
||||
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
|
||||
<!-- Google -->
|
||||
<item>"com.google.android.googlequicksearchbox"</item>
|
||||
</string-array>
|
||||
|
||||
<!-- An allowlist which packages won't show entry in battery usage screen.
|
||||
[CHAR LIMIT=NONE] -->
|
||||
<string-array name="allowlist_hide_entry_in_battery_usage" translatable="false">
|
||||
<item>"com.google.android.gms.persistent"</item>
|
||||
<item>"dex2oat64"</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Array of titles palette list for accessibility. -->
|
||||
<string-array name="setting_palette_data" translatable="false" >
|
||||
<item>@string/color_red</item>
|
||||
|
@@ -86,6 +86,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
private final InstrumentedPreferenceFragment mFragment;
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private final CharSequence[] mNotAllowShowSummaryPackages;
|
||||
private final CharSequence[] mNotAllowShowEntryPackages;
|
||||
|
||||
// Preference cache to avoid create new instance each time.
|
||||
@VisibleForTesting
|
||||
@@ -103,6 +104,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
mPreferenceKey = preferenceKey;
|
||||
mNotAllowShowSummaryPackages = context.getResources()
|
||||
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
||||
mNotAllowShowEntryPackages = context.getResources()
|
||||
.getTextArray(R.array.allowlist_hide_entry_in_battery_usage);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
@@ -180,8 +183,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
isValidPackage = mBatteryUtils.getPackageUid(packageName)
|
||||
!= BatteryUtils.UID_NULL;
|
||||
}
|
||||
Log.d(TAG, String.format("handleClick() label=%s key=%s isValid:%b %s",
|
||||
diffEntry.getAppLabel(), histEntry.getKey(), isValidPackage, packageName));
|
||||
Log.d(TAG, String.format("handleClick() label=%s key=%s isValid:%b\n%s",
|
||||
diffEntry.getAppLabel(), histEntry.getKey(), isValidPackage, histEntry));
|
||||
if (isValidPackage) {
|
||||
AdvancedPowerUsageDetail.startBatteryDetailPage(
|
||||
mActivity, mFragment, diffEntry, powerPref.getPercent(),
|
||||
@@ -315,6 +318,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
|
||||
mSystemEntries.clear();
|
||||
entries.forEach(entry -> {
|
||||
final String packageName = entry.getPackageName();
|
||||
if (!isValidToShowEntry(packageName)) {
|
||||
Log.w(TAG, "ignore showing item:" + packageName);
|
||||
return;
|
||||
}
|
||||
if (entry.isSystemEntry()) {
|
||||
mSystemEntries.add(entry);
|
||||
} else {
|
||||
@@ -510,15 +518,14 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
return mPrefContext.getString(resourceId, timeSequence);
|
||||
}
|
||||
|
||||
private boolean isValidToShowSummary(String packageName) {
|
||||
if (mNotAllowShowSummaryPackages != null) {
|
||||
for (CharSequence notAllowPackageName : mNotAllowShowSummaryPackages) {
|
||||
if (TextUtils.equals(packageName, notAllowPackageName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@VisibleForTesting
|
||||
boolean isValidToShowSummary(String packageName) {
|
||||
return !contains(packageName, mNotAllowShowSummaryPackages);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isValidToShowEntry(String packageName) {
|
||||
return !contains(packageName, mNotAllowShowEntryPackages);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -552,6 +559,17 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static boolean contains(String target, CharSequence[] packageNames) {
|
||||
if (target != null && packageNames != null) {
|
||||
for (CharSequence packageName : packageNames) {
|
||||
if (TextUtils.equals(target, packageName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static boolean validateUsageTime(BatteryDiffEntry entry) {
|
||||
final long foregroundUsageTimeInMs = entry.mForegroundUsageTimeInMs;
|
||||
|
@@ -581,6 +581,33 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
assertThat(mBatteryChartPreferenceController.mIsExpanded).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsValidToShowSummary_returnExpectedResult() {
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowSummary("com.google.android.apps.scone"))
|
||||
.isTrue();
|
||||
|
||||
// Verifies the item which is defined in the array list.
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowSummary("com.google.android.googlequicksearchbox"))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsValidToShowEntry_returnExpectedResult() {
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowEntry("com.google.android.apps.scone"))
|
||||
.isTrue();
|
||||
|
||||
// Verifies the items which are defined in the array list.
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowEntry("com.google.android.gms.persistent"))
|
||||
.isFalse();
|
||||
assertThat(mBatteryChartPreferenceController
|
||||
.isValidToShowEntry("dex2oat64"))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
private static Map<Long, Map<String, BatteryHistEntry>> createBatteryHistoryMap() {
|
||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
|
||||
for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
|
||||
|
Reference in New Issue
Block a user