init: separate out epoll into a class
Test: init_tests
Bug: 64114943
Change-Id: I5f03314773b02b9e30e8e21895b6bdcfd4909e88
diff --git a/init/keychords.cpp b/init/keychords.cpp
index 293736d..418cdeb 100644
--- a/init/keychords.cpp
+++ b/init/keychords.cpp
@@ -36,6 +36,7 @@
#include <android-base/properties.h>
#include "init.h"
+#include "service.h"
namespace android {
namespace init {
@@ -43,6 +44,7 @@
namespace {
int keychords_count;
+Epoll* epoll;
struct KeychordEntry {
const std::vector<int> keycodes;
@@ -214,7 +216,7 @@
keychord_current |= mask & available & set;
KeychordLambdaCheck();
}
- register_epoll_handler(fd, [fd]() { KeychordLambdaHandler(fd); });
+ epoll->RegisterHandler(fd, [fd]() { KeychordLambdaHandler(fd); });
return true;
}
@@ -236,7 +238,7 @@
auto it = keychord_registration.find(device);
if (it == keychord_registration.end()) return;
auto fd = (*it).second;
- unregister_epoll_handler(fd);
+ epoll->UnregisterHandler(fd);
keychord_registration.erase(it);
::close(fd);
}
@@ -294,7 +296,7 @@
}
}
- if (inotify_fd >= 0) register_epoll_handler(inotify_fd, InotifyHandler);
+ if (inotify_fd >= 0) epoll->RegisterHandler(inotify_fd, InotifyHandler);
}
void AddServiceKeycodes(Service* svc) {
@@ -309,7 +311,8 @@
} // namespace
-void KeychordInit() {
+void KeychordInit(Epoll* init_epoll) {
+ epoll = init_epoll;
for (const auto& service : ServiceList::GetInstance()) {
AddServiceKeycodes(service.get());
}