diff options
author | mango.chen <mango.chen@realtek.com> | 2024-04-19 13:29:38 +0800 |
---|---|---|
committer | mango.chen <mango.chen@realtek.com> | 2024-04-19 13:29:38 +0800 |
commit | 360c58452b66b62c4d19160132ade1df0c629441 (patch) | |
tree | 7d7cadb3e7d9b0a7ac00033dbfd356eca7a21523 | |
parent | 8a829c2df343308120b0124148c0179cd9452c28 (diff) | |
download | TvSettings-360c58452b66b62c4d19160132ade1df0c629441.tar.gz |
Fix android.appsecurity.cts.StorageHostTest#testFullDisk failed
UiAutomator create a motion event with button state 0, which
will be filtered out. Here let 0 and BUTTON_STYLUS_PRIMARY could
be translated to KEYCODE_DPAD_CENTER.
Bug: 230555866
Change-Id: I1afb55eaccd289b647f753e53880d64812fa9a28
-rw-r--r-- | Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java b/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java index 98e76a39a..2f31da8e2 100644 --- a/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java +++ b/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java @@ -203,13 +203,13 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF } vh.itemView.setOnTouchListener((v, e) -> { if (e.getActionMasked() == MotionEvent.ACTION_DOWN - && e.getButtonState() == MotionEvent.BUTTON_PRIMARY) { + && isPrimaryKey(e.getButtonState())) { vh.itemView.requestFocus(); v.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); return true; } else if (e.getActionMasked() == MotionEvent.ACTION_UP - && e.getButtonState() == MotionEvent.BUTTON_PRIMARY) { + && isPrimaryKey(e.getButtonState())) { v.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); return true; @@ -316,4 +316,11 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF protected int getPageId() { return TvSettingsEnums.PAGE_CLASSIC_DEFAULT; } + + // check if such motion event should translate to key event DPAD_CENTER + private boolean isPrimaryKey(int buttonState) { + return buttonState == MotionEvent.BUTTON_PRIMARY + || buttonState == MotionEvent.BUTTON_STYLUS_PRIMARY + || buttonState == 0; // motion events which creates by UI Automator + } } |