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
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 := \
--- /dev/null
+/*
+ * 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();
+}
#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 {
} // 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;
--- /dev/null
+/*
+ * 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
+
--- /dev/null
+/*
+ * 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
+