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/gatt/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(FROM_HERE, base::BindOnce(
34                                      [](std::promise<pid_t> promise) {
35                                        promise.set_value(getpid());
36                                      },
37                                      std::move(promise)));
38     main_pid_ = future.get();
39   }
40 
41   {
42     std::promise<pid_t> promise;
43     auto future = promise.get_future();
44     do_in_jni_thread(base::BindOnce(
45         [](std::promise<pid_t> promise) { promise.set_value(getpid()); },
46         std::move(promise)));
47     jni_pid_ = future.get();
48   }
49 }
50 
DumpsysLite()51 void BtStackInfo::DumpsysLite() {
52   LOG_CONSOLE("main_pid:%u", main_pid_);
53   LOG_CONSOLE("jni_pid:%u", jni_pid_);
54 
55   int fd = STDIN_FILENO;
56   const char** arguments = nullptr;
57 
58   connection_manager::dump(fd);
59   PAN_Dumpsys(fd);
60   DumpsysHid(fd);
61   DumpsysBtaDm(fd);
62   bluetooth::shim::Dump(fd, arguments);
63 }
64