Merge "Disabled Settings preference in case Satellite's conditions." into main
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d50f865..d387ceb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4681,6 +4681,9 @@
     <string name="pointer_stroke_style_name_none">None</string>
     <!-- Title for the button to trigger the 'touch gesture' education. [CHAR LIMIT=35] -->
     <string name="trackpad_touch_gesture">Learn touchpad gestures</string>
+    <!-- TODO(b/353947750): finalize this string and mark it translatable. -->
+    <!-- Notice displayed at the end of the touchpad settings page when the user has disabled system navigation gestures. "Pointer & touchpad accessibility" and "Use touchpad gestures" refer to other labels in Settings, and should be translated in exactly the same way. -->
+    <string name="trackpad_gestures_disabled_footer_text" translatable="false">Some settings are unavailable as touchpad gestures have been turned off. You can turn them on via Pointer &amp; touchpad accessibility > Use touchpad gestures</string>
     <!-- Search keywords for "touchpad" -->
     <string name="keywords_touchpad">trackpad, track pad, mouse, cursor, scroll, swipe, right click, click, pointer</string>
     <!-- Search keywords for 'Bottom-right tap', the name of the touchpad setting that allows the user to click the bottom right corner of the touchpad for more options. -->
@@ -4963,6 +4966,15 @@
     <string name="accessibility_pointer_and_touchpad_summary">Pointer color, pointer size &amp; more</string>
     <!-- Title for the accessibility pointer color customization page. [CHAR LIMIT=50] -->
     <string name="accessibility_pointer_color_customization_title">Pointer color customization</string>
+    <!-- TODO(b/353947750): finalize the four strings below and mark them translatable. -->
+    <!-- Title for the touchpad section of the accessibility pointer and touchpad page. -->
+    <string name="accessibility_touchpad_title" translatable="false">Touchpad</string>
+    <!-- Title for a settings toggle that allows the user to enable or disable system gestures (3- or 4-finger swipes for going home, back, to the overview screen, or between apps) being made on a touchpad. -->
+    <string name="accessibility_touchpad_system_gestures_enable_title" translatable="false">Use system gestures</string>
+    <!-- Description text for a settings toggle that allows the user to enable or disable system gestures (3- or 4-finger swipes for going home, back, to the overview screen, or between apps) being made on a touchpad. -->
+    <string name="accessibility_touchpad_system_gestures_enable_summary" translatable="false">When turned off, 3- or 4-finger gestures are ignored</string>
+    <!-- List of synonyms used in the settings search bar to find the "Use system gestures" touchpad setting, which allows the user to enable or disable system gestures (3- or 4-finger swipes for going home, back, to the overview screen, or between apps) being made on a touchpad. -->
+    <string name="keywords_accessibility_touchpad_system_gestures_enable" translatable="false">touchpad, trackpad, swipe</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_pointer_and_touchpad.xml b/res/xml/accessibility_pointer_and_touchpad.xml
index 8da4177..a46c857 100644
--- a/res/xml/accessibility_pointer_and_touchpad.xml
+++ b/res/xml/accessibility_pointer_and_touchpad.xml
@@ -46,4 +46,17 @@
         settings:keywords="@string/keywords_auto_click"
         settings:controller="com.android.settings.accessibility.AutoclickPreferenceController"/>
 
+    <PreferenceCategory
+        android:key="touchpad_category"
+        android:persistent="false"
+        android:title="@string/accessibility_touchpad_title">
+
+        <SwitchPreferenceCompat
+            android:key="touchpad_system_gestures_enable"
+            android:title="@string/accessibility_touchpad_system_gestures_enable_title"
+            android:summary="@string/accessibility_touchpad_system_gestures_enable_summary"
+            settings:keywords="@string/keywords_accessibility_touchpad_system_gestures_enable"/>
+
+    </PreferenceCategory>
+
 </PreferenceScreen>
diff --git a/res/xml/touchpad_and_mouse_settings.xml b/res/xml/touchpad_and_mouse_settings.xml
index cdfd398..b82b3a6 100644
--- a/res/xml/touchpad_and_mouse_settings.xml
+++ b/res/xml/touchpad_and_mouse_settings.xml
@@ -96,4 +96,10 @@
         android:key="trackpad_touch_gesture"
         android:title="@string/trackpad_touch_gesture"
         settings:controller="com.android.settings.inputmethod.TouchGesturesButtonPreferenceController"/>
+
+    <com.android.settingslib.widget.FooterPreference
+        android:key="trackpad_gestures_disabled_footer"
+        android:title="@string/trackpad_gestures_disabled_footer_text"
+        settings:searchable="false"
+        settings:controller="com.android.settings.inputmethod.TrackpadGesturesDisabledFooterPreferenceController"/>
 </PreferenceScreen>
diff --git a/src/com/android/settings/inputmethod/PointerTouchpadFragment.java b/src/com/android/settings/inputmethod/PointerTouchpadFragment.java
index 890d9b6..441bddd 100644
--- a/src/com/android/settings/inputmethod/PointerTouchpadFragment.java
+++ b/src/com/android/settings/inputmethod/PointerTouchpadFragment.java
@@ -25,8 +25,12 @@
 import com.android.settings.R;
 import com.android.settings.dashboard.DashboardFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.PreferenceCategoryController;
+import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.search.SearchIndexable;
 
+import java.util.List;
+
 /** Accessibility settings for pointer and touchpad. */
 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
 public class PointerTouchpadFragment extends DashboardFragment {
@@ -34,6 +38,21 @@
     private static final String TAG = "PointerTouchpadFragment";
 
     @Override
+    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
+        return buildPreferenceControllers(context);
+    }
+
+    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
+        TouchpadSystemGesturesPreferenceController systemGesturesController =
+                new TouchpadSystemGesturesPreferenceController(
+                        context, "touchpad_system_gestures_enable");
+        return List.of(
+                systemGesturesController,
+                new PreferenceCategoryController(context, "touchpad_category")
+                        .setChildren(List.of(systemGesturesController)));
+    }
+
+    @Override
     public int getMetricsCategory() {
         return SettingsEnums.ACCESSIBILITY_POINTER_TOUCHPAD;
     }
@@ -54,5 +73,11 @@
                 protected boolean isPageSearchEnabled(Context context) {
                     return isTouchpad() || isMouse();
                 }
+
+                @Override
+                public List<AbstractPreferenceController> createPreferenceControllers(
+                        Context context) {
+                    return buildPreferenceControllers(context);
+                }
             };
 }
diff --git a/src/com/android/settings/inputmethod/TouchGesturesButtonPreferenceController.java b/src/com/android/settings/inputmethod/TouchGesturesButtonPreferenceController.java
index 5154623..8b0ae4c 100644
--- a/src/com/android/settings/inputmethod/TouchGesturesButtonPreferenceController.java
+++ b/src/com/android/settings/inputmethod/TouchGesturesButtonPreferenceController.java
@@ -21,6 +21,7 @@
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.content.Intent;
+import android.hardware.input.InputSettings;
 import android.os.UserHandle;
 import android.util.FeatureFlagUtils;
 
@@ -75,7 +76,14 @@
     @Override
     public int getAvailabilityStatus() {
         boolean isTouchpad = InputPeripheralsSettingsUtils.isTouchpad();
-        return isTouchpad ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+        if (isTouchpad) {
+            // If the user's disabled touchpad system gestures in the accessibility settings, the
+            // tutorial won't work or be relevant, so disable the button.
+            return InputSettings.useTouchpadSystemGestures(mContext) ? AVAILABLE
+                    : DISABLED_DEPENDENT_SETTING;
+        } else {
+            return CONDITIONALLY_UNAVAILABLE;
+        }
     }
 
     private void showTouchpadGestureEducation() {
diff --git a/src/com/android/settings/inputmethod/TouchpadSystemGesturesPreferenceController.java b/src/com/android/settings/inputmethod/TouchpadSystemGesturesPreferenceController.java
new file mode 100644
index 0000000..9f0acb1
--- /dev/null
+++ b/src/com/android/settings/inputmethod/TouchpadSystemGesturesPreferenceController.java
@@ -0,0 +1,54 @@
+/*
+ * 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.InputSettings;
+
+import com.android.settings.R;
+import com.android.settings.core.TogglePreferenceController;
+
+public class TouchpadSystemGesturesPreferenceController extends TogglePreferenceController {
+
+    public TouchpadSystemGesturesPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return InputSettings.isTouchpadSystemGestureDisableFeatureFlagEnabled()
+                && InputPeripheralsSettingsUtils.isTouchpad() ? AVAILABLE
+                                                              : CONDITIONALLY_UNAVAILABLE;
+    }
+
+    @Override
+    public boolean isChecked() {
+        return InputSettings.useTouchpadSystemGestures(mContext);
+    }
+
+    @Override
+    public boolean setChecked(boolean isChecked) {
+        InputSettings.setTouchpadSystemGesturesEnabled(mContext, isChecked);
+        // TODO(b/353947750): add a metric for when the setting changes.
+        return true;
+    }
+
+    @Override
+    public int getSliceHighlightMenuRes() {
+        return R.string.menu_key_accessibility;
+    }
+}
diff --git a/src/com/android/settings/inputmethod/TrackpadGesturesDisabledFooterPreferenceController.java b/src/com/android/settings/inputmethod/TrackpadGesturesDisabledFooterPreferenceController.java
new file mode 100644
index 0000000..1fed57e
--- /dev/null
+++ b/src/com/android/settings/inputmethod/TrackpadGesturesDisabledFooterPreferenceController.java
@@ -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.
+ */
+
+package com.android.settings.inputmethod;
+
+import android.content.Context;
+import android.hardware.input.InputSettings;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class TrackpadGesturesDisabledFooterPreferenceController extends BasePreferenceController {
+
+    public TrackpadGesturesDisabledFooterPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return InputSettings.useTouchpadSystemGestures(mContext) ? CONDITIONALLY_UNAVAILABLE
+                : AVAILABLE;
+    }
+}