• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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_shim_storage"
18 
19 #include <unordered_map>
20 
21 #include "main/shim/dumpsys.h"
22 #include "main/shim/entry.h"
23 #include "main/shim/shim.h"
24 
25 #include "shim/dumpsys.h"
26 
27 namespace {
28 
29 constexpr char kModuleName[] = "shim::legacy::dumpsys";
30 static std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>
31     dumpsys_functions_;
32 
33 }  // namespace
34 
RegisterDumpsysFunction(const void * token,DumpsysFunction func)35 void bluetooth::shim::RegisterDumpsysFunction(const void* token,
36                                               DumpsysFunction func) {
37   CHECK(dumpsys_functions_.find(token) == dumpsys_functions_.end());
38   dumpsys_functions_.insert({token, func});
39 }
40 
UnregisterDumpsysFunction(const void * token)41 void bluetooth::shim::UnregisterDumpsysFunction(const void* token) {
42   CHECK(dumpsys_functions_.find(token) != dumpsys_functions_.end());
43   dumpsys_functions_.erase(token);
44 }
45 
Dump(int fd,const char ** args)46 void bluetooth::shim::Dump(int fd, const char** args) {
47   if (dumpsys_functions_.empty()) {
48     dprintf(fd, "%s No registered dumpsys shim legacy targets\n", kModuleName);
49   } else {
50     dprintf(fd, "%s Dumping shim legacy targets:%zd\n", kModuleName,
51             dumpsys_functions_.size());
52     for (auto& dumpsys : dumpsys_functions_) {
53       dumpsys.second(fd);
54     }
55   }
56   if (bluetooth::shim::is_gd_stack_started_up()) {
57     if (bluetooth::shim::is_gd_dumpsys_module_started()) {
58       bluetooth::shim::GetDumpsys()->Dump(fd, args);
59     } else {
60       dprintf(fd, "%s NOTE: gd dumpsys module not loaded or started\n",
61               kModuleName);
62     }
63   } else {
64     dprintf(fd, "%s gd stack is enabled but not started\n", kModuleName);
65   }
66 }
67