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