diff options
author | 2020-03-19 11:55:01 -0700 | |
---|---|---|
committer | 2020-03-21 18:24:48 +0000 | |
commit | c60da19f2a012a15971dcd8f4fa3b7c22a90a670 (patch) | |
tree | 92e0f47ddbff00f1534d014c6fd5c996efe8d266 /services/inputflinger/InputClassifier.cpp | |
parent | f08d9c835f9e422e34f19b0ed779cea1ec983105 (diff) |
Disable deep press when long press timeout is long
If the user sets the long press timeout to anything > default value,
then we should disable deep press. That means, if the user is triggering
long press too easily, it is likely that the user will trigger deep
press too easily as well.
To prevent unwanted long press invocations, we disable deep press in
such situations.
Bug: 148311342
Test: Add logging to both cases where deep press is enabled and
disabled. Go to accessibility -> touch & hold delay, and change the
value. Ensure that the logging matches expectation (short -> enable,
medium/long -> disable). The state should persist across the reboot.
Change-Id: Ic631c684609c4436e9eaa6f9389939c5a6e4e1cd
Merged-In: Ic631c684609c4436e9eaa6f9389939c5a6e4e1cd
(cherry picked from commit c9ac19eb3d3c3f185fea95906541249dd4c3baf8)
Diffstat (limited to 'services/inputflinger/InputClassifier.cpp')
-rw-r--r-- | services/inputflinger/InputClassifier.cpp | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/services/inputflinger/InputClassifier.cpp b/services/inputflinger/InputClassifier.cpp index 8ba1f7f8c1..77a0716269 100644 --- a/services/inputflinger/InputClassifier.cpp +++ b/services/inputflinger/InputClassifier.cpp @@ -27,7 +27,6 @@ #if defined(__linux__) #include <pthread.h> #endif -#include <server_configurable_flags/get_flags.h> #include <unordered_set> #include <android/hardware/input/classifier/1.0/IInputClassifier.h> @@ -46,11 +45,6 @@ using namespace android::hardware::input; namespace android { -// Category (=namespace) name for the input settings that are applied at boot time -static const char* INPUT_NATIVE_BOOT = "input_native_boot"; -// Feature flag name for the deep press feature -static const char* DEEP_PRESS_ENABLED = "deep_press_enabled"; - //Max number of elements to store in mEvents. static constexpr size_t MAX_EVENTS = 5; @@ -77,20 +71,6 @@ static bool isTouchEvent(const NotifyMotionArgs& args) { return args.source == AINPUT_SOURCE_TOUCHPAD || args.source == AINPUT_SOURCE_TOUCHSCREEN; } -// Check if the "deep touch" feature is on. -static bool deepPressEnabled() { - std::string flag_value = server_configurable_flags::GetServerConfigurableFlag( - INPUT_NATIVE_BOOT, DEEP_PRESS_ENABLED, "true"); - std::transform(flag_value.begin(), flag_value.end(), flag_value.begin(), ::tolower); - if (flag_value == "1" || flag_value == "true") { - ALOGI("Deep press feature enabled."); - return true; - } - ALOGI("Deep press feature is not enabled."); - return false; -} - - // --- ClassifierEvent --- ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : @@ -157,12 +137,6 @@ MotionClassifier::MotionClassifier( std::unique_ptr<MotionClassifierInterface> MotionClassifier::create( sp<android::hardware::hidl_death_recipient> deathRecipient) { - if (!deepPressEnabled()) { - // If feature is not enabled, MotionClassifier should stay null to avoid unnecessary work. - // When MotionClassifier is null, InputClassifier will forward all events - // to the next InputListener, unmodified. - return nullptr; - } sp<android::hardware::input::classifier::V1_0::IInputClassifier> service = classifier::V1_0::IInputClassifier::getService(); if (!service) { @@ -372,14 +346,25 @@ void InputClassifier::HalDeathRecipient::serviceDied( // --- InputClassifier --- InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) - : mListener(listener), mHalDeathRecipient(new HalDeathRecipient(*this)) { - mInitializeMotionClassifierThread = std::thread( - [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); + : mListener(listener), mHalDeathRecipient(new HalDeathRecipient(*this)) {} + +void InputClassifier::setMotionClassifierEnabled(bool enabled) { + if (enabled) { + ALOGI("Enabling motion classifier"); + if (mInitializeMotionClassifierThread.joinable()) { + mInitializeMotionClassifierThread.join(); + } + mInitializeMotionClassifierThread = std::thread( + [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); #if defined(__linux__) - // Set the thread name for debugging - pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), - "Create MotionClassifier"); + // Set the thread name for debugging + pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), + "Create MotionClassifier"); #endif + } else { + ALOGI("Disabling motion classifier"); + setMotionClassifier(nullptr); + } } void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { @@ -429,8 +414,6 @@ void InputClassifier::setMotionClassifier( void InputClassifier::dump(std::string& dump) { std::scoped_lock lock(mLock); dump += "Input Classifier State:\n"; - dump += StringPrintf(INDENT1 "Deep press: %s\n", deepPressEnabled() ? "enabled" : "disabled"); - dump += INDENT1 "Motion Classifier:\n"; if (mMotionClassifier) { mMotionClassifier->dump(dump); @@ -441,7 +424,9 @@ void InputClassifier::dump(std::string& dump) { } InputClassifier::~InputClassifier() { - mInitializeMotionClassifierThread.join(); + if (mInitializeMotionClassifierThread.joinable()) { + mInitializeMotionClassifierThread.join(); + } } } // namespace android |