diff --git a/bluetooth/lmp_event/aidl/Android.bp b/bluetooth/lmp_event/aidl/Android.bp new file mode 100644 index 0000000000..6c2f27826b --- /dev/null +++ b/bluetooth/lmp_event/aidl/Android.bp @@ -0,0 +1,33 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +aidl_interface { + name: "android.hardware.bluetooth.lmp_event", + vendor_available: true, + host_supported: true, + srcs: ["android/hardware/bluetooth/lmp_event/*.aidl"], + stability: "vintf", + backend: { + java: { + enabled: true, + platform_apis: true, + }, + cpp: { + enabled: true, + }, + ndk: { + enabled: true, + min_sdk_version: "33", + }, + rust: { + enabled: true, + min_sdk_version: "33", + }, + }, +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/AddressType.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/AddressType.aidl new file mode 100644 index 0000000000..0f239e8055 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/AddressType.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@Backing(type="byte") @VintfStability +enum AddressType { + PUBLIC = 0x00, + RANDOM = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Direction.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Direction.aidl new file mode 100644 index 0000000000..6f807cc836 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Direction.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@Backing(type="byte") @VintfStability +enum Direction { + TX = 0x00, + RX = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl new file mode 100644 index 0000000000..3431010d21 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@VintfStability +interface IBluetoothLmpEvent { + void registerForLmpEvents(in android.hardware.bluetooth.lmp_event.IBluetoothLmpEventCallback callback, in android.hardware.bluetooth.lmp_event.AddressType addressType, in byte[6] address, in android.hardware.bluetooth.lmp_event.LmpEventId[] lmpEventIds); + void unregisterLmpEvents(in android.hardware.bluetooth.lmp_event.AddressType addressType, in byte[6] address); +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl new file mode 100644 index 0000000000..fc6758c608 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@VintfStability +interface IBluetoothLmpEventCallback { + void onEventGenerated(in android.hardware.bluetooth.lmp_event.Timestamp timestamp, in android.hardware.bluetooth.lmp_event.AddressType addressType, in byte[6] address, in android.hardware.bluetooth.lmp_event.Direction direction, in android.hardware.bluetooth.lmp_event.LmpEventId lmpEventId, in char connEventCounter); + void onRegistered(in boolean status); +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/LmpEventId.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/LmpEventId.aidl new file mode 100644 index 0000000000..4ee95d1147 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/LmpEventId.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@Backing(type="byte") @VintfStability +enum LmpEventId { + CONNECT_IND = 0x00, + LL_PHY_UPDATE_IND = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Timestamp.aidl b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Timestamp.aidl new file mode 100644 index 0000000000..5ef32ba716 --- /dev/null +++ b/bluetooth/lmp_event/aidl/aidl_api/android.hardware.bluetooth.lmp_event/current/android/hardware/bluetooth/lmp_event/Timestamp.aidl @@ -0,0 +1,39 @@ +/* + * Copyright 2023 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.bluetooth.lmp_event; +@VintfStability +parcelable Timestamp { + long systemTimeUs; + long bluetoothTimeUs; +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/AddressType.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/AddressType.aidl new file mode 100644 index 0000000000..6bfc7c7180 --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/AddressType.aidl @@ -0,0 +1,27 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +/** + * Type of Address + */ +@VintfStability +@Backing(type="byte") +enum AddressType { + PUBLIC = 0x00, + RANDOM = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Direction.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Direction.aidl new file mode 100644 index 0000000000..884c2bb4b9 --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Direction.aidl @@ -0,0 +1,27 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +/** + * Direction of the LMP event + */ +@VintfStability +@Backing(type="byte") +enum Direction { + TX = 0x00, + RX = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl new file mode 100644 index 0000000000..3828af6537 --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEvent.aidl @@ -0,0 +1,45 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +import android.hardware.bluetooth.lmp_event.IBluetoothLmpEventCallback; +import android.hardware.bluetooth.lmp_event.AddressType; +import android.hardware.bluetooth.lmp_event.LmpEventId; + +@VintfStability +interface IBluetoothLmpEvent { + /** + * API to monitor specific LMP event timestamp for given Bluetooth device. + * + * @param callback An instance of the |IBluetoothLmpEventCallback| AIDL interface object. + * @param addressType Type of bluetooth address. + * @param address Bluetooth address to monitor. + * @param lmpEventIds LMP events to monitor. + */ + void registerForLmpEvents(in IBluetoothLmpEventCallback callback, + in AddressType addressType, + in byte[6] address, + in LmpEventId[] lmpEventIds); + + /** + * API to stop monitoring a given Bluetooth device. + * + * @param addressType Type of Bluetooth address. + * @param address Bluetooth device to stop monitoring. + */ + void unregisterLmpEvents(in AddressType addressType, in byte[6] address); +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl new file mode 100644 index 0000000000..3295ef015d --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/IBluetoothLmpEventCallback.aidl @@ -0,0 +1,47 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +import android.hardware.bluetooth.lmp_event.Direction; +import android.hardware.bluetooth.lmp_event.AddressType; +import android.hardware.bluetooth.lmp_event.LmpEventId; +import android.hardware.bluetooth.lmp_event.Timestamp; + +@VintfStability +interface IBluetoothLmpEventCallback { + /** + * Callback when monitored LMP event invoked. + * + * @param timestamp Timestamp when the LMP event invoked + * @param addressType Type of Bluetooth address. + * @param address Remote bluetooth address that invoke LMP event + * @param direction Direction of the invoked LMP event + * @param lmpEventId LMP event id that bluetooth chip invoked + * @param connEventCounter counter incremented by one for each new connection event + */ + void onEventGenerated(in Timestamp timestamp, + in AddressType addressType, + in byte[6] address, + in Direction direction, + in LmpEventId lmpEventId, + in char connEventCounter); + + /** + * Callback when registration done. + */ + void onRegistered(in boolean status); +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/LmpEventId.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/LmpEventId.aidl new file mode 100644 index 0000000000..3584b0c047 --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/LmpEventId.aidl @@ -0,0 +1,29 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +/** + * LMP event id to be monitored + * CONNECT_IND indicator for initiating connection + * LL_PHY_UPDATE_IND indicator for PHY update + */ +@VintfStability +@Backing(type="byte") +enum LmpEventId { + CONNECT_IND = 0x00, + LL_PHY_UPDATE_IND = 0x01, +} diff --git a/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Timestamp.aidl b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Timestamp.aidl new file mode 100644 index 0000000000..e3c991d31e --- /dev/null +++ b/bluetooth/lmp_event/aidl/android/hardware/bluetooth/lmp_event/Timestamp.aidl @@ -0,0 +1,33 @@ +/* + * Copyright 2023 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. + */ + +package android.hardware.bluetooth.lmp_event; + +/** + * Generic structure to return the timestamp + */ +@VintfStability +parcelable Timestamp { + /** + * Timestamp in microsecond since system boot. + * if systemTimeUs is set to 0, its value is to be ignored + */ + long systemTimeUs; + /** + * Timestamp in microsecond since Bluetooth controller power up. + */ + long bluetoothTimeUs; +} diff --git a/bluetooth/lmp_event/aidl/default/Android.bp b/bluetooth/lmp_event/aidl/default/Android.bp new file mode 100644 index 0000000000..f8ca5e6404 --- /dev/null +++ b/bluetooth/lmp_event/aidl/default/Android.bp @@ -0,0 +1,28 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "hardware_interfaces_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["hardware_interfaces_license"], +} + +rust_binary { + name: "android.hardware.bluetooth.lmp_event-service.default", + relative_install_path: "hw", + init_rc: ["lmp_event-default.rc"], + vintf_fragments: [":manifest_android.hardware.bluetooth.lmp_event-service.default.xml"], + vendor: true, + rustlibs: [ + "liblogger", + "liblog_rust", + "libbinder_rs", + "android.hardware.bluetooth.lmp_event-V1-rust", + ], + srcs: [ "src/main.rs" ], +} + +filegroup { + name: "manifest_android.hardware.bluetooth.lmp_event-service.default.xml", + srcs: [ "lmp_event-default.xml" ], +} diff --git a/bluetooth/lmp_event/aidl/default/lmp_event-default.rc b/bluetooth/lmp_event/aidl/default/lmp_event-default.rc new file mode 100644 index 0000000000..845e04dba1 --- /dev/null +++ b/bluetooth/lmp_event/aidl/default/lmp_event-default.rc @@ -0,0 +1,6 @@ +service vendor.bluetooth.lmp_event-default /vendor/bin/hw/android.hardware.bluetooth.lmp_event-service.default + class hal + capabilities BLOCK_SUSPEND NET_ADMIN SYS_NICE + user bluetooth + group bluetooth + task_profiles HighPerformance diff --git a/bluetooth/lmp_event/aidl/default/lmp_event-default.xml b/bluetooth/lmp_event/aidl/default/lmp_event-default.xml new file mode 100644 index 0000000000..24d93f89f3 --- /dev/null +++ b/bluetooth/lmp_event/aidl/default/lmp_event-default.xml @@ -0,0 +1,10 @@ + + + android.hardware.bluetooth.lmp_event + 1 + + IBluetoothLmpEvent + default + + + diff --git a/bluetooth/lmp_event/aidl/default/src/lmp_event.rs b/bluetooth/lmp_event/aidl/default/src/lmp_event.rs new file mode 100644 index 0000000000..f016c3f9eb --- /dev/null +++ b/bluetooth/lmp_event/aidl/default/src/lmp_event.rs @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2023 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. + */ +//! Implements LMP Event AIDL Interface. + +use android_hardware_bluetooth_lmp_event::aidl::android::hardware::bluetooth::lmp_event::{ + Direction::Direction, AddressType::AddressType, IBluetoothLmpEvent::IBluetoothLmpEvent, + IBluetoothLmpEventCallback::IBluetoothLmpEventCallback, LmpEventId::LmpEventId, + Timestamp::Timestamp, +}; + +use binder::{Interface, Result, Strong}; + +use log::info; +use std::thread; +use std::time; + + +pub struct LmpEvent; + +impl LmpEvent { + pub fn new() -> Self { + Self + } +} + +impl Interface for LmpEvent {} + +impl IBluetoothLmpEvent for LmpEvent { + fn registerForLmpEvents(&self, + callback: &Strong, + address_type: AddressType, + address: &[u8; 6], + lmp_event_ids: &[LmpEventId] + ) -> Result<()> { + info!("registerForLmpEvents"); + + let cb = callback.clone(); + let addr_type = address_type; + let addr = address.clone(); + let lmp_event = lmp_event_ids.to_vec(); + + let thread_handle = thread::spawn(move || { + let ts = Timestamp { + bluetoothTimeUs: 1000000, + systemTimeUs: 2000000, + }; + + info!("sleep for 1000 ms"); + thread::sleep(time::Duration::from_millis(1000)); + + info!("callback event"); + cb.onEventGenerated(&ts, addr_type, &addr, Direction::RX, lmp_event[0], 1) + .expect("onEventGenerated failed"); + }); + + info!("callback register"); + callback.onRegistered(true)?; + + thread_handle.join().expect("join failed"); + Ok(()) + } + fn unregisterLmpEvents(&self, _address_type: AddressType, _address: &[u8; 6]) -> Result<()> { + info!("unregisterLmpEvents"); + + Ok(()) + } +} diff --git a/bluetooth/lmp_event/aidl/default/src/main.rs b/bluetooth/lmp_event/aidl/default/src/main.rs new file mode 100644 index 0000000000..cbdd4d1521 --- /dev/null +++ b/bluetooth/lmp_event/aidl/default/src/main.rs @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 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. + */ +//! Implements LMP Event Example Service. + + +use android_hardware_bluetooth_lmp_event::aidl::android::hardware::bluetooth::lmp_event::IBluetoothLmpEvent::{ + IBluetoothLmpEvent, BnBluetoothLmpEvent +}; + +use binder::BinderFeatures; +use log::{info, Level}; + +mod lmp_event; + +const LOG_TAG: &str = "lmp_event_service_example"; + +fn main() { + info!("{LOG_TAG}: starting service"); + let logger_success = logger::init( + logger::Config::default().with_tag_on_device(LOG_TAG).with_min_level(Level::Trace) + ); + if !logger_success { + panic!("{LOG_TAG}: Failed to start logger"); + } + + binder::ProcessState::set_thread_pool_max_thread_count(0); + + let lmp_event_service = lmp_event::LmpEvent::new(); + let lmp_event_service_binder = BnBluetoothLmpEvent::new_binder(lmp_event_service, BinderFeatures::default()); + + binder::add_service( + &format!("{}/default", lmp_event::LmpEvent::get_descriptor()), + lmp_event_service_binder.as_binder(), + ).expect("Failed to register service"); + + binder::ProcessState::join_thread_pool() +} diff --git a/bluetooth/lmp_event/aidl/vts/Android.bp b/bluetooth/lmp_event/aidl/vts/Android.bp new file mode 100644 index 0000000000..b89351ed16 --- /dev/null +++ b/bluetooth/lmp_event/aidl/vts/Android.bp @@ -0,0 +1,20 @@ +cc_test { + name: "VtsHalLmpEventTargetTest", + defaults: [ + "VtsHalTargetTestDefaults", + "use_libaidlvintf_gtest_helper_static", + ], + srcs: ["VtsHalLmpEventTargetTest.cpp"], + shared_libs: [ + "libbinder", + "libbinder_ndk" + ], + static_libs: [ + "android.hardware.bluetooth.lmp_event-V1-ndk", + ], + test_suites: [ + "general-tests", + "vts", + ] +} + diff --git a/bluetooth/lmp_event/aidl/vts/VtsHalLmpEventTargetTest.cpp b/bluetooth/lmp_event/aidl/vts/VtsHalLmpEventTargetTest.cpp new file mode 100644 index 0000000000..c49f60bdd8 --- /dev/null +++ b/bluetooth/lmp_event/aidl/vts/VtsHalLmpEventTargetTest.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2023 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 std::shared_ptrecific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "lmp_event_hal_test" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using ::aidl::android::hardware::bluetooth::lmp_event::BnBluetoothLmpEventCallback; +using ::aidl::android::hardware::bluetooth::lmp_event::IBluetoothLmpEvent; +using ::aidl::android::hardware::bluetooth::lmp_event::IBluetoothLmpEventCallback; +using ::aidl::android::hardware::bluetooth::lmp_event::Direction; +using ::aidl::android::hardware::bluetooth::lmp_event::AddressType; +using ::aidl::android::hardware::bluetooth::lmp_event::LmpEventId; +using ::aidl::android::hardware::bluetooth::lmp_event::Timestamp; + +using ::android::ProcessState; +using ::ndk::SpAIBinder; + +namespace { + static constexpr std::chrono::milliseconds kEventTimeoutMs(10000); +} + +class BluetoothLmpEventTest : public testing::TestWithParam { + public: + virtual void SetUp() override { + ALOGI("%s", __func__); + + ibt_lmp_event_ = IBluetoothLmpEvent::fromBinder(SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); + ASSERT_NE(ibt_lmp_event_, nullptr); + + ibt_lmp_event_cb_ = ndk::SharedRefBase::make(*this); + ASSERT_NE(ibt_lmp_event_cb_, nullptr); + } + + virtual void TearDown() override { + ALOGI("%s", __func__); + ibt_lmp_event_->unregisterLmpEvents(address_type, address); + + ibt_lmp_event_cb_ = nullptr; + } + + class BluetoothLmpEventCallback : public BnBluetoothLmpEventCallback { + public: + BluetoothLmpEventTest& parent_; + BluetoothLmpEventCallback(BluetoothLmpEventTest& parent) + : parent_(parent) {} + ~BluetoothLmpEventCallback() = default; + + ::ndk::ScopedAStatus onEventGenerated(const Timestamp& timestamp, AddressType address_type, + const std::array& address, Direction direction, + LmpEventId lmp_event_id, char16_t conn_event_counter) override { + for (auto t: address) { + ALOGD("%s: 0x%02x", __func__, t); + } + if (direction == Direction::TX) { + ALOGD("%s: Transmitting", __func__); + } else if (direction == Direction::RX) { + ALOGD("%s: Receiving", __func__); + } + if (address_type == AddressType::PUBLIC) { + ALOGD("%s: Public address", __func__); + } else if (address_type == AddressType::RANDOM) { + ALOGD("%s: Random address", __func__); + } + if (lmp_event_id == LmpEventId::CONNECT_IND) { + ALOGD("%s: initiating connection", __func__); + } else if (lmp_event_id == LmpEventId::LL_PHY_UPDATE_IND) { + ALOGD("%s: PHY update indication", __func__); + } + + ALOGD("%s: time: %" PRId64 "counter value: %x", __func__, timestamp.bluetoothTimeUs, conn_event_counter); + + parent_.event_recv = true; + parent_.notify(); + + return ::ndk::ScopedAStatus::ok(); + } + ::ndk::ScopedAStatus onRegistered(bool status) override { + ALOGD("%s: status: %d", __func__, status); + parent_.status_recv = status; + parent_.notify(); + return ::ndk::ScopedAStatus::ok(); + } + }; + + inline void notify() { + std::unique_lock lock(lmp_event_mtx); + lmp_event_cv.notify_one(); + } + + inline void wait(bool is_register_event) { + std::unique_lock lock(lmp_event_mtx); + + + if (is_register_event) { + lmp_event_cv.wait(lock, [&]() { return status_recv == true; }); + } else { + lmp_event_cv.wait_for(lock, kEventTimeoutMs, + [&](){ return event_recv == true; }); + } + + } + + std::shared_ptr ibt_lmp_event_; + std::shared_ptr ibt_lmp_event_cb_; + + AddressType address_type; + std::array address; + + std::atomic event_recv; + bool status_recv; + + std::mutex lmp_event_mtx; + std::condition_variable lmp_event_cv; +}; + +TEST_P(BluetoothLmpEventTest, RegisterAndReceive) { + address = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; + address_type = AddressType::RANDOM; + std::vector lmp_event_ids{LmpEventId::CONNECT_IND, LmpEventId::LL_PHY_UPDATE_IND}; + + ibt_lmp_event_->registerForLmpEvents(ibt_lmp_event_cb_, address_type, address, lmp_event_ids); + wait(true); + EXPECT_EQ(true, status_recv); + + /* Wait for event generated here */ + wait(false); + EXPECT_EQ(true, event_recv); + + ibt_lmp_event_->unregisterLmpEvents(address_type, address); +} + +GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothLmpEventTest); +INSTANTIATE_TEST_SUITE_P(BluetoothLmpEvent, BluetoothLmpEventTest, + testing::ValuesIn(android::getAidlHalInstanceNames(IBluetoothLmpEvent::descriptor)), + android::PrintInstanceNameToString); + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + ProcessState::self()->setThreadPoolMaxThreadCount(1); + ProcessState::self()->startThreadPool(); + return RUN_ALL_TESTS(); +} + diff --git a/compatibility_matrices/compatibility_matrix.9.xml b/compatibility_matrices/compatibility_matrix.9.xml index de2e1d14bf..c86bb72f06 100644 --- a/compatibility_matrices/compatibility_matrix.9.xml +++ b/compatibility_matrices/compatibility_matrix.9.xml @@ -154,6 +154,14 @@ default + + android.hardware.bluetooth.lmp_event + 1 + + IBluetoothLmpEvent + default + + android.hardware.boot