Loading services/inputflinger/Android.bp +0 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,6 @@ cc_defaults { "libstatslog", "libstatslog", "libutils", "libutils", "libui", "libui", "server_configurable_flags", ], ], } } Loading services/inputflinger/InputClassifier.cpp +20 −35 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ #if defined(__linux__) #if defined(__linux__) #include <pthread.h> #include <pthread.h> #endif #endif #include <server_configurable_flags/get_flags.h> #include <unordered_set> #include <unordered_set> #include <android/hardware/input/classifier/1.0/IInputClassifier.h> #include <android/hardware/input/classifier/1.0/IInputClassifier.h> Loading @@ -46,11 +45,6 @@ using namespace android::hardware::input; namespace android { 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. //Max number of elements to store in mEvents. static constexpr size_t MAX_EVENTS = 5; static constexpr size_t MAX_EVENTS = 5; Loading @@ -77,20 +71,6 @@ static bool isTouchEvent(const NotifyMotionArgs& args) { return args.source == AINPUT_SOURCE_TOUCHPAD || args.source == AINPUT_SOURCE_TOUCHSCREEN; 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::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : Loading Loading @@ -157,12 +137,6 @@ MotionClassifier::MotionClassifier( std::unique_ptr<MotionClassifierInterface> MotionClassifier::create( std::unique_ptr<MotionClassifierInterface> MotionClassifier::create( sp<android::hardware::hidl_death_recipient> deathRecipient) { 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 = sp<android::hardware::input::classifier::V1_0::IInputClassifier> service = classifier::V1_0::IInputClassifier::getService(); classifier::V1_0::IInputClassifier::getService(); if (!service) { if (!service) { Loading Loading @@ -372,7 +346,14 @@ void InputClassifier::HalDeathRecipient::serviceDied( // --- InputClassifier --- // --- InputClassifier --- InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) : mListener(listener), mHalDeathRecipient(new HalDeathRecipient(*this)) { : 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( mInitializeMotionClassifierThread = std::thread( [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); #if defined(__linux__) #if defined(__linux__) Loading @@ -380,6 +361,10 @@ InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), "Create MotionClassifier"); "Create MotionClassifier"); #endif #endif } else { ALOGI("Disabling motion classifier"); setMotionClassifier(nullptr); } } } void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { Loading Loading @@ -429,8 +414,6 @@ void InputClassifier::setMotionClassifier( void InputClassifier::dump(std::string& dump) { void InputClassifier::dump(std::string& dump) { std::scoped_lock lock(mLock); std::scoped_lock lock(mLock); dump += "Input Classifier State:\n"; dump += "Input Classifier State:\n"; dump += StringPrintf(INDENT1 "Deep press: %s\n", deepPressEnabled() ? "enabled" : "disabled"); dump += INDENT1 "Motion Classifier:\n"; dump += INDENT1 "Motion Classifier:\n"; if (mMotionClassifier) { if (mMotionClassifier) { mMotionClassifier->dump(dump); mMotionClassifier->dump(dump); Loading @@ -441,7 +424,9 @@ void InputClassifier::dump(std::string& dump) { } } InputClassifier::~InputClassifier() { InputClassifier::~InputClassifier() { if (mInitializeMotionClassifierThread.joinable()) { mInitializeMotionClassifierThread.join(); mInitializeMotionClassifierThread.join(); } } } } // namespace android } // namespace android services/inputflinger/InputClassifier.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -90,6 +90,7 @@ public: */ */ class InputClassifierInterface : public virtual RefBase, public InputListenerInterface { class InputClassifierInterface : public virtual RefBase, public InputListenerInterface { public: public: virtual void setMotionClassifierEnabled(bool enabled) = 0; /** /** * Dump the state of the input classifier. * Dump the state of the input classifier. * This method may be called on any thread (usually by the input manager). * This method may be called on any thread (usually by the input manager). Loading Loading @@ -234,6 +235,9 @@ public: ~InputClassifier(); ~InputClassifier(); // Called from InputManager virtual void setMotionClassifierEnabled(bool enabled) override; private: private: // Protect access to mMotionClassifier, since it may become null via a hidl callback // Protect access to mMotionClassifier, since it may become null via a hidl callback std::mutex mLock; std::mutex mLock; Loading services/inputflinger/InputManager.cpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -132,4 +132,8 @@ void InputManager::unregisterInputChannel(const sp<InputChannel>& channel) { mDispatcher->unregisterInputChannel(channel); mDispatcher->unregisterInputChannel(channel); } } void InputManager::setMotionClassifierEnabled(bool enabled) { mClassifier->setMotionClassifierEnabled(enabled); } } // namespace android } // namespace android services/inputflinger/InputManager.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -100,6 +100,8 @@ public: virtual void registerInputChannel(const sp<InputChannel>& channel); virtual void registerInputChannel(const sp<InputChannel>& channel); virtual void unregisterInputChannel(const sp<InputChannel>& channel); virtual void unregisterInputChannel(const sp<InputChannel>& channel); void setMotionClassifierEnabled(bool enabled); private: private: sp<InputReaderInterface> mReader; sp<InputReaderInterface> mReader; Loading Loading
services/inputflinger/Android.bp +0 −1 Original line number Original line Diff line number Diff line Loading @@ -52,7 +52,6 @@ cc_defaults { "libstatslog", "libstatslog", "libutils", "libutils", "libui", "libui", "server_configurable_flags", ], ], } } Loading
services/inputflinger/InputClassifier.cpp +20 −35 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,6 @@ #if defined(__linux__) #if defined(__linux__) #include <pthread.h> #include <pthread.h> #endif #endif #include <server_configurable_flags/get_flags.h> #include <unordered_set> #include <unordered_set> #include <android/hardware/input/classifier/1.0/IInputClassifier.h> #include <android/hardware/input/classifier/1.0/IInputClassifier.h> Loading @@ -46,11 +45,6 @@ using namespace android::hardware::input; namespace android { 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. //Max number of elements to store in mEvents. static constexpr size_t MAX_EVENTS = 5; static constexpr size_t MAX_EVENTS = 5; Loading @@ -77,20 +71,6 @@ static bool isTouchEvent(const NotifyMotionArgs& args) { return args.source == AINPUT_SOURCE_TOUCHPAD || args.source == AINPUT_SOURCE_TOUCHSCREEN; 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::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : ClassifierEvent::ClassifierEvent(std::unique_ptr<NotifyMotionArgs> args) : Loading Loading @@ -157,12 +137,6 @@ MotionClassifier::MotionClassifier( std::unique_ptr<MotionClassifierInterface> MotionClassifier::create( std::unique_ptr<MotionClassifierInterface> MotionClassifier::create( sp<android::hardware::hidl_death_recipient> deathRecipient) { 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 = sp<android::hardware::input::classifier::V1_0::IInputClassifier> service = classifier::V1_0::IInputClassifier::getService(); classifier::V1_0::IInputClassifier::getService(); if (!service) { if (!service) { Loading Loading @@ -372,7 +346,14 @@ void InputClassifier::HalDeathRecipient::serviceDied( // --- InputClassifier --- // --- InputClassifier --- InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) : mListener(listener), mHalDeathRecipient(new HalDeathRecipient(*this)) { : 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( mInitializeMotionClassifierThread = std::thread( [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); [this] { setMotionClassifier(MotionClassifier::create(mHalDeathRecipient)); }); #if defined(__linux__) #if defined(__linux__) Loading @@ -380,6 +361,10 @@ InputClassifier::InputClassifier(const sp<InputListenerInterface>& listener) pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), pthread_setname_np(mInitializeMotionClassifierThread.native_handle(), "Create MotionClassifier"); "Create MotionClassifier"); #endif #endif } else { ALOGI("Disabling motion classifier"); setMotionClassifier(nullptr); } } } void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { void InputClassifier::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) { Loading Loading @@ -429,8 +414,6 @@ void InputClassifier::setMotionClassifier( void InputClassifier::dump(std::string& dump) { void InputClassifier::dump(std::string& dump) { std::scoped_lock lock(mLock); std::scoped_lock lock(mLock); dump += "Input Classifier State:\n"; dump += "Input Classifier State:\n"; dump += StringPrintf(INDENT1 "Deep press: %s\n", deepPressEnabled() ? "enabled" : "disabled"); dump += INDENT1 "Motion Classifier:\n"; dump += INDENT1 "Motion Classifier:\n"; if (mMotionClassifier) { if (mMotionClassifier) { mMotionClassifier->dump(dump); mMotionClassifier->dump(dump); Loading @@ -441,7 +424,9 @@ void InputClassifier::dump(std::string& dump) { } } InputClassifier::~InputClassifier() { InputClassifier::~InputClassifier() { if (mInitializeMotionClassifierThread.joinable()) { mInitializeMotionClassifierThread.join(); mInitializeMotionClassifierThread.join(); } } } } // namespace android } // namespace android
services/inputflinger/InputClassifier.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -90,6 +90,7 @@ public: */ */ class InputClassifierInterface : public virtual RefBase, public InputListenerInterface { class InputClassifierInterface : public virtual RefBase, public InputListenerInterface { public: public: virtual void setMotionClassifierEnabled(bool enabled) = 0; /** /** * Dump the state of the input classifier. * Dump the state of the input classifier. * This method may be called on any thread (usually by the input manager). * This method may be called on any thread (usually by the input manager). Loading Loading @@ -234,6 +235,9 @@ public: ~InputClassifier(); ~InputClassifier(); // Called from InputManager virtual void setMotionClassifierEnabled(bool enabled) override; private: private: // Protect access to mMotionClassifier, since it may become null via a hidl callback // Protect access to mMotionClassifier, since it may become null via a hidl callback std::mutex mLock; std::mutex mLock; Loading
services/inputflinger/InputManager.cpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -132,4 +132,8 @@ void InputManager::unregisterInputChannel(const sp<InputChannel>& channel) { mDispatcher->unregisterInputChannel(channel); mDispatcher->unregisterInputChannel(channel); } } void InputManager::setMotionClassifierEnabled(bool enabled) { mClassifier->setMotionClassifierEnabled(enabled); } } // namespace android } // namespace android
services/inputflinger/InputManager.h +2 −0 Original line number Original line Diff line number Diff line Loading @@ -100,6 +100,8 @@ public: virtual void registerInputChannel(const sp<InputChannel>& channel); virtual void registerInputChannel(const sp<InputChannel>& channel); virtual void unregisterInputChannel(const sp<InputChannel>& channel); virtual void unregisterInputChannel(const sp<InputChannel>& channel); void setMotionClassifierEnabled(bool enabled); private: private: sp<InputReaderInterface> mReader; sp<InputReaderInterface> mReader; Loading