1 /*
2  * Copyright 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 
17 #include "test/headless/bt_stack_info.h"
18 
19 #include <unistd.h>
20 
21 #include "btif/include/btif_common.h"  // do_in_jni_thread
22 #include "btif/include/btif_hh.h"      // DumpsysHid
23 #include "main/shim/dumpsys.h"
24 #include "stack/connection_manager/connection_manager.h"
25 #include "stack/include/main_thread.h"
26 #include "stack/include/pan_api.h"  // PAN_Dumpsys
27 #include "test/headless/log.h"
28 
BtStackInfo()29 BtStackInfo::BtStackInfo() {
30   {
31     std::promise<pid_t> promise;
32     auto future = promise.get_future();
33     do_in_main_thread(base::BindOnce(
34             [](std::promise<pid_t> promise) { promise.set_value(getpid()); }, std::move(promise)));
35     main_pid_ = future.get();
36   }
37 
38   {
39     std::promise<pid_t> promise;
40     auto future = promise.get_future();
41     do_in_jni_thread(base::BindOnce(
42             [](std::promise<pid_t> promise) { promise.set_value(getpid()); }, std::move(promise)));
43     jni_pid_ = future.get();
44   }
45 }
46 
DumpsysLite()47 void BtStackInfo::DumpsysLite() {
48   LOG_CONSOLE("main_pid:%u", main_pid_);
49   LOG_CONSOLE("jni_pid:%u", jni_pid_);
50 
51   int fd = STDIN_FILENO;
52   const char** arguments = nullptr;
53 
54   connection_manager::dump(fd);
55   PAN_Dumpsys(fd);
56   DumpsysHid(fd);
57   DumpsysBtaDm(fd);
58   bluetooth::shim::Dump(fd, arguments);
59 }
60