Conditionally block battery percantage from search

The PowerUsageSummary fragment doesn't use the regular pattern
of a static method to build preference controllers, which can be
accessed by both DashboardFragment and BaseSearchIndexProvider,
because it depends on the Activity & Fragment in the creation of
the preference controllers.

The correct & long-term solution here would be to move those dependencies
out of the getPreferenceControllers method, such that the we could use a
static buildPreferenceControllers method, as seen in DisplaySettings.java.

In the mean time, we know that BatteryPercentagePrefController should not
show up on devices, so we conditionally add the the preference controller's
into getNonIndexableKeys method based on controller Availability, which
BasePreferenceController normally does automatically with a getPreferenceController
method in the host fragment's SEARCH_INDEX_DATA_PROVIDER.

Since this is a short-term solution, it should not be merged into master, and thus
I am not marking the bug as fixed.

Bug: 110894466
Test: Robotests
Change-Id: I06f814571d0b72fbf020dd11a9d23a9eb9907bfd
Merged-In: I5993d332dbd218c981ef5432aebb735d0000f67a
This commit is contained in:
Matthew Fritze
2018-07-02 11:22:59 -07:00
parent f32310a7e6
commit 5e8005db42
2 changed files with 36 additions and 0 deletions

View File

@@ -472,6 +472,12 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
@Override
public List<String> getNonIndexableKeys(Context context) {
List<String> niks = super.getNonIndexableKeys(context);
final BatteryPercentagePreferenceController controller =
new BatteryPercentagePreferenceController(context);
if (!controller.isAvailable()) {
niks.add(controller.getPreferenceKey());
}
niks.add(KEY_BATTERY_SAVER_SUMMARY);
return niks;
}