Loading system/service/Android.mk +4 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,9 @@ btserviceCommonSrc := \ uuid.cpp btserviceBinderSrc := \ ipc/binder/IBluetooth.cpp ipc/binder/IBluetooth.cpp \ ipc/binder/bluetooth_binder_server.cpp \ ipc/binder/ipc_handler_binder.cpp btserviceCommonIncludes := $(LOCAL_PATH)/../ Loading Loading @@ -67,6 +69,7 @@ LOCAL_SRC_FILES := \ test/fake_hal_util.cpp \ test/ipc_unix_unittest.cpp \ test/settings_unittest.cpp \ test/stub_ipc_handler_binder.cpp \ test/uuid_unittest.cpp LOCAL_C_INCLUDES += $(btserviceCommonIncludes) LOCAL_CFLAGS += -std=c++11 Loading system/service/daemon.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -66,13 +66,17 @@ class DaemonImpl : public Daemon { ipc_manager_.reset(new ipc::IPCManager(core_stack_.get())); // If an IPC socket path was given, initialize IPC with it. if ((!settings_->create_ipc_socket_path().empty() || !settings_->android_ipc_socket_suffix().empty()) && !ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) { // If an IPC socket path was given, initialize IPC with it. Otherwise // initialize Binder IPC. if (settings_->UseSocketIPC()) { if (!ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) { LOG(ERROR) << "Failed to set up UNIX domain-socket IPCManager"; return false; } } else if (!ipc_manager_->Start(ipc::IPCManager::TYPE_BINDER, nullptr)) { LOG(ERROR) << "Failed to set up Binder IPCManager"; return false; } return true; } Loading system/service/ipc/binder/bluetooth_binder_server.cpp 0 → 100644 +58 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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 "service/ipc/binder/bluetooth_binder_server.h" #include <base/logging.h> namespace ipc { BluetoothBinderServer::BluetoothBinderServer(bluetooth::CoreStack* core_stack) : core_stack_(core_stack) { CHECK(core_stack_); } BluetoothBinderServer::~BluetoothBinderServer() { } // binder::BnBluetooth overrides: bool BluetoothBinderServer::IsEnabled() { // TODO(armansito): Implement. VLOG(2) << __func__; return false; } int BluetoothBinderServer::GetState() { // TODO(armansito): Implement. return -1; } bool BluetoothBinderServer::Enable() { // TODO(armansito): Implement. return false; } bool BluetoothBinderServer::EnableNoAutoConnect() { // TODO(armansito): Implement. return false; } bool BluetoothBinderServer::Disable() { // TODO(armansito): Implement. return false; } } // namespace ipc system/service/ipc/binder/bluetooth_binder_server.h 0 → 100644 +49 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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. // #pragma once #include <base/macros.h> #include "service/ipc/binder/IBluetooth.h" namespace bluetooth { class CoreStack; } // namespace bluetooth namespace ipc { // Implements the server side of the IBluetooth Binder interface. class BluetoothBinderServer : public binder::BnBluetooth { public: explicit BluetoothBinderServer(bluetooth::CoreStack* core_stack); ~BluetoothBinderServer() override; // binder::BnBluetooth overrides: bool IsEnabled() override; int GetState() override; bool Enable() override; bool EnableNoAutoConnect() override; bool Disable() override; private: // Weak handle on the CoreStack. bluetooth::CoreStack* core_stack_; DISALLOW_COPY_AND_ASSIGN(BluetoothBinderServer); }; } // namespace ipc system/service/ipc/binder/ipc_handler_binder.cpp 0 → 100644 +82 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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 "service/ipc/binder/ipc_handler_binder.h" #include <base/bind.h> #include <base/logging.h> #include <base/message_loop/message_loop.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <binder/ProcessState.h> #include "service/ipc/binder/bluetooth_binder_server.h" using android::defaultServiceManager; using android::sp; using android::status_t; using android::String16; namespace ipc { IPCHandlerBinder::IPCHandlerBinder( bluetooth::CoreStack* core_stack, IPCManager::Delegate* delegate) : IPCHandler(core_stack, delegate) { } IPCHandlerBinder::~IPCHandlerBinder() { } bool IPCHandlerBinder::Run() { CHECK(core_stack()); // Register the IBluetooth service with the Android ServiceManager. android::sp<BluetoothBinderServer> bt_server = new BluetoothBinderServer(core_stack()); status_t status = defaultServiceManager()->addService( String16(binder::IBluetooth::kBluetoothServiceName), bt_server); if (status != android::NO_ERROR) { LOG(ERROR) << "Failed to register Bluetooth service with ServiceManager"; return false; } // Notify the delegate. We do this in the message loop to avoid reentrancy. if (delegate()) { base::MessageLoop::current()->task_runner()->PostTask( FROM_HERE, base::Bind(&IPCHandlerBinder::NotifyStarted, this)); } android::ProcessState::self()->startThreadPool(); return true; } void IPCHandlerBinder::Stop() { // TODO(armansito): There are several methods in android::IPCThreadState that // are related to shutting down the threadpool, however I haven't been able to // make them shut things down cleanly. Figure out the right way to stop the // Binder IPC here. } void IPCHandlerBinder::NotifyStarted() { if (delegate()) delegate()->OnIPCHandlerStarted(IPCManager::TYPE_BINDER); } } // namespace ipc Loading
system/service/Android.mk +4 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,9 @@ btserviceCommonSrc := \ uuid.cpp btserviceBinderSrc := \ ipc/binder/IBluetooth.cpp ipc/binder/IBluetooth.cpp \ ipc/binder/bluetooth_binder_server.cpp \ ipc/binder/ipc_handler_binder.cpp btserviceCommonIncludes := $(LOCAL_PATH)/../ Loading Loading @@ -67,6 +69,7 @@ LOCAL_SRC_FILES := \ test/fake_hal_util.cpp \ test/ipc_unix_unittest.cpp \ test/settings_unittest.cpp \ test/stub_ipc_handler_binder.cpp \ test/uuid_unittest.cpp LOCAL_C_INCLUDES += $(btserviceCommonIncludes) LOCAL_CFLAGS += -std=c++11 Loading
system/service/daemon.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -66,13 +66,17 @@ class DaemonImpl : public Daemon { ipc_manager_.reset(new ipc::IPCManager(core_stack_.get())); // If an IPC socket path was given, initialize IPC with it. if ((!settings_->create_ipc_socket_path().empty() || !settings_->android_ipc_socket_suffix().empty()) && !ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) { // If an IPC socket path was given, initialize IPC with it. Otherwise // initialize Binder IPC. if (settings_->UseSocketIPC()) { if (!ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) { LOG(ERROR) << "Failed to set up UNIX domain-socket IPCManager"; return false; } } else if (!ipc_manager_->Start(ipc::IPCManager::TYPE_BINDER, nullptr)) { LOG(ERROR) << "Failed to set up Binder IPCManager"; return false; } return true; } Loading
system/service/ipc/binder/bluetooth_binder_server.cpp 0 → 100644 +58 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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 "service/ipc/binder/bluetooth_binder_server.h" #include <base/logging.h> namespace ipc { BluetoothBinderServer::BluetoothBinderServer(bluetooth::CoreStack* core_stack) : core_stack_(core_stack) { CHECK(core_stack_); } BluetoothBinderServer::~BluetoothBinderServer() { } // binder::BnBluetooth overrides: bool BluetoothBinderServer::IsEnabled() { // TODO(armansito): Implement. VLOG(2) << __func__; return false; } int BluetoothBinderServer::GetState() { // TODO(armansito): Implement. return -1; } bool BluetoothBinderServer::Enable() { // TODO(armansito): Implement. return false; } bool BluetoothBinderServer::EnableNoAutoConnect() { // TODO(armansito): Implement. return false; } bool BluetoothBinderServer::Disable() { // TODO(armansito): Implement. return false; } } // namespace ipc
system/service/ipc/binder/bluetooth_binder_server.h 0 → 100644 +49 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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. // #pragma once #include <base/macros.h> #include "service/ipc/binder/IBluetooth.h" namespace bluetooth { class CoreStack; } // namespace bluetooth namespace ipc { // Implements the server side of the IBluetooth Binder interface. class BluetoothBinderServer : public binder::BnBluetooth { public: explicit BluetoothBinderServer(bluetooth::CoreStack* core_stack); ~BluetoothBinderServer() override; // binder::BnBluetooth overrides: bool IsEnabled() override; int GetState() override; bool Enable() override; bool EnableNoAutoConnect() override; bool Disable() override; private: // Weak handle on the CoreStack. bluetooth::CoreStack* core_stack_; DISALLOW_COPY_AND_ASSIGN(BluetoothBinderServer); }; } // namespace ipc
system/service/ipc/binder/ipc_handler_binder.cpp 0 → 100644 +82 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 Google, Inc. // // 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 "service/ipc/binder/ipc_handler_binder.h" #include <base/bind.h> #include <base/logging.h> #include <base/message_loop/message_loop.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <binder/ProcessState.h> #include "service/ipc/binder/bluetooth_binder_server.h" using android::defaultServiceManager; using android::sp; using android::status_t; using android::String16; namespace ipc { IPCHandlerBinder::IPCHandlerBinder( bluetooth::CoreStack* core_stack, IPCManager::Delegate* delegate) : IPCHandler(core_stack, delegate) { } IPCHandlerBinder::~IPCHandlerBinder() { } bool IPCHandlerBinder::Run() { CHECK(core_stack()); // Register the IBluetooth service with the Android ServiceManager. android::sp<BluetoothBinderServer> bt_server = new BluetoothBinderServer(core_stack()); status_t status = defaultServiceManager()->addService( String16(binder::IBluetooth::kBluetoothServiceName), bt_server); if (status != android::NO_ERROR) { LOG(ERROR) << "Failed to register Bluetooth service with ServiceManager"; return false; } // Notify the delegate. We do this in the message loop to avoid reentrancy. if (delegate()) { base::MessageLoop::current()->task_runner()->PostTask( FROM_HERE, base::Bind(&IPCHandlerBinder::NotifyStarted, this)); } android::ProcessState::self()->startThreadPool(); return true; } void IPCHandlerBinder::Stop() { // TODO(armansito): There are several methods in android::IPCThreadState that // are related to shutting down the threadpool, however I haven't been able to // make them shut things down cleanly. Figure out the right way to stop the // Binder IPC here. } void IPCHandlerBinder::NotifyStarted() { if (delegate()) delegate()->OnIPCHandlerStarted(IPCManager::TYPE_BINDER); } } // namespace ipc