#[doc(hidden)]
pub mod backend;
#[cfg(target_os = "android")]
pub mod peripheral_backend;
pub mod ble;
pub mod bluetooth;
#[cfg(feature = "classic-l2cap")]
pub mod classic_l2cap;
pub mod dex;
pub mod jni;
pub mod l2cap;
#[cfg(feature = "rfcomm")]
pub mod rfcomm;
pub mod runtime;
use dex::DexBuilder;
pub const PACKAGE: &str = "dev/webbluetooth";
pub fn dex_classes() -> Vec<(&'static str, Vec<u8>)> {
vec![
("gatt", gatt_callback_dex()),
("scan", scan_callback_dex()),
#[cfg(feature = "classic")]
("classic-discovery", classic_discovery_receiver_dex()),
("server", gatt_server_callback_dex()),
("advertise", advertise_callback_dex()),
]
}
pub fn gatt_callback_dex() -> Vec<u8> {
let mut builder = DexBuilder::new(
&format!("{PACKAGE}/GattCallback"),
"android/bluetooth/BluetoothGattCallback",
);
for (name, descriptor, _) in crate::bluetooth::gatt_natives() {
builder = builder.native_method(name, descriptor);
}
builder.build()
}
pub fn scan_callback_dex() -> Vec<u8> {
DexBuilder::new(
&format!("{PACKAGE}/ScanCallback"),
"android/bluetooth/le/ScanCallback",
)
.native_method("onScanResult", "(ILandroid/bluetooth/le/ScanResult;)V")
.native_method("onBatchScanResults", "(Ljava/util/List;)V")
.native_method("onScanFailed", "(I)V")
.build()
}
#[cfg(feature = "classic")]
pub fn classic_discovery_receiver_dex() -> Vec<u8> {
DexBuilder::new(
&format!("{PACKAGE}/ClassicDiscoveryReceiver"),
"android/content/BroadcastReceiver",
)
.native_method(
"onReceive",
"(Landroid/content/Context;Landroid/content/Intent;)V",
)
.build()
}
pub fn gatt_server_callback_dex() -> Vec<u8> {
const DEVICE: &str = "Landroid/bluetooth/BluetoothDevice;";
const CHARACTERISTIC: &str = "Landroid/bluetooth/BluetoothGattCharacteristic;";
const DESCRIPTOR: &str = "Landroid/bluetooth/BluetoothGattDescriptor;";
const SERVICE: &str = "Landroid/bluetooth/BluetoothGattService;";
DexBuilder::new(
&format!("{PACKAGE}/GattServerCallback"),
"android/bluetooth/BluetoothGattServerCallback",
)
.native_method("onConnectionStateChange", &format!("({DEVICE}II)V"))
.native_method("onServiceAdded", &format!("(I{SERVICE})V"))
.native_method(
"onCharacteristicReadRequest",
&format!("({DEVICE}II{CHARACTERISTIC})V"),
)
.native_method(
"onCharacteristicWriteRequest",
&format!("({DEVICE}I{CHARACTERISTIC}ZZI[B)V"),
)
.native_method(
"onDescriptorReadRequest",
&format!("({DEVICE}II{DESCRIPTOR})V"),
)
.native_method(
"onDescriptorWriteRequest",
&format!("({DEVICE}I{DESCRIPTOR}ZZI[B)V"),
)
.native_method("onNotificationSent", &format!("({DEVICE}I)V"))
.native_method("onMtuChanged", &format!("({DEVICE}I)V"))
.build()
}
pub fn advertise_callback_dex() -> Vec<u8> {
DexBuilder::new(
&format!("{PACKAGE}/AdvertiseCallback"),
"android/bluetooth/le/AdvertiseCallback",
)
.native_method(
"onStartSuccess",
"(Landroid/bluetooth/le/AdvertiseSettings;)V",
)
.native_method("onStartFailure", "(I)V")
.build()
}