From e092fefc822f4b4fb101345f74a7c951413c97b7 Mon Sep 17 00:00:00 2001 From: Vaibhav Devmurari Date: Thu, 22 Feb 2024 22:36:23 +0000 Subject: Don't repeat when slow keys A11y feature enabled Currently when slow keys is enabled, user has to press and hold for the key to be registered, but since, we still haven't added settings to modify repeat thresholds, usually it ends up repeating the pressed key as well which may be annoying for the user. As a stop gap, we block repeat for now when slow keys is enabled. Future plan at V+ is to have repat threshold modification in Settings allowing user to properly configure it as per the need. Bug: 322327461 Test: Manual Change-Id: I44503746c16ed992bbfbfe852e26e22896f32595 --- services/inputflinger/rust/slow_keys_filter.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/inputflinger/rust/slow_keys_filter.rs b/services/inputflinger/rust/slow_keys_filter.rs index 01165b57fa..09fbf40842 100644 --- a/services/inputflinger/rust/slow_keys_filter.rs +++ b/services/inputflinger/rust/slow_keys_filter.rs @@ -28,6 +28,9 @@ use log::debug; use std::collections::HashSet; use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; +// Policy flags from Input.h +const POLICY_FLAG_DISABLE_KEY_REPEAT: i32 = 0x08000000; + #[derive(Debug)] struct OngoingKeyDown { scancode: i32, @@ -129,6 +132,12 @@ impl Filter for SlowKeysFilter { let mut pending_event = *event; pending_event.downTime += slow_filter.slow_key_threshold_ns; pending_event.eventTime = pending_event.downTime; + // Currently a slow keys user ends up repeating the presses key quite often + // since default repeat thresholds are very low, so blocking repeat for events + // when slow keys is enabled. + // TODO(b/322327461): Allow key repeat with slow keys, once repeat key rate and + // thresholds can be modified in the settings. + pending_event.policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT; slow_filter.pending_down_events.push(pending_event); } KeyEventAction::UP => { @@ -200,7 +209,7 @@ impl ThreadCallback for SlowKeysFilter { mod tests { use crate::input_filter::{test_callbacks::TestCallbacks, test_filter::TestFilter, Filter}; use crate::input_filter_thread::test_thread::TestThread; - use crate::slow_keys_filter::SlowKeysFilter; + use crate::slow_keys_filter::{SlowKeysFilter, POLICY_FLAG_DISABLE_KEY_REPEAT}; use android_hardware_input_common::aidl::android::hardware::input::common::Source::Source; use com_android_server_inputflinger::aidl::com::android::server::inputflinger::{ DeviceInfo::DeviceInfo, KeyEvent::KeyEvent, KeyEventAction::KeyEventAction, @@ -285,6 +294,7 @@ mod tests { action: KeyEventAction::DOWN, downTime: 100, eventTime: 100, + policyFlags: POLICY_FLAG_DISABLE_KEY_REPEAT, ..BASE_KEY_EVENT } ); -- cgit v1.2.3-59-g8ed1b