Use std::shared_ptr for InputChannel
Modernize the code by moving away from RefBase.
We can further improve this by switching to unique_ptr in some places.
Current refactor is to get off of RefBase only.
Test: interact with cf after device boots
Bug: 142581626
Change-Id: Ib90fc721970113310b87411bcc2ba62e30ddfd01
diff --git a/services/inputflinger/InputManager.cpp b/services/inputflinger/InputManager.cpp
index c5f60ad..088c6f1 100644
--- a/services/inputflinger/InputManager.cpp
+++ b/services/inputflinger/InputManager.cpp
@@ -119,7 +119,7 @@
}
// Used by tests only.
-binder::Status InputManager::registerInputChannel(const InputChannelInfo& info) {
+binder::Status InputManager::registerInputChannel(const InputChannel& channel) {
IPCThreadState* ipc = IPCThreadState::self();
const int uid = ipc->getCallingUid();
if (uid != AID_SHELL && uid != AID_ROOT) {
@@ -127,15 +127,12 @@
"from non shell/root entity (PID: %d)", ipc->getCallingPid());
return binder::Status::ok();
}
- android::base::unique_fd newFd(::dup(info.mFd));
- sp<InputChannel> channel = InputChannel::create(info.mName, std::move(newFd), info.mToken);
- mDispatcher->registerInputChannel(channel);
+
+ mDispatcher->registerInputChannel(channel.dup());
return binder::Status::ok();
}
-binder::Status InputManager::unregisterInputChannel(const InputChannelInfo& info) {
- android::base::unique_fd newFd(::dup(info.mFd));
- sp<InputChannel> channel = InputChannel::create(info.mName, std::move(newFd), info.mToken);
+binder::Status InputManager::unregisterInputChannel(const InputChannel& channel) {
mDispatcher->unregisterInputChannel(channel);
return binder::Status::ok();
}