Move pointer and touchpad customization settings to their own pages.
Bug: 269100659
Test: PointerTouchpadFragmentTest
Test: PointerTouchpadPreferenceControllerTest
Flag: android.view.flags.enable_vector_cursor_a11y_settings
Change-Id: I0dccf48f9b5416ad8e6d3c263188d4bb850f69e9
diff --git a/res/drawable/ic_pointer_and_touchpad.xml b/res/drawable/ic_pointer_and_touchpad.xml
new file mode 100644
index 0000000..c077900
--- /dev/null
+++ b/res/drawable/ic_pointer_and_touchpad.xml
@@ -0,0 +1,35 @@
+<!--
+ 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.
+ -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item>
+ <com.android.settingslib.widget.AdaptiveIconShapeDrawable
+ android:width="@dimen/accessibility_icon_size"
+ android:height="@dimen/accessibility_icon_size"
+ android:color="@color/accessibility_feature_background"/>
+ </item>
+ <item android:gravity="center">
+ <vector
+ android:height="32dp"
+ android:width="32dp"
+ android:viewportHeight="32"
+ android:viewportWidth="32">
+ <path
+ android:fillColor="#fff"
+ android:pathData="M19.15,22.35a2.6,2.6 0,0 0,1.91 -0.79,2.6 2.6,0 0,0 0.79,-1.91v-0.9h-5.4v0.9c0,0.75 0.26,1.39 0.79,1.91a2.6,2.6 0,0 0,1.91 0.79ZM16.49,17.4h1.98v-2.17a2.6,2.6 0,0 0,-1.98 2.17ZM19.82,17.4h2a2.6,2.6 0,0 0,-0.68 -1.39,2.62 2.62,0 0,0 -1.32,-0.78v2.17ZM19.15,23.7a3.96,3.96 0,0 1,-4.05 -4.05v-1.8c0,-1.14 0.39,-2.1 1.16,-2.87a3.93,3.93 0,0 1,2.89 -1.18c1.14,0 2.1,0.4 2.87,1.18a3.87,3.87 0,0 1,1.18 2.87v1.8c0,1.14 -0.4,2.1 -1.18,2.89a3.9,3.9 0,0 1,-2.87 1.16ZM10.15,20.55v-8.1,8.1ZM10.15,21.9c-0.38,0 -0.7,-0.13 -0.96,-0.4s-0.39,-0.59 -0.39,-0.95v-8.1c0,-0.36 0.13,-0.67 0.4,-0.94 0.26,-0.27 0.57,-0.41 0.95,-0.41h11.7c0.37,0 0.7,0.14 0.96,0.41 0.26,0.27 0.39,0.58 0.39,0.94L10.15,12.45v8.1h3.6v1.35h-3.6Z"/>
+ </vector>
+ </item>
+</layer-list>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3494afd..2270804 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4532,8 +4532,8 @@
<string name="trackpad_bottom_right_tap_summary">Click in the bottom right corner of the touchpad for more options</string>
<!-- Title text for 'Pointer speed'. [CHAR LIMIT=35] -->
<string name="trackpad_pointer_speed">Pointer speed</string>
- <!-- Title text for mouse pointer fill style. [CHAR LIMIT=35] -->
- <string name="pointer_fill_style">Pointer fill style</string>
+ <!-- Title text for mouse pointer color. [CHAR LIMIT=35] -->
+ <string name="pointer_fill_style">Pointer color</string>
<!-- Content description for black pointer fill style. [CHAR LIMIT=60] -->
<string name="pointer_fill_style_black_button">Change pointer fill style to black</string>
<!-- Content description for green pointer fill style. [CHAR LIMIT=60] -->
@@ -4810,6 +4810,12 @@
<string name="display_category_title">Display</string>
<!-- Title for the accessibility color and motion page. [CHAR LIMIT=50] -->
<string name="accessibility_color_and_motion_title">Color and motion</string>
+ <!-- Title for the accessibility pointer and touchpad page. [CHAR LIMIT=50] -->
+ <string name="accessibility_pointer_and_touchpad_title">Pointer & touchpad accessibility</string>
+ <!-- Summary for the accessibility pointer and touchpad page. [CHAR LIMIT=50] -->
+ <string name="accessibility_pointer_and_touchpad_summary">Pointer color, pointer size & more</string>
+ <!-- Title for the accessibility pointer color customization page. [CHAR LIMIT=50] -->
+ <string name="accessibility_pointer_color_customization_title">Pointer color customization</string>
<!-- Title for the accessibility color contrast page. [CHAR LIMIT=50] -->
<string name="accessibility_color_contrast_title">Color contrast</string>
<!-- Intro for the accessibility color contrast page. [CHAR LIMIT=NONE] -->
diff --git a/res/xml/accessibility_color_and_motion.xml b/res/xml/accessibility_color_and_motion.xml
index 4c4490c..a500b72 100644
--- a/res/xml/accessibility_color_and_motion.xml
+++ b/res/xml/accessibility_color_and_motion.xml
@@ -72,17 +72,6 @@
android:title="@string/accessibility_toggle_large_pointer_icon_title"
settings:controller="com.android.settings.accessibility.LargePointerIconPreferenceController"/>
- <com.android.settings.widget.LabeledSeekBarPreference
- android:key="large_pointer_scale"
- android:title="@string/accessibility_toggle_large_pointer_icon_title"
- android:summary="@string/accessibility_toggle_large_pointer_icon_summary"
- android:max="@integer/pointer_scale_seek_bar_end"
- settings:iconStart="@drawable/ic_remove_24dp"
- settings:iconStartContentDescription="@string/pointer_scale_decrease_content_description"
- settings:iconEnd="@drawable/ic_add_24dp"
- settings:iconEndContentDescription="@string/pointer_scale_increase_content_description"
- settings:controller="com.android.settings.inputmethod.PointerScaleSeekBarController" />
-
<PreferenceCategory
android:key="experimental_category"
android:persistent="false"
diff --git a/res/xml/accessibility_pointer_and_touchpad.xml b/res/xml/accessibility_pointer_and_touchpad.xml
new file mode 100644
index 0000000..1d3b0f2
--- /dev/null
+++ b/res/xml/accessibility_pointer_and_touchpad.xml
@@ -0,0 +1,48 @@
+<?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:key="accessibility_pointer_and_touchpad"
+ android:persistent="false"
+ android:title="@string/accessibility_pointer_and_touchpad_title">
+
+ <com.android.settings.widget.LabeledSeekBarPreference
+ android:key="pointer_scale_preference"
+ android:title="@string/pointer_scale"
+ android:max="@integer/pointer_scale_seek_bar_end"
+ settings:iconStart="@drawable/ic_remove_24dp"
+ settings:iconStartContentDescription="@string/pointer_scale_decrease_content_description"
+ settings:iconEnd="@drawable/ic_add_24dp"
+ settings:iconEndContentDescription="@string/pointer_scale_increase_content_description"
+ settings:controller="com.android.settings.inputmethod.PointerScaleSeekBarController" />
+
+ <Preference
+ android:fragment="com.android.settings.inputmethod.PointerColorCustomizationFragment"
+ android:key="pointer_color_customization_preference"
+ android:persistent="false"
+ android:title="@string/accessibility_pointer_color_customization_title"/>
+
+ <Preference
+ android:fragment="com.android.settings.accessibility.ToggleAutoclickPreferenceFragment"
+ android:key="autoclick_preference"
+ android:persistent="false"
+ android:title="@string/accessibility_autoclick_preference_title"
+ settings:keywords="@string/keywords_auto_click"
+ settings:controller="com.android.settings.accessibility.AutoclickPreferenceController"/>
+
+</PreferenceScreen>
diff --git a/res/xml/accessibility_pointer_color_customization.xml b/res/xml/accessibility_pointer_color_customization.xml
new file mode 100644
index 0000000..6d767b4
--- /dev/null
+++ b/res/xml/accessibility_pointer_color_customization.xml
@@ -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:key="accessibility_pointer_color_customization"
+ android:persistent="false"
+ android:title="@string/accessibility_pointer_color_customization_title">
+
+ <com.android.settings.inputmethod.PointerFillStylePreference
+ android:key="pointer_fill_style"
+ android:title="@string/pointer_fill_style"
+ settings:controller="com.android.settings.inputmethod.PointerFillStylePreferenceController"/>
+
+ <com.android.settings.inputmethod.PointerStrokeStylePreference
+ android:key="pointer_stroke_style"
+ android:title="@string/pointer_stroke_style"
+ settings:controller="com.android.settings.inputmethod.PointerStrokeStylePreferenceController"/>
+
+</PreferenceScreen>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 6561775..18e6455 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -110,6 +110,16 @@
settings:keywords="@string/keywords_vibration"
android:summary="@string/accessibility_vibration_settings_summary"/>
+ <Preference
+ android:fragment="com.android.settings.inputmethod.PointerTouchpadFragment"
+ android:key="pointer_and_touchpad"
+ android:icon="@drawable/ic_pointer_and_touchpad"
+ android:persistent="false"
+ android:title="@string/accessibility_pointer_and_touchpad_title"
+ android:summary="@string/accessibility_pointer_and_touchpad_summary"
+ settings:controller="com.android.settings.inputmethod.PointerTouchpadPreferenceController"
+ settings:searchable="true"/>
+
</PreferenceCategory>
<PreferenceCategory
diff --git a/res/xml/accessibility_tap_assistance.xml b/res/xml/accessibility_tap_assistance.xml
index d2ec653..6a53d83 100644
--- a/res/xml/accessibility_tap_assistance.xml
+++ b/res/xml/accessibility_tap_assistance.xml
@@ -37,12 +37,4 @@
android:title="@string/accessibility_setting_item_control_timeout_title"
settings:controller="com.android.settings.accessibility.AccessibilityTimeoutPreferenceController"
settings:keywords="@string/keywords_accessibility_timeout"/>
-
- <Preference
- android:fragment="com.android.settings.accessibility.ToggleAutoclickPreferenceFragment"
- android:key="autoclick_preference"
- android:persistent="false"
- android:title="@string/accessibility_autoclick_preference_title"
- settings:keywords="@string/keywords_auto_click"
- settings:controller="com.android.settings.accessibility.AutoclickPreferenceController"/>
</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/trackpad_settings.xml b/res/xml/trackpad_settings.xml
index 935de82..7e94944 100644
--- a/res/xml/trackpad_settings.xml
+++ b/res/xml/trackpad_settings.xml
@@ -62,29 +62,14 @@
android:selectable="false"
settings:controller="com.android.settings.inputmethod.TrackpadPointerSpeedPreferenceController"/>
- <com.android.settings.inputmethod.PointerFillStylePreference
- android:key="pointer_fill_style"
- android:title="@string/pointer_fill_style"
+ <Preference
+ android:fragment="com.android.settings.inputmethod.PointerTouchpadFragment"
+ android:key="pointer_and_touchpad"
android:order="50"
- settings:controller="com.android.settings.inputmethod.PointerFillStylePreferenceController"/>
-
- <com.android.settings.inputmethod.PointerStrokeStylePreference
- android:key="pointer_stroke_style"
- android:title="@string/pointer_stroke_style"
- android:order="60"
- settings:controller="com.android.settings.inputmethod.PointerStrokeStylePreferenceController"/>
-
- <com.android.settings.widget.LabeledSeekBarPreference
- android:key="pointer_scale"
- android:title="@string/pointer_scale"
- android:order="70"
- android:max="@integer/pointer_scale_seek_bar_end"
- settings:iconStart="@drawable/ic_remove_24dp"
- settings:searchable="false"
- settings:iconStartContentDescription="@string/pointer_scale_decrease_content_description"
- settings:iconEnd="@drawable/ic_add_24dp"
- settings:iconEndContentDescription="@string/pointer_scale_increase_content_description"
- settings:controller="com.android.settings.inputmethod.PointerScaleSeekBarController" />
+ 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"
diff --git a/src/com/android/settings/inputmethod/PointerColorCustomizationFragment.java b/src/com/android/settings/inputmethod/PointerColorCustomizationFragment.java
new file mode 100644
index 0000000..2324c5e
--- /dev/null
+++ b/src/com/android/settings/inputmethod/PointerColorCustomizationFragment.java
@@ -0,0 +1,59 @@
+/*
+ * 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.android.settings.inputmethod.NewKeyboardSettingsUtils.isMouse;
+import static com.android.settings.inputmethod.NewKeyboardSettingsUtils.isTouchpad;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+/** Settings for pointer and touchpad. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class PointerColorCustomizationFragment extends DashboardFragment {
+
+ private static final String TAG = "PointerColorCustomizationFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.ACCESSIBILITY_POINTER_COLOR_CUSTOMIZATION;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.accessibility_pointer_color_customization;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.accessibility_pointer_color_customization) {
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return isTouchpad() || isMouse();
+ }
+ };
+}
diff --git a/src/com/android/settings/inputmethod/PointerTouchpadFragment.java b/src/com/android/settings/inputmethod/PointerTouchpadFragment.java
new file mode 100644
index 0000000..fc069ca
--- /dev/null
+++ b/src/com/android/settings/inputmethod/PointerTouchpadFragment.java
@@ -0,0 +1,58 @@
+/*
+ * 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.android.settings.inputmethod.NewKeyboardSettingsUtils.isMouse;
+import static com.android.settings.inputmethod.NewKeyboardSettingsUtils.isTouchpad;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+/** Accessibility settings for pointer and touchpad. */
+@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
+public class PointerTouchpadFragment extends DashboardFragment {
+
+ private static final String TAG = "PointerTouchpadFragment";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.ACCESSIBILITY_POINTER_TOUCHPAD;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.accessibility_pointer_and_touchpad;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.accessibility_pointer_and_touchpad) {
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return isTouchpad() || isMouse();
+ }
+ };
+}
diff --git a/src/com/android/settings/inputmethod/PointerTouchpadPreferenceController.java b/src/com/android/settings/inputmethod/PointerTouchpadPreferenceController.java
new file mode 100644
index 0000000..b6ea063
--- /dev/null
+++ b/src/com/android/settings/inputmethod/PointerTouchpadPreferenceController.java
@@ -0,0 +1,39 @@
+/*
+ * 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.core.BasePreferenceController;
+
+/** Controller that shows and updates the pointer touchpad preference. */
+public class PointerTouchpadPreferenceController extends BasePreferenceController {
+
+ public PointerTouchpadPreferenceController(@NonNull Context context,
+ @NonNull String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ boolean isTouchpad = NewKeyboardSettingsUtils.isTouchpad();
+ boolean isMouse = NewKeyboardSettingsUtils.isMouse();
+ return (isTouchpad || isMouse) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadFragmentTest.java b/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadFragmentTest.java
new file mode 100644
index 0000000..68cd768
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadFragmentTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.app.settings.SettingsEnums;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+@RunWith(RobolectricTestRunner.class)
+public class PointerTouchpadFragmentTest {
+
+ private PointerTouchpadFragment mFragment;
+
+ @Before
+ public void setUp() {
+ mFragment = new PointerTouchpadFragment();
+ }
+
+ @Test
+ public void getPreferenceScreenResId_isPointerTouchpad() {
+ assertThat(mFragment.getPreferenceScreenResId())
+ .isEqualTo(R.xml.accessibility_pointer_and_touchpad);
+ }
+
+ @Test
+ public void getMetricsCategory_returnsCorrectCategory() {
+ assertThat(mFragment.getMetricsCategory()).isEqualTo(
+ SettingsEnums.ACCESSIBILITY_POINTER_TOUCHPAD);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadPreferenceControllerTest.java
new file mode 100644
index 0000000..6fceeba
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/inputmethod/PointerTouchpadPreferenceControllerTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.view.InputDevice;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.core.BasePreferenceController;
+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 PointerTouchpadPreferenceController}. */
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+ ShadowInputDevice.class,
+})
+public final class PointerTouchpadPreferenceControllerTest {
+ @Rule public MockitoRule rule = MockitoJUnit.rule();
+
+ private PointerTouchpadPreferenceController mController;
+
+ @Before
+ public void initObjects() {
+ Context context = ApplicationProvider.getApplicationContext();
+ mController = new PointerTouchpadPreferenceController(context, "pointer_touchpad");
+ ShadowInputDevice.reset();
+ }
+
+ @Test
+ public void getAvailableStatus_noTouchpadOrMouseConditionallyUnavailable() {
+ int deviceId = 1;
+ ShadowInputDevice.sDeviceIds = new int[]{deviceId};
+ InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
+ InputDevice.SOURCE_BLUETOOTH_STYLUS);
+ ShadowInputDevice.addDevice(deviceId, device);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_isTouchpadAvailable() {
+ 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);
+ }
+
+ @Test
+ public void getAvailabilityStatus_isMouseAvailable() {
+ 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);
+ }
+}