[Physical Keyboard][Setting] New pk a11y entry under a11y page
Add entry for physical keyboard a11y page under a11y setting Bug: 345399212 Test: atest SettingsRoboTests Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled Change-Id: I0c59c3a9df1b5df5e22349ab3907f767682d6fb9
This commit is contained in:
@@ -120,37 +120,14 @@
|
|||||||
settings:controller="com.android.settings.inputmethod.PointerTouchpadPreferenceController"
|
settings:controller="com.android.settings.inputmethod.PointerTouchpadPreferenceController"
|
||||||
settings:searchable="true"/>
|
settings:searchable="true"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
<Preference
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="physical_keyboard_options_category"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/keyboard_category_title">
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:icon="@drawable/ic_sticky_keys"
|
android:icon="@drawable/ic_sticky_keys"
|
||||||
android:key="toggle_keyboard_sticky_keys"
|
android:key="physical_keyboard_a11y"
|
||||||
|
android:title="@string/keyboard_a11y_settings"
|
||||||
|
android:summary="@string/keyboard_a11y_settings_summary"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:summary="@string/sticky_keys_summary"
|
android:fragment="com.android.settings.inputmethod.PhysicalKeyboardA11yFragment"
|
||||||
android:title="@string/sticky_keys"
|
settings:controller="com.android.settings.inputmethod.PhysicalKeyboardA11yPreferenceController" />
|
||||||
settings:controller="com.android.settings.accessibility.KeyboardStickyKeyPreferenceController"
|
|
||||||
settings:searchable="true" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:icon="@drawable/ic_bounce_keys"
|
|
||||||
android:key="toggle_keyboard_bounce_keys"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/bounce_keys"
|
|
||||||
settings:controller="com.android.settings.accessibility.KeyboardBounceKeyPreferenceController"
|
|
||||||
settings:searchable="true" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:icon="@drawable/ic_slow_keys"
|
|
||||||
android:key="toggle_keyboard_slow_keys"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/slow_keys"
|
|
||||||
settings:controller="com.android.settings.accessibility.KeyboardSlowKeyPreferenceController"
|
|
||||||
settings:searchable="true" />
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@@ -30,7 +30,6 @@ import android.os.UserHandle;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.view.InputDevice;
|
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -45,7 +44,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.accessibility.AccessibilityUtil.AccessibilityServiceFragmentType;
|
import com.android.settings.accessibility.AccessibilityUtil.AccessibilityServiceFragmentType;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.development.Enable16kUtils;
|
import com.android.settings.development.Enable16kUtils;
|
||||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
@@ -73,14 +71,12 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
private static final String CATEGORY_DISPLAY = "display_category";
|
private static final String CATEGORY_DISPLAY = "display_category";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
|
static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category";
|
||||||
private static final String CATEGORY_KEYBOARD_OPTIONS = "physical_keyboard_options_category";
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";
|
static final String CATEGORY_INTERACTION_CONTROL = "interaction_control_category";
|
||||||
|
|
||||||
private static final String[] CATEGORIES = new String[]{
|
private static final String[] CATEGORIES = new String[]{
|
||||||
CATEGORY_SCREEN_READER, CATEGORY_CAPTIONS, CATEGORY_AUDIO, CATEGORY_DISPLAY,
|
CATEGORY_SCREEN_READER, CATEGORY_CAPTIONS, CATEGORY_AUDIO, CATEGORY_DISPLAY,
|
||||||
CATEGORY_SPEECH, CATEGORY_INTERACTION_CONTROL,
|
CATEGORY_SPEECH, CATEGORY_INTERACTION_CONTROL, CATEGORY_DOWNLOADED_SERVICES
|
||||||
CATEGORY_KEYBOARD_OPTIONS, CATEGORY_DOWNLOADED_SERVICES
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extras passed to sub-fragments.
|
// Extras passed to sub-fragments.
|
||||||
@@ -275,7 +271,7 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
* @return The service summary
|
* @return The service summary
|
||||||
*/
|
*/
|
||||||
public static CharSequence getServiceSummary(Context context, AccessibilityServiceInfo info,
|
public static CharSequence getServiceSummary(Context context, AccessibilityServiceInfo info,
|
||||||
boolean serviceEnabled) {
|
boolean serviceEnabled) {
|
||||||
if (serviceEnabled && info.crashed) {
|
if (serviceEnabled && info.crashed) {
|
||||||
return context.getText(R.string.accessibility_summary_state_stopped);
|
return context.getText(R.string.accessibility_summary_state_stopped);
|
||||||
}
|
}
|
||||||
@@ -461,7 +457,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
// Hide category if it is empty.
|
// Hide category if it is empty.
|
||||||
updatePreferenceCategoryVisibility(CATEGORY_SCREEN_READER);
|
updatePreferenceCategoryVisibility(CATEGORY_SCREEN_READER);
|
||||||
updatePreferenceCategoryVisibility(CATEGORY_SPEECH);
|
updatePreferenceCategoryVisibility(CATEGORY_SPEECH);
|
||||||
updatePreferenceCategoryVisibility(CATEGORY_KEYBOARD_OPTIONS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -556,9 +551,7 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
/**
|
/**
|
||||||
* Updates preferences related to system configurations.
|
* Updates preferences related to system configurations.
|
||||||
*/
|
*/
|
||||||
protected void updateSystemPreferences() {
|
protected void updateSystemPreferences() {}
|
||||||
updateKeyboardPreferencesVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePreferencesState() {
|
private void updatePreferencesState() {
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
@@ -567,53 +560,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
findPreference(controller.getPreferenceKey())));
|
findPreference(controller.getPreferenceKey())));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateKeyboardPreferencesVisibility() {
|
|
||||||
if (!mCategoryToPrefCategoryMap.containsKey(CATEGORY_KEYBOARD_OPTIONS)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean isVisible = isAnyHardKeyboardsExist()
|
|
||||||
&& isAnyKeyboardPreferenceAvailable();
|
|
||||||
mCategoryToPrefCategoryMap.get(CATEGORY_KEYBOARD_OPTIONS).setVisible(
|
|
||||||
isVisible);
|
|
||||||
if (isVisible) {
|
|
||||||
//set summary here.
|
|
||||||
findPreference(KeyboardBounceKeyPreferenceController.PREF_KEY).setSummary(
|
|
||||||
getContext().getString(R.string.bounce_keys_summary,
|
|
||||||
PhysicalKeyboardFragment.BOUNCE_KEYS_THRESHOLD));
|
|
||||||
findPreference(KeyboardSlowKeyPreferenceController.PREF_KEY).setSummary(
|
|
||||||
getContext().getString(R.string.slow_keys_summary,
|
|
||||||
PhysicalKeyboardFragment.SLOW_KEYS_THRESHOLD));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isAnyHardKeyboardsExist() {
|
|
||||||
for (int deviceId : InputDevice.getDeviceIds()) {
|
|
||||||
final InputDevice device = InputDevice.getDevice(deviceId);
|
|
||||||
if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAnyKeyboardPreferenceAvailable() {
|
|
||||||
for (List<AbstractPreferenceController> controllerList : getPreferenceControllers()) {
|
|
||||||
for (AbstractPreferenceController controller : controllerList) {
|
|
||||||
if (controller.getPreferenceKey().equals(
|
|
||||||
KeyboardBounceKeyPreferenceController.PREF_KEY)
|
|
||||||
|| controller.getPreferenceKey().equals(
|
|
||||||
KeyboardSlowKeyPreferenceController.PREF_KEY)
|
|
||||||
|| controller.getPreferenceKey().equals(
|
|
||||||
KeyboardStickyKeyPreferenceController.PREF_KEY)) {
|
|
||||||
if (controller.isAvailable()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider(R.xml.accessibility_settings) {
|
new BaseSearchIndexProvider(R.xml.accessibility_settings) {
|
||||||
@Override
|
@Override
|
||||||
@@ -671,10 +617,12 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceAdded(int deviceId) {}
|
public void onInputDeviceAdded(int deviceId) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceRemoved(int deviceId) {}
|
public void onInputDeviceRemoved(int deviceId) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
public void onInputDeviceChanged(int deviceId) {
|
||||||
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputSettings;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A toggle preference controller for keyboard bounce key.
|
|
||||||
*/
|
|
||||||
public class KeyboardBounceKeyPreferenceController extends TogglePreferenceController {
|
|
||||||
private static final String TAG = "BounceKeyPrefController";
|
|
||||||
static final String PREF_KEY = "toggle_keyboard_bounce_keys";
|
|
||||||
|
|
||||||
public KeyboardBounceKeyPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return InputSettings.isAccessibilityBounceKeysFeatureEnabled()
|
|
||||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return InputSettings.isAccessibilityBounceKeysEnabled(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
InputSettings.setAccessibilityBounceKeysThreshold(mContext,
|
|
||||||
isChecked ? PhysicalKeyboardFragment.BOUNCE_KEYS_THRESHOLD
|
|
||||||
: 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSliceHighlightMenuRes() {
|
|
||||||
return R.string.menu_key_accessibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateNonIndexableKeys(@NonNull List<String> keys) {
|
|
||||||
super.updateNonIndexableKeys(keys);
|
|
||||||
|
|
||||||
if (Flags.fixA11ySettingsSearch() && !AccessibilitySettings.isAnyHardKeyboardsExist()) {
|
|
||||||
if (keys.contains(getPreferenceKey())) {
|
|
||||||
Log.w(TAG, "Skipping updateNonIndexableKeys, key already in list.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keys.add(getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputSettings;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A toggle preference controller for keyboard slow key.
|
|
||||||
*/
|
|
||||||
public class KeyboardSlowKeyPreferenceController extends TogglePreferenceController {
|
|
||||||
private static final String TAG = "SlowKeyPrefController";
|
|
||||||
|
|
||||||
static final String PREF_KEY = "toggle_keyboard_slow_keys";
|
|
||||||
|
|
||||||
public KeyboardSlowKeyPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return InputSettings.isAccessibilitySlowKeysFeatureFlagEnabled()
|
|
||||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return InputSettings.isAccessibilitySlowKeysEnabled(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
InputSettings.setAccessibilitySlowKeysThreshold(mContext,
|
|
||||||
isChecked ? PhysicalKeyboardFragment.SLOW_KEYS_THRESHOLD
|
|
||||||
: 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSliceHighlightMenuRes() {
|
|
||||||
return R.string.menu_key_accessibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateNonIndexableKeys(@NonNull List<String> keys) {
|
|
||||||
super.updateNonIndexableKeys(keys);
|
|
||||||
|
|
||||||
if (Flags.fixA11ySettingsSearch() && !AccessibilitySettings.isAnyHardKeyboardsExist()) {
|
|
||||||
if (keys.contains(getPreferenceKey())) {
|
|
||||||
Log.w(TAG, "Skipping updateNonIndexableKeys, key already in list.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keys.add(getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputSettings;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A toggle preference controller for keyboard sticky key.
|
|
||||||
*/
|
|
||||||
public class KeyboardStickyKeyPreferenceController extends TogglePreferenceController {
|
|
||||||
private static final String TAG = "StickyKeyPrefController";
|
|
||||||
static final String PREF_KEY = "toggle_keyboard_sticky_keys";
|
|
||||||
|
|
||||||
public KeyboardStickyKeyPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return InputSettings.isAccessibilityStickyKeysFeatureEnabled()
|
|
||||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return InputSettings.isAccessibilityStickyKeysEnabled(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
InputSettings.setAccessibilityStickyKeysEnabled(mContext, isChecked);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSliceHighlightMenuRes() {
|
|
||||||
return R.string.menu_key_accessibility;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateNonIndexableKeys(@NonNull List<String> keys) {
|
|
||||||
super.updateNonIndexableKeys(keys);
|
|
||||||
|
|
||||||
if (Flags.fixA11ySettingsSearch() && !AccessibilitySettings.isAnyHardKeyboardsExist()) {
|
|
||||||
if (keys.contains(getPreferenceKey())) {
|
|
||||||
Log.w(TAG, "Skipping updateNonIndexableKeys, key already in list.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keys.add(getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.inputmethod;
|
||||||
|
|
||||||
|
import static com.android.settings.keyboard.Flags.keyboardAndTouchpadA11yNewPageEnabled;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.InputDevice;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/** Controller that shows and updates the Physical Keyboard a11y preference. */
|
||||||
|
public class PhysicalKeyboardA11yPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
|
||||||
|
public PhysicalKeyboardA11yPreferenceController(Context context,
|
||||||
|
String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return keyboardAndTouchpadA11yNewPageEnabled()
|
||||||
|
&& isAnyHardKeyboardsExist() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAnyHardKeyboardsExist() {
|
||||||
|
for (int deviceId : InputDevice.getDeviceIds()) {
|
||||||
|
final InputDevice device = InputDevice.getDevice(deviceId);
|
||||||
|
if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class KeyboardBounceKeyPreferenceControllerTest {
|
|
||||||
private static final String KEY_ACCESSIBILITY_BOUNCE_KEYS =
|
|
||||||
Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS;
|
|
||||||
private static final int UNKNOWN = -1;
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final SetFlagsRule mSetFlagRule = new SetFlagsRule();
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
private final SwitchPreference mSwitchPreference = spy(new SwitchPreference(mContext));
|
|
||||||
private final KeyboardBounceKeyPreferenceController mController =
|
|
||||||
new KeyboardBounceKeyPreferenceController(mContext,
|
|
||||||
KeyboardBounceKeyPreferenceController.PREF_KEY);
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
mSwitchPreference.setKey(KeyboardBounceKeyPreferenceController.PREF_KEY);
|
|
||||||
screen.addPreference(mSwitchPreference);
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
|
||||||
BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_disableBounceKey_onResumeShouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_enableBounceKey_onResumeShouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_enableBounceKey_shouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(true);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_disableBounceKey_shouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(false);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setFalse_shouldDisableBounceKey() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS, UNKNOWN)).isEqualTo(
|
|
||||||
OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setTrue_shouldEnableBounceKey() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_BOUNCE_KEYS,
|
|
||||||
UNKNOWN)).isNotEqualTo(OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_physicalKeyboardExists_returnEmptyList() {
|
|
||||||
Assume.assumeTrue(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_noPhysicalKeyboard_returnPreKey() {
|
|
||||||
Assume.assumeFalse(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).contains(mController.getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,163 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class KeyboardSlowKeyPreferenceControllerTest {
|
|
||||||
private static final String KEY_ACCESSIBILITY_SLOW_KEYS =
|
|
||||||
Settings.Secure.ACCESSIBILITY_SLOW_KEYS;
|
|
||||||
private static final int UNKNOWN = -1;
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final SetFlagsRule mSetFlagRule = new SetFlagsRule();
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
private final SwitchPreference mSwitchPreference = spy(new SwitchPreference(mContext));
|
|
||||||
private final KeyboardSlowKeyPreferenceController mController =
|
|
||||||
new KeyboardSlowKeyPreferenceController(mContext,
|
|
||||||
KeyboardSlowKeyPreferenceController.PREF_KEY);
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
mSwitchPreference.setKey(KeyboardSlowKeyPreferenceController.PREF_KEY);
|
|
||||||
screen.addPreference(mSwitchPreference);
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
|
||||||
BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_disableSlowKey_onResumeShouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_enableSlowKey_onResumeShouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_enableSlowKey_shouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(true);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_disableSlowKey_shouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(false);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setFalse_shouldDisableSlowKey() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, UNKNOWN)).isEqualTo(
|
|
||||||
OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setTrue_shouldEnableSlowKey() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_SLOW_KEYS, UNKNOWN)).isNotEqualTo(
|
|
||||||
OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_physicalKeyboardExists_returnEmptyList() {
|
|
||||||
Assume.assumeTrue(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_noPhysicalKeyboard_returnPreKey() {
|
|
||||||
Assume.assumeFalse(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).contains(mController.getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,161 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2024 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.accessibility;
|
|
||||||
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
|
||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.platform.test.annotations.EnableFlags;
|
|
||||||
import android.platform.test.flag.junit.SetFlagsRule;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class KeyboardStickyKeyPreferenceControllerTest {
|
|
||||||
private static final String KEY_ACCESSIBILITY_STICKY_KEYS =
|
|
||||||
Settings.Secure.ACCESSIBILITY_STICKY_KEYS;
|
|
||||||
private static final int UNKNOWN = -1;
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final SetFlagsRule mSetFlagRule = new SetFlagsRule();
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
|
||||||
private final SwitchPreference mSwitchPreference = spy(new SwitchPreference(mContext));
|
|
||||||
private final KeyboardStickyKeyPreferenceController mController =
|
|
||||||
new KeyboardStickyKeyPreferenceController(mContext,
|
|
||||||
KeyboardStickyKeyPreferenceController.PREF_KEY);
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
mSwitchPreference.setKey(KeyboardStickyKeyPreferenceController.PREF_KEY);
|
|
||||||
screen.addPreference(mSwitchPreference);
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
|
||||||
BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_disableStickyKey_onResumeShouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isChecked_enableStickyKey_onResumeShouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_enableStickyKey_shouldReturnTrue() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, OFF);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(true);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void performClick_disableStickyKey_shouldReturnFalse() {
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, ON);
|
|
||||||
|
|
||||||
mController.updateState(mSwitchPreference);
|
|
||||||
|
|
||||||
mSwitchPreference.performClick();
|
|
||||||
|
|
||||||
verify(mSwitchPreference).setChecked(false);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setFalse_shouldDisableStickyKey() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, UNKNOWN)).isEqualTo(OFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_setTrue_shouldEnableStickyKey() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
|
|
||||||
assertThat(Settings.Secure.getInt(
|
|
||||||
mContext.getContentResolver(), KEY_ACCESSIBILITY_STICKY_KEYS, UNKNOWN)).isEqualTo(ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_physicalKeyboardExists_returnEmptyList() {
|
|
||||||
Assume.assumeTrue(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH)
|
|
||||||
public void updateNonIndexableKeys_noPhysicalKeyboard_returnPreKey() {
|
|
||||||
Assume.assumeFalse(AccessibilitySettings.isAnyHardKeyboardsExist());
|
|
||||||
|
|
||||||
List<String> nonIndexableKeys = new ArrayList<>();
|
|
||||||
mController.updateNonIndexableKeys(nonIndexableKeys);
|
|
||||||
|
|
||||||
assertThat(nonIndexableKeys).contains(mController.getPreferenceKey());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.inputmethod;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.view.InputDevice;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.keyboard.Flags;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowInputDevice;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
/** Tests for {@link PhysicalKeyboardA11yPreferenceController} */
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(shadows = {
|
||||||
|
com.android.settings.testutils.shadow.ShadowInputDevice.class,
|
||||||
|
})
|
||||||
|
public class PhysicalKeyboardA11yPreferenceControllerTest {
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
@Rule
|
||||||
|
public MockitoRule rule = MockitoJUnit.rule();
|
||||||
|
private static final String PREFERENCE_KEY = "physical_keyboard_a11y";
|
||||||
|
private Context mContext;
|
||||||
|
private PhysicalKeyboardA11yPreferenceController mController;
|
||||||
|
@Mock
|
||||||
|
InputDevice mInputDevice;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
mController = new PhysicalKeyboardA11yPreferenceController(mContext, PREFERENCE_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
|
||||||
|
public void getAvailabilityStatus_expected() {
|
||||||
|
int deviceId = 1;
|
||||||
|
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
|
||||||
|
when(mInputDevice.isVirtual()).thenReturn(false);
|
||||||
|
when(mInputDevice.isFullKeyboard()).thenReturn(true);
|
||||||
|
|
||||||
|
ShadowInputDevice.addDevice(deviceId, mInputDevice);
|
||||||
|
|
||||||
|
assertThat(InputDevice.getDeviceIds()).isNotEmpty();
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
|
||||||
|
public void getAvailabilityStatus_deviceIsNotAsExpected_unavailable() {
|
||||||
|
int deviceId = 1;
|
||||||
|
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
|
||||||
|
when(mInputDevice.isVirtual()).thenReturn(true);
|
||||||
|
when(mInputDevice.isFullKeyboard()).thenReturn(false);
|
||||||
|
|
||||||
|
ShadowInputDevice.addDevice(deviceId, mInputDevice);
|
||||||
|
|
||||||
|
assertThat(InputDevice.getDeviceIds()).isNotEmpty();
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user