Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea97a663 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Conditionally block battery percantage from search" into pi-dev

parents f406fd79 5e8005db
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;
                }
+30 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static org.mockito.Mockito.when;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.Menu;
@@ -49,6 +50,7 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.display.BatteryPercentagePreferenceController;
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -390,6 +392,34 @@ public class PowerUsageSummaryTest {
                .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 {
        private Context mContext;