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:
@@ -472,6 +472,12 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
List<String> niks = super.getNonIndexableKeys(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);
|
niks.add(KEY_BATTERY_SAVER_SUMMARY);
|
||||||
return niks;
|
return niks;
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.LoaderManager;
|
import android.app.LoaderManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -49,6 +50,7 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.applications.LayoutPreference;
|
import com.android.settings.applications.LayoutPreference;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
|
import com.android.settings.display.BatteryPercentagePreferenceController;
|
||||||
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
@@ -390,6 +392,34 @@ public class PowerUsageSummaryTest {
|
|||||||
.isEqualTo("3% - Phone will shut down soon");
|
.isEqualTo("3% - Phone will shut down soon");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void percentageSettingAvailable_shouldNotBeHiddenInSearch() {
|
||||||
|
final Resources resources = spy(mRealContext.getResources());
|
||||||
|
doReturn(true).when(resources).getBoolean(anyInt());
|
||||||
|
doReturn(resources).when(mRealContext).getResources();
|
||||||
|
final String prefKey = new BatteryPercentagePreferenceController(mRealContext)
|
||||||
|
.getPreferenceKey();
|
||||||
|
|
||||||
|
final List<String> nonIndexableKeys =
|
||||||
|
PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mRealContext);
|
||||||
|
|
||||||
|
assertThat(nonIndexableKeys).doesNotContain(prefKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void percentageSettingNotAvailable_shouldBeHiddenInSearch() {
|
||||||
|
final Resources resources = spy(mRealContext.getResources());
|
||||||
|
doReturn(false).when(resources).getBoolean(anyInt());
|
||||||
|
doReturn(resources).when(mRealContext).getResources();
|
||||||
|
final String prefKey = new BatteryPercentagePreferenceController(mRealContext)
|
||||||
|
.getPreferenceKey();
|
||||||
|
|
||||||
|
final List<String> nonIndexableKeys =
|
||||||
|
PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mRealContext);
|
||||||
|
|
||||||
|
assertThat(nonIndexableKeys).contains(prefKey);
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestFragment extends PowerUsageSummary {
|
public static class TestFragment extends PowerUsageSummary {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user