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
This commit is contained in:
Abdelrahman Awadalla
2024-08-13 14:34:49 +00:00
parent 2a01b356ae
commit 5ef762b2b0
2 changed files with 38 additions and 38 deletions

View File

@@ -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 androidx.preference.SwitchPreference;
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 @@ public class TouchpadVisualizerPreferenceController extends
@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);
}
}