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

Commit 216353a7 authored by Daniel Norman's avatar Daniel Norman
Browse files

Makes Caption Language searchable only if captions are enabled.

Fix: 354785578
Flag: com.android.settings.accessibility.fix_a11y_settings_search
Test: atest CaptioningMoreOptionsFragmentTest
Test: adb shell pm clear com.google.android.settings.intelligence;
      disable captioning;
      search Settings for 'language', observe caption language missing
      enable captioning;
      search Settings for 'language', observe caption language present
Change-Id: I015d2c77fbd3f7b8fe713bafb3a49a86160ca958
parent c3cfb425
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);
    }
}