1 // Copyright 2024, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //! Declared HAL services
16 //! - android.hardware.bluetooth.IBluetoothHci/default
17
18 #![allow(unused_imports)]
19
20 use android_hardware_bluetooth::aidl::android::hardware::bluetooth::IBluetoothHci::BnBluetoothHci;
21 use binder::{self, BinderFeatures, ProcessState};
22 use log::{error, info};
23
24 mod hci;
25
26 #[derive(argh::FromArgs, Debug)]
27 /// Bluetooth HAL service.
28 struct Opt {
29 #[argh(option, default = "String::from(\"/dev/hvc5\")")]
30 /// select the HCI serial device.
31 serial: String,
32 }
33
main()34 fn main() {
35 let opt: Opt = argh::from_env();
36
37 android_logger::init_once(
38 android_logger::Config::default()
39 .with_tag("bluetooth-cf")
40 .with_max_level(log::LevelFilter::Debug),
41 );
42
43 // Redirect panic messages to logcat.
44 std::panic::set_hook(Box::new(|message| {
45 error!("{}", message);
46 std::process::exit(-1);
47 }));
48
49 // Start binder thread pool with the minimum threads pool (= 1),
50 // because Bluetooth APEX is the only user of the Bluetooth Audio HAL.
51 ProcessState::set_thread_pool_max_thread_count(0);
52 ProcessState::start_thread_pool();
53
54 let hci_binder =
55 BnBluetoothHci::new_binder(hci::BluetoothHci::new(&opt.serial), BinderFeatures::default());
56
57 info!("Starting ..IBluetoothHci/default");
58 binder::add_service("android.hardware.bluetooth.IBluetoothHci/default", hci_binder.as_binder())
59 .expect("Failed to register IBluetoothHci/default service");
60
61 ProcessState::join_thread_pool();
62 info!("The Bluetooth HAL is shutting down");
63 }
64