• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "common/audit_log.h"
18 
19 #include <format>
20 
21 #ifdef __ANDROID__
22 #include <log/log_event_list.h>
23 #endif  // __ANDROID__
24 
25 #include "common/strings.h"
26 #include "hci/hci_packets.h"
27 
28 namespace {
29 #if defined(__ANDROID__) && !defined(FUZZ_TARGET)
30 
31 // Tags for security logging, should be in sync with
32 // frameworks/base/core/java/android/app/admin/SecurityLogTags.logtags
33 constexpr int SEC_TAG_BLUETOOTH_CONNECTION = 210039;
34 
35 #endif /* defined(__ANDROID__) && !defined (FUZZ_TARGET) */
36 }  // namespace
37 
38 namespace bluetooth {
39 namespace common {
40 
LogConnectionAdminAuditEvent(const char * action,const hci::Address & address,hci::ErrorCode status)41 void LogConnectionAdminAuditEvent([[maybe_unused]] const char* action,
42                                   [[maybe_unused]] const hci::Address& address,
43                                   [[maybe_unused]] hci::ErrorCode status) {
44 #if defined(__ANDROID__) && !defined(FUZZ_TARGET)
45 
46   android_log_event_list(SEC_TAG_BLUETOOTH_CONNECTION)
47           << address.ToRedactedStringForLogging()
48           << /* success */ int32_t(status == hci::ErrorCode::SUCCESS)
49           << std::format("{}: {}", action, ErrorCodeText(status)) << LOG_ID_SECURITY;
50 
51 #endif /* defined(__ANDROID__) && !defined (FUZZ_TARGET) */
52 }
53 
54 }  // namespace common
55 }  // namespace bluetooth
56