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

Commit 7db5b7a0 authored by Daniel Norman's avatar Daniel Norman Committed by Android (Google) Code Review
Browse files

Merge "Makes Caption Language searchable only if captions are enabled." into main

parents c3fb1e6d 216353a7
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.settings.accessibility;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.provider.Settings;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -50,5 +52,16 @@ public class CaptioningMoreOptionsFragment extends DashboardFragment {
    }

    public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider(R.xml.captioning_more_options);
            new BaseSearchIndexProvider(R.xml.captioning_more_options) {
                @Override
                protected boolean isPageSearchEnabled(Context context) {
                    if (!Flags.fixA11ySettingsSearch()) {
                        return super.isPageSearchEnabled(context);
                    }
                    // CaptioningMoreOptions is only searchable if captions are enabled, so that we
                    // don't show search results for settings that will cause no change to the user.
                    return Settings.Secure.getInt(context.getContentResolver(),
                            Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, 0) == 1;
                }
            };
}
+43 −3
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import static com.google.common.truth.Truth.assertThat;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;

import androidx.test.core.app.ApplicationProvider;

@@ -27,15 +30,23 @@ import com.android.settings.R;
import com.android.settings.testutils.XmlTestUtils;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/** Tests for {@link CaptioningMoreOptionsFragment}. */
@RunWith(RobolectricTestRunner.class)
public class CaptioningMoreOptionsFragmentTest {
    // Language/locale preference key, from captioning_more_options.xml
    private static final String CAPTIONING_LOCALE_KEY = "captioning_locale";

    @Rule
    public final SetFlagsRule mSetFlagRule = new SetFlagsRule();

    private final Context mContext = ApplicationProvider.getApplicationContext();
    private CaptioningMoreOptionsFragment mFragment;
@@ -65,11 +76,40 @@ public class CaptioningMoreOptionsFragmentTest {
    @Test
    public void getNonIndexableKeys_existInXmlLayout() {
        final List<String> niks = CaptioningMoreOptionsFragment.SEARCH_INDEX_DATA_PROVIDER
                .getNonIndexableKeys(mContext);
                .getNonIndexableKeys(mContext)
                .stream().filter(Objects::nonNull).collect(Collectors.toList());
        final List<String> keys =
                XmlTestUtils.getKeysFromPreferenceXml(mContext,
                        R.xml.captioning_more_options);
                XmlTestUtils.getKeysFromPreferenceXml(mContext, R.xml.captioning_more_options);

        assertThat(keys).containsAtLeastElementsIn(niks);
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
    public void getNonIndexableKeys_captioningEnabled_localeIsSearchable() {
        setCaptioningEnabled(true);

        final List<String> niks = CaptioningMoreOptionsFragment.SEARCH_INDEX_DATA_PROVIDER
                .getNonIndexableKeys(mContext);

        // Not in NonIndexableKeys == searchable
        assertThat(niks).doesNotContain(CAPTIONING_LOCALE_KEY);
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
    public void getNonIndexableKeys_captioningDisabled_localeIsNotSearchable() {
        setCaptioningEnabled(false);

        final List<String> niks = CaptioningMoreOptionsFragment.SEARCH_INDEX_DATA_PROVIDER
                .getNonIndexableKeys(mContext);

        // In NonIndexableKeys == not searchable
        assertThat(niks).contains(CAPTIONING_LOCALE_KEY);
    }

    private void setCaptioningEnabled(boolean enabled) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, enabled ? 1 : 0);
    }
}