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>
|
<item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
|
||||||
</string-array>
|
</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">
|
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
|
||||||
<!-- Google -->
|
<!-- Google -->
|
||||||
<item>"com.google.android.googlequicksearchbox"</item>
|
<item>"com.google.android.googlequicksearchbox"</item>
|
||||||
</string-array>
|
</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. -->
|
<!-- Array of titles palette list for accessibility. -->
|
||||||
<string-array name="setting_palette_data" translatable="false" >
|
<string-array name="setting_palette_data" translatable="false" >
|
||||||
<item>@string/color_red</item>
|
<item>@string/color_red</item>
|
||||||
|
@@ -86,6 +86,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
private final InstrumentedPreferenceFragment mFragment;
|
private final InstrumentedPreferenceFragment mFragment;
|
||||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
private final CharSequence[] mNotAllowShowSummaryPackages;
|
private final CharSequence[] mNotAllowShowSummaryPackages;
|
||||||
|
private final CharSequence[] mNotAllowShowEntryPackages;
|
||||||
|
|
||||||
// Preference cache to avoid create new instance each time.
|
// Preference cache to avoid create new instance each time.
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -103,6 +104,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
mPreferenceKey = preferenceKey;
|
mPreferenceKey = preferenceKey;
|
||||||
mNotAllowShowSummaryPackages = context.getResources()
|
mNotAllowShowSummaryPackages = context.getResources()
|
||||||
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
||||||
|
mNotAllowShowEntryPackages = context.getResources()
|
||||||
|
.getTextArray(R.array.allowlist_hide_entry_in_battery_usage);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
@@ -180,8 +183,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
isValidPackage = mBatteryUtils.getPackageUid(packageName)
|
isValidPackage = mBatteryUtils.getPackageUid(packageName)
|
||||||
!= BatteryUtils.UID_NULL;
|
!= BatteryUtils.UID_NULL;
|
||||||
}
|
}
|
||||||
Log.d(TAG, String.format("handleClick() label=%s key=%s isValid:%b %s",
|
Log.d(TAG, String.format("handleClick() label=%s key=%s isValid:%b\n%s",
|
||||||
diffEntry.getAppLabel(), histEntry.getKey(), isValidPackage, packageName));
|
diffEntry.getAppLabel(), histEntry.getKey(), isValidPackage, histEntry));
|
||||||
if (isValidPackage) {
|
if (isValidPackage) {
|
||||||
AdvancedPowerUsageDetail.startBatteryDetailPage(
|
AdvancedPowerUsageDetail.startBatteryDetailPage(
|
||||||
mActivity, mFragment, diffEntry, powerPref.getPercent(),
|
mActivity, mFragment, diffEntry, powerPref.getPercent(),
|
||||||
@@ -315,6 +318,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
|
final List<BatteryDiffEntry> appEntries = new ArrayList<>();
|
||||||
mSystemEntries.clear();
|
mSystemEntries.clear();
|
||||||
entries.forEach(entry -> {
|
entries.forEach(entry -> {
|
||||||
|
final String packageName = entry.getPackageName();
|
||||||
|
if (!isValidToShowEntry(packageName)) {
|
||||||
|
Log.w(TAG, "ignore showing item:" + packageName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (entry.isSystemEntry()) {
|
if (entry.isSystemEntry()) {
|
||||||
mSystemEntries.add(entry);
|
mSystemEntries.add(entry);
|
||||||
} else {
|
} else {
|
||||||
@@ -510,15 +518,14 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
return mPrefContext.getString(resourceId, timeSequence);
|
return mPrefContext.getString(resourceId, timeSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidToShowSummary(String packageName) {
|
@VisibleForTesting
|
||||||
if (mNotAllowShowSummaryPackages != null) {
|
boolean isValidToShowSummary(String packageName) {
|
||||||
for (CharSequence notAllowPackageName : mNotAllowShowSummaryPackages) {
|
return !contains(packageName, mNotAllowShowSummaryPackages);
|
||||||
if (TextUtils.equals(packageName, notAllowPackageName)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
@VisibleForTesting
|
||||||
return true;
|
boolean isValidToShowEntry(String packageName) {
|
||||||
|
return !contains(packageName, mNotAllowShowEntryPackages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -552,6 +559,17 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
return builder.toString();
|
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
|
@VisibleForTesting
|
||||||
static boolean validateUsageTime(BatteryDiffEntry entry) {
|
static boolean validateUsageTime(BatteryDiffEntry entry) {
|
||||||
final long foregroundUsageTimeInMs = entry.mForegroundUsageTimeInMs;
|
final long foregroundUsageTimeInMs = entry.mForegroundUsageTimeInMs;
|
||||||
|
@@ -581,6 +581,33 @@ public final class BatteryChartPreferenceControllerTest {
|
|||||||
assertThat(mBatteryChartPreferenceController.mIsExpanded).isTrue();
|
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() {
|
private static Map<Long, Map<String, BatteryHistEntry>> createBatteryHistoryMap() {
|
||||||
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
|
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
|
||||||
for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
|
for (int index = 0; index < DESIRED_HISTORY_SIZE; index++) {
|
||||||
|
Reference in New Issue
Block a user