OSDN Git Service

Binder interface skeleten of wificond
authorNingyuan Wang <nywang@google.com>
Thu, 2 Jun 2016 22:33:10 +0000 (15:33 -0700)
committerNingyuan Wang <nywang@google.com>
Fri, 3 Jun 2016 00:04:53 +0000 (17:04 -0700)
This CL adds a dummy binder interface of wificond.
There is only one function called Ping() which is
supposed to return a std string "Pong".

BUG=28867093
TEST=compile
TEST=Mannually modify wificond sepolicy file to allow
  binder operations.
     Use an executable to test this interface by calling
  Ping() through binder and verifying the response is
  "Pong".

Change-Id: I8b5b1b65811f018612ad095f692d8acf2289c3c9

Android.mk
aidl/android/wificond/IServer.aidl [new file with mode: 0644]
main.cpp
server.cpp [new file with mode: 0644]
server.h [new file with mode: 0644]

index 99e5668..6b5f7da 100644 (file)
@@ -24,9 +24,13 @@ include $(CLEAR_VARS)
 LOCAL_MODULE := wificond
 LOCAL_CPPFLAGS := $(wificond_cpp_flags)
 LOCAL_INIT_RC := wificond.rc
+LOCAL_AIDL_INCLUDES += $(LOCAL_PATH)/aidl
 LOCAL_SRC_FILES := \
-    main.cpp
+    main.cpp \
+    aidl/android/wificond/IServer.aidl \
+    server.cpp
 LOCAL_SHARED_LIBRARIES := \
+    libbinder \
     libbase \
     libutils
 LOCAL_STATIC_LIBRARIES := \
diff --git a/aidl/android/wificond/IServer.aidl b/aidl/android/wificond/IServer.aidl
new file mode 100644 (file)
index 0000000..112f7b4
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+package android.wificond;
+
+interface IServer {
+  // Retrieve a quick response message from the server.
+  @utf8InCpp String Ping();
+}
index 1f0e3f1..7c90299 100644 (file)
--- a/main.cpp
+++ b/main.cpp
 
 #include <android-base/logging.h>
 #include <android-base/macros.h>
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+#include <binder/ProcessState.h>
+#include <utils/String16.h>
 
 #include <looper_backed_event_loop.h>
+#include <server.h>
 
 namespace {
 
@@ -59,12 +64,34 @@ android::wificond::LooperBackedEventLoop*
 
 }  // namespace
 
+void OnBinderReadReady(int fd) {
+  android::IPCThreadState::self()->handlePolledCommands();
+}
+
 int main(int argc, char** argv) {
   android::base::InitLogging(argv);
   LOG(INFO) << "wificond is starting up...";
   std::unique_ptr<android::wificond::LooperBackedEventLoop> event_dispatcher_(
       new android::wificond::LooperBackedEventLoop());
   ScopedSignalHandler scoped_signal_handler(event_dispatcher_.get());
+
+  int binder_fd = -1;
+  android::ProcessState::self()->setThreadPoolMaxThreadCount(0);
+  android::IPCThreadState::self()->disableBackgroundScheduling(true);
+  int err = android::IPCThreadState::self()->setupPolling(&binder_fd);
+  CHECK_EQ(err, 0) << "Error setting up binder polling: " << err;
+  CHECK_GE(binder_fd, 0) << "Invalid binder FD: " << binder_fd;
+  if (!event_dispatcher_->WatchFileDescriptor(
+      binder_fd,
+      android::wificond::EventLoop::kModeInput,
+      &OnBinderReadReady)) {
+    LOG(FATAL) << "Failed to watch binder FD";
+  }
+  android::sp<android::IServiceManager> sm = android::defaultServiceManager();
+  CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager";
+  android::sp<android::wificond::Server> server = new android::wificond::Server();
+  sm->addService(android::String16("wificond"), server);
+
   event_dispatcher_->Poll();
   LOG(INFO) << "Leaving the loop...";
   return 0;
diff --git a/server.cpp b/server.cpp
new file mode 100644 (file)
index 0000000..a530e6d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "server.h"
+
+#include "android/wificond/BnServer.h"
+
+namespace android {
+namespace wificond {
+
+android::binder::Status Server::Ping(::std::string* _aidl_return) {
+  *_aidl_return = std::string("Pong");
+  return binder::Status::ok();
+}
+
+}  // namespace android
+}  // namespace wificond
+
diff --git a/server.h b/server.h
new file mode 100644 (file)
index 0000000..af2ccc5
--- /dev/null
+++ b/server.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include "android/wificond/BnServer.h"
+
+namespace android {
+namespace wificond {
+
+class Server : public BnServer {
+ public:
+  android::binder::Status Ping(::std::string* _aidl_return) override;
+};
+
+}  // namespace android
+}  // namespace wificond
+