Merge "[Physical Keybaord] Add keyboard touchpad/Mouse page - part1" into main

This commit is contained in:
Shaowei Shen
2024-11-25 09:31:58 +00:00
committed by Android (Google) Code Review
15 changed files with 575 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/mouse_settings">
<SwitchPreferenceCompat
android:key="mouse_reverse_vertical_scrolling"
android:title="@string/mouse_reverse_vertical_scrolling"
android:summary="@string/mouse_reverse_vertical_scrolling_summary"
settings:controller="com.android.settings.inputmethod.MouseReverseVerticalScrollingPreferenceController" />
<SwitchPreferenceCompat
android:key="mouse_swap_primary_button"
android:title="@string/mouse_swap_primary_button"
android:summary="@string/mouse_swap_primary_button_summary"
settings:controller="com.android.settings.inputmethod.MouseSwapPrimaryButtonPreferenceController" />
</PreferenceScreen>

View File

@@ -43,8 +43,8 @@
android:summary="@string/trackpad_settings_summary" android:summary="@string/trackpad_settings_summary"
android:icon="@drawable/ic_settings_trackpad" android:icon="@drawable/ic_settings_trackpad"
android:order="-254" android:order="-254"
android:fragment="com.android.settings.inputmethod.TrackpadSettings" android:fragment="com.android.settings.inputmethod.TouchpadAndMouseSettings"
settings:controller="com.android.settings.inputmethod.TrackpadSettingsController"/> settings:controller="com.android.settings.inputmethod.TouchpadAndMouseSettingsController"/>
<Preference <Preference
android:key="gesture_settings" android:key="gesture_settings"

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/trackpad_settings">
<Preference
android:key="trackpad_gesture_settings"
android:title="@string/trackpad_touchpad_gesture_title"
android:summary="@string/trackpad_touchpad_gesture_summary"
android:order="-10"
android:fragment="com.android.settings.inputmethod.TrackpadTouchGestureSettings"
settings:controller="com.android.settings.inputmethod.TrackpadTouchGestureSettingsController"/>
<SwitchPreferenceCompat
android:key="trackpad_tap_to_click"
android:title="@string/trackpad_tap_to_click"
settings:controller="com.android.settings.inputmethod.TrackpadTapToClickPreferenceController"
android:order="10"/>
<SwitchPreferenceCompat
android:key="trackpad_reverse_scrolling"
android:title="@string/trackpad_reverse_scrolling_title"
android:summary="@string/trackpad_reverse_scrolling_summary"
settings:controller="com.android.settings.inputmethod.TrackpadReverseScrollingPreferenceController"
android:order="20"/>
<SwitchPreferenceCompat
android:key="trackpad_bottom_right_tap"
android:title="@string/trackpad_bottom_right_tap_title"
android:summary="@string/trackpad_bottom_right_tap_summary"
settings:controller="com.android.settings.inputmethod.TrackpadBottomPreferenceController"
android:order="30"
settings:keywords="@string/keywords_trackpad_bottom_right_tap"/>
<SwitchPreferenceCompat
android:key="trackpad_tap_dragging"
android:title="@string/trackpad_tap_dragging_title"
android:summary="@string/trackpad_tap_dragging_summary"
settings:controller="com.android.settings.inputmethod.TrackpadTapDraggingPreferenceController"
android:order="35"/>
<com.android.settings.widget.SeekBarPreference
android:key="trackpad_pointer_speed"
android:title="@string/trackpad_pointer_speed"
android:order="40"
android:selectable="false"
settings:controller="com.android.settings.inputmethod.TrackpadPointerSpeedPreferenceController"/>
<Preference
android:fragment="com.android.settings.inputmethod.PointerTouchpadFragment"
android:key="pointer_and_touchpad"
android:order="50"
android:persistent="false"
android:title="@string/accessibility_pointer_and_touchpad_title"
android:summary="@string/accessibility_pointer_and_touchpad_summary"
settings:searchable="true"/>
<com.android.settingslib.widget.ButtonPreference
android:key="trackpad_touch_gesture"
android:title="@string/trackpad_touch_gesture"
settings:controller="com.android.settings.inputmethod.TouchGesturesButtonPreferenceController"/>
</PreferenceScreen>

View File

@@ -136,7 +136,7 @@ import com.android.settings.inputmethod.ModifierKeysSettings;
import com.android.settings.inputmethod.NewKeyboardLayoutEnabledLocalesFragment; import com.android.settings.inputmethod.NewKeyboardLayoutEnabledLocalesFragment;
import com.android.settings.inputmethod.PhysicalKeyboardFragment; import com.android.settings.inputmethod.PhysicalKeyboardFragment;
import com.android.settings.inputmethod.SpellCheckersSettings; import com.android.settings.inputmethod.SpellCheckersSettings;
import com.android.settings.inputmethod.TrackpadSettings; import com.android.settings.inputmethod.TouchpadAndMouseSettings;
import com.android.settings.inputmethod.UserDictionaryList; import com.android.settings.inputmethod.UserDictionaryList;
import com.android.settings.inputmethod.UserDictionarySettings; import com.android.settings.inputmethod.UserDictionarySettings;
import com.android.settings.language.LanguageSettings; import com.android.settings.language.LanguageSettings;
@@ -237,7 +237,7 @@ public class SettingsGateway {
KeyboardSettings.class.getName(), KeyboardSettings.class.getName(),
ModifierKeysSettings.class.getName(), ModifierKeysSettings.class.getName(),
NewKeyboardLayoutEnabledLocalesFragment.class.getName(), NewKeyboardLayoutEnabledLocalesFragment.class.getName(),
TrackpadSettings.class.getName(), TouchpadAndMouseSettings.class.getName(),
SpellCheckersSettings.class.getName(), SpellCheckersSettings.class.getName(),
UserDictionaryList.class.getName(), UserDictionaryList.class.getName(),
UserDictionarySettings.class.getName(), UserDictionarySettings.class.getName(),

View File

@@ -0,0 +1,83 @@
/*
* Copyright 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 android.content.Context;
import android.hardware.input.InputManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
public abstract class InputDeviceSettingsController extends BasePreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
InputManager.InputDeviceListener {
private final InputManager mIm;
@Nullable
private Preference mPreference;
public InputDeviceSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
mIm = context.getSystemService(InputManager.class);
}
@Override
public void onInputDeviceAdded(int deviceId) {
updateEntry();
}
@Override
public void onInputDeviceRemoved(int deviceId) {
updateEntry();
}
@Override
public void onInputDeviceChanged(int deviceId) {
updateEntry();
}
@Override
public void onStart() {
mIm.registerInputDeviceListener(this, null);
}
@Override
public void onStop() {
mIm.unregisterInputDeviceListener(this);
}
@Override
public void updateState(Preference preference) {
mPreference = preference;
updateEntry();
}
private void updateEntry() {
if (mPreference == null) {
return;
}
mPreference.setVisible(isAvailable());
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright 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 android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@SearchIndexable
public class MouseSettingFragment extends DashboardFragment {
private static final String TAG = MouseSettingFragment.class.getSimpleName();
@Override
protected int getPreferenceScreenResId() {
return R.xml.mouse_settings;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_KEYBOARD_MOUSE;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.mouse_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return Flags.keyboardAndTouchpadA11yNewPageEnabled()
&& InputPeripheralsSettingsUtils.isMouse();
}
};
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 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 android.content.Context;
import androidx.annotation.NonNull;
import com.android.settings.keyboard.Flags;
public class MouseSettingsController extends InputDeviceSettingsController {
public MouseSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
boolean isFeatureOn = Flags.keyboardAndTouchpadA11yNewPageEnabled();
boolean isPointerCustomizationEnabled =
android.view.flags.Flags.enableVectorCursorA11ySettings();
boolean isMouse = InputPeripheralsSettingsUtils.isMouse();
return (isFeatureOn && isPointerCustomizationEnabled && isMouse) ? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -29,9 +29,9 @@ import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
@SearchIndexable @SearchIndexable
public class TrackpadSettings extends DashboardFragment { public class TouchpadAndMouseSettings extends DashboardFragment {
private static final String TAG = "TrackpadSettings"; private static final String TAG = TouchpadAndMouseSettings.class.getSimpleName();
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
@@ -58,11 +58,11 @@ public class TrackpadSettings extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return R.xml.trackpad_settings; return R.xml.touchpad_and_mouse_settings;
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.trackpad_settings) { new BaseSearchIndexProvider(R.xml.touchpad_and_mouse_settings) {
@Override @Override
protected boolean isPageSearchEnabled(Context context) { protected boolean isPageSearchEnabled(Context context) {
return FeatureFlagUtils return FeatureFlagUtils

View File

@@ -20,6 +20,8 @@ import android.content.Context;
import android.hardware.input.InputManager; import android.hardware.input.InputManager;
import android.util.FeatureFlagUtils; import android.util.FeatureFlagUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
@@ -28,15 +30,16 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
public class TrackpadSettingsController extends BasePreferenceController public class TouchpadAndMouseSettingsController extends BasePreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop, implements PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop,
InputManager.InputDeviceListener { InputManager.InputDeviceListener {
private final InputManager mIm; private final InputManager mIm;
@Nullable
private Preference mPreference; private Preference mPreference;
public TrackpadSettingsController(Context context, String key) { public TouchpadAndMouseSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key); super(context, key);
mIm = context.getSystemService(InputManager.class); mIm = context.getSystemService(InputManager.class);
} }

View File

@@ -0,0 +1,55 @@
/*
* Copyright 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 android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
@SearchIndexable
public class TouchpadSettingFragment extends DashboardFragment {
private static final String TAG = TouchpadSettingFragment.class.getSimpleName();
@Override
protected int getPreferenceScreenResId() {
return R.xml.touchpad_settings;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_KEYBOARDS_TOUCHPAD;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.touchpad_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return Flags.keyboardAndTouchpadA11yNewPageEnabled()
&& InputPeripheralsSettingsUtils.isTouchpad();
}
};
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 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 android.content.Context;
import androidx.annotation.NonNull;
import com.android.settings.keyboard.Flags;
public class TouchpadSettingsController extends InputDeviceSettingsController {
public TouchpadSettingsController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
boolean isFeatureOn = Flags.keyboardAndTouchpadA11yNewPageEnabled();
boolean isTouchpad = InputPeripheralsSettingsUtils.isTouchpad();
return (isFeatureOn && isTouchpad) ? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright 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 android.content.Context;
import android.platform.test.annotations.DisableFlags;
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.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** Tests for {@link TouchpadSettingsController} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowSystemSettings.class,
ShadowInputDevice.class,
})
public class MouseSettingsControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private static final String PREFERENCE_KEY = "keyboard_mouse_settings";
private Context mContext;
private MouseSettingsController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new MouseSettingsController(mContext, PREFERENCE_KEY);
ShadowInputDevice.reset();
}
@Test
@DisableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
public void getAvailabilityStatus_flagIsDisable_returnsUnavailable() {
int deviceId = 1;
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
ShadowInputDevice.addDevice(deviceId, ShadowInputDevice.makeInputDevicebyId(deviceId));
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
@EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
public void getAvailabilityStatus_isMouse_returnsAvailable() {
int deviceId = 1;
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
InputDevice.SOURCE_MOUSE);
ShadowInputDevice.addDevice(deviceId, device);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
}

View File

@@ -40,26 +40,26 @@ import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
/** Tests for {@link TrackpadSettingsController} */ /** Tests for {@link TouchpadAndMouseSettingsController} */
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(shadows = { @Config(shadows = {
com.android.settings.testutils.shadow.ShadowSystemSettings.class, com.android.settings.testutils.shadow.ShadowSystemSettings.class,
ShadowInputDevice.class, ShadowInputDevice.class,
}) })
public class TrackpadSettingsControllerTest { public class TouchpadAndMouseSettingsControllerTest {
@Rule @Rule
public MockitoRule rule = MockitoJUnit.rule(); public MockitoRule rule = MockitoJUnit.rule();
private static final String PREFERENCE_KEY = "trackpad_settings"; private static final String PREFERENCE_KEY = "trackpad_settings";
private Context mContext; private Context mContext;
private TrackpadSettingsController mController; private TouchpadAndMouseSettingsController mController;
private Preference mPreference; private Preference mPreference;
@Before @Before
public void setUp() { public void setUp() {
mContext = ApplicationProvider.getApplicationContext(); mContext = ApplicationProvider.getApplicationContext();
mController = new TrackpadSettingsController(mContext, PREFERENCE_KEY); mController = new TouchpadAndMouseSettingsController(mContext, PREFERENCE_KEY);
mPreference = new Preference(mContext); mPreference = new Preference(mContext);
ShadowInputDevice.reset(); ShadowInputDevice.reset();
} }

View File

@@ -0,0 +1,88 @@
/*
* Copyright 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 android.content.Context;
import android.platform.test.annotations.DisableFlags;
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.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** Tests for {@link TouchpadSettingsController} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowSystemSettings.class,
ShadowInputDevice.class,
})
public class TouchpadSettingsControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private static final String PREFERENCE_KEY = "keyboard_touchpad_settings";
private Context mContext;
private TouchpadSettingsController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new TouchpadSettingsController(mContext, PREFERENCE_KEY);
ShadowInputDevice.reset();
}
@Test
@DisableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
public void getAvailabilityStatus_flagIsDisable_returnsUnavailable() {
int deviceId = 1;
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
ShadowInputDevice.addDevice(deviceId, ShadowInputDevice.makeInputDevicebyId(deviceId));
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
}
@Test
@EnableFlags(Flags.FLAG_KEYBOARD_AND_TOUCHPAD_A11Y_NEW_PAGE_ENABLED)
public void getAvailabilityStatus_isTouchpad_returnsAvailable() {
int deviceId = 1;
ShadowInputDevice.sDeviceIds = new int[]{deviceId};
InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
InputDevice.SOURCE_TOUCHPAD);
ShadowInputDevice.addDevice(deviceId, device);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
}