• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 //! Implements LMP Event Example Service.
17 
18 
19 use android_hardware_bluetooth_lmp_event::aidl::android::hardware::bluetooth::lmp_event::IBluetoothLmpEvent::{
20     IBluetoothLmpEvent, BnBluetoothLmpEvent
21 };
22 
23 use binder::BinderFeatures;
24 use log::{info, LevelFilter};
25 
26 mod lmp_event;
27 
28 const LOG_TAG: &str = "lmp_event_service_example";
29 
main()30 fn main() {
31     info!("{LOG_TAG}: starting service");
32     let logger_success = logger::init(
33         logger::Config::default().with_tag_on_device(LOG_TAG).with_max_level(LevelFilter::Trace)
34     );
35     if !logger_success {
36         panic!("{LOG_TAG}: Failed to start logger");
37     }
38 
39     binder::ProcessState::set_thread_pool_max_thread_count(0);
40 
41     let lmp_event_service = lmp_event::LmpEvent::new();
42     let lmp_event_service_binder = BnBluetoothLmpEvent::new_binder(lmp_event_service, BinderFeatures::default());
43 
44     let descriptor = format!("{}/default", lmp_event::LmpEvent::get_descriptor());
45     if binder::is_declared(&descriptor).expect("Failed to check if declared") {
46         binder::add_service(&descriptor, lmp_event_service_binder.as_binder()).expect("Failed to register service");
47     } else {
48         info!("{LOG_TAG}: Failed to register service. Not declared.");
49     }
50     binder::ProcessState::join_thread_pool()
51 }
52