OSDN Git Service

Remove direct dependency on libcutils
authorSonny Sasaka <sonnysasaka@google.com>
Tue, 9 Feb 2021 06:09:54 +0000 (22:09 -0800)
committerSonny Sasaka <sonnysasaka@google.com>
Tue, 9 Feb 2021 06:09:54 +0000 (22:09 -0800)
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
common/Android.bp
common/os_utils.cc [new file with mode: 0644]
common/os_utils.h [new file with mode: 0644]
stack/avdt/avdt_scb_act.cc
stack/smp/smp_l2c.cc

index b7aa7b9..5e67b7c 100644 (file)
@@ -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;
index 8757949..d21c593 100644 (file)
@@ -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 (file)
index 0000000..d6a0f32
--- /dev/null
@@ -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/common/os_utils.h b/common/os_utils.h
new file mode 100644 (file)
index 0000000..cf94243
--- /dev/null
@@ -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();
index 9ff9265..bf5a60a 100644 (file)
@@ -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
index 32d633f..d6e7c9a 100644 (file)
@@ -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"