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

Commit 26810278 authored by Rahul Arya's avatar Rahul Arya Committed by Gerrit Code Review
Browse files

Merge changes Iec10e55b,Ie235a33b,I68154999

* changes:
  [Private GATT] Add support for GATT write requests
  [Private GATT] Add support for reading attributes over JNI
  [Private GATT] Add GATT transactions needed for service discovery
parents 684f5fa9 8cab37dc
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "gd/common/init_flags.h"
#include "hardware/bt_gatt.h"
#include "rust/cxx.h"
#include "rust/src/gatt/ffi/gatt_shim.h"
#include "src/core/ffi.rs.h"
#include "src/gatt/ffi.rs.h"
#include "utils/Log.h"
@@ -1393,7 +1394,9 @@ static void initializeNative(JNIEnv* env, jobject object) {

  mCallbacksObj = env->NewGlobalRef(object);

  bluetooth::rust_shim::init();
  auto callbacks = std::make_unique<bluetooth::gatt::GattServerCallbacks>(
      sGattServerCallbacks);
  bluetooth::rust_shim::init(std::move(callbacks));
}

static void cleanupNative(JNIEnv* env, jobject object) {
@@ -2192,7 +2195,9 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject object,
  }

  if (bluetooth::gatt::is_connection_isolated(conn_id)) {
    // no-op
    auto data = ::rust::Slice<const uint8_t>(response.attr_value.value,
                                             response.attr_value.len);
    bluetooth::gatt::send_response(server_if, conn_id, trans_id, status, data);
  } else {
    sGattIf->server->send_response(conn_id, trans_id, status, response);
  }
+3 −0
Original line number Diff line number Diff line
@@ -94,6 +94,9 @@ cc_library_static {
    defaults: [
        "libchrome_support_defaults",
    ],
    srcs: [
        "src/gatt/ffi/gatt_shim.cc",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/include",
+9 −1
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ use crate::core::init;
use cxx::{type_id, ExternType};
pub use inner::*;

unsafe impl Send for GattServerCallbacks {}

unsafe impl ExternType for Uuid {
    type Id = type_id!("bluetooth::Uuid");
    type Kind = cxx::kind::Trivial;
@@ -31,8 +33,14 @@ mod inner {
        type Uuid = crate::core::uuid::Uuid;
    }

    #[namespace = "bluetooth::gatt"]
    unsafe extern "C++" {
        include!("src/gatt/ffi/gatt_shim.h");
        type GattServerCallbacks = crate::gatt::GattServerCallbacks;
    }

    #[namespace = "bluetooth::rust_shim"]
    extern "Rust" {
        fn init();
        fn init(gatt_server_callbacks: UniquePtr<GattServerCallbacks>);
    }
}
+12 −3
Original line number Diff line number Diff line
@@ -6,13 +6,22 @@ pub mod uuid;
use std::{rc::Rc, thread};

use bt_common::init_flags::rust_event_loop_is_enabled;
use cxx::UniquePtr;

use crate::{gatt::ffi::AttTransportImpl, GlobalModuleRegistry};
use crate::{
    gatt::ffi::{AttTransportImpl, GattCallbacksImpl},
    GlobalModuleRegistry,
};

fn init() {
use self::ffi::GattServerCallbacks;

fn init(gatt_server_callbacks: UniquePtr<GattServerCallbacks>) {
    if rust_event_loop_is_enabled() {
        thread::spawn(move || {
            GlobalModuleRegistry::start(Rc::new(AttTransportImpl()));
            GlobalModuleRegistry::start(
                Rc::new(GattCallbacksImpl(gatt_server_callbacks)),
                Rc::new(AttTransportImpl()),
            );
        });
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -2,8 +2,13 @@
//! existing C++ GATT client. See go/private-gatt-in-platform for the design.

pub mod arbiter;
pub mod callbacks;
pub mod channel;
pub mod ffi;
pub mod ids;
pub mod mocks;
pub mod server;

pub use self::callbacks::GattCallbacks;

pub use ffi::GattServerCallbacks;
Loading