[Physical Keyboard] Clean up old ui and flag
Change-Id: I9423d0e9debcef37338e5733aab56b98920621e3 Test: n/a Bug: 330517633 Change-Id: I485848f67e0eb3ab207413a6ed8f7de809f80c5c
This commit is contained in:
committed by
Shaowei Shen
parent
3a1252ebcc
commit
90e70b15d7
@@ -20,14 +20,6 @@
|
||||
android:key="system_dashboard_screen"
|
||||
android:title="@string/header_category_system">
|
||||
|
||||
<Preference
|
||||
android:key="language_input_settings"
|
||||
android:title="@string/language_settings"
|
||||
android:icon="@drawable/ic_settings_language"
|
||||
android:order="-260"
|
||||
android:fragment="com.android.settings.language.LanguageAndInputSettings"
|
||||
settings:controller="com.android.settings.language.LanguageAndInputPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="language_settings"
|
||||
android:title="@string/languages_settings"
|
||||
|
@@ -135,7 +135,6 @@ import com.android.settings.inputmethod.SpellCheckersSettings;
|
||||
import com.android.settings.inputmethod.TrackpadSettings;
|
||||
import com.android.settings.inputmethod.UserDictionaryList;
|
||||
import com.android.settings.inputmethod.UserDictionarySettings;
|
||||
import com.android.settings.language.LanguageAndInputSettings;
|
||||
import com.android.settings.language.LanguageSettings;
|
||||
import com.android.settings.localepicker.LocaleListEditor;
|
||||
import com.android.settings.location.LocationServices;
|
||||
@@ -226,7 +225,6 @@ public class SettingsGateway {
|
||||
DateTimeSettings.class.getName(),
|
||||
LocaleListEditor.class.getName(),
|
||||
AvailableVirtualKeyboardFragment.class.getName(),
|
||||
LanguageAndInputSettings.class.getName(),
|
||||
LanguageSettings.class.getName(),
|
||||
KeyboardSettings.class.getName(),
|
||||
ModifierKeysSettings.class.getName(),
|
||||
|
@@ -38,7 +38,6 @@ import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
|
||||
import com.android.settings.fuelgauge.batteryusage.PowerUsageSummary;
|
||||
import com.android.settings.gestures.GestureSettings;
|
||||
import com.android.settings.homepage.TopLevelSettings;
|
||||
import com.android.settings.language.LanguageAndInputSettings;
|
||||
import com.android.settings.network.NetworkDashboardFragment;
|
||||
import com.android.settings.notification.ConfigureNotificationSettings;
|
||||
import com.android.settings.notification.SoundSettings;
|
||||
@@ -102,8 +101,6 @@ public class DashboardFragmentRegistry {
|
||||
CategoryKey.CATEGORY_ACCOUNT);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(
|
||||
SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndInputSettings.class.getName(),
|
||||
CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
|
||||
// TODO(b/242680328) Tie new category key to LanguageSettings and KeyboardSettings page
|
||||
PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettingsDashboardFragment.class.getName(),
|
||||
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -78,9 +77,7 @@ public class KeyboardPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
private void updateSummary() {
|
||||
|
@@ -23,7 +23,6 @@ import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROF
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -111,11 +110,5 @@ public class KeyboardSettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.keyboard_settings) {
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return FeatureFlagUtils
|
||||
.isEnabled(context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
}
|
||||
};
|
||||
new BaseSearchIndexProvider(R.xml.keyboard_settings);
|
||||
}
|
@@ -20,7 +20,6 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -69,8 +68,7 @@ public class KeyboardSettingsPreferenceController extends BasePreferenceControll
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
List<HardKeyboardDeviceInfo> newHardKeyboards = getHardKeyboardList();
|
||||
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI)
|
||||
&& !newHardKeyboards.isEmpty()) {
|
||||
if (!newHardKeyboards.isEmpty()) {
|
||||
for (HardKeyboardDeviceInfo hardKeyboardDeviceInfo : newHardKeyboards) {
|
||||
if (mCachedDevice.getAddress() != null
|
||||
&& hardKeyboardDeviceInfo.mBluetoothAddress != null
|
||||
|
@@ -110,7 +110,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
|
||||
|
||||
private Intent mIntentWaitingForResult;
|
||||
private boolean mIsNewKeyboardSettings;
|
||||
private boolean mSupportsFirmwareUpdate;
|
||||
|
||||
static final String EXTRA_BT_ADDRESS = "extra_bt_address";
|
||||
@@ -152,8 +151,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
if (mSupportsFirmwareUpdate) {
|
||||
mFeatureProvider.addFirmwareUpdateCategory(getContext(), getPreferenceScreen());
|
||||
}
|
||||
mIsNewKeyboardSettings = FeatureFlagUtils.isEnabled(
|
||||
getContext(), FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
boolean isModifierKeySettingsEnabled = FeatureFlagUtils
|
||||
.isEnabled(getContext(), FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_MODIFIER_KEY);
|
||||
if (!isModifierKeySettingsEnabled) {
|
||||
@@ -287,7 +284,6 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
// TODO(yukawa): Consider using com.android.settings.widget.GearPreference
|
||||
final Preference pref = new Preference(getPrefContext());
|
||||
pref.setTitle(hardKeyboardDeviceInfo.mDeviceName);
|
||||
if (mIsNewKeyboardSettings) {
|
||||
String currentLayout =
|
||||
NewKeyboardSettingsUtils.getSelectedKeyboardLayoutLabelForUser(getContext(),
|
||||
UserHandle.myUserId(), hardKeyboardDeviceInfo.mDeviceIdentifier);
|
||||
@@ -300,14 +296,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
|
||||
hardKeyboardDeviceInfo.mDeviceIdentifier);
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
pref.setSummary(hardKeyboardDeviceInfo.mLayoutLabel);
|
||||
pref.setOnPreferenceClickListener(
|
||||
preference -> {
|
||||
showKeyboardLayoutDialog(hardKeyboardDeviceInfo.mDeviceIdentifier);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
category.addPreference(pref);
|
||||
StringBuilder vendorAndProductId = new StringBuilder();
|
||||
String vendorId = String.valueOf(hardKeyboardDeviceInfo.mVendorId);
|
||||
|
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LanguageAndInputPreferenceController extends BasePreferenceController {
|
||||
|
||||
private PackageManager mPackageManager;
|
||||
private InputMethodManager mInputMethodManager;
|
||||
|
||||
public LanguageAndInputPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mPackageManager = mContext.getPackageManager();
|
||||
mInputMethodManager = mContext.getSystemService(InputMethodManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
boolean isFeatureOn = FeatureFlagUtils
|
||||
.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
return isFeatureOn ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final String flattenComponent = Settings.Secure.getString(
|
||||
mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
if (!TextUtils.isEmpty(flattenComponent)) {
|
||||
final String pkg = ComponentName.unflattenFromString(flattenComponent)
|
||||
.getPackageName();
|
||||
final List<InputMethodInfo> imis = mInputMethodManager.getInputMethodList();
|
||||
for (InputMethodInfo imi : imis) {
|
||||
if (TextUtils.equals(imi.getPackageName(), pkg)) {
|
||||
return imi.loadLabel(mPackageManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_DICTIONARY_FOR_WORK;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.SPELL_CHECKER_FOR_WORK;
|
||||
import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_KEYBOARDS_AND_TOOLS;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
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;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
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_SPEECH_CATEGORY = "speech_category";
|
||||
private static final String KEY_ON_DEVICE_RECOGNITION = "odsr_settings";
|
||||
private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary";
|
||||
private static final String KEY_POINTER_CATEGORY = "pointer_category";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_LANGUAGE_CATEGORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// Hack to update action bar title. It's necessary to refresh title because this page user
|
||||
// can change locale from here and fragment won't relaunch. Once language changes, title
|
||||
// must display in the new language.
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
activity.setTitle(R.string.language_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
replaceEnterpriseStringTitle("language_and_input_for_work_category",
|
||||
WORK_PROFILE_KEYBOARDS_AND_TOOLS,
|
||||
R.string.language_and_input_for_work_category_title);
|
||||
replaceEnterpriseStringTitle("spellcheckers_settings_for_work_pref",
|
||||
SPELL_CHECKER_FOR_WORK,
|
||||
R.string.spellcheckers_settings_for_work_title);
|
||||
replaceEnterpriseStringTitle("user_dictionary_settings_for_work_pref",
|
||||
PERSONAL_DICTIONARY_FOR_WORK,
|
||||
R.string.user_dict_settings_for_work_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.language_and_input;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
|
||||
// Input
|
||||
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).setChildren(
|
||||
Arrays.asList(virtualKeyboardPreferenceController,
|
||||
physicalKeyboardPreferenceController)));
|
||||
|
||||
// Speech
|
||||
final DefaultVoiceInputPreferenceController defaultVoiceInputPreferenceController =
|
||||
new DefaultVoiceInputPreferenceController(context, lifecycle);
|
||||
final TtsPreferenceController ttsPreferenceController =
|
||||
new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH);
|
||||
final OnDeviceRecognitionPreferenceController onDeviceRecognitionPreferenceController =
|
||||
new OnDeviceRecognitionPreferenceController(context, KEY_ON_DEVICE_RECOGNITION);
|
||||
|
||||
controllers.add(defaultVoiceInputPreferenceController);
|
||||
controllers.add(ttsPreferenceController);
|
||||
List<AbstractPreferenceController> speechCategoryChildren = new ArrayList<>(
|
||||
List.of(defaultVoiceInputPreferenceController, ttsPreferenceController));
|
||||
|
||||
if (onDeviceRecognitionPreferenceController.isAvailable()) {
|
||||
controllers.add(onDeviceRecognitionPreferenceController);
|
||||
speechCategoryChildren.add(onDeviceRecognitionPreferenceController);
|
||||
}
|
||||
|
||||
controllers.add(new PreferenceCategoryController(context, KEY_SPEECH_CATEGORY)
|
||||
.setChildren(speechCategoryChildren));
|
||||
|
||||
// Pointer
|
||||
final PointerSpeedController pointerController = new PointerSpeedController(context);
|
||||
controllers.add(pointerController);
|
||||
controllers.add(new PreferenceCategoryController(context,
|
||||
KEY_POINTER_CATEGORY).setChildren(Arrays.asList(pointerController)));
|
||||
|
||||
// Input Assistance
|
||||
controllers.add(new SpellCheckerPreferenceController(context));
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.language_and_input) {
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !FeatureFlagUtils
|
||||
.isEnabled(context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
}
|
||||
};
|
||||
}
|
@@ -19,7 +19,6 @@ package com.android.settings.language;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -29,28 +28,14 @@ import com.android.settings.core.BasePreferenceController;
|
||||
* TODO(b/273642892): When new layout is on board, this class shall be removed.
|
||||
*/
|
||||
public class LanguagePreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = LanguagePreferenceController.class.getSimpleName();
|
||||
|
||||
private boolean mCacheIsFeatureOn = false;
|
||||
|
||||
public LanguagePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
boolean isFeatureOn = FeatureFlagUtils
|
||||
.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
|
||||
// LanguageSettingsActivity is a new entry page for new language layout.
|
||||
// LanguageAndInputSettingsActivity is existed entry page for current language layout.
|
||||
if (mCacheIsFeatureOn != isFeatureOn) {
|
||||
setActivityEnabled(
|
||||
mContext, Settings.LanguageAndInputSettingsActivity.class, !isFeatureOn);
|
||||
setActivityEnabled(mContext, Settings.LanguageSettingsActivity.class, isFeatureOn);
|
||||
mCacheIsFeatureOn = isFeatureOn;
|
||||
}
|
||||
return isFeatureOn ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
setActivityEnabled(mContext, Settings.LanguageSettingsActivity.class, true);
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
private static void setActivityEnabled(Context context, Class klass, final boolean isEnabled) {
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.language;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -112,8 +111,7 @@ public class LanguageSettings extends DashboardFragment {
|
||||
}
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return FeatureFlagUtils
|
||||
.isEnabled(context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowInputMethodManagerWithMethodList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowInputMethodManagerWithMethodList.class)
|
||||
public class LanguageAndInputPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_shouldSetToCurrentImeName() {
|
||||
final ComponentName componentName = new ComponentName("name1", "cls");
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
Settings.Secure.putString(cr, Settings.Secure.DEFAULT_INPUT_METHOD,
|
||||
componentName.flattenToString());
|
||||
final List<InputMethodInfo> imis = new ArrayList<>();
|
||||
imis.add(mock(InputMethodInfo.class));
|
||||
when(imis.get(0).getPackageName()).thenReturn("name1");
|
||||
when(imis.get(0).loadLabel(any())).thenReturn("label");
|
||||
ShadowInputMethodManagerWithMethodList.getShadow().setInputMethodList(imis);
|
||||
|
||||
final LanguageAndInputPreferenceController controller =
|
||||
new LanguageAndInputPreferenceController(mContext, "key");
|
||||
|
||||
assertThat(controller.getSummary().toString()).contains("label");
|
||||
}
|
||||
}
|
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.os.UserManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.view.autofill.AutofillManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.textservice.TextServicesManager;
|
||||
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LanguageAndInputSettingsTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private InputManager mIm;
|
||||
@Mock
|
||||
private InputMethodManager mImm;
|
||||
@Mock
|
||||
private DevicePolicyManager mDpm;
|
||||
@Mock
|
||||
private AutofillManager mAutofillManager;
|
||||
private TestFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
|
||||
when(mActivity.getSystemService(Context.INPUT_SERVICE))
|
||||
.thenReturn(mock(InputManager.class));
|
||||
when(mActivity.getSystemService(Context.INPUT_SERVICE)).thenReturn(mIm);
|
||||
when(mActivity.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE))
|
||||
.thenReturn(mock(TextServicesManager.class));
|
||||
when(mActivity.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(mDpm);
|
||||
when(mActivity.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(mImm);
|
||||
when((Object) mActivity.getSystemService(AutofillManager.class))
|
||||
.thenReturn(mAutofillManager);
|
||||
mFragment = new TestFragment(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceScreenResId() {
|
||||
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(R.xml.language_and_input);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceControllers_shouldRegisterLifecycleObservers() {
|
||||
final List<AbstractPreferenceController> controllers =
|
||||
mFragment.createPreferenceControllers(mActivity);
|
||||
int lifecycleObserverCount = 0;
|
||||
for (AbstractPreferenceController controller : controllers) {
|
||||
if (controller instanceof LifecycleObserver) {
|
||||
lifecycleObserverCount++;
|
||||
}
|
||||
}
|
||||
verify(mFragment.getSettingsLifecycle(), times(lifecycleObserverCount))
|
||||
.addObserver(any(LifecycleObserver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceControllers_shouldAllBeCreated() {
|
||||
final List<AbstractPreferenceController> controllers =
|
||||
mFragment.createPreferenceControllers(mActivity);
|
||||
|
||||
assertThat(controllers.isEmpty()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKeys_existInXmlLayout() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final Resources res = spy(RuntimeEnvironment.application.getResources());
|
||||
final InputManager inputManager = mock(InputManager.class);
|
||||
final TextServicesManager textServicesManager = mock(TextServicesManager.class);
|
||||
FeatureFlagUtils.setEnabled(context, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI, false);
|
||||
when(inputManager.getInputDeviceIds()).thenReturn(new int[0]);
|
||||
doReturn(inputManager).when(context).getSystemService(Context.INPUT_SERVICE);
|
||||
doReturn(textServicesManager).when(context)
|
||||
.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||
doReturn(res).when(context).getResources();
|
||||
doReturn(false).when(res)
|
||||
.getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys);
|
||||
final List<String> niks =
|
||||
LanguageAndInputSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(context);
|
||||
LanguageAndInputSettings settings = new LanguageAndInputSettings();
|
||||
final int xmlId = settings.getPreferenceScreenResId();
|
||||
|
||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
||||
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final TextServicesManager textServicesManager = mock(TextServicesManager.class);
|
||||
doReturn(textServicesManager).when(context)
|
||||
.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||
final LanguageAndInputSettings fragment = new LanguageAndInputSettings();
|
||||
final List<String> preferenceScreenKeys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(context, fragment.getPreferenceScreenResId());
|
||||
final List<String> preferenceKeys = new ArrayList<>();
|
||||
|
||||
for (AbstractPreferenceController controller : fragment.createPreferenceControllers(context)) {
|
||||
preferenceKeys.add(controller.getPreferenceKey());
|
||||
}
|
||||
|
||||
assertThat(preferenceScreenKeys).containsAtLeastElementsIn(preferenceKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fragment to expose lifecycle and context so we can verify behavior for observables.
|
||||
*/
|
||||
public static class TestFragment extends LanguageAndInputSettings {
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
private Context mContext;
|
||||
|
||||
public TestFragment(Context context) {
|
||||
mContext = context;
|
||||
mLifecycle = mock(Lifecycle.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lifecycle getSettingsLifecycle() {
|
||||
if (mLifecycle == null) {
|
||||
return super.getSettingsLifecycle();
|
||||
}
|
||||
return mLifecycle;
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,71 +16,32 @@
|
||||
|
||||
package com.android.settings.language;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LanguagePreferenceControllerTest {
|
||||
private boolean mCacheFeatureFlagSwitch = false;
|
||||
private Context mContext;
|
||||
private LanguagePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mCacheFeatureFlagSwitch =
|
||||
FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI);
|
||||
mController = new LanguagePreferenceController(mContext, "key");
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
FeatureFlagUtils.setEnabled(
|
||||
mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI, mCacheFeatureFlagSwitch);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_featureFlagOff_returnUnavailable() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI,
|
||||
false);
|
||||
|
||||
int result = mController.getAvailabilityStatus();
|
||||
|
||||
assertEquals(CONDITIONALLY_UNAVAILABLE, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_featureFlagOff_LanguageAndInputSettingsActivityEnabled() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI,
|
||||
false);
|
||||
|
||||
mController.getAvailabilityStatus();
|
||||
|
||||
assertTrue(isActivityEnable(mContext, Settings.LanguageAndInputSettingsActivity.class));
|
||||
assertFalse(isActivityEnable(mContext, Settings.LanguageSettingsActivity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_featureFlagOff_LanguageAndInputSettingsActivitydisabled() {
|
||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlagUtils.SETTINGS_NEW_KEYBOARD_UI,
|
||||
true);
|
||||
|
||||
mController.getAvailabilityStatus();
|
||||
|
||||
assertFalse(isActivityEnable(mContext, Settings.LanguageAndInputSettingsActivity.class));
|
||||
|
Reference in New Issue
Block a user