From 3720ed06a4be83f6cec4ad7233ed6b6773fb7403 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Wed, 8 Aug 2018 16:08:27 -0700 Subject: Implement Parcelling functions for InputWindowInfo In preparation for parcelling across the SurfaceControl interface. As a dependency we move the parcelling of InputChannels from frameworks/base JNI code in to InputChannel.h. Bug: 80101428 Bug: 113136004 Bug: 111440400 Test: None Change-Id: Ib27f03282e9872274b834bb00737fd351e7a1b30 --- libs/input/InputApplication.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libs/input/InputApplication.cpp (limited to 'libs/input/InputApplication.cpp') diff --git a/libs/input/InputApplication.cpp b/libs/input/InputApplication.cpp new file mode 100644 index 0000000000..a0d1668029 --- /dev/null +++ b/libs/input/InputApplication.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "InputApplication" + +#include + +#include + +namespace android { + +// --- InputApplicationHandle --- + +InputApplicationHandle::InputApplicationHandle() : + mInfo(nullptr) { +} + +InputApplicationHandle::~InputApplicationHandle() { + delete mInfo; +} + +void InputApplicationHandle::releaseInfo() { + if (mInfo) { + delete mInfo; + mInfo = nullptr; + } +} + +} // namespace android -- cgit v1.2.3-59-g8ed1b From 740167f1a2b5a141debb0efc952eb4e57152bdd4 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Thu, 11 Oct 2018 19:03:41 -0700 Subject: Rework InputApplicationInfo First we move it inside of InputWindowInfo instead of InputWindowHandle so it is part of the data sent across binder. Second we give it a persistent identity of an IBinder token and use this for comparisons. Bug: 80101428 Bug: 113136004 Bug: 111440400 Test: EndToEndNativeInputTest. Existing tests pass. Change-Id: Id89a40e66887d834020f8e645fd1fb48adb7ee2e --- include/input/InputApplication.h | 11 +++++++++++ include/input/InputWindow.h | 8 ++++++-- libs/gui/tests/EndToEndNativeInputTest.cpp | 7 +++++++ libs/input/InputApplication.cpp | 17 +++++++++++++++++ libs/input/InputWindow.cpp | 5 +++-- services/inputflinger/InputDispatcher.cpp | 21 +++++++++++---------- services/inputflinger/InputDispatcher.h | 2 +- services/inputflinger/InputManager.cpp | 13 +------------ .../inputflinger/tests/InputDispatcher_test.cpp | 7 ++++++- 9 files changed, 63 insertions(+), 28 deletions(-) (limited to 'libs/input/InputApplication.cpp') diff --git a/include/input/InputApplication.h b/include/input/InputApplication.h index 9b365b9f0d..71a8f20468 100644 --- a/include/input/InputApplication.h +++ b/include/input/InputApplication.h @@ -19,6 +19,9 @@ #include +#include +#include + #include #include #include @@ -29,8 +32,12 @@ namespace android { * Describes the properties of an application that can receive input. */ struct InputApplicationInfo { + sp token; std::string name; nsecs_t dispatchingTimeout; + + status_t write(Parcel& output) const; + static InputApplicationInfo read(const Parcel& from); }; @@ -54,6 +61,10 @@ public: return mInfo ? mInfo->dispatchingTimeout : defaultValue; } + inline sp getApplicationToken() const { + return mInfo ? mInfo->token : nullptr; + } + /** * Requests that the state of this object be updated to reflect * the most current available information about the application. diff --git a/include/input/InputWindow.h b/include/input/InputWindow.h index 6164aa6f09..1a46825692 100644 --- a/include/input/InputWindow.h +++ b/include/input/InputWindow.h @@ -138,6 +138,7 @@ struct InputWindowInfo { int32_t ownerUid; int32_t inputFeatures; int32_t displayId; + InputApplicationInfo applicationInfo; void addTouchableRegion(const Rect& region); @@ -168,7 +169,6 @@ struct InputWindowInfo { */ class InputWindowHandle : public RefBase { public: - const sp inputApplicationHandle; inline const InputWindowInfo* getInfo() const { return &mInfo; @@ -176,6 +176,10 @@ public: sp getToken() const; + sp getApplicationToken() { + return mInfo.applicationInfo.token; + } + inline std::string getName() const { return mInfo.token ? mInfo.name : ""; } @@ -202,7 +206,7 @@ public: void releaseChannel(); protected: - explicit InputWindowHandle(const sp& inputApplicationHandle); + explicit InputWindowHandle(); virtual ~InputWindowHandle(); InputWindowInfo mInfo; diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index 7b727047d1..2cc0c54708 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -153,6 +153,13 @@ private: mInputInfo.ownerUid = 11111; mInputInfo.inputFeatures = 0; mInputInfo.displayId = 0; + + InputApplicationInfo aInfo; + aInfo.token = new BBinder(); + aInfo.name = "Test app info"; + aInfo.dispatchingTimeout = 100000; + + mInputInfo.applicationInfo = aInfo; } public: sp mSurfaceControl; diff --git a/libs/input/InputApplication.cpp b/libs/input/InputApplication.cpp index a0d1668029..7936f50d54 100644 --- a/libs/input/InputApplication.cpp +++ b/libs/input/InputApplication.cpp @@ -39,4 +39,21 @@ void InputApplicationHandle::releaseInfo() { } } +InputApplicationInfo InputApplicationInfo::read(const Parcel& from) { + InputApplicationInfo ret; + ret.token = from.readStrongBinder(); + ret.name = from.readString8().c_str(); + ret.dispatchingTimeout = from.readInt64(); + + return ret; +} + +status_t InputApplicationInfo::write(Parcel& output) const { + output.writeStrongBinder(token); + output.writeString8(String8(name.c_str())); + output.writeInt64(dispatchingTimeout); + + return OK; +} + } // namespace android diff --git a/libs/input/InputWindow.cpp b/libs/input/InputWindow.cpp index 96646dc6f8..b1d9d6af15 100644 --- a/libs/input/InputWindow.cpp +++ b/libs/input/InputWindow.cpp @@ -92,6 +92,7 @@ status_t InputWindowInfo::write(Parcel& output) const { output.writeInt32(ownerUid); output.writeInt32(inputFeatures); output.writeInt32(displayId); + applicationInfo.write(output); output.write(touchableRegion); return OK; @@ -129,6 +130,7 @@ InputWindowInfo InputWindowInfo::read(const Parcel& from) { ret.ownerUid = from.readInt32(); ret.inputFeatures = from.readInt32(); ret.displayId = from.readInt32(); + ret.applicationInfo = InputApplicationInfo::read(from); from.read(ret.touchableRegion); return ret; @@ -140,8 +142,7 @@ InputWindowInfo::InputWindowInfo(const Parcel& from) { // --- InputWindowHandle --- -InputWindowHandle::InputWindowHandle(const sp& inputApplicationHandle) : - inputApplicationHandle(inputApplicationHandle) { +InputWindowHandle::InputWindowHandle() { } InputWindowHandle::~InputWindowHandle() { diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index e0082a5a95..49aac72e28 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -489,7 +489,7 @@ bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) { if (motionEntry->action == AMOTION_EVENT_ACTION_DOWN && (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) && mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY - && mInputTargetWaitApplicationHandle != nullptr) { + && mInputTargetWaitApplicationToken != nullptr) { int32_t displayId = motionEntry->displayId; int32_t x = int32_t(motionEntry->pointerCoords[0]. getAxisValue(AMOTION_EVENT_AXIS_X)); @@ -497,8 +497,8 @@ bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) { getAxisValue(AMOTION_EVENT_AXIS_Y)); sp touchedWindowHandle = findTouchedWindowAtLocked(displayId, x, y); if (touchedWindowHandle != nullptr - && touchedWindowHandle->inputApplicationHandle - != mInputTargetWaitApplicationHandle) { + && touchedWindowHandle->getApplicationToken() + != mInputTargetWaitApplicationToken) { // User touched a different application than the one we are waiting on. // Flag the event, and start pruning the input queue. mNextUnblockedEvent = motionEntry; @@ -819,7 +819,8 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry, sp focusedWindowHandle = getValueByKey(mFocusedWindowHandlesByDisplay, getTargetDisplayId(entry)); if (focusedWindowHandle != nullptr) { - commandEntry->inputChannel = getInputChannelLocked(focusedWindowHandle->getToken()); + commandEntry->inputChannel = + getInputChannelLocked(focusedWindowHandle->getToken()); } commandEntry->keyEntry = entry; entry->refCount += 1; @@ -1010,7 +1011,7 @@ int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime, mInputTargetWaitStartTime = currentTime; mInputTargetWaitTimeoutTime = LONG_LONG_MAX; mInputTargetWaitTimeoutExpired = false; - mInputTargetWaitApplicationHandle.clear(); + mInputTargetWaitApplicationToken.clear(); } } else { if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) { @@ -1033,13 +1034,13 @@ int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime, mInputTargetWaitStartTime = currentTime; mInputTargetWaitTimeoutTime = currentTime + timeout; mInputTargetWaitTimeoutExpired = false; - mInputTargetWaitApplicationHandle.clear(); + mInputTargetWaitApplicationToken.clear(); if (windowHandle != nullptr) { - mInputTargetWaitApplicationHandle = windowHandle->inputApplicationHandle; + mInputTargetWaitApplicationToken = windowHandle->getApplicationToken(); } - if (mInputTargetWaitApplicationHandle == nullptr && applicationHandle != nullptr) { - mInputTargetWaitApplicationHandle = applicationHandle; + if (mInputTargetWaitApplicationToken == nullptr && applicationHandle != nullptr) { + mInputTargetWaitApplicationToken = applicationHandle->getApplicationToken(); } } } @@ -1117,7 +1118,7 @@ void InputDispatcher::resetANRTimeoutsLocked() { // Reset input target wait timeout. mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE; - mInputTargetWaitApplicationHandle.clear(); + mInputTargetWaitApplicationToken.clear(); } /** diff --git a/services/inputflinger/InputDispatcher.h b/services/inputflinger/InputDispatcher.h index 38c7b45c59..9ecabdbf08 100644 --- a/services/inputflinger/InputDispatcher.h +++ b/services/inputflinger/InputDispatcher.h @@ -1060,7 +1060,7 @@ private: nsecs_t mInputTargetWaitStartTime; nsecs_t mInputTargetWaitTimeoutTime; bool mInputTargetWaitTimeoutExpired; - sp mInputTargetWaitApplicationHandle; + sp mInputTargetWaitApplicationToken; // Contains the last window which received a hover event. sp mLastHoverWindowHandle; diff --git a/services/inputflinger/InputManager.cpp b/services/inputflinger/InputManager.cpp index cf3ca42d93..15d80703aa 100644 --- a/services/inputflinger/InputManager.cpp +++ b/services/inputflinger/InputManager.cpp @@ -87,20 +87,9 @@ sp InputManager::getDispatcher() { return mDispatcher; } -class BinderApplicationHandle : public InputApplicationHandle { -public: - BinderApplicationHandle() = default; - - bool updateInfo() override { - return true; - } -}; - class BinderWindowHandle : public InputWindowHandle { public: - BinderWindowHandle(const InputWindowInfo& info) : - InputWindowHandle(new BinderApplicationHandle()) { - + BinderWindowHandle(const InputWindowInfo& info) { mInfo = info; } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 26adcdd8a9..3afee73b02 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -63,6 +63,9 @@ private: virtual void notifyInputChannelBroken(const sp&) { } + virtual void notifyFocusChanged(const sp&) { + } + virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) { *outConfig = mConfig; } @@ -366,11 +369,13 @@ public: FakeWindowHandle(const sp& inputApplicationHandle, const sp& dispatcher, const std::string name, int32_t displayId) : - InputWindowHandle(inputApplicationHandle), FakeInputReceiver(dispatcher, name, displayId), mFocused(false) { mServerChannel->setToken(new BBinder()); mDispatcher->registerInputChannel(mServerChannel, displayId); + + inputApplicationHandle->updateInfo(); + mInfo.applicationInfo = *inputApplicationHandle->getInfo(); } virtual bool updateInfo() { -- cgit v1.2.3-59-g8ed1b From 7a0c39a5b46bbb8f2e7b869c642078e892d4804c Mon Sep 17 00:00:00 2001 From: Arthur Hung Date: Wed, 20 Mar 2019 16:52:24 +0800 Subject: Make InputApplicationInfo as a part of InputApplicationHandle (1/2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- include/input/InputApplication.h | 17 +++++------------ libs/input/InputApplication.cpp | 11 +---------- services/inputflinger/InputDispatcher.cpp | 2 -- services/inputflinger/tests/InputDispatcher_test.cpp | 5 +---- 4 files changed, 7 insertions(+), 28 deletions(-) (limited to 'libs/input/InputApplication.cpp') 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 : ""; + return !mInfo.name.empty() ? mInfo.name : ""; } inline nsecs_t getDispatchingTimeout(nsecs_t defaultValue) const { - return mInfo ? mInfo->dispatchingTimeout : defaultValue; + return mInfo.token ? mInfo.dispatchingTimeout : defaultValue; } inline sp 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; } }; -- cgit v1.2.3-59-g8ed1b