internal dependency updates

PiperOrigin-RevId: 672555643
This commit is contained in:
Guogang Li
2024-09-09 08:36:04 -07:00
committed by Copybara-Service
parent b15cbddb8b
commit 3c8737f92d
16 changed files with 189 additions and 209 deletions
+131 -124
View File
@@ -16,13 +16,27 @@
licenses(["notice"])
cc_library(
name = "logging",
hdrs = [
"logging.h",
],
visibility = [
"//:__subpackages__",
],
deps = [
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/log:globals",
],
)
cc_library(
name = "base",
srcs = [
"base64_utils.cc",
"bluetooth_utils.cc",
"input_stream.cc",
"nsd_service_info.cc",
"prng.cc",
],
hdrs = [
@@ -46,18 +60,12 @@ cc_library(
],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//:__subpackages__",
"//chrome/chromeos/assistant/data_migration/lib:__pkg__",
"//connections:__subpackages__",
"//fastpair:__subpackages__",
"//internal/platform:__subpackages__",
"//internal/platform/implementation:__subpackages__",
"//internal/preferences:__subpackages__",
"//internal/weave:__subpackages__",
"//presence:__subpackages__",
"//sharing:__subpackages__",
],
deps = [
"//proto:connections_enums_cc_proto",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/functional:any_invocable",
@@ -77,7 +85,6 @@ cc_library(
],
hdrs = [
"base_input_stream.h",
"base_mutex_lock.h",
"byte_utils.h",
],
visibility = [
@@ -86,7 +93,6 @@ cc_library(
],
deps = [
":base",
"//internal/platform/implementation:types",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings:str_format",
],
@@ -113,37 +119,6 @@ cc_library(
],
)
cc_library(
name = "connection_info",
srcs = [
"ble_connection_info.cc",
"bluetooth_connection_info.cc",
"connection_info.cc",
"wifi_lan_connection_info.cc",
],
hdrs = [
"ble_connection_info.h",
"bluetooth_connection_info.h",
"connection_info.h",
"wifi_lan_connection_info.h",
],
visibility = [
"//connections/implementation:__pkg__",
"//connections/v3:__pkg__",
"//internal/interop:__pkg__",
"//presence:__subpackages__",
],
deps = [
":types",
"//proto:connections_enums_cc_proto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:variant",
],
)
cc_library(
name = "error_code_recorder",
srcs = [
@@ -155,7 +130,7 @@ cc_library(
],
visibility = ["//connections/implementation:__subpackages__"],
deps = [
":types",
":logging",
"//proto:connections_enums_cc_proto",
"//proto/errorcode:error_code_enums_cc_proto",
"@com_google_absl//absl/functional:any_invocable",
@@ -177,103 +152,40 @@ cc_library(
"//presence:__subpackages__",
],
deps = [
"//internal/platform/implementation:types",
":base",
"@boringssl//:crypto",
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "test_util",
testonly = True,
name = "connection_info",
srcs = [
"medium_environment.cc",
"ble_connection_info.cc",
"bluetooth_connection_info.cc",
"connection_info.cc",
"wifi_lan_connection_info.cc",
],
hdrs = [
"medium_environment.h",
"ble_connection_info.h",
"bluetooth_connection_info.h",
"connection_info.h",
"wifi_lan_connection_info.h",
],
visibility = [
"//connections:__subpackages__",
"//fastpair:__subpackages__",
"//internal/platform/implementation:__subpackages__",
"//connections/implementation:__pkg__",
"//connections/v3:__pkg__",
"//internal/interop:__pkg__",
"//presence:__subpackages__",
],
deps = [
":base",
":types",
":uuid",
"//internal/base",
"//internal/platform/implementation:comm",
"//internal/test",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
":logging",
"//proto:connections_enums_cc_proto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:optional",
],
)
cc_test(
name = "platform_base_test",
srcs = [
"bluetooth_utils_test.cc",
"byte_array_test.cc",
"feature_flags_test.cc",
"input_stream_test.cc",
"prng_test.cc",
],
deps = [
":base",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/hash:hash_testing",
"@com_google_absl//absl/synchronization",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "platform_util_test",
srcs = [
"byte_utils_test.cc",
],
deps = [
":base",
":util",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "cancellation_flag_test",
srcs = [
"cancellation_flag_test.cc",
],
deps = [
":base",
":cancellation_flag",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "error_code_recorder_test",
srcs = [
"error_code_recorder_test.cc",
],
deps = [
":error_code_recorder",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/types:variant",
],
)
@@ -432,6 +344,101 @@ cc_library(
],
)
cc_library(
name = "test_util",
testonly = True,
srcs = [
"medium_environment.cc",
],
hdrs = [
"medium_environment.h",
],
visibility = [
"//connections:__subpackages__",
"//fastpair:__subpackages__",
"//internal/platform/implementation:__subpackages__",
"//presence:__subpackages__",
],
deps = [
":base",
":types",
":uuid",
"//internal/base",
"//internal/platform/implementation:comm",
"//internal/test",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:optional",
],
)
cc_test(
name = "platform_base_test",
srcs = [
"bluetooth_utils_test.cc",
"byte_array_test.cc",
"feature_flags_test.cc",
"input_stream_test.cc",
"prng_test.cc",
],
deps = [
":base",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/hash:hash_testing",
"@com_google_absl//absl/synchronization",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "platform_util_test",
srcs = [
"byte_utils_test.cc",
],
deps = [
":base",
":util",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "cancellation_flag_test",
srcs = [
"cancellation_flag_test.cc",
],
deps = [
":base",
":cancellation_flag",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "error_code_recorder_test",
srcs = [
"error_code_recorder_test.cc",
],
deps = [
":error_code_recorder",
":test_util",
"//internal/platform/implementation/g3", # build_cleaner: keep
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "public_device_test",
size = "small",
+4
View File
@@ -15,6 +15,10 @@
#ifndef PLATFORM_BASE_BASE_INPUT_STREAM_H_
#define PLATFORM_BASE_BASE_INPUT_STREAM_H_
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include "internal/platform/byte_array.h"
#include "internal/platform/exception.h"
#include "internal/platform/input_stream.h"
-38
View File
@@ -1,38 +0,0 @@
// Copyright 2020 Google LLC
//
// 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
//
// https://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.
#ifndef PLATFORM_BASE_BASE_MUTEX_LOCK_H_
#define PLATFORM_BASE_BASE_MUTEX_LOCK_H_
#include "absl/base/thread_annotations.h"
#include "internal/platform/implementation/mutex.h"
namespace nearby {
// An RAII mechanism to acquire a Lock over a block of code.
class ABSL_SCOPED_LOCKABLE BaseMutexLock final {
public:
explicit BaseMutexLock(api::Mutex* mutex) ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex)
: mutex_(mutex) {
mutex_->Lock();
}
~BaseMutexLock() ABSL_UNLOCK_FUNCTION() { mutex_->Unlock(); }
private:
api::Mutex* mutex_;
};
} // namespace nearby
#endif // PLATFORM_BASE_BASE_MUTEX_LOCK_H_
+6
View File
@@ -15,9 +15,15 @@
#include "internal/platform/bluetooth_utils.h"
#include <algorithm>
#include <cstdint>
#include <string>
#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
namespace nearby {
+3
View File
@@ -15,6 +15,9 @@
#ifndef PLATFORM_BASE_BLUETOOTH_UTILS_H_
#define PLATFORM_BASE_BLUETOOTH_UTILS_H_
#include <cstdint>
#include <string>
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
+1
View File
@@ -24,6 +24,7 @@
#include <utility>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
namespace nearby {
+2
View File
@@ -15,9 +15,11 @@
#include "internal/platform/byte_utils.h"
#include <cstdlib>
#include <string>
#include "absl/strings/str_format.h"
#include "internal/platform/base_input_stream.h"
#include "internal/platform/byte_array.h"
namespace nearby {
+1
View File
@@ -15,6 +15,7 @@
#ifndef PLATFORM_BASE_BYTE_UTILS_H_
#define PLATFORM_BASE_BYTE_UTILS_H_
#include <string>
#include "internal/platform/byte_array.h"
namespace nearby {
+3 -2
View File
@@ -17,6 +17,7 @@
#include <cstdint>
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/time.h"
@@ -45,7 +46,7 @@ class FeatureFlags {
bool enable_send_payload_offset = true;
// Provide better bookkeeping for bandwidth upgrade initiation. This is
// necessary to properly support multiple BWU mediums, multiple service, and
// multiple endpionts.
// multiple endpoints.
bool support_multiple_bwu_mediums = true;
// Allows the code to change the bluetooth radio state
bool enable_set_radio_state = false;
@@ -53,7 +54,7 @@ class FeatureFlags {
// create connection with remote device in a duration.
bool enable_connection_timeout = true;
// Controls enable or disable to track the status of Bluetooth classic
// conncetion.
// connection.
bool enable_bluetooth_connection_status_track = true;
// Controls enable or disable BLE scan advertisement for fast pair
// service uuid 0x2cfe
+1
View File
@@ -15,6 +15,7 @@
#ifndef PLATFORM_BASE_INPUT_STREAM_H_
#define PLATFORM_BASE_INPUT_STREAM_H_
#include <cstddef>
#include <cstdint>
#include "internal/platform/byte_array.h"
+1
View File
@@ -15,6 +15,7 @@
#ifndef PLATFORM_BASE_LISTENERS_H_
#define PLATFORM_BASE_LISTENERS_H_
#include <functional>
#include "absl/functional/any_invocable.h"
namespace nearby {
-21
View File
@@ -1,21 +0,0 @@
// Copyright 2021 Google LLC
//
// 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
//
// https://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.
#include "internal/platform/nsd_service_info.h"
namespace nearby {
constexpr absl::string_view NsdServiceInfo::kNsdTypeFormat;
} // namespace nearby
+2
View File
@@ -16,8 +16,10 @@
#define PLATFORM_BASE_NSD_SERVICE_INFO_H_
#include <string>
#include <utility>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
namespace nearby {
+13 -22
View File
@@ -21,29 +21,20 @@
#include <utility>
#include "absl/base/thread_annotations.h"
#include "internal/platform/base_mutex_lock.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/condition_variable.h"
#include "internal/platform/exception.h"
#include "internal/platform/implementation/condition_variable.h"
#include "internal/platform/implementation/mutex.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/input_stream.h"
#include "internal/platform/mutex.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/output_stream.h"
namespace nearby {
namespace {
using Platform = api::ImplementationPlatform;
class Pipe {
public:
Pipe() {
#pragma push_macro("CreateMutex")
#undef CreateMutex
mutex_ = Platform::CreateMutex(api::Mutex::Mode::kRegular);
#pragma pop_macro("CreateMutex")
cond_ = Platform::CreateConditionVariable(mutex_.get());
}
Pipe() = default;
class PipeInputStream : public InputStream {
public:
@@ -99,12 +90,12 @@ class Pipe {
std::deque<ByteArray> ABSL_GUARDED_BY(mutex_) buffer_;
// Order of declaration matters:
// - mutex must be defined before condvar;
std::unique_ptr<api::Mutex> mutex_;
std::unique_ptr<api::ConditionVariable> cond_;
Mutex mutex_;
ConditionVariable cond_{&mutex_};
};
ExceptionOr<ByteArray> Pipe::Read(size_t size) {
BaseMutexLock lock(mutex_.get());
MutexLock lock(&mutex_);
// We're done reading all the chunks that were written before the OutputStream
// was closed, so there's nothing to do here other than return an empty chunk
@@ -114,7 +105,7 @@ ExceptionOr<ByteArray> Pipe::Read(size_t size) {
}
while (buffer_.empty() && !input_stream_closed_) {
Exception wait_exception = cond_->Wait();
Exception wait_exception = cond_.Wait();
if (wait_exception.Raised()) {
return ExceptionOr<ByteArray>{wait_exception};
@@ -149,22 +140,22 @@ ExceptionOr<ByteArray> Pipe::Read(size_t size) {
}
Exception Pipe::Write(const ByteArray& data) {
BaseMutexLock lock(mutex_.get());
MutexLock lock(&mutex_);
return WriteLocked(data);
}
void Pipe::MarkInputStreamClosed() {
BaseMutexLock lock(mutex_.get());
MutexLock lock(&mutex_);
if (input_stream_closed_) return;
input_stream_closed_ = true;
// Trigger cond_ to unblock a potentially-blocked call to read(), and to let
// it know to return Exception::IO.
cond_->Notify();
cond_.Notify();
}
void Pipe::MarkOutputStreamClosed() {
BaseMutexLock lock(mutex_.get());
MutexLock lock(&mutex_);
if (output_stream_closed_) return;
// Write a sentinel null chunk before marking output_stream_closed as true.
WriteLocked(ByteArray{});
@@ -179,7 +170,7 @@ Exception Pipe::WriteLocked(const ByteArray& data) {
buffer_.push_back(data);
// Trigger cond_ to unblock a potentially-blocked call to read(), now that
// there's more data for it to consume.
cond_->Notify();
cond_.Notify();
return {Exception::kSuccess};
}
+2
View File
@@ -14,6 +14,8 @@
#include "internal/platform/prng.h"
#include <cstdint>
#include <cstdlib>
#include <limits>
#include "absl/time/clock.h"
+19 -2
View File
@@ -28,7 +28,9 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "internal/platform/implementation/crypto.h"
#include "internal/platform/byte_array.h"
#include <openssl/base.h>
#include <openssl/digest.h>
namespace nearby {
namespace {
@@ -39,6 +41,21 @@ std::ostream& write_hex(std::ostream& os, absl::string_view data) {
}
return os;
}
ByteArray Hash(absl::string_view input, const EVP_MD* algo) {
unsigned int md_out_size = EVP_MAX_MD_SIZE;
uint8_t digest_buffer[EVP_MAX_MD_SIZE];
if (input.empty()) return {};
if (!EVP_Digest(input.data(), input.size(), digest_buffer, &md_out_size, algo,
nullptr))
return {};
return ByteArray{reinterpret_cast<char*>(digest_buffer), md_out_size};
}
ByteArray Md5(absl::string_view input) { return Hash(input, EVP_md5()); }
} // namespace
// Based on the Java implementation
@@ -87,7 +104,7 @@ std::optional<Uuid> Uuid::FromString(absl::string_view data) {
Uuid::Uuid(absl::string_view data) {
// Based on the Java counterpart at
// http://androidxref.com/8.0.0_r4/xref/libcore/ojluni/src/main/java/java/util/UUID.java#162.
std::string md5_data(Crypto::Md5(data));
std::string md5_data(Md5(data));
md5_data[6] &= 0x0f; // Clear version.
md5_data[6] |= 0x30; // Set to version 3.
md5_data[8] &= 0x3f; // Clear variant.