Introduce boolean flags to show/hide items for Language & input.

This adds seven new boolean flags:
config_show_phone_language
config_show_virtual_keyboard_pref
config_show_physical_keyboard_pref
config_show_spellcheckers_settings
config_show_tts_settings_summary
config_show_pointer_speed
config_show_vibrate_input_devices

Which when individually set to false, will hide the item from "Language
& input" in System. It will also hide them from surfacing in search
results.

Bug: 62379555
Test: Individual controller tests are all updated.

Change-Id: I9ef1c3037b0bec6ffa5a627006507f4f16e534c4
This commit is contained in:
Ben Lin
2017-12-21 11:09:39 -08:00
parent de4bef0243
commit c28b46f2ea
17 changed files with 265 additions and 22 deletions

View File

@@ -72,6 +72,27 @@
<!-- Whether enabled_vr_listeners should be shown or not. -->
<bool name="config_show_enabled_vr_listeners">true</bool>
<!-- Whether phone_language should be shown or not. -->
<bool name="config_show_phone_language">true</bool>
<!-- Whether virtual_keyboard_pref should be shown or not. -->
<bool name="config_show_virtual_keyboard_pref">true</bool>
<!-- Whether physical_keyboard_pref should be shown or not. -->
<bool name="config_show_physical_keyboard_pref">true</bool>
<!-- Whether spellcheckers_settings should be shown or not. -->
<bool name="config_show_spellcheckers_settings">true</bool>
<!-- Whether tts_settings_summary should be shown or not. -->
<bool name="config_show_tts_settings_summary">true</bool>
<!-- Whether pointer_speed should be shown or not. -->
<bool name="config_show_pointer_speed">true</bool>
<!-- Whether vibrate_input_devices should be shown or not. -->
<bool name="config_show_vibrate_input_devices">true</bool>
<!-- Whether wallpaper attribution should be shown or not. -->
<bool name="config_show_wallpaper_attribution">true</bool>

View File

@@ -27,6 +27,7 @@ import android.text.TextUtils;
import android.view.InputDevice;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
@@ -73,6 +74,11 @@ public class GameControllerPreferenceController extends AbstractPreferenceContro
@Override
public boolean isAvailable() {
// If device explicitly wants to hide this, return early.
if (!mContext.getResources().getBoolean(R.bool.config_show_vibrate_input_devices)) {
return false;
}
final int[] devices = mIm.getInputDeviceIds();
for (int deviceId : devices) {
InputDevice device = mIm.getInputDevice(deviceId);

View File

@@ -50,7 +50,7 @@ public class PhysicalKeyboardPreferenceController extends AbstractPreferenceCont
@Override
public boolean isAvailable() {
return true;
return mContext.getResources().getBoolean(R.bool.config_show_physical_keyboard_pref);
}
@Override

View File

@@ -51,7 +51,7 @@ public class SpellCheckerPreferenceController extends AbstractPreferenceControll
@Override
public boolean isAvailable() {
return true;
return mContext.getResources().getBoolean(R.bool.config_show_spellcheckers_settings);
}
@Override

View File

@@ -47,7 +47,7 @@ public class VirtualKeyboardPreferenceController extends AbstractPreferenceContr
@Override
public boolean isAvailable() {
return true;
return mContext.getResources().getBoolean(R.bool.config_show_virtual_keyboard_pref);
}
@Override

View File

@@ -21,6 +21,7 @@ import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.speech.tts.TtsEngines;
@@ -40,6 +41,7 @@ import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController;
import com.android.settings.inputmethod.SpellCheckerPreferenceController;
import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -51,7 +53,10 @@ public class LanguageAndInputSettings extends DashboardFragment {
private static final String TAG = "LangAndInputSettings";
private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category";
private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary";
private static final String KEY_POINTER_AND_TTS_CATEGORY = "pointer_and_tts_category";
private static final String KEY_GAME_CONTROLLER_CATEGORY = "game_controller_settings_category";
private static final String KEY_PHYSICAL_KEYBOARD = "physical_keyboard_pref";
@Override
@@ -92,20 +97,45 @@ public class LanguageAndInputSettings extends DashboardFragment {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
// Language
controllers.add(new PhoneLanguagePreferenceController(context));
controllers.add(new SpellCheckerPreferenceController(context));
controllers.add(new UserDictionaryPreferenceController(context));
controllers.add(new TtsPreferenceController(context, new TtsEngines(context)));
// Input
controllers.add(new VirtualKeyboardPreferenceController(context));
controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle));
final VirtualKeyboardPreferenceController virtualKeyboardPreferenceController =
new VirtualKeyboardPreferenceController(context);
final PhysicalKeyboardPreferenceController physicalKeyboardPreferenceController =
new PhysicalKeyboardPreferenceController(context, lifecycle);
controllers.add(virtualKeyboardPreferenceController);
controllers.add(physicalKeyboardPreferenceController);
controllers.add(new PreferenceCategoryController(context,
KEY_KEYBOARDS_CATEGORY,
Arrays.asList(virtualKeyboardPreferenceController,
physicalKeyboardPreferenceController)));
// Pointer and Tts
final TtsPreferenceController ttsPreferenceController =
new TtsPreferenceController(context, new TtsEngines(context));
controllers.add(ttsPreferenceController);
final PointerSpeedController pointerController = new PointerSpeedController(context);
controllers.add(pointerController);
controllers.add(new PreferenceCategoryController(context,
KEY_POINTER_AND_TTS_CATEGORY,
Arrays.asList(pointerController, ttsPreferenceController)));
// Input Assistance
controllers.add(new SpellCheckerPreferenceController(context));
controllers.add(new DefaultAutofillPreferenceController(context));
controllers.add(new UserDictionaryPreferenceController(context));
// Game Controller
final GameControllerPreferenceController gameControllerPreferenceController
= new GameControllerPreferenceController(context);
if (lifecycle != null) {
lifecycle.addObserver(gameControllerPreferenceController);
}
controllers.add(gameControllerPreferenceController);
controllers.add(new DefaultAutofillPreferenceController(context));
controllers.add(new PreferenceCategoryController(context,
KEY_GAME_CONTROLLER_CATEGORY,
Arrays.asList(gameControllerPreferenceController)));
return controllers;
}

View File

@@ -41,7 +41,8 @@ public class PhoneLanguagePreferenceController extends AbstractPreferenceControl
@Override
public boolean isAvailable() {
return mContext.getAssets().getLocales().length > 1;
return mContext.getResources().getBoolean(R.bool.config_show_phone_language)
&& mContext.getAssets().getLocales().length > 1;
}
@Override

View File

@@ -0,0 +1,41 @@
/*
* 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.settings.language;
import android.content.Context;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;
import android.support.annotation.VisibleForTesting;
public class PointerSpeedController extends BasePreferenceController {
@VisibleForTesting static final String KEY_POINTER_SPEED = "pointer_speed";
public PointerSpeedController(Context context) {
super(context, KEY_POINTER_SPEED);
}
@AvailabilityStatus
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(R.bool.config_show_pointer_speed)
? AVAILABLE
: DISABLED_UNSUPPORTED;
}
}

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.speech.tts.TtsEngines;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
public class TtsPreferenceController extends AbstractPreferenceController
@@ -37,7 +38,8 @@ public class TtsPreferenceController extends AbstractPreferenceController
@Override
public boolean isAvailable() {
return !mTtsEngines.getEngines().isEmpty();
return !mTtsEngines.getEngines().isEmpty() &&
mContext.getResources().getBoolean(R.bool.config_show_tts_settings_summary);
}
@Override

View File

@@ -31,4 +31,10 @@
<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>
<bool name="config_show_physical_keyboard_pref">false</bool>
<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>
</resources>

View File

@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,6 +35,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -44,18 +46,18 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class GameControllerPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private InputManager mInputManager;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private InputDevice mInputDevice;
private Context mContext;
private GameControllerPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
mController = new GameControllerPreferenceController(mContext);
}
@@ -110,6 +112,14 @@ public class GameControllerPreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
mController = new GameControllerPreferenceController(mContext);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});

View File

@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,6 +38,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -65,10 +67,22 @@ public class PhysicalKeyboardPreferenceControllerTest {
}
@Test
public void shouldAlwaysBeAvailable() {
public void testPhysicalKeyboard_byDefault_shouldBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PhysicalKeyboardPreferenceController(context, null);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testPhysicalKeyboard_ifDisabled_shouldNotBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PhysicalKeyboardPreferenceController(context, null);
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(shadows = {
ShadowInputDevice.class,

View File

@@ -16,7 +16,10 @@
package com.android.settings.inputmethod;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.preference.Preference;
import android.view.textservice.SpellCheckerInfo;
import android.view.textservice.TextServicesManager;
@@ -46,6 +49,9 @@ public class SpellCheckerPreferenceControllerTest {
private Context mContext;
@Mock
private TextServicesManager mTextServicesManager;
@Mock
private Resources mResources;
private Context mAppContext;
private Preference mPreference;
private SpellCheckerPreferenceController mController;
@@ -56,10 +62,23 @@ public class SpellCheckerPreferenceControllerTest {
mAppContext = RuntimeEnvironment.application;
when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
.thenReturn(mTextServicesManager);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(R.bool.config_show_spellcheckers_settings)).thenReturn(true);
mPreference = new Preference(mAppContext);
mController = new SpellCheckerPreferenceController(mContext);
}
@Test
public void testSpellChecker_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testSpellChecker_ifDisabled_shouldNotBeShown() {
when(mResources.getBoolean(R.bool.config_show_spellcheckers_settings)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateState_NoSpellerChecker_shouldSetSummaryToDefault() {
when(mTextServicesManager.isSpellCheckerEnabled()).thenReturn(true);

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -75,10 +76,20 @@ public class VirtualKeyboardPreferenceControllerTest {
}
@Test
public void shouldAlwaysBeAvailable() {
public void testVirtualKeyboard_byDefault_shouldBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new VirtualKeyboardPreferenceController(context);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testVirtualKeyboard_ifDisabled_shouldNotBeShown() {
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new VirtualKeyboardPreferenceController(context);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void updateState_noEnabledIMEs_setEmptySummary() {
mController.updateState(mPreference);

View File

@@ -17,10 +17,13 @@
package com.android.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.AssetManager;
import android.support.v7.preference.Preference;
import com.android.settings.TestConfig;
@@ -33,6 +36,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -42,34 +46,44 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PhoneLanguagePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private Preference mPreference;
@Mock
private AssetManager mAssets;
private Context mContext;
private FakeFeatureFactory mFeatureFactory;
private PhoneLanguagePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getAssets()).thenReturn(mAssets);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mController = new PhoneLanguagePreferenceController(mContext);
}
@Test
public void testIsAvailable_hasMultipleLocales_shouldReturnTrue() {
when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en", "de"});
when(mAssets.getLocales()).thenReturn(new String[] {"en", "de"});
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_hasSingleLocales_shouldReturnFalse() {
when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en"});
when(mAssets.getLocales()).thenReturn(new String[] {"en"});
assertThat(mController.isAvailable()).isFalse();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testUpdateState_shouldUpdateSummary() {
final String testSummary = "test";

View File

@@ -0,0 +1,60 @@
/*
* 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.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class PointerSpeedControllerTest {
private Context mContext;
private PointerSpeedController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PointerSpeedController(mContext);
}
@Test
public void testDeviceAdministrators_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testDeviceAdministrators_ifDisabled_shouldNotBeShown() {
assertThat(mController.isAvailable()).isFalse();
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -45,19 +46,19 @@ import java.util.List;
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class TtsPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private TtsEngines mTtsEngines;
@Mock
private PreferenceScreen mScreen;
private Context mContext;
private TtsPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new TtsPreferenceController(mContext, mTtsEngines);
mPreference = new Preference(RuntimeEnvironment.application);
@@ -89,4 +90,11 @@ public class TtsPreferenceControllerTest {
assertThat(mPreference.isVisible()).isTrue();
}
@Test
@Config(qualifiers = "mcc999")
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
assertThat(mController.isAvailable()).isFalse();
}
}