summaryrefslogtreecommitdiff
path: root/system/main/shim/dumpsys.h
blob: 818e4f8ebe1eee2fef6b3fb1b1fd20bd68af44d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <functional>
#include <list>
#include <string>

#define LOG_DUMPSYS(fd, fmt, args...)                 \
  do {                                                \
    dprintf(fd, "%s " fmt "\n", DUMPSYS_TAG, ##args); \
  } while (false)

#define LOG_DUMPSYS_TITLE(fd, title)         \
  do {                                       \
    dprintf(fd, " ----- %s -----\n", title); \
  } while (false)

constexpr char kPrivateAddressPrefix[] = "xx:xx:xx:xx";
#define PRIVATE_ADDRESS(addr)                                            \
  (addr.ToString()                                                       \
       .replace(0, strlen(kPrivateAddressPrefix), kPrivateAddressPrefix) \
       .c_str())

#define PRIVATE_CELL(number)                                      \
  (number                                                         \
       .replace(0, (number.size() > 2) ? number.size() - 2 : 0,   \
                (number.size() > 2) ? number.size() - 2 : 0, '*') \
       .c_str())

#define PRIVATE_NAME(name) (name)

inline double ticks_to_seconds(uint16_t ticks) {
  return (static_cast<double>(ticks) * 0.625 * 0.001);
}

inline double supervision_timeout_to_seconds(uint16_t timeout) {
  return (static_cast<double>(timeout) * 0.01);
}

namespace bluetooth {
namespace shim {

using DumpsysFunction = std::function<void(int fd)>;

/**
 * Entrypoint from legacy stack to provide dumpsys functionality
 * for both the legacy shim and the Gabeldorsche stack.
 */
void Dump(int fd, const char** args);

/**
 * Dumpsys access for legacy shim modules.
 */
void RegisterDumpsysFunction(const void* token, DumpsysFunction func);
void UnregisterDumpsysFunction(const void* token);

}  // namespace shim
}  // namespace bluetooth