Loading src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +6 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.provider.Settings; import android.provider.Settings.Secure; import android.util.Log; import android.view.InputDevice; Loading Loading @@ -125,6 +126,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem pref.setTitle(mContext.getString(R.string.stylus_ignore_button)); pref.setIcon(R.drawable.ic_block); pref.setOnPreferenceClickListener(this); pref.setChecked(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 0) == 1); return pref; } Loading @@ -147,7 +150,9 @@ public class StylusDevicesController extends AbstractPreferenceController implem ((SwitchPreference) preference).isChecked() ? 1 : 0); break; case KEY_IGNORE_BUTTON: // TODO(b/251199452): to turn off stylus button presses Settings.Secure.putInt(mContext.getContentResolver(), Secure.STYLUS_BUTTONS_DISABLED, ((SwitchPreference) preference).isChecked() ? 1 : 0); break; } return true; Loading tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings.Secure; import android.view.InputDevice; import android.view.inputmethod.InputMethodManager; Loading Loading @@ -227,6 +228,42 @@ public class StylusDevicesControllerTest { Settings.Global.STYLUS_HANDWRITING_ENABLED, -1)).isEqualTo(1); } @Test public void buttonsPreference_checkedWhenFlagTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 1); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); assertThat(buttonsPref.isChecked()).isEqualTo(true); } @Test public void buttonsPreference_uncheckedWhenFlagFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 0); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); assertThat(buttonsPref.isChecked()).isEqualTo(false); } @Test public void buttonsPreference_updatesFlagOnClick() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 1); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); buttonsPref.performClick(); assertThat(buttonsPref.isChecked()).isEqualTo(false); assertThat(Settings.Secure.getInt(mContext.getContentResolver(), Secure.STYLUS_BUTTONS_DISABLED, -1)).isEqualTo(0); } private void showScreen(StylusDevicesController controller) { controller.displayPreference(mScreen); } Loading Loading
src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +6 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.provider.Settings; import android.provider.Settings.Secure; import android.util.Log; import android.view.InputDevice; Loading Loading @@ -125,6 +126,8 @@ public class StylusDevicesController extends AbstractPreferenceController implem pref.setTitle(mContext.getString(R.string.stylus_ignore_button)); pref.setIcon(R.drawable.ic_block); pref.setOnPreferenceClickListener(this); pref.setChecked(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 0) == 1); return pref; } Loading @@ -147,7 +150,9 @@ public class StylusDevicesController extends AbstractPreferenceController implem ((SwitchPreference) preference).isChecked() ? 1 : 0); break; case KEY_IGNORE_BUTTON: // TODO(b/251199452): to turn off stylus button presses Settings.Secure.putInt(mContext.getContentResolver(), Secure.STYLUS_BUTTONS_DISABLED, ((SwitchPreference) preference).isChecked() ? 1 : 0); break; } return true; Loading
tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings.Secure; import android.view.InputDevice; import android.view.inputmethod.InputMethodManager; Loading Loading @@ -227,6 +228,42 @@ public class StylusDevicesControllerTest { Settings.Global.STYLUS_HANDWRITING_ENABLED, -1)).isEqualTo(1); } @Test public void buttonsPreference_checkedWhenFlagTrue() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 1); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); assertThat(buttonsPref.isChecked()).isEqualTo(true); } @Test public void buttonsPreference_uncheckedWhenFlagFalse() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 0); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); assertThat(buttonsPref.isChecked()).isEqualTo(false); } @Test public void buttonsPreference_updatesFlagOnClick() { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STYLUS_BUTTONS_DISABLED, 1); showScreen(mController); SwitchPreference buttonsPref = (SwitchPreference) mPreferenceContainer.getPreference(2); buttonsPref.performClick(); assertThat(buttonsPref.isChecked()).isEqualTo(false); assertThat(Settings.Secure.getInt(mContext.getContentResolver(), Secure.STYLUS_BUTTONS_DISABLED, -1)).isEqualTo(0); } private void showScreen(StylusDevicesController controller) { controller.displayPreference(mScreen); } Loading