1 /*
2  * Copyright 2022 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 #define LOG_TAG "bt_headless_discovery"
18 
19 #include "test/headless/discovery/discovery.h"
20 
21 #include <future>
22 
23 #include "btif/include/btif_api.h"
24 #include "os/log.h"  // android log only
25 #include "stack/include/sdp_api.h"
26 #include "test/headless/bt_property.h"
27 #include "test/headless/get_options.h"
28 #include "test/headless/headless.h"
29 #include "test/headless/interface.h"
30 #include "test/headless/log.h"
31 #include "test/headless/messenger.h"
32 #include "test/headless/sdp/sdp.h"
33 #include "test/headless/stopwatch.h"
34 #include "test/headless/timeout.h"
35 #include "types/bluetooth/uuid.h"
36 #include "types/raw_address.h"
37 
38 using namespace bluetooth::test::headless;
39 using namespace std::chrono_literals;
40 
41 namespace {
42 
start_discovery(unsigned int num_loops,const RawAddress & raw_address)43 int start_discovery([[maybe_unused]] unsigned int num_loops,
44                     const RawAddress& raw_address) {
45   RawAddress bd_addr{raw_address};
46 
47   Stopwatch acl_stopwatch("ACL_connection");
48   Stopwatch sdp_stopwatch("SDP_discovery");
49 
50   LOG_CONSOLE("Started service discovery %s", bd_addr.ToString().c_str());
51 
52   LOG_CONSOLE("Dumpsys system");
53   bluetoothInterface.dump(2, nullptr);
54   LOG_CONSOLE("Done dumpsys system");
55 
56   return 0;
57 }
58 
59 }  // namespace
60 
Run()61 int bluetooth::test::headless::Discovery::Run() {
62   if (options_.loop_ < 1) {
63     LOG_CONSOLE("This test requires at least a single loop");
64     options_.Usage();
65     return -1;
66   }
67   if (options_.device_.size() != 1) {
68     LOG_CONSOLE("This test requires a single device specified");
69     options_.Usage();
70     return -1;
71   }
72   return RunOnHeadlessStack<int>([this]() {
73     return start_discovery(options_.loop_, options_.device_.front());
74   });
75 }
76