Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c040adc8 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

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
parent efc13cd1
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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",
    ],
+28 −0
Original line number Diff line number Diff line
/*
 * 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
}
+17 −0
Original line number Diff line number Diff line
/*
 * 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();
+1 −1
Original line number Diff line number Diff line
@@ -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
Loading