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:
@@ -72,6 +72,27 @@
|
|||||||
<!-- Whether enabled_vr_listeners should be shown or not. -->
|
<!-- Whether enabled_vr_listeners should be shown or not. -->
|
||||||
<bool name="config_show_enabled_vr_listeners">true</bool>
|
<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. -->
|
<!-- Whether wallpaper attribution should be shown or not. -->
|
||||||
<bool name="config_show_wallpaper_attribution">true</bool>
|
<bool name="config_show_wallpaper_attribution">true</bool>
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@ import android.text.TextUtils;
|
|||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
@@ -73,6 +74,11 @@ public class GameControllerPreferenceController extends AbstractPreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
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();
|
final int[] devices = mIm.getInputDeviceIds();
|
||||||
for (int deviceId : devices) {
|
for (int deviceId : devices) {
|
||||||
InputDevice device = mIm.getInputDevice(deviceId);
|
InputDevice device = mIm.getInputDevice(deviceId);
|
||||||
|
@@ -50,7 +50,7 @@ public class PhysicalKeyboardPreferenceController extends AbstractPreferenceCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return mContext.getResources().getBoolean(R.bool.config_show_physical_keyboard_pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -51,7 +51,7 @@ public class SpellCheckerPreferenceController extends AbstractPreferenceControll
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return mContext.getResources().getBoolean(R.bool.config_show_spellcheckers_settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -47,7 +47,7 @@ public class VirtualKeyboardPreferenceController extends AbstractPreferenceContr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return mContext.getResources().getBoolean(R.bool.config_show_virtual_keyboard_pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -21,6 +21,7 @@ import android.content.ComponentName;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.speech.tts.TtsEngines;
|
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.SpellCheckerPreferenceController;
|
||||||
import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
|
import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settings.widget.PreferenceCategoryController;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
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 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_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";
|
private static final String KEY_PHYSICAL_KEYBOARD = "physical_keyboard_pref";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,20 +97,45 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
|||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
// Language
|
// Language
|
||||||
controllers.add(new PhoneLanguagePreferenceController(context));
|
controllers.add(new PhoneLanguagePreferenceController(context));
|
||||||
controllers.add(new SpellCheckerPreferenceController(context));
|
|
||||||
controllers.add(new UserDictionaryPreferenceController(context));
|
|
||||||
controllers.add(new TtsPreferenceController(context, new TtsEngines(context)));
|
|
||||||
// Input
|
// Input
|
||||||
controllers.add(new VirtualKeyboardPreferenceController(context));
|
final VirtualKeyboardPreferenceController virtualKeyboardPreferenceController =
|
||||||
controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle));
|
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
|
final GameControllerPreferenceController gameControllerPreferenceController
|
||||||
= new GameControllerPreferenceController(context);
|
= new GameControllerPreferenceController(context);
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(gameControllerPreferenceController);
|
lifecycle.addObserver(gameControllerPreferenceController);
|
||||||
}
|
}
|
||||||
|
|
||||||
controllers.add(gameControllerPreferenceController);
|
controllers.add(gameControllerPreferenceController);
|
||||||
controllers.add(new DefaultAutofillPreferenceController(context));
|
controllers.add(new PreferenceCategoryController(context,
|
||||||
|
KEY_GAME_CONTROLLER_CATEGORY,
|
||||||
|
Arrays.asList(gameControllerPreferenceController)));
|
||||||
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,7 +41,8 @@ public class PhoneLanguagePreferenceController extends AbstractPreferenceControl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
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
|
@Override
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import android.speech.tts.TtsEngines;
|
import android.speech.tts.TtsEngines;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
public class TtsPreferenceController extends AbstractPreferenceController
|
public class TtsPreferenceController extends AbstractPreferenceController
|
||||||
@@ -37,7 +38,8 @@ public class TtsPreferenceController extends AbstractPreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return !mTtsEngines.getEngines().isEmpty();
|
return !mTtsEngines.getEngines().isEmpty() &&
|
||||||
|
mContext.getResources().getBoolean(R.bool.config_show_tts_settings_summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -31,4 +31,10 @@
|
|||||||
<bool name="config_show_default_home">false</bool>
|
<bool name="config_show_default_home">false</bool>
|
||||||
<bool name="config_show_accessibility_shortcut_preference">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_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>
|
</resources>
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -44,18 +46,18 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class GameControllerPreferenceControllerTest {
|
public class GameControllerPreferenceControllerTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private InputManager mInputManager;
|
private InputManager mInputManager;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private InputDevice mInputDevice;
|
private InputDevice mInputDevice;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private GameControllerPreferenceController mController;
|
private GameControllerPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
|
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
|
||||||
mController = new GameControllerPreferenceController(mContext);
|
mController = new GameControllerPreferenceController(mContext);
|
||||||
}
|
}
|
||||||
@@ -110,6 +112,14 @@ public class GameControllerPreferenceControllerTest {
|
|||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
|
||||||
|
mController = new GameControllerPreferenceController(mContext);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
|
public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
|
||||||
when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});
|
when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.inputmethod;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -65,10 +67,22 @@ public class PhysicalKeyboardPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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();
|
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
|
@Test
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
ShadowInputDevice.class,
|
ShadowInputDevice.class,
|
||||||
|
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.view.textservice.SpellCheckerInfo;
|
import android.view.textservice.SpellCheckerInfo;
|
||||||
import android.view.textservice.TextServicesManager;
|
import android.view.textservice.TextServicesManager;
|
||||||
@@ -46,6 +49,9 @@ public class SpellCheckerPreferenceControllerTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private TextServicesManager mTextServicesManager;
|
private TextServicesManager mTextServicesManager;
|
||||||
|
@Mock
|
||||||
|
private Resources mResources;
|
||||||
|
|
||||||
private Context mAppContext;
|
private Context mAppContext;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
private SpellCheckerPreferenceController mController;
|
private SpellCheckerPreferenceController mController;
|
||||||
@@ -56,10 +62,23 @@ public class SpellCheckerPreferenceControllerTest {
|
|||||||
mAppContext = RuntimeEnvironment.application;
|
mAppContext = RuntimeEnvironment.application;
|
||||||
when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
|
when(mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
|
||||||
.thenReturn(mTextServicesManager);
|
.thenReturn(mTextServicesManager);
|
||||||
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mResources.getBoolean(R.bool.config_show_spellcheckers_settings)).thenReturn(true);
|
||||||
mPreference = new Preference(mAppContext);
|
mPreference = new Preference(mAppContext);
|
||||||
mController = new SpellCheckerPreferenceController(mContext);
|
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
|
@Test
|
||||||
public void updateState_NoSpellerChecker_shouldSetSummaryToDefault() {
|
public void updateState_NoSpellerChecker_shouldSetSummaryToDefault() {
|
||||||
when(mTextServicesManager.isSpellCheckerEnabled()).thenReturn(true);
|
when(mTextServicesManager.isSpellCheckerEnabled()).thenReturn(true);
|
||||||
|
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -75,10 +76,20 @@ public class VirtualKeyboardPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldAlwaysBeAvailable() {
|
public void testVirtualKeyboard_byDefault_shouldBeShown() {
|
||||||
|
final Context context = spy(RuntimeEnvironment.application.getApplicationContext());
|
||||||
|
mController = new VirtualKeyboardPreferenceController(context);
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
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
|
@Test
|
||||||
public void updateState_noEnabledIMEs_setEmptySummary() {
|
public void updateState_noEnabledIMEs_setEmptySummary() {
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
@@ -17,10 +17,13 @@
|
|||||||
package com.android.settings.language;
|
package com.android.settings.language;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.AssetManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
@@ -33,6 +36,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -42,34 +46,44 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class PhoneLanguagePreferenceControllerTest {
|
public class PhoneLanguagePreferenceControllerTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private AssetManager mAssets;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
private PhoneLanguagePreferenceController mController;
|
private PhoneLanguagePreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
when(mContext.getAssets()).thenReturn(mAssets);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mController = new PhoneLanguagePreferenceController(mContext);
|
mController = new PhoneLanguagePreferenceController(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_hasMultipleLocales_shouldReturnTrue() {
|
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();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsAvailable_hasSingleLocales_shouldReturnFalse() {
|
public void testIsAvailable_hasSingleLocales_shouldReturnFalse() {
|
||||||
when(mContext.getAssets().getLocales()).thenReturn(new String[] {"en"});
|
when(mAssets.getLocales()).thenReturn(new String[] {"en"});
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_shouldUpdateSummary() {
|
public void testUpdateState_shouldUpdateSummary() {
|
||||||
final String testSummary = "test";
|
final String testSummary = "test";
|
||||||
|
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,7 @@ package com.android.settings.language;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -45,19 +46,19 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class TtsPreferenceControllerTest {
|
public class TtsPreferenceControllerTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
@Mock
|
||||||
private TtsEngines mTtsEngines;
|
private TtsEngines mTtsEngines;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private TtsPreferenceController mController;
|
private TtsPreferenceController mController;
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
|
||||||
mController = new TtsPreferenceController(mContext, mTtsEngines);
|
mController = new TtsPreferenceController(mContext, mTtsEngines);
|
||||||
mPreference = new Preference(RuntimeEnvironment.application);
|
mPreference = new Preference(RuntimeEnvironment.application);
|
||||||
@@ -89,4 +90,11 @@ public class TtsPreferenceControllerTest {
|
|||||||
|
|
||||||
assertThat(mPreference.isVisible()).isTrue();
|
assertThat(mPreference.isVisible()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void testIsAvailable_ifDisabled_shouldReturnFalse() {
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user