summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Suter <csuter@google.com> 2025-02-13 12:48:43 +1100
committer Chris Suter <csuter@google.com> 2025-02-12 18:30:26 -0800
commit5395d25d4287a208a3ab1a9ce6a11f3447ffd1e3 (patch)
treec3c01bff43afa5195eefca5ffbbb71982a7d1574
parent8388cbe97c1854014348dd9c70688a3d208acbef (diff)
system/rust: Set imports_granularity rustfmt option to Module
This matches the Fuchsia style. See https://fxbug.dev/340943530 for rationale. I've also reformatted all Rust files under system/rust with this style as there seemed to be some inconsistencies. Fix: 396241824 Test: m com.android.btservices Flag: EXEMPT refactor only Change-Id: I74425bfbe98a402fa5f9fd5f1746a00b9767a321
-rw-r--r--rustfmt.toml1
-rw-r--r--system/rust/build.rs5
-rw-r--r--system/rust/src/core/mod.rs6
-rw-r--r--system/rust/src/core/shared_box.rs6
-rw-r--r--system/rust/src/core/shared_mutex.rs4
-rw-r--r--system/rust/src/gatt/arbiter.rs21
-rw-r--r--system/rust/src/gatt/callbacks.rs17
-rw-r--r--system/rust/src/gatt/callbacks/callback_transaction_manager.rs20
-rw-r--r--system/rust/src/gatt/ffi.rs30
-rw-r--r--system/rust/src/gatt/mocks/mock_callbacks.rs12
-rw-r--r--system/rust/src/gatt/mocks/mock_database_callbacks.rs14
-rw-r--r--system/rust/src/gatt/mocks/mock_datastore.rs18
-rw-r--r--system/rust/src/gatt/mocks/mock_raw_datastore.rs18
-rw-r--r--system/rust/src/gatt/mocks/mock_transport.rs10
-rw-r--r--system/rust/src/gatt/mtu.rs3
-rw-r--r--system/rust/src/gatt/server.rs40
-rw-r--r--system/rust/src/gatt/server/att_database.rs8
-rw-r--r--system/rust/src/gatt/server/att_server_bearer.rs65
-rw-r--r--system/rust/src/gatt/server/command_handler.rs22
-rw-r--r--system/rust/src/gatt/server/gatt_database.rs51
-rw-r--r--system/rust/src/gatt/server/indication_handler.rs35
-rw-r--r--system/rust/src/gatt/server/request_handler.rs44
-rw-r--r--system/rust/src/gatt/server/services.rs3
-rw-r--r--system/rust/src/gatt/server/services/gap.rs30
-rw-r--r--system/rust/src/gatt/server/services/gatt.rs53
-rw-r--r--system/rust/src/gatt/server/test/test_att_db.rs14
-rw-r--r--system/rust/src/gatt/server/transactions/find_by_type_value.rs35
-rw-r--r--system/rust/src/gatt/server/transactions/find_information_request.rs18
-rw-r--r--system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs24
-rw-r--r--system/rust/src/gatt/server/transactions/helpers/att_grouping.rs7
-rw-r--r--system/rust/src/gatt/server/transactions/helpers/att_range_filter.rs5
-rw-r--r--system/rust/src/gatt/server/transactions/read_by_group_type_request.rs38
-rw-r--r--system/rust/src/gatt/server/transactions/read_by_type_request.rs33
-rw-r--r--system/rust/src/gatt/server/transactions/read_request.rs19
-rw-r--r--system/rust/src/gatt/server/transactions/write_request.rs21
-rw-r--r--system/rust/src/lib.rs7
-rw-r--r--system/rust/src/utils/task.rs14
-rw-r--r--system/rust/tests/gatt_callbacks_test.rs27
-rw-r--r--system/rust/tests/gatt_server_test.rs56
39 files changed, 347 insertions, 507 deletions
diff --git a/rustfmt.toml b/rustfmt.toml
index 05a76b507b..deeeb145aa 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -7,3 +7,4 @@
edition = "2021"
use_small_heuristics = "Max"
newline_style = "Unix"
+imports_granularity = "Module"
diff --git a/system/rust/build.rs b/system/rust/build.rs
index bae31cdcaa..08cb84c6a2 100644
--- a/system/rust/build.rs
+++ b/system/rust/build.rs
@@ -2,7 +2,10 @@
//!
//! Run `cargo install --path .` in `external/rust/crates/pdl-compiler` to ensure `pdlc`
//! is in your path.
-use std::{env, fs::File, io::Write, path::Path};
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::path::Path;
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
diff --git a/system/rust/src/core/mod.rs b/system/rust/src/core/mod.rs
index e4f4932b79..ebcd65c353 100644
--- a/system/rust/src/core/mod.rs
+++ b/system/rust/src/core/mod.rs
@@ -10,10 +10,8 @@ use std::pin::Pin;
use cxx::UniquePtr;
-use crate::{
- gatt::ffi::{AttTransportImpl, GattCallbacksImpl},
- RustModuleRunner,
-};
+use crate::gatt::ffi::{AttTransportImpl, GattCallbacksImpl};
+use crate::RustModuleRunner;
use self::ffi::{future_ready, Future, GattServerCallbacks};
diff --git a/system/rust/src/core/shared_box.rs b/system/rust/src/core/shared_box.rs
index accd1ae6ec..2f28c79c68 100644
--- a/system/rust/src/core/shared_box.rs
+++ b/system/rust/src/core/shared_box.rs
@@ -5,10 +5,8 @@
//! not be held across async points. This reduces the risk of accidental
//! lifetime extension.
-use std::{
- ops::Deref,
- rc::{Rc, Weak},
-};
+use std::ops::Deref;
+use std::rc::{Rc, Weak};
/// A Box<> where static "weak" references to the contents can be taken,
/// and fallibly upgraded at a later point. Unlike Rc<>, weak references
diff --git a/system/rust/src/core/shared_mutex.rs b/system/rust/src/core/shared_mutex.rs
index 8477932601..ef28223495 100644
--- a/system/rust/src/core/shared_mutex.rs
+++ b/system/rust/src/core/shared_mutex.rs
@@ -1,7 +1,9 @@
//! The motivation for SharedMutex is to guard a resource without having to
//! extend its lifetime using an Rc<> (and potentially create reference cycles)
-use std::{future::Future, rc::Rc, sync::Arc};
+use std::future::Future;
+use std::rc::Rc;
+use std::sync::Arc;
use tokio::sync::{Mutex, OwnedMutexGuard, Semaphore, TryLockError};
diff --git a/system/rust/src/gatt/arbiter.rs b/system/rust/src/gatt/arbiter.rs
index f25250043b..3abe6d2ff3 100644
--- a/system/rust/src/gatt/arbiter.rs
+++ b/system/rust/src/gatt/arbiter.rs
@@ -7,15 +7,14 @@ use std::sync::{Arc, Mutex};
use log::{error, trace, warn};
use std::sync::RwLock;
-use crate::{do_in_rust_thread, packets::att};
+use crate::do_in_rust_thread;
+use crate::packets::att;
-use super::{
- ffi::{InterceptAction, StoreCallbacksFromRust},
- ids::{AdvertiserId, TransportIndex},
- mtu::MtuEvent,
- opcode_types::{classify_opcode, OperationType},
- server::isolation_manager::IsolationManager,
-};
+use super::ffi::{InterceptAction, StoreCallbacksFromRust};
+use super::ids::{AdvertiserId, TransportIndex};
+use super::mtu::MtuEvent;
+use super::opcode_types::{classify_opcode, OperationType};
+use super::server::isolation_manager::IsolationManager;
static ARBITER: RwLock<Option<Arc<Mutex<IsolationManager>>>> = RwLock::new(None);
@@ -156,10 +155,8 @@ fn on_mtu_event(tcb_idx: TransportIndex, event: MtuEvent) {
mod test {
use super::*;
- use crate::{
- gatt::ids::{AttHandle, ServerId},
- packets::att,
- };
+ use crate::gatt::ids::{AttHandle, ServerId};
+ use crate::packets::att;
const TCB_IDX: TransportIndex = TransportIndex(1);
const ADVERTISER_ID: AdvertiserId = AdvertiserId(3);
diff --git a/system/rust/src/gatt/callbacks.rs b/system/rust/src/gatt/callbacks.rs
index 377d5a81f6..41b81a4f35 100644
--- a/system/rust/src/gatt/callbacks.rs
+++ b/system/rust/src/gatt/callbacks.rs
@@ -11,11 +11,9 @@ use log::warn;
use crate::packets::att::AttErrorCode;
-use super::{
- ffi::AttributeBackingType,
- ids::{AttHandle, ConnectionId, TransactionId, TransportIndex},
- server::IndicationError,
-};
+use super::ffi::AttributeBackingType;
+use super::ids::{AttHandle, ConnectionId, TransactionId, TransportIndex};
+use super::server::IndicationError;
/// These callbacks are expected to be made available to the GattModule from
/// JNI.
@@ -209,12 +207,11 @@ impl<T: GattDatastore + ?Sized> RawGattDatastore for T {
#[cfg(test)]
mod test {
- use tokio::{sync::mpsc::error::TryRecvError, task::spawn_local};
+ use tokio::sync::mpsc::error::TryRecvError;
+ use tokio::task::spawn_local;
- use crate::{
- gatt::mocks::mock_datastore::{MockDatastore, MockDatastoreEvents},
- utils::task::block_on_locally,
- };
+ use crate::gatt::mocks::mock_datastore::{MockDatastore, MockDatastoreEvents};
+ use crate::utils::task::block_on_locally;
use super::*;
diff --git a/system/rust/src/gatt/callbacks/callback_transaction_manager.rs b/system/rust/src/gatt/callbacks/callback_transaction_manager.rs
index f877f17d81..f00a6a4f42 100644
--- a/system/rust/src/gatt/callbacks/callback_transaction_manager.rs
+++ b/system/rust/src/gatt/callbacks/callback_transaction_manager.rs
@@ -1,16 +1,16 @@
-use std::{cell::RefCell, collections::HashMap, rc::Rc, time::Duration};
+use std::cell::RefCell;
+use std::collections::HashMap;
+use std::rc::Rc;
+use std::time::Duration;
use async_trait::async_trait;
use log::{trace, warn};
-use tokio::{sync::oneshot, time::timeout};
-
-use crate::{
- gatt::{
- ids::{AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex},
- GattCallbacks,
- },
- packets::att::AttErrorCode,
-};
+use tokio::sync::oneshot;
+use tokio::time::timeout;
+
+use crate::gatt::ids::{AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex};
+use crate::gatt::GattCallbacks;
+use crate::packets::att::AttErrorCode;
use super::{
AttributeBackingType, GattWriteRequestType, GattWriteType, RawGattDatastore,
diff --git a/system/rust/src/gatt/ffi.rs b/system/rust/src/gatt/ffi.rs
index 4a54dd9f71..8afbdd88e2 100644
--- a/system/rust/src/gatt/ffi.rs
+++ b/system/rust/src/gatt/ffi.rs
@@ -1,8 +1,7 @@
//! FFI interfaces for the GATT module. Some structs are exported so that
//! core::init can instantiate and pass them into the main loop.
-use pdl_runtime::EncodeError;
-use pdl_runtime::Packet;
+use pdl_runtime::{EncodeError, Packet};
use std::iter::Peekable;
use anyhow::{bail, Result};
@@ -11,25 +10,18 @@ pub use inner::*;
use log::{error, info, trace, warn};
use tokio::task::spawn_local;
-use crate::{
- do_in_rust_thread,
- packets::att::{self, AttErrorCode},
-};
+use crate::do_in_rust_thread;
+use crate::packets::att::{self, AttErrorCode};
-use super::{
- arbiter::with_arbiter,
- callbacks::{GattWriteRequestType, GattWriteType, TransactionDecision},
- channel::AttTransport,
- ids::{AdvertiserId, AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex},
- server::{
- gatt_database::{
- AttPermissions, GattCharacteristicWithHandle, GattDescriptorWithHandle,
- GattServiceWithHandle,
- },
- IndicationError,
- },
- GattCallbacks,
+use super::arbiter::with_arbiter;
+use super::callbacks::{GattWriteRequestType, GattWriteType, TransactionDecision};
+use super::channel::AttTransport;
+use super::ids::{AdvertiserId, AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex};
+use super::server::gatt_database::{
+ AttPermissions, GattCharacteristicWithHandle, GattDescriptorWithHandle, GattServiceWithHandle,
};
+use super::server::IndicationError;
+use super::GattCallbacks;
#[cxx::bridge]
#[allow(clippy::needless_lifetimes)]
diff --git a/system/rust/src/gatt/mocks/mock_callbacks.rs b/system/rust/src/gatt/mocks/mock_callbacks.rs
index 14a8da7a6b..cb81487e63 100644
--- a/system/rust/src/gatt/mocks/mock_callbacks.rs
+++ b/system/rust/src/gatt/mocks/mock_callbacks.rs
@@ -1,12 +1,10 @@
//! Mocked implementation of GattCallbacks for use in test
-use crate::gatt::{
- callbacks::{GattWriteType, TransactionDecision},
- ffi::AttributeBackingType,
- ids::{AttHandle, ConnectionId, TransactionId},
- server::IndicationError,
- GattCallbacks,
-};
+use crate::gatt::callbacks::{GattWriteType, TransactionDecision};
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, ConnectionId, TransactionId};
+use crate::gatt::server::IndicationError;
+use crate::gatt::GattCallbacks;
use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
/// Routes calls to GattCallbacks into a channel of MockCallbackEvents
diff --git a/system/rust/src/gatt/mocks/mock_database_callbacks.rs b/system/rust/src/gatt/mocks/mock_database_callbacks.rs
index 991b2f5f04..38d13ae948 100644
--- a/system/rust/src/gatt/mocks/mock_database_callbacks.rs
+++ b/system/rust/src/gatt/mocks/mock_database_callbacks.rs
@@ -2,16 +2,10 @@
use std::ops::RangeInclusive;
-use crate::{
- core::shared_box::{WeakBox, WeakBoxRef},
- gatt::{
- ids::{AttHandle, TransportIndex},
- server::{
- att_server_bearer::AttServerBearer,
- gatt_database::{AttDatabaseImpl, GattDatabaseCallbacks},
- },
- },
-};
+use crate::core::shared_box::{WeakBox, WeakBoxRef};
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::gatt::server::att_server_bearer::AttServerBearer;
+use crate::gatt::server::gatt_database::{AttDatabaseImpl, GattDatabaseCallbacks};
use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
/// Routes calls to GattDatabaseCallbacks into a channel of MockCallbackEvents
diff --git a/system/rust/src/gatt/mocks/mock_datastore.rs b/system/rust/src/gatt/mocks/mock_datastore.rs
index 0e024efd91..852ee69ddd 100644
--- a/system/rust/src/gatt/mocks/mock_datastore.rs
+++ b/system/rust/src/gatt/mocks/mock_datastore.rs
@@ -1,19 +1,13 @@
//! Mocked implementation of GattDatastore for use in test
-use crate::{
- gatt::{
- callbacks::GattDatastore,
- ffi::AttributeBackingType,
- ids::{AttHandle, TransportIndex},
- },
- packets::att::AttErrorCode,
-};
+use crate::gatt::callbacks::GattDatastore;
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::packets::att::AttErrorCode;
use async_trait::async_trait;
use log::info;
-use tokio::sync::{
- mpsc::{self, unbounded_channel, UnboundedReceiver},
- oneshot,
-};
+use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
+use tokio::sync::oneshot;
/// Routes calls to GattDatastore into a channel of MockDatastoreEvents
pub struct MockDatastore(mpsc::UnboundedSender<MockDatastoreEvents>);
diff --git a/system/rust/src/gatt/mocks/mock_raw_datastore.rs b/system/rust/src/gatt/mocks/mock_raw_datastore.rs
index c43b47d586..28dc3e202d 100644
--- a/system/rust/src/gatt/mocks/mock_raw_datastore.rs
+++ b/system/rust/src/gatt/mocks/mock_raw_datastore.rs
@@ -1,19 +1,13 @@
//! Mocked implementation of GattDatastore for use in test
-use crate::{
- gatt::{
- callbacks::{GattWriteRequestType, RawGattDatastore, TransactionDecision},
- ffi::AttributeBackingType,
- ids::{AttHandle, TransportIndex},
- },
- packets::att::AttErrorCode,
-};
+use crate::gatt::callbacks::{GattWriteRequestType, RawGattDatastore, TransactionDecision};
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::packets::att::AttErrorCode;
use async_trait::async_trait;
use log::info;
-use tokio::sync::{
- mpsc::{self, unbounded_channel, UnboundedReceiver},
- oneshot,
-};
+use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
+use tokio::sync::oneshot;
/// Routes calls to RawGattDatastore into a channel of MockRawDatastoreEvents
pub struct MockRawDatastore(mpsc::UnboundedSender<MockRawDatastoreEvents>);
diff --git a/system/rust/src/gatt/mocks/mock_transport.rs b/system/rust/src/gatt/mocks/mock_transport.rs
index 4db740c71a..cfccf4a125 100644
--- a/system/rust/src/gatt/mocks/mock_transport.rs
+++ b/system/rust/src/gatt/mocks/mock_transport.rs
@@ -1,11 +1,9 @@
//! Mocked implementation of AttTransport for use in test
-use crate::{
- gatt::{channel::AttTransport, ids::TransportIndex},
- packets::att,
-};
-use pdl_runtime::EncodeError;
-use pdl_runtime::Packet;
+use crate::gatt::channel::AttTransport;
+use crate::gatt::ids::TransportIndex;
+use crate::packets::att;
+use pdl_runtime::{EncodeError, Packet};
use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
/// Routes calls to AttTransport into a channel containing AttBuilders
diff --git a/system/rust/src/gatt/mtu.rs b/system/rust/src/gatt/mtu.rs
index 3e7eaa4dbe..09c9d64c33 100644
--- a/system/rust/src/gatt/mtu.rs
+++ b/system/rust/src/gatt/mtu.rs
@@ -5,7 +5,8 @@
//! set. If the MTU is pending, ATT notifications/indications may not be sent.
//! Refer to Core Spec 5.3 Vol 3F 3.4.2 MTU exchange for full details.
-use std::{cell::Cell, future::Future};
+use std::cell::Cell;
+use std::future::Future;
use anyhow::{bail, Result};
use log::info;
diff --git a/system/rust/src/gatt/server.rs b/system/rust/src/gatt/server.rs
index c75be163aa..b7769f19dc 100644
--- a/system/rust/src/gatt/server.rs
+++ b/system/rust/src/gatt/server.rs
@@ -14,30 +14,22 @@ pub mod isolation_manager;
#[cfg(test)]
mod test;
-use std::{
- collections::HashMap,
- rc::Rc,
- sync::{Arc, Mutex, MutexGuard},
-};
-
-use crate::{
- core::shared_box::{SharedBox, WeakBox, WeakBoxRef},
- gatt::server::gatt_database::GattDatabase,
-};
-
-use self::{
- super::ids::ServerId,
- att_server_bearer::AttServerBearer,
- gatt_database::{AttDatabaseImpl, GattServiceWithHandle},
- isolation_manager::IsolationManager,
- services::register_builtin_services,
-};
-
-use super::{
- callbacks::RawGattDatastore,
- channel::AttTransport,
- ids::{AdvertiserId, AttHandle, TransportIndex},
-};
+use std::collections::HashMap;
+use std::rc::Rc;
+use std::sync::{Arc, Mutex, MutexGuard};
+
+use crate::core::shared_box::{SharedBox, WeakBox, WeakBoxRef};
+use crate::gatt::server::gatt_database::GattDatabase;
+
+use self::super::ids::ServerId;
+use self::att_server_bearer::AttServerBearer;
+use self::gatt_database::{AttDatabaseImpl, GattServiceWithHandle};
+use self::isolation_manager::IsolationManager;
+use self::services::register_builtin_services;
+
+use super::callbacks::RawGattDatastore;
+use super::channel::AttTransport;
+use super::ids::{AdvertiserId, AttHandle, TransportIndex};
use anyhow::{anyhow, bail, Result};
use log::info;
diff --git a/system/rust/src/gatt/server/att_database.rs b/system/rust/src/gatt/server/att_database.rs
index cd322c6f8c..bc171a8ac9 100644
--- a/system/rust/src/gatt/server/att_database.rs
+++ b/system/rust/src/gatt/server/att_database.rs
@@ -1,11 +1,9 @@
use async_trait::async_trait;
use bitflags::bitflags;
-use crate::{
- core::uuid::Uuid,
- gatt::ids::AttHandle,
- packets::att::{self, AttErrorCode},
-};
+use crate::core::uuid::Uuid;
+use crate::gatt::ids::AttHandle;
+use crate::packets::att::{self, AttErrorCode};
impl From<att::AttHandle> for AttHandle {
fn from(value: att::AttHandle) -> Self {
diff --git a/system/rust/src/gatt/server/att_server_bearer.rs b/system/rust/src/gatt/server/att_server_bearer.rs
index 0d78ad1278..8ec140da14 100644
--- a/system/rust/src/gatt/server/att_server_bearer.rs
+++ b/system/rust/src/gatt/server/att_server_bearer.rs
@@ -3,32 +3,25 @@
//! AttDatabase (that may in turn be backed by an upper-layer protocol)
use pdl_runtime::EncodeError;
-use std::{cell::Cell, future::Future};
+use std::cell::Cell;
+use std::future::Future;
use anyhow::Result;
use log::{error, trace, warn};
use tokio::task::spawn_local;
-use crate::{
- core::{
- shared_box::{WeakBox, WeakBoxRef},
- shared_mutex::SharedMutex,
- },
- gatt::{
- ids::AttHandle,
- mtu::{AttMtu, MtuEvent},
- opcode_types::{classify_opcode, OperationType},
- },
- packets::att::{self, AttErrorCode},
- utils::owned_handle::OwnedHandle,
-};
-
-use super::{
- att_database::AttDatabase,
- command_handler::AttCommandHandler,
- indication_handler::{ConfirmationWatcher, IndicationError, IndicationHandler},
- request_handler::AttRequestHandler,
-};
+use crate::core::shared_box::{WeakBox, WeakBoxRef};
+use crate::core::shared_mutex::SharedMutex;
+use crate::gatt::ids::AttHandle;
+use crate::gatt::mtu::{AttMtu, MtuEvent};
+use crate::gatt::opcode_types::{classify_opcode, OperationType};
+use crate::packets::att::{self, AttErrorCode};
+use crate::utils::owned_handle::OwnedHandle;
+
+use super::att_database::AttDatabase;
+use super::command_handler::AttCommandHandler;
+use super::indication_handler::{ConfirmationWatcher, IndicationError, IndicationHandler};
+use super::request_handler::AttRequestHandler;
enum AttRequestState<T: AttDatabase> {
Idle(AttRequestHandler<T>),
@@ -212,27 +205,23 @@ impl<T: AttDatabase + Clone + 'static> WeakBox<AttServerBearer<T>> {
mod test {
use std::rc::Rc;
- use tokio::sync::mpsc::{error::TryRecvError, unbounded_channel, UnboundedReceiver};
+ use tokio::sync::mpsc::error::TryRecvError;
+ use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use super::*;
- use crate::{
- core::{shared_box::SharedBox, uuid::Uuid},
- gatt::{
- ffi::AttributeBackingType,
- ids::TransportIndex,
- mocks::mock_datastore::{MockDatastore, MockDatastoreEvents},
- server::{
- att_database::{AttAttribute, AttPermissions},
- gatt_database::{
- GattCharacteristicWithHandle, GattDatabase, GattServiceWithHandle,
- },
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- utils::task::{block_on_locally, try_await},
+ use crate::core::shared_box::SharedBox;
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ffi::AttributeBackingType;
+ use crate::gatt::ids::TransportIndex;
+ use crate::gatt::mocks::mock_datastore::{MockDatastore, MockDatastoreEvents};
+ use crate::gatt::server::att_database::{AttAttribute, AttPermissions};
+ use crate::gatt::server::gatt_database::{
+ GattCharacteristicWithHandle, GattDatabase, GattServiceWithHandle,
};
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
+ use crate::utils::task::{block_on_locally, try_await};
const VALID_HANDLE: AttHandle = AttHandle(3);
const INVALID_HANDLE: AttHandle = AttHandle(4);
diff --git a/system/rust/src/gatt/server/command_handler.rs b/system/rust/src/gatt/server/command_handler.rs
index da54bb1ad8..8d9ac5afd9 100644
--- a/system/rust/src/gatt/server/command_handler.rs
+++ b/system/rust/src/gatt/server/command_handler.rs
@@ -33,20 +33,14 @@ impl<Db: AttDatabase> AttCommandHandler<Db> {
#[cfg(test)]
mod test {
- use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::{
- att_database::{AttAttribute, AttDatabase},
- command_handler::AttCommandHandler,
- gatt_database::AttPermissions,
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- utils::task::block_on_locally,
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::{AttAttribute, AttDatabase};
+ use crate::gatt::server::command_handler::AttCommandHandler;
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
+ use crate::utils::task::block_on_locally;
#[test]
fn test_write_command() {
diff --git a/system/rust/src/gatt/server/gatt_database.rs b/system/rust/src/gatt/server/gatt_database.rs
index d1590b3866..2eaaeaa2ef 100644
--- a/system/rust/src/gatt/server/gatt_database.rs
+++ b/system/rust/src/gatt/server/gatt_database.rs
@@ -3,29 +3,24 @@
//! ATT read/write requests into characteristic reads/writes
use pdl_runtime::Packet;
-use std::{cell::RefCell, collections::BTreeMap, ops::RangeInclusive, rc::Rc};
+use std::cell::RefCell;
+use std::collections::BTreeMap;
+use std::ops::RangeInclusive;
+use std::rc::Rc;
use anyhow::{bail, Result};
use async_trait::async_trait;
use log::{error, warn};
-use crate::{
- core::{
- shared_box::{SharedBox, WeakBox, WeakBoxRef},
- uuid::Uuid,
- },
- gatt::{
- callbacks::{GattWriteRequestType, RawGattDatastore},
- ffi::AttributeBackingType,
- ids::{AttHandle, TransportIndex},
- },
- packets::att::{self, AttErrorCode},
-};
-
-use super::{
- att_database::{AttAttribute, AttDatabase},
- att_server_bearer::AttServerBearer,
-};
+use crate::core::shared_box::{SharedBox, WeakBox, WeakBoxRef};
+use crate::core::uuid::Uuid;
+use crate::gatt::callbacks::{GattWriteRequestType, RawGattDatastore};
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::packets::att::{self, AttErrorCode};
+
+use super::att_database::{AttAttribute, AttDatabase};
+use super::att_server_bearer::AttServerBearer;
pub use super::att_database::AttPermissions;
@@ -510,17 +505,15 @@ impl AttDatabaseImpl {
#[cfg(test)]
mod test {
- use tokio::{join, sync::mpsc::error::TryRecvError, task::spawn_local};
-
- use crate::{
- gatt::mocks::{
- mock_database_callbacks::{MockCallbackEvents, MockCallbacks},
- mock_datastore::{MockDatastore, MockDatastoreEvents},
- mock_raw_datastore::{MockRawDatastore, MockRawDatastoreEvents},
- },
- packets::att,
- utils::task::block_on_locally,
- };
+ use tokio::join;
+ use tokio::sync::mpsc::error::TryRecvError;
+ use tokio::task::spawn_local;
+
+ use crate::gatt::mocks::mock_database_callbacks::{MockCallbackEvents, MockCallbacks};
+ use crate::gatt::mocks::mock_datastore::{MockDatastore, MockDatastoreEvents};
+ use crate::gatt::mocks::mock_raw_datastore::{MockRawDatastore, MockRawDatastoreEvents};
+ use crate::packets::att;
+ use crate::utils::task::block_on_locally;
use super::*;
diff --git a/system/rust/src/gatt/server/indication_handler.rs b/system/rust/src/gatt/server/indication_handler.rs
index 44ffe7ef27..4a0eb77654 100644
--- a/system/rust/src/gatt/server/indication_handler.rs
+++ b/system/rust/src/gatt/server/indication_handler.rs
@@ -1,17 +1,15 @@
use std::time::Duration;
use log::{trace, warn};
-use tokio::{
- sync::mpsc::{self, error::TrySendError},
- time::timeout,
-};
+use tokio::sync::mpsc::error::TrySendError;
+use tokio::sync::mpsc::{self};
+use tokio::time::timeout;
-use crate::{gatt::ids::AttHandle, packets::att};
+use crate::gatt::ids::AttHandle;
+use crate::packets::att;
-use super::{
- att_database::{AttDatabase, StableAttDatabase},
- att_server_bearer::SendError,
-};
+use super::att_database::{AttDatabase, StableAttDatabase};
+use super::att_server_bearer::SendError;
#[derive(Debug)]
/// Errors that can occur while sending an indication
@@ -116,16 +114,15 @@ impl ConfirmationWatcher {
#[cfg(test)]
mod test {
use crate::packets::att;
- use tokio::{sync::oneshot, task::spawn_local, time::Instant};
-
- use crate::{
- core::uuid::Uuid,
- gatt::server::{
- att_database::AttAttribute, gatt_database::AttPermissions,
- test::test_att_db::TestAttDatabase,
- },
- utils::task::block_on_locally,
- };
+ use tokio::sync::oneshot;
+ use tokio::task::spawn_local;
+ use tokio::time::Instant;
+
+ use crate::core::uuid::Uuid;
+ use crate::gatt::server::att_database::AttAttribute;
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::utils::task::block_on_locally;
use super::*;
diff --git a/system/rust/src/gatt/server/request_handler.rs b/system/rust/src/gatt/server/request_handler.rs
index a84bdfcea9..c6695ec7ae 100644
--- a/system/rust/src/gatt/server/request_handler.rs
+++ b/system/rust/src/gatt/server/request_handler.rs
@@ -1,22 +1,16 @@
use log::warn;
-use pdl_runtime::DecodeError;
-use pdl_runtime::EncodeError;
-
-use crate::{
- gatt::ids::AttHandle,
- packets::att::{self, AttErrorCode},
-};
-
-use super::{
- att_database::AttDatabase,
- transactions::{
- find_by_type_value::handle_find_by_type_value_request,
- find_information_request::handle_find_information_request,
- read_by_group_type_request::handle_read_by_group_type_request,
- read_by_type_request::handle_read_by_type_request, read_request::handle_read_request,
- write_request::handle_write_request,
- },
-};
+use pdl_runtime::{DecodeError, EncodeError};
+
+use crate::gatt::ids::AttHandle;
+use crate::packets::att::{self, AttErrorCode};
+
+use super::att_database::AttDatabase;
+use super::transactions::find_by_type_value::handle_find_by_type_value_request;
+use super::transactions::find_information_request::handle_find_information_request;
+use super::transactions::read_by_group_type_request::handle_read_by_group_type_request;
+use super::transactions::read_by_type_request::handle_read_by_type_request;
+use super::transactions::read_request::handle_read_request;
+use super::transactions::write_request::handle_write_request;
/// This struct handles all requests needing ACKs. Only ONE should exist per
/// bearer per database, to ensure serialization.
@@ -108,15 +102,11 @@ impl<Db: AttDatabase> AttRequestHandler<Db> {
mod test {
use super::*;
- use crate::{
- core::uuid::Uuid,
- gatt::server::{
- att_database::{AttAttribute, AttPermissions},
- request_handler::AttRequestHandler,
- test::test_att_db::TestAttDatabase,
- },
- packets::att,
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::server::att_database::{AttAttribute, AttPermissions};
+ use crate::gatt::server::request_handler::AttRequestHandler;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
#[test]
fn test_read_request() {
diff --git a/system/rust/src/gatt/server/services.rs b/system/rust/src/gatt/server/services.rs
index a97db3a441..641bbc174a 100644
--- a/system/rust/src/gatt/server/services.rs
+++ b/system/rust/src/gatt/server/services.rs
@@ -6,7 +6,8 @@ pub mod gatt;
use anyhow::Result;
-use self::{gap::register_gap_service, gatt::register_gatt_service};
+use self::gap::register_gap_service;
+use self::gatt::register_gatt_service;
use super::gatt_database::GattDatabase;
diff --git a/system/rust/src/gatt/server/services/gap.rs b/system/rust/src/gatt/server/services/gap.rs
index 81853fa006..6402375954 100644
--- a/system/rust/src/gatt/server/services/gap.rs
+++ b/system/rust/src/gatt/server/services/gap.rs
@@ -5,18 +5,14 @@ use std::rc::Rc;
use anyhow::Result;
use async_trait::async_trait;
-use crate::{
- core::uuid::Uuid,
- gatt::{
- callbacks::GattDatastore,
- ffi::AttributeBackingType,
- ids::{AttHandle, TransportIndex},
- server::gatt_database::{
- AttPermissions, GattCharacteristicWithHandle, GattDatabase, GattServiceWithHandle,
- },
- },
- packets::att::AttErrorCode,
+use crate::core::uuid::Uuid;
+use crate::gatt::callbacks::GattDatastore;
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::gatt::server::gatt_database::{
+ AttPermissions, GattCharacteristicWithHandle, GattDatabase, GattServiceWithHandle,
};
+use crate::packets::att::AttErrorCode;
struct GapService;
@@ -95,14 +91,12 @@ pub fn register_gap_service(database: &mut GattDatabase) -> Result<()> {
mod test {
use super::*;
- use crate::{
- core::shared_box::SharedBox,
- gatt::server::{
- att_database::AttDatabase,
- gatt_database::{GattDatabase, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID},
- },
- utils::task::block_on_locally,
+ use crate::core::shared_box::SharedBox;
+ use crate::gatt::server::att_database::AttDatabase;
+ use crate::gatt::server::gatt_database::{
+ GattDatabase, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
};
+ use crate::utils::task::block_on_locally;
const TCB_IDX: TransportIndex = TransportIndex(1);
diff --git a/system/rust/src/gatt/server/services/gatt.rs b/system/rust/src/gatt/server/services/gatt.rs
index 40514b4812..57cbe7c6b4 100644
--- a/system/rust/src/gatt/server/services/gatt.rs
+++ b/system/rust/src/gatt/server/services/gatt.rs
@@ -1,32 +1,27 @@
//! The GATT service as defined in Core Spec 5.3 Vol 3G Section 7
use pdl_runtime::Packet;
-use std::{cell::RefCell, collections::HashMap, ops::RangeInclusive, rc::Rc};
+use std::cell::RefCell;
+use std::collections::HashMap;
+use std::ops::RangeInclusive;
+use std::rc::Rc;
use anyhow::Result;
use async_trait::async_trait;
use log::{error, warn};
use tokio::task::spawn_local;
-use crate::{
- core::{
- shared_box::{WeakBox, WeakBoxRef},
- uuid::Uuid,
- },
- gatt::{
- callbacks::GattDatastore,
- ffi::AttributeBackingType,
- ids::{AttHandle, TransportIndex},
- server::{
- att_server_bearer::AttServerBearer,
- gatt_database::{
- AttDatabaseImpl, AttPermissions, GattCharacteristicWithHandle, GattDatabase,
- GattDatabaseCallbacks, GattDescriptorWithHandle, GattServiceWithHandle,
- },
- },
- },
- packets::att::{self, AttErrorCode},
+use crate::core::shared_box::{WeakBox, WeakBoxRef};
+use crate::core::uuid::Uuid;
+use crate::gatt::callbacks::GattDatastore;
+use crate::gatt::ffi::AttributeBackingType;
+use crate::gatt::ids::{AttHandle, TransportIndex};
+use crate::gatt::server::att_server_bearer::AttServerBearer;
+use crate::gatt::server::gatt_database::{
+ AttDatabaseImpl, AttPermissions, GattCharacteristicWithHandle, GattDatabase,
+ GattDatabaseCallbacks, GattDescriptorWithHandle, GattServiceWithHandle,
};
+use crate::packets::att::{self, AttErrorCode};
#[derive(Default)]
struct GattService {
@@ -178,20 +173,14 @@ mod test {
use super::*;
- use crate::{
- core::shared_box::SharedBox,
- gatt::{
- mocks::mock_datastore::MockDatastore,
- server::{
- att_database::AttDatabase,
- gatt_database::{
- GattDatabase, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
- },
- },
- },
- packets::att,
- utils::task::{block_on_locally, try_await},
+ use crate::core::shared_box::SharedBox;
+ use crate::gatt::mocks::mock_datastore::MockDatastore;
+ use crate::gatt::server::att_database::AttDatabase;
+ use crate::gatt::server::gatt_database::{
+ GattDatabase, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
};
+ use crate::packets::att;
+ use crate::utils::task::{block_on_locally, try_await};
const TCB_IDX: TransportIndex = TransportIndex(1);
const ANOTHER_TCB_IDX: TransportIndex = TransportIndex(2);
diff --git a/system/rust/src/gatt/server/test/test_att_db.rs b/system/rust/src/gatt/server/test/test_att_db.rs
index 64752f51cf..2011bafe64 100644
--- a/system/rust/src/gatt/server/test/test_att_db.rs
+++ b/system/rust/src/gatt/server/test/test_att_db.rs
@@ -1,14 +1,12 @@
-use crate::{
- gatt::{
- ids::AttHandle,
- server::att_database::{AttAttribute, AttDatabase, StableAttDatabase},
- },
- packets::att::AttErrorCode,
-};
+use crate::gatt::ids::AttHandle;
+use crate::gatt::server::att_database::{AttAttribute, AttDatabase, StableAttDatabase};
+use crate::packets::att::AttErrorCode;
use async_trait::async_trait;
use log::{info, warn};
-use std::{cell::RefCell, collections::BTreeMap, rc::Rc};
+use std::cell::RefCell;
+use std::collections::BTreeMap;
+use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct TestAttDatabase {
diff --git a/system/rust/src/gatt/server/transactions/find_by_type_value.rs b/system/rust/src/gatt/server/transactions/find_by_type_value.rs
index 382990f894..c967158db9 100644
--- a/system/rust/src/gatt/server/transactions/find_by_type_value.rs
+++ b/system/rust/src/gatt/server/transactions/find_by_type_value.rs
@@ -1,19 +1,14 @@
use log::warn;
use pdl_runtime::EncodeError;
-use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::att_database::{AttAttribute, StableAttDatabase},
- },
- packets::att::{self, AttErrorCode},
-};
+use crate::core::uuid::Uuid;
+use crate::gatt::ids::AttHandle;
+use crate::gatt::server::att_database::{AttAttribute, StableAttDatabase};
+use crate::packets::att::{self, AttErrorCode};
-use super::helpers::{
- att_grouping::find_group_end, att_range_filter::filter_to_range,
- payload_accumulator::PayloadAccumulator,
-};
+use super::helpers::att_grouping::find_group_end;
+use super::helpers::att_range_filter::filter_to_range;
+use super::helpers::payload_accumulator::PayloadAccumulator;
pub async fn handle_find_by_type_value_request(
request: att::AttFindByTypeValueRequest,
@@ -72,18 +67,12 @@ pub async fn handle_find_by_type_value_request(
#[cfg(test)]
mod test {
- use crate::{
- gatt::{
- ffi::Uuid,
- server::{
- gatt_database::{
- AttPermissions, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
- },
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
+ use crate::gatt::ffi::Uuid;
+ use crate::gatt::server::gatt_database::{
+ AttPermissions, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
};
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
use super::*;
diff --git a/system/rust/src/gatt/server/transactions/find_information_request.rs b/system/rust/src/gatt/server/transactions/find_information_request.rs
index e9079f3a1d..b33cacce69 100644
--- a/system/rust/src/gatt/server/transactions/find_information_request.rs
+++ b/system/rust/src/gatt/server/transactions/find_information_request.rs
@@ -1,10 +1,9 @@
-use crate::{
- gatt::server::att_database::{AttAttribute, AttDatabase},
- packets::att::{self, AttErrorCode},
-};
+use crate::gatt::server::att_database::{AttAttribute, AttDatabase};
+use crate::packets::att::{self, AttErrorCode};
use pdl_runtime::EncodeError;
-use super::helpers::{att_range_filter::filter_to_range, payload_accumulator::PayloadAccumulator};
+use super::helpers::att_range_filter::filter_to_range;
+use super::helpers::payload_accumulator::PayloadAccumulator;
pub fn handle_find_information_request<T: AttDatabase>(
request: att::AttFindInformationRequest,
@@ -89,12 +88,11 @@ fn handle_find_information_request_long(
#[cfg(test)]
mod test {
+ use crate::core::uuid::Uuid;
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
use crate::gatt::server::AttHandle;
- use crate::{
- core::uuid::Uuid,
- gatt::server::{gatt_database::AttPermissions, test::test_att_db::TestAttDatabase},
- packets::att,
- };
+ use crate::packets::att;
use super::*;
diff --git a/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs b/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs
index 1674597bc4..1e8870c642 100644
--- a/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs
+++ b/system/rust/src/gatt/server/transactions/helpers/att_filter_by_size_type.rs
@@ -1,11 +1,9 @@
//! This module extracts the common logic in filtering attributes by type +
//! length, used in READ_BY_TYPE_REQ and READ_BY_GROUP_TYPE_REQ
-use crate::{
- core::uuid::Uuid,
- gatt::server::att_database::{AttAttribute, StableAttDatabase},
- packets::att::AttErrorCode,
-};
+use crate::core::uuid::Uuid;
+use crate::gatt::server::att_database::{AttAttribute, StableAttDatabase};
+use crate::packets::att::AttErrorCode;
/// An attribute and the value
#[derive(Debug, PartialEq, Eq)]
@@ -67,17 +65,11 @@ pub async fn filter_read_attributes_by_size_type(
mod test {
use super::*;
- use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::{
- att_database::{AttAttribute, AttDatabase, StableAttDatabase},
- gatt_database::AttPermissions,
- test::test_att_db::TestAttDatabase,
- },
- },
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::{AttAttribute, AttDatabase, StableAttDatabase};
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
const UUID: Uuid = Uuid::new(1234);
const ANOTHER_UUID: Uuid = Uuid::new(2345);
diff --git a/system/rust/src/gatt/server/transactions/helpers/att_grouping.rs b/system/rust/src/gatt/server/transactions/helpers/att_grouping.rs
index fee52d7c60..1596475ac6 100644
--- a/system/rust/src/gatt/server/transactions/helpers/att_grouping.rs
+++ b/system/rust/src/gatt/server/transactions/helpers/att_grouping.rs
@@ -54,10 +54,9 @@ pub fn find_group_end(
#[cfg(test)]
mod test {
- use crate::gatt::{
- ids::AttHandle,
- server::{gatt_database::AttPermissions, test::test_att_db::TestAttDatabase},
- };
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
use super::*;
diff --git a/system/rust/src/gatt/server/transactions/helpers/att_range_filter.rs b/system/rust/src/gatt/server/transactions/helpers/att_range_filter.rs
index 70be91d6a6..b70119b0a4 100644
--- a/system/rust/src/gatt/server/transactions/helpers/att_range_filter.rs
+++ b/system/rust/src/gatt/server/transactions/helpers/att_range_filter.rs
@@ -2,7 +2,8 @@
//! in many ATT commands, such as ATT_FIND_INFORMATION_REQ and
//! ATT_FIND_BY_TYPE_VALUE REQ
-use crate::gatt::{ids::AttHandle, server::att_database::AttAttribute};
+use crate::gatt::ids::AttHandle;
+use crate::gatt::server::att_database::AttAttribute;
/// Filter a (sorted) iterator of attributes to those that lie within
/// the specified range. If the range is invalid (start = 0, or start > end),
@@ -24,7 +25,7 @@ pub fn filter_to_range(
#[cfg(test)]
mod test {
- use crate::gatt::server::{gatt_database::AttPermissions, gatt_database::CHARACTERISTIC_UUID};
+ use crate::gatt::server::gatt_database::{AttPermissions, CHARACTERISTIC_UUID};
use super::*;
diff --git a/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs b/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs
index 319d5e6c45..7bff62c72e 100644
--- a/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs
+++ b/system/rust/src/gatt/server/transactions/read_by_group_type_request.rs
@@ -1,19 +1,17 @@
-use crate::{
- core::uuid::Uuid,
- gatt::server::{
- att_database::StableAttDatabase,
- gatt_database::{PRIMARY_SERVICE_DECLARATION_UUID, SECONDARY_SERVICE_DECLARATION_UUID},
- },
- packets::att::{self, AttErrorCode},
+use crate::core::uuid::Uuid;
+use crate::gatt::server::att_database::StableAttDatabase;
+use crate::gatt::server::gatt_database::{
+ PRIMARY_SERVICE_DECLARATION_UUID, SECONDARY_SERVICE_DECLARATION_UUID,
};
+use crate::packets::att::{self, AttErrorCode};
use pdl_runtime::EncodeError;
-use super::helpers::{
- att_filter_by_size_type::{filter_read_attributes_by_size_type, AttributeWithValue},
- att_grouping::find_group_end,
- att_range_filter::filter_to_range,
- payload_accumulator::PayloadAccumulator,
+use super::helpers::att_filter_by_size_type::{
+ filter_read_attributes_by_size_type, AttributeWithValue,
};
+use super::helpers::att_grouping::find_group_end;
+use super::helpers::att_range_filter::filter_to_range;
+use super::helpers::payload_accumulator::PayloadAccumulator;
pub async fn handle_read_by_group_type_request(
request: att::AttReadByGroupTypeRequest,
@@ -92,17 +90,11 @@ pub async fn handle_read_by_group_type_request(
#[cfg(test)]
mod test {
- use crate::{
- gatt::{
- ids::AttHandle,
- server::{
- att_database::AttAttribute,
- gatt_database::{AttPermissions, CHARACTERISTIC_UUID},
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- };
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::AttAttribute;
+ use crate::gatt::server::gatt_database::{AttPermissions, CHARACTERISTIC_UUID};
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
use super::*;
diff --git a/system/rust/src/gatt/server/transactions/read_by_type_request.rs b/system/rust/src/gatt/server/transactions/read_by_type_request.rs
index 3e7f3b44c4..eec8815ee8 100644
--- a/system/rust/src/gatt/server/transactions/read_by_type_request.rs
+++ b/system/rust/src/gatt/server/transactions/read_by_type_request.rs
@@ -1,15 +1,13 @@
-use crate::{
- core::uuid::Uuid,
- gatt::server::att_database::StableAttDatabase,
- packets::att::{self, AttErrorCode},
-};
+use crate::core::uuid::Uuid;
+use crate::gatt::server::att_database::StableAttDatabase;
+use crate::packets::att::{self, AttErrorCode};
use pdl_runtime::EncodeError;
-use super::helpers::{
- att_filter_by_size_type::{filter_read_attributes_by_size_type, AttributeWithValue},
- att_range_filter::filter_to_range,
- payload_accumulator::PayloadAccumulator,
+use super::helpers::att_filter_by_size_type::{
+ filter_read_attributes_by_size_type, AttributeWithValue,
};
+use super::helpers::att_range_filter::filter_to_range;
+use super::helpers::payload_accumulator::PayloadAccumulator;
pub async fn handle_read_by_type_request(
request: att::AttReadByTypeRequest,
@@ -74,17 +72,12 @@ pub async fn handle_read_by_type_request(
mod test {
use super::*;
- use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::{
- att_database::AttAttribute, gatt_database::AttPermissions,
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::AttAttribute;
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
const UUID: Uuid = Uuid::new(1234);
const ANOTHER_UUID: Uuid = Uuid::new(2345);
diff --git a/system/rust/src/gatt/server/transactions/read_request.rs b/system/rust/src/gatt/server/transactions/read_request.rs
index b5827deeb5..17cb6e8e83 100644
--- a/system/rust/src/gatt/server/transactions/read_request.rs
+++ b/system/rust/src/gatt/server/transactions/read_request.rs
@@ -1,4 +1,5 @@
-use crate::{gatt::server::att_database::AttDatabase, packets::att};
+use crate::gatt::server::att_database::AttDatabase;
+use crate::packets::att;
use pdl_runtime::EncodeError;
pub async fn handle_read_request<T: AttDatabase>(
@@ -27,17 +28,11 @@ pub async fn handle_read_request<T: AttDatabase>(
mod test {
use super::*;
- use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::{
- att_database::{AttAttribute, AttPermissions},
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::{AttAttribute, AttPermissions};
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
fn make_db_with_handle_and_value(handle: u16, value: Vec<u8>) -> TestAttDatabase {
TestAttDatabase::new(vec![(
diff --git a/system/rust/src/gatt/server/transactions/write_request.rs b/system/rust/src/gatt/server/transactions/write_request.rs
index 226d57fc98..f3a41e6937 100644
--- a/system/rust/src/gatt/server/transactions/write_request.rs
+++ b/system/rust/src/gatt/server/transactions/write_request.rs
@@ -1,4 +1,5 @@
-use crate::{gatt::server::att_database::AttDatabase, packets::att};
+use crate::gatt::server::att_database::AttDatabase;
+use crate::packets::att;
use pdl_runtime::EncodeError;
pub async fn handle_write_request<T: AttDatabase>(
@@ -24,18 +25,12 @@ mod test {
use tokio_test::block_on;
- use crate::{
- core::uuid::Uuid,
- gatt::{
- ids::AttHandle,
- server::{
- att_database::{AttAttribute, AttDatabase},
- gatt_database::AttPermissions,
- test::test_att_db::TestAttDatabase,
- },
- },
- packets::att,
- };
+ use crate::core::uuid::Uuid;
+ use crate::gatt::ids::AttHandle;
+ use crate::gatt::server::att_database::{AttAttribute, AttDatabase};
+ use crate::gatt::server::gatt_database::AttPermissions;
+ use crate::gatt::server::test::test_att_db::TestAttDatabase;
+ use crate::packets::att;
#[test]
fn test_successful_write() {
diff --git a/system/rust/src/lib.rs b/system/rust/src/lib.rs
index 3886ee4772..f88e635911 100644
--- a/system/rust/src/lib.rs
+++ b/system/rust/src/lib.rs
@@ -15,11 +15,14 @@
//! The core event loop for Rust modules. Here Rust modules are started in
//! dependency order.
-use gatt::{channel::AttTransport, GattCallbacks};
+use gatt::channel::AttTransport;
+use gatt::GattCallbacks;
use log::{info, warn};
use tokio::task::LocalSet;
-use std::{rc::Rc, sync::Mutex, thread::JoinHandle};
+use std::rc::Rc;
+use std::sync::Mutex;
+use std::thread::JoinHandle;
use tokio::runtime::Builder;
use tokio::sync::mpsc;
diff --git a/system/rust/src/utils/task.rs b/system/rust/src/utils/task.rs
index 4e2753be7c..087f714260 100644
--- a/system/rust/src/utils/task.rs
+++ b/system/rust/src/utils/task.rs
@@ -1,16 +1,12 @@
//! This module provides utilities relating to async tasks, typically for usage
//! only in test
-use std::{
- future::{Future, IntoFuture},
- time::Duration,
-};
+use std::future::{Future, IntoFuture};
+use std::time::Duration;
-use tokio::{
- runtime::Builder,
- select,
- task::{spawn_local, LocalSet},
-};
+use tokio::runtime::Builder;
+use tokio::select;
+use tokio::task::{spawn_local, LocalSet};
/// Run the supplied future on a single-threaded runtime
pub fn block_on_locally<T>(f: impl Future<Output = T>) -> T {
diff --git a/system/rust/tests/gatt_callbacks_test.rs b/system/rust/tests/gatt_callbacks_test.rs
index 84409f376e..8bb1c37bdd 100644
--- a/system/rust/tests/gatt_callbacks_test.rs
+++ b/system/rust/tests/gatt_callbacks_test.rs
@@ -1,20 +1,19 @@
mod utils;
-use std::{rc::Rc, time::Duration};
-
-use bluetooth_core::{
- gatt::{
- callbacks::{
- CallbackResponseError, CallbackTransactionManager, GattWriteRequestType, GattWriteType,
- RawGattDatastore, TransactionDecision,
- },
- ffi::AttributeBackingType,
- ids::{AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex},
- mocks::mock_callbacks::{MockCallbackEvents, MockCallbacks},
- },
- packets::att::AttErrorCode,
+use std::rc::Rc;
+use std::time::Duration;
+
+use bluetooth_core::gatt::callbacks::{
+ CallbackResponseError, CallbackTransactionManager, GattWriteRequestType, GattWriteType,
+ RawGattDatastore, TransactionDecision,
};
-use tokio::{sync::mpsc::UnboundedReceiver, task::spawn_local, time::Instant};
+use bluetooth_core::gatt::ffi::AttributeBackingType;
+use bluetooth_core::gatt::ids::{AttHandle, ConnectionId, ServerId, TransactionId, TransportIndex};
+use bluetooth_core::gatt::mocks::mock_callbacks::{MockCallbackEvents, MockCallbacks};
+use bluetooth_core::packets::att::AttErrorCode;
+use tokio::sync::mpsc::UnboundedReceiver;
+use tokio::task::spawn_local;
+use tokio::time::Instant;
use utils::start_test;
const TCB_IDX: TransportIndex = TransportIndex(1);
diff --git a/system/rust/tests/gatt_server_test.rs b/system/rust/tests/gatt_server_test.rs
index cf91d35ad8..2f14f0b4cb 100644
--- a/system/rust/tests/gatt_server_test.rs
+++ b/system/rust/tests/gatt_server_test.rs
@@ -1,42 +1,28 @@
use pdl_runtime::Packet;
-use std::{
- rc::Rc,
- sync::{Arc, Mutex},
+use std::rc::Rc;
+use std::sync::{Arc, Mutex};
+
+use bluetooth_core::core::uuid::Uuid;
+use bluetooth_core::gatt::ffi::AttributeBackingType;
+use bluetooth_core::gatt::ids::{AdvertiserId, AttHandle, ServerId, TransportIndex};
+use bluetooth_core::gatt::mocks::mock_datastore::{MockDatastore, MockDatastoreEvents};
+use bluetooth_core::gatt::mocks::mock_transport::MockAttTransport;
+use bluetooth_core::gatt::server::gatt_database::{
+ AttPermissions, GattCharacteristicWithHandle, GattDescriptorWithHandle, GattServiceWithHandle,
+ CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
};
-
-use bluetooth_core::{
- core::uuid::Uuid,
- gatt::{
- self,
- ffi::AttributeBackingType,
- ids::{AdvertiserId, AttHandle, ServerId, TransportIndex},
- mocks::{
- mock_datastore::{MockDatastore, MockDatastoreEvents},
- mock_transport::MockAttTransport,
- },
- server::{
- gatt_database::{
- AttPermissions, GattCharacteristicWithHandle, GattDescriptorWithHandle,
- GattServiceWithHandle, CHARACTERISTIC_UUID, PRIMARY_SERVICE_DECLARATION_UUID,
- },
- isolation_manager::IsolationManager,
- services::{
- gap::DEVICE_NAME_UUID,
- gatt::{
- CLIENT_CHARACTERISTIC_CONFIGURATION_UUID, GATT_SERVICE_UUID,
- SERVICE_CHANGE_UUID,
- },
- },
- GattModule, IndicationError,
- },
- },
- packets::att::{self, AttErrorCode},
+use bluetooth_core::gatt::server::isolation_manager::IsolationManager;
+use bluetooth_core::gatt::server::services::gap::DEVICE_NAME_UUID;
+use bluetooth_core::gatt::server::services::gatt::{
+ CLIENT_CHARACTERISTIC_CONFIGURATION_UUID, GATT_SERVICE_UUID, SERVICE_CHANGE_UUID,
};
+use bluetooth_core::gatt::server::{GattModule, IndicationError};
+use bluetooth_core::gatt::{self};
+use bluetooth_core::packets::att::{self, AttErrorCode};
-use tokio::{
- sync::mpsc::{error::TryRecvError, UnboundedReceiver},
- task::spawn_local,
-};
+use tokio::sync::mpsc::error::TryRecvError;
+use tokio::sync::mpsc::UnboundedReceiver;
+use tokio::task::spawn_local;
use utils::start_test;
mod utils;