From 6e9f864088187ecc59282a80c84a21b5d33a26f3 Mon Sep 17 00:00:00 2001 From: Garfield Tan Date: Mon, 14 Sep 2020 21:05:27 -0700 Subject: Let InputFlinger create the server InputChannel We can be sure that server channel won't leave InputFlinger. Bug: 167947395 Test: Touch events are still dispatched. Test: m -j inputflinger Test: atest inputflinger_tests Test: atest inputflinger_benchmarks Test: atest libgui_tests Change-Id: I35f768c8a7b3bfe11e04577c028e52556b60ff14 --- services/inputflinger/InputManager.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'services/inputflinger/InputManager.cpp') diff --git a/services/inputflinger/InputManager.cpp b/services/inputflinger/InputManager.cpp index 8af9bcba89..3d995899d0 100644 --- a/services/inputflinger/InputManager.cpp +++ b/services/inputflinger/InputManager.cpp @@ -31,6 +31,25 @@ namespace android { +static int32_t exceptionCodeFromStatusT(status_t status) { + switch (status) { + case OK: + return binder::Status::EX_NONE; + case INVALID_OPERATION: + return binder::Status::EX_UNSUPPORTED_OPERATION; + case BAD_VALUE: + case BAD_TYPE: + case NAME_NOT_FOUND: + return binder::Status::EX_ILLEGAL_ARGUMENT; + case NO_INIT: + return binder::Status::EX_ILLEGAL_STATE; + case PERMISSION_DENIED: + return binder::Status::EX_SECURITY; + default: + return binder::Status::EX_TRANSACTION_FAILED; + } +} + InputManager::InputManager( const sp& readerPolicy, const sp& dispatcherPolicy) { @@ -119,7 +138,7 @@ binder::Status InputManager::setInputWindows( } // Used by tests only. -binder::Status InputManager::registerInputChannel(const InputChannel& channel) { +binder::Status InputManager::createInputChannel(const std::string& name, InputChannel* outChannel) { IPCThreadState* ipc = IPCThreadState::self(); const int uid = ipc->getCallingUid(); if (uid != AID_SHELL && uid != AID_ROOT) { @@ -128,12 +147,17 @@ binder::Status InputManager::registerInputChannel(const InputChannel& channel) { return binder::Status::ok(); } - mDispatcher->registerInputChannel(channel.dup()); + base::Result> channel = mDispatcher->createInputChannel(name); + if (!channel) { + return binder::Status::fromExceptionCode(exceptionCodeFromStatusT(channel.error().code()), + channel.error().message().c_str()); + } + (*channel)->copyTo(*outChannel); return binder::Status::ok(); } -binder::Status InputManager::unregisterInputChannel(const sp& connectionToken) { - mDispatcher->unregisterInputChannel(connectionToken); +binder::Status InputManager::removeInputChannel(const sp& connectionToken) { + mDispatcher->removeInputChannel(connectionToken); return binder::Status::ok(); } -- cgit v1.2.3-59-g8ed1b