From fa9619e3efeb8afab8be0a71f77cda26261622cb Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Thu, 2 Jun 2016 15:33:10 -0700 Subject: [PATCH] Binder interface skeleten of wificond 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 | 6 +++++- aidl/android/wificond/IServer.aidl | 22 ++++++++++++++++++++++ main.cpp | 27 +++++++++++++++++++++++++++ server.cpp | 31 +++++++++++++++++++++++++++++++ server.h | 29 +++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 aidl/android/wificond/IServer.aidl create mode 100644 server.cpp create mode 100644 server.h diff --git a/Android.mk b/Android.mk index 99e5668..6b5f7da 100644 --- a/Android.mk +++ b/Android.mk @@ -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 index 0000000..112f7b4 --- /dev/null +++ b/aidl/android/wificond/IServer.aidl @@ -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(); +} diff --git a/main.cpp b/main.cpp index 1f0e3f1..7c90299 100644 --- a/main.cpp +++ b/main.cpp @@ -21,8 +21,13 @@ #include #include +#include +#include +#include +#include #include +#include 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 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 sm = android::defaultServiceManager(); + CHECK_EQ(sm != NULL, true) << "Could not obtain IServiceManager"; + android::sp 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 index 0000000..a530e6d --- /dev/null +++ b/server.cpp @@ -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 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 + -- 2.11.0