diff options
author | 2019-03-20 16:52:24 +0800 | |
---|---|---|
committer | 2019-03-22 18:14:29 +0800 | |
commit | 7a0c39a5b46bbb8f2e7b869c642078e892d4804c (patch) | |
tree | 0dbccb8e489d3977be760d85e206b86baac08047 | |
parent | ebb52c5ac8b95637f5048b993aad88253cd85205 (diff) |
Make InputApplicationInfo as a part of InputApplicationHandle (1/2)
InputWindowHandle::updateInfo would also call
InputApplicationHandle::updateInfo that may access the null pointer if the
focus application changed in same time.
- To replace allocated mInfo in updateInfo(), make it as an object
member variable of InputApplicationHandle.
Bug: 128930899
Test: atest inputflinger_tests
Change-Id: Id19d2d8cd1be181ea994d0efa7afbb2567c4d734
-rw-r--r-- | include/input/InputApplication.h | 17 | ||||
-rw-r--r-- | libs/input/InputApplication.cpp | 11 | ||||
-rw-r--r-- | services/inputflinger/InputDispatcher.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 5 |
4 files changed, 7 insertions, 28 deletions
diff --git a/include/input/InputApplication.h b/include/input/InputApplication.h index 71a8f20468..7f04611309 100644 --- a/include/input/InputApplication.h +++ b/include/input/InputApplication.h @@ -50,19 +50,19 @@ struct InputApplicationInfo { class InputApplicationHandle : public RefBase { public: inline const InputApplicationInfo* getInfo() const { - return mInfo; + return &mInfo; } inline std::string getName() const { - return mInfo ? mInfo->name : "<invalid>"; + return !mInfo.name.empty() ? mInfo.name : "<invalid>"; } inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { - return mInfo ? mInfo->dispatchingTimeout : defaultValue; + return mInfo.token ? mInfo.dispatchingTimeout : defaultValue; } inline sp<IBinder> getApplicationToken() const { - return mInfo ? mInfo->token : nullptr; + return mInfo.token; } /** @@ -75,18 +75,11 @@ public: * Returns true on success, or false if the handle is no longer valid. */ virtual bool updateInfo() = 0; - - /** - * Releases the storage used by the associated information when it is - * no longer needed. - */ - void releaseInfo(); - protected: InputApplicationHandle(); virtual ~InputApplicationHandle(); - InputApplicationInfo* mInfo; + InputApplicationInfo mInfo; }; } // namespace android diff --git a/libs/input/InputApplication.cpp b/libs/input/InputApplication.cpp index 7936f50d54..1d9f8a7091 100644 --- a/libs/input/InputApplication.cpp +++ b/libs/input/InputApplication.cpp @@ -24,19 +24,10 @@ namespace android { // --- InputApplicationHandle --- -InputApplicationHandle::InputApplicationHandle() : - mInfo(nullptr) { +InputApplicationHandle::InputApplicationHandle() { } InputApplicationHandle::~InputApplicationHandle() { - delete mInfo; -} - -void InputApplicationHandle::releaseInfo() { - if (mInfo) { - delete mInfo; - mInfo = nullptr; - } } InputApplicationInfo InputApplicationInfo::read(const Parcel& from) { diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index bcb1ec5fb8..2f2d690d75 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -3243,13 +3243,11 @@ void InputDispatcher::setFocusedApplication( if (oldFocusedApplicationHandle != inputApplicationHandle) { if (oldFocusedApplicationHandle != nullptr) { resetANRTimeoutsLocked(); - oldFocusedApplicationHandle->releaseInfo(); } mFocusedApplicationHandlesByDisplay[displayId] = inputApplicationHandle; } } else if (oldFocusedApplicationHandle != nullptr) { resetANRTimeoutsLocked(); - oldFocusedApplicationHandle->releaseInfo(); oldFocusedApplicationHandle.clear(); mFocusedApplicationHandlesByDisplay.erase(displayId); } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 3b6fe52a5a..088ad9ccaa 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -340,10 +340,7 @@ public: virtual ~FakeApplicationHandle() {} virtual bool updateInfo() { - if (!mInfo) { - mInfo = new InputApplicationInfo(); - } - mInfo->dispatchingTimeout = DISPATCHING_TIMEOUT; + mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; return true; } }; |