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

Commit c07124fe authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge changes from topic "move-a11y-changes"

* changes:
  Revert "Add ability to show/hide Color Correction and Color Inversion."
  Revert "Add ability to show/hide accessibility_shortcut_preference."
parents 119ea0f0 c64531bb
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -150,15 +150,6 @@
    <!-- Whether default_home should be shown or not. -->
    <bool name="config_show_default_home">true</bool>

    <!-- Whether color correction preference should be shown or not. -->
    <bool name="config_show_color_correction_preference">true</bool>

    <!-- Whether color inversion preference should be shown or not. -->
    <bool name="config_show_color_inversion_preference">true</bool>

    <!-- Whether accessibility shortcut preference should be shown or not. -->
    <bool name="config_show_accessibility_shortcut_preference">true</bool>

    <!-- Whether assist_and_voice_input should be shown or not. -->
    <bool name="config_show_assist_and_voice_input">true</bool>

+5 −37
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.os.UserHandle;
import android.os.Vibrator;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.ListPreference;
@@ -93,6 +92,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
    // Preferences
    private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE =
            "toggle_high_text_contrast_preference";
    private static final String TOGGLE_INVERSION_PREFERENCE =
            "toggle_inversion_preference";
    private static final String TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE =
            "toggle_power_button_ends_call_preference";
    private static final String TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE =
@@ -104,6 +105,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
            "toggle_master_mono";
    private static final String SELECT_LONG_PRESS_TIMEOUT_PREFERENCE =
            "select_long_press_timeout_preference";
    private static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
            "accessibility_shortcut_preference";
    private static final String CAPTIONING_PREFERENCE_SCREEN =
            "captioning_preference_screen";
    private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN =
@@ -116,13 +119,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
            "autoclick_preference_screen";
    private static final String VIBRATION_PREFERENCE_SCREEN =
            "vibration_preference_screen";

    @VisibleForTesting static final String TOGGLE_INVERSION_PREFERENCE =
            "toggle_inversion_preference";
    @VisibleForTesting static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
    private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
            "daltonizer_preference_screen";
    @VisibleForTesting static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
            "accessibility_shortcut_preference";

    // Extras passed to sub-fragments.
    static final String EXTRA_PREFERENCE_KEY = "preference_key";
@@ -627,8 +625,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
            displayCategory.addPreference(mToggleInversionPreference);
            displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
        }
        checkColorCorrectionVisibility(mDisplayDaltonizerPreferenceScreen);
        checkColorInversionVisibility(mToggleInversionPreference);

        // Text contrast.
        mToggleHighTextContrastPreference.setChecked(
@@ -683,7 +679,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
        updateAutoclickSummary(mAutoclickPreferenceScreen);

        updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
        checkAccessibilityShortcutVisibility(mAccessibilityShortcutPreferenceScreen);
    }

    private void updateMagnificationSummary(Preference pref) {
@@ -804,27 +799,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
        }
    }

    @VisibleForTesting void checkColorCorrectionVisibility(Preference preference) {
        if (!getContext().getResources().getBoolean(
                R.bool.config_show_color_correction_preference)) {
            removePreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
        }
    }

    @VisibleForTesting void checkColorInversionVisibility(Preference preference) {
        if (!getContext().getResources().getBoolean(
                R.bool.config_show_color_inversion_preference)) {
            removePreference(TOGGLE_INVERSION_PREFERENCE);
        }
    }

    @VisibleForTesting void checkAccessibilityShortcutVisibility(Preference preference) {
        if (!getContext().getResources().getBoolean(
                R.bool.config_show_accessibility_shortcut_preference)) {
            removePreference(ACCESSIBILITY_SHORTCUT_PREFERENCE);
        }
    }

    private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
        // Some devices support only a single magnification mode. In these cases, we redirect to
        // the magnification mode's UI directly, rather than showing a PreferenceScreen with a
@@ -860,12 +834,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
                    keys.add(FONT_SIZE_PREFERENCE_SCREEN);
                    keys.add(KEY_DISPLAY_SIZE);

                    // Remove Accessibility Shortcuts if it's not visible
                    if (!context.getResources().getBoolean(
                            R.bool.config_show_accessibility_shortcut_preference)) {
                        keys.add(ACCESSIBILITY_SHORTCUT_PREFERENCE);
                    }

                    // Duplicates in Language & Input
                    keys.add(TTS_SETTINGS_PREFERENCE);

+0 −3
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@
    <bool name="config_show_trust_agent_click_intent">false</bool>
    <bool name="config_show_wallpaper_attribution">false</bool>
    <bool name="config_show_default_home">false</bool>
    <bool name="config_show_accessibility_shortcut_preference">false</bool>
    <bool name="config_show_assist_and_voice_input">false</bool>
    <bool name="config_show_phone_language">false</bool>
    <bool name="config_show_virtual_keyboard_pref">false</bool>
@@ -55,8 +54,6 @@
    <bool name="config_show_tts_settings_summary">false</bool>
    <bool name="config_show_pointer_speed">false</bool>
    <bool name="config_show_vibrate_input_devices">false</bool>
    <bool name="config_show_color_correction_preference">false</bool>
    <bool name="config_show_color_inversion_preference">false</bool>
    <bool name="config_show_system_update_settings">false</bool>
    <bool name="config_wifi_support_connected_mac_randomization">false</bool>
    <bool name="config_show_device_model">false</bool>
+0 −42
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.accessibility;

import android.content.ComponentName;

import java.util.HashMap;
import java.util.Map;

/**
 * Fake controller to make robolectric test compile. Should be removed when Robolectric supports
 * API 25.
 */
public class AccessibilityShortcutController {

    public static Map<ComponentName, AccessibilityShortcutController.ToggleableFrameworkFeatureInfo>
        getFrameworkShortcutFeaturesMap() {
        return new HashMap<>();
    }

    public static class ToggleableFrameworkFeatureInfo {
        private String mSettingKey;

        public String getSettingKey() {
            return mSettingKey;
        }
    }
}
+5 −107
Original line number Diff line number Diff line
@@ -16,137 +16,35 @@

package com.android.settings.accessibility;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

import android.content.Context;
import android.support.v7.preference.Preference;

import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.XmlTestUtils;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.util.ArrayList;
import java.util.List;

import static com.google.common.truth.Truth.assertThat;

@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AccessibilitySettingsTest {

    private Context mContext;
    private AccessibilitySettings mFragment;
    private boolean mAccessibilityShortcutPreferenceRemoved;
    private boolean mColorInversionPreferenceRemoved;
    private boolean mColorCorrectionPreferenceRemoved;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = spy(RuntimeEnvironment.application);
        mFragment = new AccessibilitySettings() {
            @Override
            public Context getContext() {
                return mContext;
            }

            @Override
            protected boolean removePreference(String key) {
                if (AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE.equals(key)) {
                    mAccessibilityShortcutPreferenceRemoved = true;
                    return true;
                }

                if (AccessibilitySettings.TOGGLE_INVERSION_PREFERENCE.equals(key)) {
                    mColorInversionPreferenceRemoved = true;
                    return true;
                }

                if (AccessibilitySettings.DISPLAY_DALTONIZER_PREFERENCE_SCREEN.equals(key)) {
                    mColorCorrectionPreferenceRemoved = true;
                    return true;
                }
                return false;
            }
        };
    }

    @Test
    public void testNonIndexableKeys_existInXmlLayout() {
        final Context context = RuntimeEnvironment.application;
        final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER
                .getNonIndexableKeys(mContext);
                .getNonIndexableKeys(context);
        final List<String> keys = new ArrayList<>();

        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(mContext, R.xml.accessibility_settings));
        keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.accessibility_settings));

        assertThat(keys).containsAllIn(niks);
    }

    @Test
    public void testAccessibilityShortcutPreference_byDefault_shouldBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkAccessibilityShortcutVisibility(preference);

        assertThat(mAccessibilityShortcutPreferenceRemoved).isFalse();
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void testAccessibilityShortcutPreference_ifDisabled_shouldNotBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkAccessibilityShortcutVisibility(preference);

        assertThat(mAccessibilityShortcutPreferenceRemoved).isTrue();
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void testNonIndexableKeys_ifAccessibilityShortcutNotVisible_containsKey() {
        final List<String> niks = AccessibilitySettings.SEARCH_INDEX_DATA_PROVIDER
                .getNonIndexableKeys(mContext);

        assertThat(niks).contains(AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE);
    }

    @Test
    public void testColorInversionPreference_byDefault_shouldBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkColorInversionVisibility(preference);

        assertThat(mColorInversionPreferenceRemoved).isEqualTo(false);
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void testColorInversionPreference_ifDisabled_shouldNotBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkColorInversionVisibility(preference);

        assertThat(mColorInversionPreferenceRemoved).isEqualTo(true);
    }

    @Test
    public void testColorCorrectionPreference_byDefault_shouldBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkColorCorrectionVisibility(preference);

        assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(false);
    }

    @Test
    @Config(qualifiers = "mcc999")
    public void testColorCorrectionPreference_ifDisabled_shouldNotBeShown() {
        final Preference preference = new Preference(mContext);
        mFragment.checkColorCorrectionVisibility(preference);

        assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(true);
    }
}