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