summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sonny Sasaka <sonnysasaka@google.com> 2021-02-08 22:09:54 -0800
committer Sonny Sasaka <sonnysasaka@google.com> 2021-02-08 22:09:54 -0800
commitc040adc8126d831787409e66e9c821d3c25cf7ec (patch)
tree9db591c5a3f11a09071f778908438647feac9305
parentefc13cd1cfb6c0b7ac1573c20c388bb0e033df8a (diff)
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
-rw-r--r--system/btif/src/btif_config.cc6
-rw-r--r--system/common/Android.bp1
-rw-r--r--system/common/os_utils.cc28
-rw-r--r--system/common/os_utils.h17
-rw-r--r--system/stack/avdt/avdt_scb_act.cc2
-rw-r--r--system/stack/smp/smp_l2c.cc2
6 files changed, 50 insertions, 6 deletions
diff --git a/system/btif/src/btif_config.cc b/system/btif/src/btif_config.cc
index b7aa7b94d2..5e67b7c295 100644
--- a/system/btif/src/btif_config.cc
+++ b/system/btif/src/btif_config.cc
@@ -22,7 +22,6 @@
#include <base/logging.h>
#include <openssl/rand.h>
-#include <private/android_filesystem_config.h>
#include <unistd.h>
#include <cctype>
@@ -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<config_t> 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/system/common/Android.bp b/system/common/Android.bp
index 313ad7a625..51265e425c 100644
--- a/system/common/Android.bp
+++ b/system/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/system/common/os_utils.cc b/system/common/os_utils.cc
new file mode 100644
index 0000000000..d6a0f322f2
--- /dev/null
+++ b/system/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 <private/android_filesystem_config.h>
+#include <unistd.h>
+#endif
+
+bool is_bluetooth_uid() {
+#ifdef OS_ANDROID
+ return getuid() == AID_BLUETOOTH;
+#else
+ return false;
+#endif
+}
diff --git a/system/common/os_utils.h b/system/common/os_utils.h
new file mode 100644
index 0000000000..cf94243679
--- /dev/null
+++ b/system/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/system/stack/avdt/avdt_scb_act.cc b/system/stack/avdt/avdt_scb_act.cc
index 9ff9265099..bf5a60a9fa 100644
--- a/system/stack/avdt/avdt_scb_act.cc
+++ b/system/stack/avdt/avdt_scb_act.cc
@@ -23,7 +23,6 @@
*
******************************************************************************/
-#include <cutils/log.h>
#include <string.h>
#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/system/stack/smp/smp_l2c.cc b/system/stack/smp/smp_l2c.cc
index 32d633f15c..d6e7c9af75 100644
--- a/system/stack/smp/smp_l2c.cc
+++ b/system/stack/smp/smp_l2c.cc
@@ -24,8 +24,8 @@
#define LOG_TAG "bluetooth"
-#include <cutils/log.h>
#include "bt_target.h"
+#include "log/log.h"
#include <string.h>
#include "btm_ble_api.h"