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