From 5b85d70cfe9dbe30c491b35e325df82f86f05cc2 Mon Sep 17 00:00:00 2001 From: Sonny Sasaka Date: Mon, 8 Feb 2021 22:09:54 -0800 Subject: [PATCH] Remove direct dependency on libcutils libcutils is Android-specific and does not exist in Linux/Chrome OS. This patch removes direct dependency on it and instead creates an abstract layer called os_utils which contain separate implementations for Android (using libcutils) and other OSes. Bug: 176847216 Tag: #refactor Test: atest --host bluetooth_test_common Change-Id: Ifaebbd2baf5d3f7d638d70b3a9b97a1cb7724d10 --- btif/src/btif_config.cc | 6 ++---- common/Android.bp | 1 + common/os_utils.cc | 28 ++++++++++++++++++++++++++++ common/os_utils.h | 17 +++++++++++++++++ stack/avdt/avdt_scb_act.cc | 2 +- stack/smp/smp_l2c.cc | 2 +- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 common/os_utils.cc create mode 100644 common/os_utils.h diff --git a/btif/src/btif_config.cc b/btif/src/btif_config.cc index b7aa7b94d..5e67b7c29 100644 --- a/btif/src/btif_config.cc +++ b/btif/src/btif_config.cc @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -43,6 +42,7 @@ #include "btif_keystore.h" #include "common/address_obfuscator.h" #include "common/metric_id_allocator.h" +#include "common/os_utils.h" #include "main/shim/config.h" #include "main/shim/shim.h" #include "osi/include/alarm.h" @@ -95,9 +95,7 @@ static std::unique_ptr btif_config_open(const char* filename); static bool config_checksum_pass(int check_bit) { return ((get_niap_config_compare_result() & check_bit) == check_bit); } -static bool btif_is_niap_mode() { - return getuid() == AID_BLUETOOTH && is_niap_mode(); -} +static bool btif_is_niap_mode() { return is_bluetooth_uid() && is_niap_mode(); } static bool btif_in_encrypt_key_name_list(std::string key); static const int CONFIG_FILE_COMPARE_PASS = 1; diff --git a/common/Android.bp b/common/Android.bp index 87579490e..d21c5939a 100644 --- a/common/Android.bp +++ b/common/Android.bp @@ -16,6 +16,7 @@ cc_library_static { "metric_id_allocator.cc", "metrics.cc", "once_timer.cc", + "os_utils.cc", "repeating_timer.cc", "time_util.cc", ], diff --git a/common/os_utils.cc b/common/os_utils.cc new file mode 100644 index 000000000..d6a0f322f --- /dev/null +++ b/common/os_utils.cc @@ -0,0 +1,28 @@ +/* + * Copyright 2021 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. + */ + +#ifdef OS_ANDROID +#include +#include +#endif + +bool is_bluetooth_uid() { +#ifdef OS_ANDROID + return getuid() == AID_BLUETOOTH; +#else + return false; +#endif +} diff --git a/common/os_utils.h b/common/os_utils.h new file mode 100644 index 000000000..cf9424367 --- /dev/null +++ b/common/os_utils.h @@ -0,0 +1,17 @@ +/* + * Copyright 2021 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. + */ + +bool is_bluetooth_uid(); diff --git a/stack/avdt/avdt_scb_act.cc b/stack/avdt/avdt_scb_act.cc index 9ff926509..bf5a60a9f 100644 --- a/stack/avdt/avdt_scb_act.cc +++ b/stack/avdt/avdt_scb_act.cc @@ -23,7 +23,6 @@ * ******************************************************************************/ -#include #include #include "a2dp_codec_api.h" #include "avdt_api.h" @@ -34,6 +33,7 @@ #include "bt_types.h" #include "bt_utils.h" #include "btu.h" +#include "log/log.h" #include "osi/include/osi.h" /* This table is used to lookup the callback event that matches a particular diff --git a/stack/smp/smp_l2c.cc b/stack/smp/smp_l2c.cc index 32d633f15..d6e7c9af7 100644 --- a/stack/smp/smp_l2c.cc +++ b/stack/smp/smp_l2c.cc @@ -24,8 +24,8 @@ #define LOG_TAG "bluetooth" -#include #include "bt_target.h" +#include "log/log.h" #include #include "btm_ble_api.h" -- 2.11.0