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

Commit 9975e53b authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge "Remove native binder implementation details in libbluetooth_jni"

parents 5c345f99 66de1bd3
Loading
Loading
Loading
Loading
+0 −6
Original line number Original line Diff line number Diff line
@@ -2,7 +2,6 @@ cc_library_shared {
    name: "libbluetooth_jni",
    name: "libbluetooth_jni",
    compile_multilib: "first",
    compile_multilib: "first",
    srcs: [
    srcs: [
        "bluetooth_socket_manager.cc",
        "com_android_bluetooth_btservice_AdapterService.cpp",
        "com_android_bluetooth_btservice_AdapterService.cpp",
        "com_android_bluetooth_hfp.cpp",
        "com_android_bluetooth_hfp.cpp",
        "com_android_bluetooth_hfpclient.cpp",
        "com_android_bluetooth_hfpclient.cpp",
@@ -16,18 +15,13 @@ cc_library_shared {
        "com_android_bluetooth_pan.cpp",
        "com_android_bluetooth_pan.cpp",
        "com_android_bluetooth_gatt.cpp",
        "com_android_bluetooth_gatt.cpp",
        "com_android_bluetooth_sdp.cpp",
        "com_android_bluetooth_sdp.cpp",
        "IUserManager.cc",
        "permission_helpers.cc",
    ],
    ],
    header_libs: ["libbluetooth_headers"],
    header_libs: ["libbluetooth_headers"],
    include_dirs: [
    include_dirs: [
        "system/bt/types",
        "system/bt/types",
    ],
    ],
    shared_libs: [
    shared_libs: [
        "libandroid_runtime",
        "libbase",
        "libbase",
        "libbinder",
        "libbluetooth-binder",
        "libchrome",
        "libchrome",
        "libnativehelper",
        "libnativehelper",
        "liblog",
        "liblog",

android/app/jni/IUserManager.cc

deleted100644 → 0
+0 −73
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

#define LOG_TAG "IUserManager"
#include <binder/Parcel.h>
#include <stdint.h>
#include <sys/types.h>
#include <utils/Log.h>

#include "IUserManager.h"

namespace android {

class BpUserManager : public BpInterface<IUserManager> {
 public:
  explicit BpUserManager(const sp<IBinder>& impl)
      : BpInterface<IUserManager>(impl) {}
  virtual int32_t getCredentialOwnerProfile(int32_t user_id) {
    Parcel data, reply;
    data.writeInterfaceToken(IUserManager::getInterfaceDescriptor());
    data.writeInt32(user_id);
    status_t rc =
        remote()->transact(GET_CREDENTIAL_OWNER_PROFILE, data, &reply, 0);
    if (rc != NO_ERROR) {
      ALOGE("%s: failed (%d)\n", __func__, rc);
      return -1;
    }

    int32_t exception = reply.readExceptionCode();
    if (exception != 0) {
      ALOGE("%s: got exception (%d)\n", __func__, exception);
      return -1;
    }

    return reply.readInt32();
  }

  virtual int32_t getProfileParentId(int32_t user_handle) {
    Parcel data, reply;
    data.writeInterfaceToken(IUserManager::getInterfaceDescriptor());
    data.writeInt32(user_handle);
    status_t rc = remote()->transact(GET_PROFILE_PARENT_ID, data, &reply, 0);
    if (rc != NO_ERROR) {
      ALOGE("%s: failed (%d)\n", __func__, rc);
      return -1;
    }

    int32_t exception = reply.readExceptionCode();
    if (exception != 0) {
      ALOGE("%s: got exception (%d)\n", __func__, exception);
      return -1;
    }

    return reply.readInt32();
  }
};

IMPLEMENT_META_INTERFACE(UserManager, "android.os.IUserManager");

};  // namespace android

android/app/jni/IUserManager.h

deleted100644 → 0
+0 −47
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

#ifndef IUSERMANAGER_H_
#define IUSERMANAGER_H_

#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <inttypes.h>
#include <utils/Errors.h>
#include <utils/Vector.h>

namespace android {

/*
 * Communication channel to UserManager
 */
class IUserManager : public IInterface {
 public:
  // must be kept in sync with IUserManager.aidl
  enum {
    GET_CREDENTIAL_OWNER_PROFILE = IBinder::FIRST_CALL_TRANSACTION + 0,
    GET_PROFILE_PARENT_ID,
  };

  virtual int32_t getCredentialOwnerProfile(int32_t user_id) = 0;
  virtual int32_t getProfileParentId(int32_t user_handle) = 0;

  DECLARE_META_INTERFACE(UserManager);
};

};  // namespace android

#endif  // IUSERMANAGER_H_
+0 −121
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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 "bluetooth_socket_manager.h"
#include "permission_helpers.h"

#include <base/logging.h>
#include <binder/IPCThreadState.h>

using ::android::String8;
using ::android::binder::Status;
using ::android::os::ParcelFileDescriptor;
using ::android::os::ParcelUuid;

namespace android {
namespace bluetooth {

Status BluetoothSocketManagerBinderServer::connectSocket(
    const BluetoothDevice& device, int32_t type,
    const std::unique_ptr<ParcelUuid>& uuid, int32_t port, int32_t flag,
    std::unique_ptr<ParcelFileDescriptor>* _aidl_return) {
  if (!isCallerActiveUserOrManagedProfile()) {
    LOG(WARNING) << "connectSocket() - Not allowed for non-active users";
    return Status::fromExceptionCode(
        Status::EX_SECURITY, String8("Not allowed for non-active users"));
  }

  ENFORCE_PERMISSION(PERMISSION_BLUETOOTH);

  IPCThreadState* ipc = IPCThreadState::self();

  int socket_fd = -1;
  bt_status_t status = socketInterface->connect(
      &device.address, (btsock_type_t)type, uuid ? &uuid->uuid : nullptr, port,
      &socket_fd, flag, ipc->getCallingUid());
  if (status != BT_STATUS_SUCCESS) {
    LOG(ERROR) << "Socket connection failed: " << +status;
    socket_fd = -1;
  }

  if (socket_fd < 0) {
    LOG(ERROR) << "Fail to create file descriptor on socket fd";
    return Status::ok();
  }

  _aidl_return->reset(
      new ParcelFileDescriptor(android::base::unique_fd(socket_fd)));
  return Status::ok();
}

Status BluetoothSocketManagerBinderServer::createSocketChannel(
    int32_t type, const std::unique_ptr<::android::String16>& serviceName,
    const std::unique_ptr<ParcelUuid>& uuid, int32_t port, int32_t flag,
    std::unique_ptr<ParcelFileDescriptor>* _aidl_return) {
  if (!isCallerActiveUserOrManagedProfile()) {
    LOG(WARNING) << "createSocketChannel() - Not allowed for non-active users";
    return Status::fromExceptionCode(
        Status::EX_SECURITY, String8("Not allowed for non-active users"));
  }

  ENFORCE_PERMISSION(PERMISSION_BLUETOOTH);

  VLOG(1) << __func__ << ": SOCK FLAG=" << flag;

  IPCThreadState* ipc = IPCThreadState::self();
  int socket_fd = -1;

  const std::string payload_url{};

  bt_status_t status = socketInterface->listen(
      (btsock_type_t)type,
      serviceName ? String8{*serviceName}.c_str() : nullptr,
      uuid ? &uuid->uuid : nullptr, port, &socket_fd, flag,
      ipc->getCallingUid());

  if (status != BT_STATUS_SUCCESS) {
    LOG(ERROR) << "Socket listen failed: " << +status;
    socket_fd = -1;
  }

  if (socket_fd < 0) {
    LOG(ERROR) << "Failed to create file descriptor on socket fd";
    return Status::ok();
  }

  _aidl_return->reset(
      new ParcelFileDescriptor(android::base::unique_fd(socket_fd)));
  return Status::ok();
}

Status BluetoothSocketManagerBinderServer::requestMaximumTxDataLength(
    const BluetoothDevice& device) {
  if (!isCallerActiveUserOrManagedProfile()) {
    LOG(WARNING) << __func__ << ": Not allowed for non-active users";
    return Status::fromExceptionCode(
        Status::EX_SECURITY, String8("Not allowed for non-active users"));
  }

  ENFORCE_PERMISSION(PERMISSION_BLUETOOTH);

  VLOG(1) << __func__;

  socketInterface->request_max_tx_data_length(device.address);
  return Status::ok();
}

}  // namespace bluetooth
}  // namespace android
+0 −57
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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/bluetooth/BnBluetoothSocketManager.h>
#include <android/bluetooth/IBluetoothSocketManager.h>
#include <base/macros.h>
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>

namespace android {
namespace bluetooth {

using ::android::binder::Status;

class BluetoothSocketManagerBinderServer : public BnBluetoothSocketManager {
 public:
  explicit BluetoothSocketManagerBinderServer(
      const btsock_interface_t* socketInterface)
      : socketInterface(socketInterface) {}
  ~BluetoothSocketManagerBinderServer() override = default;

  Status connectSocket(
      const BluetoothDevice& device, int32_t type,
      const std::unique_ptr<::android::os::ParcelUuid>& uuid, int32_t port,
      int32_t flag,
      std::unique_ptr<::android::os::ParcelFileDescriptor>* _aidl_return);

  Status createSocketChannel(
      int32_t type, const std::unique_ptr<::android::String16>& serviceName,
      const std::unique_ptr<::android::os::ParcelUuid>& uuid, int32_t port,
      int32_t flag,
      std::unique_ptr<::android::os::ParcelFileDescriptor>* _aidl_return)
      override;

  Status requestMaximumTxDataLength(const BluetoothDevice& device);

 private:
  const btsock_interface_t* socketInterface;
  DISALLOW_COPY_AND_ASSIGN(BluetoothSocketManagerBinderServer);
};
}  // namespace bluetooth
}  // namespace android
 No newline at end of file
Loading