OSDN Git Service

WifiCond: Setup polling on HW binder FD
authorSohani Rao <sohanirao@google.com>
Wed, 21 Jun 2017 02:49:54 +0000 (19:49 -0700)
committerSohani Rao <sohanirao@google.com>
Thu, 29 Jun 2017 17:23:39 +0000 (10:23 -0700)
To keep wificond running in single threaded mode, set it up to poll on
file descriptor of HW Binder that will receive Offload HAL callback
events

Bug: 62807929
Test: Unit tests, sanity tests, ensure Wificond has only one thread
Change-Id: Id1e977d1a62fecd9b9432d7726aee2cb5f168574

main.cpp

index 6e3f1d7..d2a9ba4 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -26,6 +26,8 @@
 #include <binder/IServiceManager.h>
 #include <binder/ProcessState.h>
 #include <cutils/properties.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/ProcessState.h>
 #include <libminijail.h>
 #include <utils/String16.h>
 #include <wifi_system/interface_tool.h>
@@ -89,6 +91,16 @@ int SetupBinderOrCrash() {
   return binder_fd;
 }
 
+// Setup our interface to the hw Binder driver or die trying.
+int SetupHwBinderOrCrash() {
+  int binder_fd = -1;
+  android::hardware::ProcessState::self()->setThreadPoolConfiguration(1, true);
+  int err = android::hardware::IPCThreadState::self()->setupPolling(&binder_fd);
+  CHECK_EQ(err, 0) << "Error setting up hw binder polling: " << strerror(-err);
+  CHECK_GE(binder_fd, 0) << "Invalid hw binder FD: " << binder_fd;
+  return binder_fd;
+}
+
 void RegisterServiceOrCrash(const android::sp<android::IBinder>& service) {
   android::sp<android::IServiceManager> sm = android::defaultServiceManager();
   CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager";
@@ -103,6 +115,10 @@ void OnBinderReadReady(int fd) {
   android::IPCThreadState::self()->handlePolledCommands();
 }
 
+void OnHwBinderReadReady(int fd) {
+  android::hardware::IPCThreadState::self()->handlePolledCommands();
+}
+
 int main(int argc, char** argv) {
   android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
   LOG(INFO) << "wificond is starting up...";
@@ -117,6 +133,11 @@ int main(int argc, char** argv) {
       android::wificond::EventLoop::kModeInput,
       &OnBinderReadReady)) << "Failed to watch binder FD";
 
+  int hw_binder_fd = SetupHwBinderOrCrash();
+  CHECK(event_dispatcher->WatchFileDescriptor(
+      hw_binder_fd, android::wificond::EventLoop::kModeInput,
+      &OnHwBinderReadReady)) << "Failed to watch Hw Binder FD";
+
   android::wificond::NetlinkManager netlink_manager(event_dispatcher.get());
   CHECK(netlink_manager.Start()) << "Failed to start netlink manager";
   android::wificond::NetlinkUtils netlink_utils(&netlink_manager);