Adding methods to enable Touchpad Visualizer option
Adding methods to enable the Touchpad Visualizer option based on both the feature flag and the value of the settings toggle.
Test: atest TouchpadVisualizerPreferenceControllerTest
Test: Enable the flag and enable the "Show touchpad input" in developer
options and trace the logs in TouchpadInputMapper.
Bug: 359801523
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I1c51bc617e907081043cea3e6bab1c719f4d2df9
diff --git a/src/com/android/settings/development/TouchpadVisualizerPreferenceController.java b/src/com/android/settings/development/TouchpadVisualizerPreferenceController.java
index f918d26..04ae92b 100644
--- a/src/com/android/settings/development/TouchpadVisualizerPreferenceController.java
+++ b/src/com/android/settings/development/TouchpadVisualizerPreferenceController.java
@@ -17,8 +17,10 @@
package com.android.settings.development;
import android.content.Context;
-import android.provider.Settings;
+import android.hardware.input.InputSettings;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
@@ -26,23 +28,13 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import android.hardware.input.InputSettings;
-
-/** PreferenceController that controls the "Touchpad visualizer" developer option. */
+/** PreferenceController that controls the "Show touchpad input" developer option. */
public class TouchpadVisualizerPreferenceController extends
DeveloperOptionsPreferenceController implements
Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
private static final String TOUCHPAD_VISUALIZER_KEY = "touchpad_visualizer";
- @VisibleForTesting
- static final int SETTING_VALUE_ON = 1;
- @VisibleForTesting
- static final int SETTING_VALUE_OFF = 0;
-
public TouchpadVisualizerPreferenceController(@NonNull Context context) {
super(context);
}
@@ -60,24 +52,22 @@
@Override
public boolean onPreferenceChange(@NonNull Preference preference, @Nullable Object newValue) {
final boolean isEnabled = newValue != null ? (Boolean) newValue : false;
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER,
- isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
+ InputSettings.setTouchpadVisualizer(mContext, isEnabled);
+
return true;
}
@Override
public void updateState(@NonNull Preference preference) {
- int touchpadVisualizer = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER, SETTING_VALUE_OFF);
- ((SwitchPreference) mPreference).setChecked(touchpadVisualizer != SETTING_VALUE_OFF);
+ boolean touchpadVisualizerEnabled = InputSettings.useTouchpadVisualizer(mContext);
+ ((SwitchPreference) mPreference).setChecked(touchpadVisualizerEnabled);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
- Settings.System.putInt(mContext.getContentResolver(), Settings.System.TOUCHPAD_VISUALIZER,
- SETTING_VALUE_OFF);
+ InputSettings.setTouchpadVisualizer(mContext, false);
+
((SwitchPreference) mPreference).setChecked(false);
}
}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/development/TouchpadVisualizerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/TouchpadVisualizerPreferenceControllerTest.java
index 98c774e..826bae9 100644
--- a/tests/robotests/src/com/android/settings/development/TouchpadVisualizerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/TouchpadVisualizerPreferenceControllerTest.java
@@ -22,22 +22,35 @@
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.provider.Settings;
+import android.hardware.input.InputSettings;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
+import com.android.hardware.input.Flags;
+import com.android.settings.testutils.shadow.ShadowSystemSettings;
+
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {
+ ShadowSystemSettings.class,
+})
public class TouchpadVisualizerPreferenceControllerTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
@Mock
private PreferenceScreen mScreen;
@Mock
@@ -57,55 +70,52 @@
}
@Test
+ @EnableFlags({Flags.FLAG_TOUCHPAD_VISUALIZER})
public void updateState_touchpadVisualizerEnabled_shouldCheckedPreference() {
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER, ShowTapsPreferenceController.SETTING_VALUE_ON);
-
+ InputSettings.setTouchpadVisualizer(mContext, true);
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
}
@Test
+ @EnableFlags({Flags.FLAG_TOUCHPAD_VISUALIZER})
public void updateState_touchpadVisualizerDisabled_shouldUncheckedPreference() {
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER,
- ShowTapsPreferenceController.SETTING_VALUE_OFF);
-
+ InputSettings.setTouchpadVisualizer(mContext, false);
mController.updateState(mPreference);
verify(mPreference).setChecked(false);
}
@Test
+ @EnableFlags({Flags.FLAG_TOUCHPAD_VISUALIZER})
public void onPreferenceChange_preferenceChecked_shouldEnableTouchpadVisualizer() {
mController.onPreferenceChange(mPreference, true /* new value */);
- final int touchpadVisualizer = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER, -1 /* default */);
+ final boolean touchpadVisualizer = InputSettings.useTouchpadVisualizer(mContext);
- assertThat(touchpadVisualizer).isEqualTo(ShowTapsPreferenceController.SETTING_VALUE_ON);
+ assertThat(touchpadVisualizer).isTrue();
}
@Test
+ @EnableFlags({Flags.FLAG_TOUCHPAD_VISUALIZER})
public void onPreferenceChange_preferenceUnchecked_shouldDisableTouchpadVisualizer() {
mController.onPreferenceChange(mPreference, false /* new value */);
- final int showTapsMode = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER, -1 /* default */);
+ final boolean touchpadVisualizer = InputSettings.useTouchpadVisualizer(mContext);
- assertThat(showTapsMode).isEqualTo(ShowTapsPreferenceController.SETTING_VALUE_OFF);
+ assertThat(touchpadVisualizer).isFalse();
}
@Test
+ @EnableFlags({Flags.FLAG_TOUCHPAD_VISUALIZER})
public void onDeveloperOptionsSwitchDisabled_preferenceShouldBeEnabled() {
mController.onDeveloperOptionsSwitchDisabled();
- final int showTapsMode = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.TOUCHPAD_VISUALIZER, -1 /* default */);
+ final boolean touchpadVisualizer = InputSettings.useTouchpadVisualizer(mContext);
- assertThat(showTapsMode).isEqualTo(ShowTapsPreferenceController.SETTING_VALUE_OFF);
+ assertThat(touchpadVisualizer).isFalse();
verify(mPreference).setEnabled(false);
verify(mPreference).setChecked(false);
}
-}
\ No newline at end of file
+}