Loading include/input/InputApplication.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace android { * Used by the native input dispatcher as a handle for the window manager objects * Used by the native input dispatcher as a handle for the window manager objects * that describe an application. * that describe an application. */ */ class InputApplicationHandle : public RefBase { class InputApplicationHandle { public: public: inline const InputApplicationInfo* getInfo() const { inline const InputApplicationInfo* getInfo() const { return &mInfo; return &mInfo; Loading @@ -55,6 +55,12 @@ public: return mInfo.token; return mInfo.token; } } bool operator==(const InputApplicationHandle& other) const { return getName() == other.getName() && getApplicationToken() == other.getApplicationToken(); } bool operator!=(const InputApplicationHandle& other) const { return !(*this == other); } /** /** * Requests that the state of this object be updated to reflect * Requests that the state of this object be updated to reflect * the most current available information about the application. * the most current available information about the application. Loading services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +5 −5 Original line number Original line Diff line number Diff line Loading @@ -47,8 +47,8 @@ protected: private: private: void notifyConfigurationChanged(nsecs_t) override {} void notifyConfigurationChanged(nsecs_t) override {} std::chrono::nanoseconds notifyAnr(const sp<InputApplicationHandle>&, const sp<IBinder>&, std::chrono::nanoseconds notifyAnr(const std::shared_ptr<InputApplicationHandle>&, const std::string& name) override { const sp<IBinder>&, const std::string& name) override { ALOGE("The window is not responding : %s", name.c_str()); ALOGE("The window is not responding : %s", name.c_str()); return 0s; return 0s; } } Loading Loading @@ -148,7 +148,7 @@ public: static const int32_t WIDTH = 200; static const int32_t WIDTH = 200; static const int32_t HEIGHT = 200; static const int32_t HEIGHT = 200; FakeWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle, FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const sp<InputDispatcher>& dispatcher, const std::string name) const sp<InputDispatcher>& dispatcher, const std::string name) : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { mDispatcher->registerInputChannel(mServerChannel); mDispatcher->registerInputChannel(mServerChannel); Loading Loading @@ -246,7 +246,7 @@ static void benchmarkNotifyMotion(benchmark::State& state) { dispatcher->start(); dispatcher->start(); // Create a window that will receive motion events // Create a window that will receive motion events sp<FakeApplicationHandle> application = new FakeApplicationHandle(); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); Loading Loading @@ -282,7 +282,7 @@ static void benchmarkInjectMotion(benchmark::State& state) { dispatcher->start(); dispatcher->start(); // Create a window that will receive motion events // Create a window that will receive motion events sp<FakeApplicationHandle> application = new FakeApplicationHandle(); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); Loading services/inputflinger/dispatcher/Entry.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -254,7 +254,7 @@ struct CommandEntry { sp<Connection> connection; sp<Connection> connection; nsecs_t eventTime; nsecs_t eventTime; KeyEntry* keyEntry; KeyEntry* keyEntry; sp<InputApplicationHandle> inputApplicationHandle; std::shared_ptr<InputApplicationHandle> inputApplicationHandle; std::string reason; std::string reason; int32_t userActivityEventType; int32_t userActivityEventType; uint32_t seq; uint32_t seq; Loading services/inputflinger/dispatcher/InputDispatcher.cpp +30 −24 Original line number Original line Diff line number Diff line Loading @@ -496,7 +496,7 @@ nsecs_t InputDispatcher::processAnrsLocked() { if (mNoFocusedWindowTimeoutTime.has_value() && mAwaitedFocusedApplication != nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && mAwaitedFocusedApplication != nullptr) { if (currentTime >= *mNoFocusedWindowTimeoutTime) { if (currentTime >= *mNoFocusedWindowTimeoutTime) { onAnrLocked(mAwaitedFocusedApplication); onAnrLocked(mAwaitedFocusedApplication); mAwaitedFocusedApplication.clear(); mAwaitedFocusedApplication.reset(); return LONG_LONG_MIN; return LONG_LONG_MIN; } else { } else { // Keep waiting // Keep waiting Loading Loading @@ -1389,7 +1389,7 @@ void InputDispatcher::resetNoFocusedWindowTimeoutLocked() { // Reset input target wait timeout. // Reset input target wait timeout. mNoFocusedWindowTimeoutTime = std::nullopt; mNoFocusedWindowTimeoutTime = std::nullopt; mAwaitedFocusedApplication.clear(); mAwaitedFocusedApplication.reset(); } } /** /** Loading Loading @@ -1459,7 +1459,7 @@ int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, int32_t displayId = getTargetDisplayId(entry); int32_t displayId = getTargetDisplayId(entry); sp<InputWindowHandle> focusedWindowHandle = sp<InputWindowHandle> focusedWindowHandle = getValueByKey(mFocusedWindowHandlesByDisplay, displayId); getValueByKey(mFocusedWindowHandlesByDisplay, displayId); sp<InputApplicationHandle> focusedApplicationHandle = std::shared_ptr<InputApplicationHandle> focusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); // If there is no currently focused window and no focused application // If there is no currently focused window and no focused application Loading Loading @@ -2149,7 +2149,7 @@ bool InputDispatcher::isWindowObscuredLocked(const sp<InputWindowHandle>& window } } std::string InputDispatcher::getApplicationWindowLabel( std::string InputDispatcher::getApplicationWindowLabel( const sp<InputApplicationHandle>& applicationHandle, const std::shared_ptr<InputApplicationHandle>& applicationHandle, const sp<InputWindowHandle>& windowHandle) { const sp<InputWindowHandle>& windowHandle) { if (applicationHandle != nullptr) { if (applicationHandle != nullptr) { if (windowHandle != nullptr) { if (windowHandle != nullptr) { Loading Loading @@ -3868,30 +3868,36 @@ void InputDispatcher::setInputWindowsLocked( } } void InputDispatcher::setFocusedApplication( void InputDispatcher::setFocusedApplication( int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) { int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { if (DEBUG_FOCUS) { if (DEBUG_FOCUS) { ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, inputApplicationHandle ? inputApplicationHandle->getName().c_str() : "<nullptr>"); inputApplicationHandle ? inputApplicationHandle->getName().c_str() : "<nullptr>"); } } { // acquire lock if (inputApplicationHandle != nullptr && inputApplicationHandle->getApplicationToken() != nullptr) { // acquire lock std::scoped_lock _l(mLock); std::scoped_lock _l(mLock); sp<InputApplicationHandle> oldFocusedApplicationHandle = std::shared_ptr<InputApplicationHandle> oldFocusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); if (oldFocusedApplicationHandle == mAwaitedFocusedApplication && // If oldFocusedApplicationHandle already exists inputApplicationHandle != oldFocusedApplicationHandle) { if (oldFocusedApplicationHandle != nullptr) { // If a new focused application handle is different from the old one and // old focus application info is awaited focused application info. if (*oldFocusedApplicationHandle != *inputApplicationHandle && mAwaitedFocusedApplication != nullptr && *oldFocusedApplicationHandle == *mAwaitedFocusedApplication) { resetNoFocusedWindowTimeoutLocked(); resetNoFocusedWindowTimeoutLocked(); } } // Erase the old application from container first if (inputApplicationHandle != nullptr && inputApplicationHandle->updateInfo()) { if (oldFocusedApplicationHandle != inputApplicationHandle) { mFocusedApplicationHandlesByDisplay[displayId] = inputApplicationHandle; } } else if (oldFocusedApplicationHandle != nullptr) { oldFocusedApplicationHandle.clear(); mFocusedApplicationHandlesByDisplay.erase(displayId); mFocusedApplicationHandlesByDisplay.erase(displayId); // Should already get freed after removed from container but just double check. oldFocusedApplicationHandle.reset(); } } // Set the new application handle. mFocusedApplicationHandlesByDisplay[displayId] = inputApplicationHandle; } // release lock } // release lock // Wake up poll loop since it may need to make new input dispatching choices. // Wake up poll loop since it may need to make new input dispatching choices. Loading Loading @@ -4138,7 +4144,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) { dump += StringPrintf(INDENT "FocusedApplications:\n"); dump += StringPrintf(INDENT "FocusedApplications:\n"); for (auto& it : mFocusedApplicationHandlesByDisplay) { for (auto& it : mFocusedApplicationHandlesByDisplay) { const int32_t displayId = it.first; const int32_t displayId = it.first; const sp<InputApplicationHandle>& applicationHandle = it.second; const std::shared_ptr<InputApplicationHandle>& applicationHandle = it.second; const int64_t timeoutMillis = millis( const int64_t timeoutMillis = millis( applicationHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT)); applicationHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT)); dump += StringPrintf(INDENT2 "displayId=%" PRId32 dump += StringPrintf(INDENT2 "displayId=%" PRId32 Loading Loading @@ -4652,7 +4658,7 @@ void InputDispatcher::onAnrLocked(const sp<Connection>& connection) { postCommandLocked(std::move(commandEntry)); postCommandLocked(std::move(commandEntry)); } } void InputDispatcher::onAnrLocked(const sp<InputApplicationHandle>& application) { void InputDispatcher::onAnrLocked(const std::shared_ptr<InputApplicationHandle>& application) { std::string reason = android::base::StringPrintf("%s does not have a focused window", std::string reason = android::base::StringPrintf("%s does not have a focused window", application->getName().c_str()); application->getName().c_str()); Loading @@ -4672,8 +4678,8 @@ void InputDispatcher::updateLastAnrStateLocked(const sp<InputWindowHandle>& wind updateLastAnrStateLocked(windowLabel, reason); updateLastAnrStateLocked(windowLabel, reason); } } void InputDispatcher::updateLastAnrStateLocked(const sp<InputApplicationHandle>& application, void InputDispatcher::updateLastAnrStateLocked( const std::string& reason) { const std::shared_ptr<InputApplicationHandle>& application, const std::string& reason) { const std::string windowLabel = getApplicationWindowLabel(application, nullptr); const std::string windowLabel = getApplicationWindowLabel(application, nullptr); updateLastAnrStateLocked(windowLabel, reason); updateLastAnrStateLocked(windowLabel, reason); } } Loading Loading @@ -4744,9 +4750,9 @@ void InputDispatcher::doNotifyAnrLockedInterruptible(CommandEntry* commandEntry) } } } } void InputDispatcher::extendAnrTimeoutsLocked(const sp<InputApplicationHandle>& application, void InputDispatcher::extendAnrTimeoutsLocked( const sp<IBinder>& connectionToken, const std::shared_ptr<InputApplicationHandle>& application, std::chrono::nanoseconds timeoutExtension) { const sp<IBinder>& connectionToken, std::chrono::nanoseconds timeoutExtension) { sp<Connection> connection = getConnectionLocked(connectionToken); sp<Connection> connection = getConnectionLocked(connectionToken); if (connection == nullptr) { if (connection == nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && application != nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && application != nullptr) { Loading services/inputflinger/dispatcher/InputDispatcher.h +11 −9 Original line number Original line Diff line number Diff line Loading @@ -115,7 +115,8 @@ public: const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>& const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>& handlesPerDisplay) override; handlesPerDisplay) override; virtual void setFocusedApplication( virtual void setFocusedApplication( int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) override; int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) override; virtual void setFocusedDisplay(int32_t displayId) override; virtual void setFocusedDisplay(int32_t displayId) override; virtual void setInputDispatchMode(bool enabled, bool frozen) override; virtual void setInputDispatchMode(bool enabled, bool frozen) override; virtual void setInputFilterEnabled(bool enabled) override; virtual void setInputFilterEnabled(bool enabled) override; Loading Loading @@ -321,8 +322,8 @@ private: std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); // Focused applications. // Focused applications. std::unordered_map<int32_t, sp<InputApplicationHandle>> mFocusedApplicationHandlesByDisplay std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>> GUARDED_BY(mLock); mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock); // Top focused display. // Top focused display. int32_t mFocusedDisplayId GUARDED_BY(mLock); int32_t mFocusedDisplayId GUARDED_BY(mLock); Loading Loading @@ -374,7 +375,7 @@ private: * The focused application at the time when no focused window was present. * The focused application at the time when no focused window was present. * Used to raise an ANR when we have no focused window. * Used to raise an ANR when we have no focused window. */ */ sp<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock); std::shared_ptr<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock); // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. // AnrTracker must be kept in-sync with all responsive connection.waitQueues. // AnrTracker must be kept in-sync with all responsive connection.waitQueues. Loading @@ -382,7 +383,7 @@ private: // Once a connection becomes unresponsive, its entries are removed from AnrTracker to // Once a connection becomes unresponsive, its entries are removed from AnrTracker to // prevent unneeded wakeups. // prevent unneeded wakeups. AnrTracker mAnrTracker GUARDED_BY(mLock); AnrTracker mAnrTracker GUARDED_BY(mLock); void extendAnrTimeoutsLocked(const sp<InputApplicationHandle>& application, void extendAnrTimeoutsLocked(const std::shared_ptr<InputApplicationHandle>& application, const sp<IBinder>& connectionToken, const sp<IBinder>& connectionToken, std::chrono::nanoseconds timeoutExtension) REQUIRES(mLock); std::chrono::nanoseconds timeoutExtension) REQUIRES(mLock); Loading Loading @@ -426,7 +427,8 @@ private: bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const REQUIRES(mLock); int32_t y) const REQUIRES(mLock); bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); std::string getApplicationWindowLabel(const sp<InputApplicationHandle>& applicationHandle, std::string getApplicationWindowLabel( const std::shared_ptr<InputApplicationHandle>& applicationHandle, const sp<InputWindowHandle>& windowHandle); const sp<InputWindowHandle>& windowHandle); // Manage the dispatch cycle for a single connection. // Manage the dispatch cycle for a single connection. Loading Loading @@ -499,10 +501,10 @@ private: void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus, void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus, const sp<InputWindowHandle>& newFocus) REQUIRES(mLock); const sp<InputWindowHandle>& newFocus) REQUIRES(mLock); void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock); void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock); void onAnrLocked(const sp<InputApplicationHandle>& application) REQUIRES(mLock); void onAnrLocked(const std::shared_ptr<InputApplicationHandle>& application) REQUIRES(mLock); void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason) void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason) REQUIRES(mLock); REQUIRES(mLock); void updateLastAnrStateLocked(const sp<InputApplicationHandle>& application, void updateLastAnrStateLocked(const std::shared_ptr<InputApplicationHandle>& application, const std::string& reason) REQUIRES(mLock); const std::string& reason) REQUIRES(mLock); void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) REQUIRES(mLock); REQUIRES(mLock); Loading Loading
include/input/InputApplication.h +7 −1 Original line number Original line Diff line number Diff line Loading @@ -36,7 +36,7 @@ namespace android { * Used by the native input dispatcher as a handle for the window manager objects * Used by the native input dispatcher as a handle for the window manager objects * that describe an application. * that describe an application. */ */ class InputApplicationHandle : public RefBase { class InputApplicationHandle { public: public: inline const InputApplicationInfo* getInfo() const { inline const InputApplicationInfo* getInfo() const { return &mInfo; return &mInfo; Loading @@ -55,6 +55,12 @@ public: return mInfo.token; return mInfo.token; } } bool operator==(const InputApplicationHandle& other) const { return getName() == other.getName() && getApplicationToken() == other.getApplicationToken(); } bool operator!=(const InputApplicationHandle& other) const { return !(*this == other); } /** /** * Requests that the state of this object be updated to reflect * Requests that the state of this object be updated to reflect * the most current available information about the application. * the most current available information about the application. Loading
services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +5 −5 Original line number Original line Diff line number Diff line Loading @@ -47,8 +47,8 @@ protected: private: private: void notifyConfigurationChanged(nsecs_t) override {} void notifyConfigurationChanged(nsecs_t) override {} std::chrono::nanoseconds notifyAnr(const sp<InputApplicationHandle>&, const sp<IBinder>&, std::chrono::nanoseconds notifyAnr(const std::shared_ptr<InputApplicationHandle>&, const std::string& name) override { const sp<IBinder>&, const std::string& name) override { ALOGE("The window is not responding : %s", name.c_str()); ALOGE("The window is not responding : %s", name.c_str()); return 0s; return 0s; } } Loading Loading @@ -148,7 +148,7 @@ public: static const int32_t WIDTH = 200; static const int32_t WIDTH = 200; static const int32_t HEIGHT = 200; static const int32_t HEIGHT = 200; FakeWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle, FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const sp<InputDispatcher>& dispatcher, const std::string name) const sp<InputDispatcher>& dispatcher, const std::string name) : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { mDispatcher->registerInputChannel(mServerChannel); mDispatcher->registerInputChannel(mServerChannel); Loading Loading @@ -246,7 +246,7 @@ static void benchmarkNotifyMotion(benchmark::State& state) { dispatcher->start(); dispatcher->start(); // Create a window that will receive motion events // Create a window that will receive motion events sp<FakeApplicationHandle> application = new FakeApplicationHandle(); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); Loading Loading @@ -282,7 +282,7 @@ static void benchmarkInjectMotion(benchmark::State& state) { dispatcher->start(); dispatcher->start(); // Create a window that will receive motion events // Create a window that will receive motion events sp<FakeApplicationHandle> application = new FakeApplicationHandle(); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); Loading
services/inputflinger/dispatcher/Entry.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -254,7 +254,7 @@ struct CommandEntry { sp<Connection> connection; sp<Connection> connection; nsecs_t eventTime; nsecs_t eventTime; KeyEntry* keyEntry; KeyEntry* keyEntry; sp<InputApplicationHandle> inputApplicationHandle; std::shared_ptr<InputApplicationHandle> inputApplicationHandle; std::string reason; std::string reason; int32_t userActivityEventType; int32_t userActivityEventType; uint32_t seq; uint32_t seq; Loading
services/inputflinger/dispatcher/InputDispatcher.cpp +30 −24 Original line number Original line Diff line number Diff line Loading @@ -496,7 +496,7 @@ nsecs_t InputDispatcher::processAnrsLocked() { if (mNoFocusedWindowTimeoutTime.has_value() && mAwaitedFocusedApplication != nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && mAwaitedFocusedApplication != nullptr) { if (currentTime >= *mNoFocusedWindowTimeoutTime) { if (currentTime >= *mNoFocusedWindowTimeoutTime) { onAnrLocked(mAwaitedFocusedApplication); onAnrLocked(mAwaitedFocusedApplication); mAwaitedFocusedApplication.clear(); mAwaitedFocusedApplication.reset(); return LONG_LONG_MIN; return LONG_LONG_MIN; } else { } else { // Keep waiting // Keep waiting Loading Loading @@ -1389,7 +1389,7 @@ void InputDispatcher::resetNoFocusedWindowTimeoutLocked() { // Reset input target wait timeout. // Reset input target wait timeout. mNoFocusedWindowTimeoutTime = std::nullopt; mNoFocusedWindowTimeoutTime = std::nullopt; mAwaitedFocusedApplication.clear(); mAwaitedFocusedApplication.reset(); } } /** /** Loading Loading @@ -1459,7 +1459,7 @@ int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime, int32_t displayId = getTargetDisplayId(entry); int32_t displayId = getTargetDisplayId(entry); sp<InputWindowHandle> focusedWindowHandle = sp<InputWindowHandle> focusedWindowHandle = getValueByKey(mFocusedWindowHandlesByDisplay, displayId); getValueByKey(mFocusedWindowHandlesByDisplay, displayId); sp<InputApplicationHandle> focusedApplicationHandle = std::shared_ptr<InputApplicationHandle> focusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); // If there is no currently focused window and no focused application // If there is no currently focused window and no focused application Loading Loading @@ -2149,7 +2149,7 @@ bool InputDispatcher::isWindowObscuredLocked(const sp<InputWindowHandle>& window } } std::string InputDispatcher::getApplicationWindowLabel( std::string InputDispatcher::getApplicationWindowLabel( const sp<InputApplicationHandle>& applicationHandle, const std::shared_ptr<InputApplicationHandle>& applicationHandle, const sp<InputWindowHandle>& windowHandle) { const sp<InputWindowHandle>& windowHandle) { if (applicationHandle != nullptr) { if (applicationHandle != nullptr) { if (windowHandle != nullptr) { if (windowHandle != nullptr) { Loading Loading @@ -3868,30 +3868,36 @@ void InputDispatcher::setInputWindowsLocked( } } void InputDispatcher::setFocusedApplication( void InputDispatcher::setFocusedApplication( int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) { int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) { if (DEBUG_FOCUS) { if (DEBUG_FOCUS) { ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, ALOGD("setFocusedApplication displayId=%" PRId32 " %s", displayId, inputApplicationHandle ? inputApplicationHandle->getName().c_str() : "<nullptr>"); inputApplicationHandle ? inputApplicationHandle->getName().c_str() : "<nullptr>"); } } { // acquire lock if (inputApplicationHandle != nullptr && inputApplicationHandle->getApplicationToken() != nullptr) { // acquire lock std::scoped_lock _l(mLock); std::scoped_lock _l(mLock); sp<InputApplicationHandle> oldFocusedApplicationHandle = std::shared_ptr<InputApplicationHandle> oldFocusedApplicationHandle = getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); getValueByKey(mFocusedApplicationHandlesByDisplay, displayId); if (oldFocusedApplicationHandle == mAwaitedFocusedApplication && // If oldFocusedApplicationHandle already exists inputApplicationHandle != oldFocusedApplicationHandle) { if (oldFocusedApplicationHandle != nullptr) { // If a new focused application handle is different from the old one and // old focus application info is awaited focused application info. if (*oldFocusedApplicationHandle != *inputApplicationHandle && mAwaitedFocusedApplication != nullptr && *oldFocusedApplicationHandle == *mAwaitedFocusedApplication) { resetNoFocusedWindowTimeoutLocked(); resetNoFocusedWindowTimeoutLocked(); } } // Erase the old application from container first if (inputApplicationHandle != nullptr && inputApplicationHandle->updateInfo()) { if (oldFocusedApplicationHandle != inputApplicationHandle) { mFocusedApplicationHandlesByDisplay[displayId] = inputApplicationHandle; } } else if (oldFocusedApplicationHandle != nullptr) { oldFocusedApplicationHandle.clear(); mFocusedApplicationHandlesByDisplay.erase(displayId); mFocusedApplicationHandlesByDisplay.erase(displayId); // Should already get freed after removed from container but just double check. oldFocusedApplicationHandle.reset(); } } // Set the new application handle. mFocusedApplicationHandlesByDisplay[displayId] = inputApplicationHandle; } // release lock } // release lock // Wake up poll loop since it may need to make new input dispatching choices. // Wake up poll loop since it may need to make new input dispatching choices. Loading Loading @@ -4138,7 +4144,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) { dump += StringPrintf(INDENT "FocusedApplications:\n"); dump += StringPrintf(INDENT "FocusedApplications:\n"); for (auto& it : mFocusedApplicationHandlesByDisplay) { for (auto& it : mFocusedApplicationHandlesByDisplay) { const int32_t displayId = it.first; const int32_t displayId = it.first; const sp<InputApplicationHandle>& applicationHandle = it.second; const std::shared_ptr<InputApplicationHandle>& applicationHandle = it.second; const int64_t timeoutMillis = millis( const int64_t timeoutMillis = millis( applicationHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT)); applicationHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT)); dump += StringPrintf(INDENT2 "displayId=%" PRId32 dump += StringPrintf(INDENT2 "displayId=%" PRId32 Loading Loading @@ -4652,7 +4658,7 @@ void InputDispatcher::onAnrLocked(const sp<Connection>& connection) { postCommandLocked(std::move(commandEntry)); postCommandLocked(std::move(commandEntry)); } } void InputDispatcher::onAnrLocked(const sp<InputApplicationHandle>& application) { void InputDispatcher::onAnrLocked(const std::shared_ptr<InputApplicationHandle>& application) { std::string reason = android::base::StringPrintf("%s does not have a focused window", std::string reason = android::base::StringPrintf("%s does not have a focused window", application->getName().c_str()); application->getName().c_str()); Loading @@ -4672,8 +4678,8 @@ void InputDispatcher::updateLastAnrStateLocked(const sp<InputWindowHandle>& wind updateLastAnrStateLocked(windowLabel, reason); updateLastAnrStateLocked(windowLabel, reason); } } void InputDispatcher::updateLastAnrStateLocked(const sp<InputApplicationHandle>& application, void InputDispatcher::updateLastAnrStateLocked( const std::string& reason) { const std::shared_ptr<InputApplicationHandle>& application, const std::string& reason) { const std::string windowLabel = getApplicationWindowLabel(application, nullptr); const std::string windowLabel = getApplicationWindowLabel(application, nullptr); updateLastAnrStateLocked(windowLabel, reason); updateLastAnrStateLocked(windowLabel, reason); } } Loading Loading @@ -4744,9 +4750,9 @@ void InputDispatcher::doNotifyAnrLockedInterruptible(CommandEntry* commandEntry) } } } } void InputDispatcher::extendAnrTimeoutsLocked(const sp<InputApplicationHandle>& application, void InputDispatcher::extendAnrTimeoutsLocked( const sp<IBinder>& connectionToken, const std::shared_ptr<InputApplicationHandle>& application, std::chrono::nanoseconds timeoutExtension) { const sp<IBinder>& connectionToken, std::chrono::nanoseconds timeoutExtension) { sp<Connection> connection = getConnectionLocked(connectionToken); sp<Connection> connection = getConnectionLocked(connectionToken); if (connection == nullptr) { if (connection == nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && application != nullptr) { if (mNoFocusedWindowTimeoutTime.has_value() && application != nullptr) { Loading
services/inputflinger/dispatcher/InputDispatcher.h +11 −9 Original line number Original line Diff line number Diff line Loading @@ -115,7 +115,8 @@ public: const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>& const std::unordered_map<int32_t, std::vector<sp<InputWindowHandle>>>& handlesPerDisplay) override; handlesPerDisplay) override; virtual void setFocusedApplication( virtual void setFocusedApplication( int32_t displayId, const sp<InputApplicationHandle>& inputApplicationHandle) override; int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) override; virtual void setFocusedDisplay(int32_t displayId) override; virtual void setFocusedDisplay(int32_t displayId) override; virtual void setInputDispatchMode(bool enabled, bool frozen) override; virtual void setInputDispatchMode(bool enabled, bool frozen) override; virtual void setInputFilterEnabled(bool enabled) override; virtual void setInputFilterEnabled(bool enabled) override; Loading Loading @@ -321,8 +322,8 @@ private: std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock); // Focused applications. // Focused applications. std::unordered_map<int32_t, sp<InputApplicationHandle>> mFocusedApplicationHandlesByDisplay std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>> GUARDED_BY(mLock); mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock); // Top focused display. // Top focused display. int32_t mFocusedDisplayId GUARDED_BY(mLock); int32_t mFocusedDisplayId GUARDED_BY(mLock); Loading Loading @@ -374,7 +375,7 @@ private: * The focused application at the time when no focused window was present. * The focused application at the time when no focused window was present. * Used to raise an ANR when we have no focused window. * Used to raise an ANR when we have no focused window. */ */ sp<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock); std::shared_ptr<InputApplicationHandle> mAwaitedFocusedApplication GUARDED_BY(mLock); // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. // Optimization: AnrTracker is used to quickly find which connection is due for a timeout next. // AnrTracker must be kept in-sync with all responsive connection.waitQueues. // AnrTracker must be kept in-sync with all responsive connection.waitQueues. Loading @@ -382,7 +383,7 @@ private: // Once a connection becomes unresponsive, its entries are removed from AnrTracker to // Once a connection becomes unresponsive, its entries are removed from AnrTracker to // prevent unneeded wakeups. // prevent unneeded wakeups. AnrTracker mAnrTracker GUARDED_BY(mLock); AnrTracker mAnrTracker GUARDED_BY(mLock); void extendAnrTimeoutsLocked(const sp<InputApplicationHandle>& application, void extendAnrTimeoutsLocked(const std::shared_ptr<InputApplicationHandle>& application, const sp<IBinder>& connectionToken, const sp<IBinder>& connectionToken, std::chrono::nanoseconds timeoutExtension) REQUIRES(mLock); std::chrono::nanoseconds timeoutExtension) REQUIRES(mLock); Loading Loading @@ -426,7 +427,8 @@ private: bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const REQUIRES(mLock); int32_t y) const REQUIRES(mLock); bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); bool isWindowObscuredLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock); std::string getApplicationWindowLabel(const sp<InputApplicationHandle>& applicationHandle, std::string getApplicationWindowLabel( const std::shared_ptr<InputApplicationHandle>& applicationHandle, const sp<InputWindowHandle>& windowHandle); const sp<InputWindowHandle>& windowHandle); // Manage the dispatch cycle for a single connection. // Manage the dispatch cycle for a single connection. Loading Loading @@ -499,10 +501,10 @@ private: void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus, void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus, const sp<InputWindowHandle>& newFocus) REQUIRES(mLock); const sp<InputWindowHandle>& newFocus) REQUIRES(mLock); void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock); void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock); void onAnrLocked(const sp<InputApplicationHandle>& application) REQUIRES(mLock); void onAnrLocked(const std::shared_ptr<InputApplicationHandle>& application) REQUIRES(mLock); void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason) void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason) REQUIRES(mLock); REQUIRES(mLock); void updateLastAnrStateLocked(const sp<InputApplicationHandle>& application, void updateLastAnrStateLocked(const std::shared_ptr<InputApplicationHandle>& application, const std::string& reason) REQUIRES(mLock); const std::string& reason) REQUIRES(mLock); void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason) REQUIRES(mLock); REQUIRES(mLock); Loading