Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a3242475 authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Add IPCHandlerBinder

This CL integrates Binder IPC into the daemon. This introduces
IPCHandlerBinder and BluetoothBinderServer which is the Binder server
proxy for IBluetooth. A new command-line switch is introduced to
optionally disable Binder on platforms that do not use it.

BluetoothBinderServer currently does not fully implement any of the IPC
calls and consists of stubs.

Bug: 22743677
Change-Id: I3e4ba7a3211898bab0c9c8061f4e4db3854711ed
parent 5f8999d0
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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)/../

@@ -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
+9 −5
Original line number Diff line number Diff line
@@ -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;
  }
+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
+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
+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