From c20d7affc4eb0f163f2145c793d8aa1cfdd9a0b5 Mon Sep 17 00:00:00 2001 From: Lasan Mahaliyana Date: Sat, 13 Jun 2026 22:02:21 +0530 Subject: [PATCH] finished merge with upstream --- .bazelrc | 6 ++ MODULE.bazel | 3 +- .../flags/nearby_connections_feature_flags.h | 4 -- internal/platform/implementation/BUILD | 3 - .../implementation/linux/ble_gatt_client.cc | 56 ------------------- .../implementation/linux/ble_gatt_client.h | 8 --- .../implementation/linux/ble_v2_socket.cc | 23 ++++---- .../implementation/linux/device_info.cc | 15 ++--- .../implementation/linux/device_info.h | 12 ++-- .../implementation/linux/file_path.cc | 4 +- .../linux/preferences_manager.cc | 2 +- 11 files changed, 31 insertions(+), 105 deletions(-) diff --git a/.bazelrc b/.bazelrc index eee8fe04..ad54b2bd 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,4 +1,10 @@ build --action_env=BAZEL_CXXOPTS=-"std=c++20" --repo_env=BAZEL_CONLYOPTS="-std=gnu17" +build --action_env=CC=/usr/bin/clang +build --action_env=CXX=/usr/bin/clang++ +build --check_visibility=false --spawn_strategy=standalone --verbose_failures +build --cxxopt=-std=c++20 +build --cxxopt='-fvisibility-inlines-hidden' +build --host_cxxopt=-std=c++20 # Definition of --config=memcheck build:memcheck --strip=never --test_timeout=3600 common --enable_bzlmod diff --git a/MODULE.bazel b/MODULE.bazel index a465e98b..ae812f69 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -190,10 +190,11 @@ cmake( "CMAKE_C_STANDARD": "17", "CMAKE_C_STANDARD_REQUIRED": "ON", "CMAKE_C_EXTENSIONS": "ON", + "CMAKE_INSTALL_LIBDIR": "lib", }, env = { # CMake still needs pkg-config to pass its internal configuration checks for systemd - "PKG_CONFIG_PATH": "/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig", + "PKG_CONFIG_PATH": "/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig", }, # Link the systemd dependency you defined in your WORKSPACE deps = ["@libsystemd//:libsystemd"], diff --git a/connections/implementation/flags/nearby_connections_feature_flags.h b/connections/implementation/flags/nearby_connections_feature_flags.h index 8218922a..d6cd22d4 100755 --- a/connections/implementation/flags/nearby_connections_feature_flags.h +++ b/connections/implementation/flags/nearby_connections_feature_flags.h @@ -92,10 +92,6 @@ constexpr auto kMediumMaxAllowedReadBytes = // Disable/Enable refactor of BLE/L2CAP in Nearby Connections SDK. constexpr auto kRefactorBleL2cap = flags::Flag(kConfigPackage, "45737079", false); -// Enable/Disable usage of shared CBPeripheralManager for GATT and L2CAP -// servers. -constexpr auto kEnableSharedPeripheralManager = - flags::Flag(kConfigPackage, "45770787", false); // Set the safe-to-disconnect version. // 0. Disabled all. 1. safe-to-disconnect 2. reserved 3. // auto-reconnect(deprecated) diff --git a/internal/platform/implementation/BUILD b/internal/platform/implementation/BUILD index 5c8e7b51..c0c94231 100644 --- a/internal/platform/implementation/BUILD +++ b/internal/platform/implementation/BUILD @@ -140,11 +140,8 @@ cc_library( "//internal/platform:uuid", "//internal/proto:credential_cc_proto", "//internal/proto:local_credential_cc_proto", -<<<<<<< HEAD # "//third_party/webrtc/files/stable/webrtc/api:create_peerconnection_factory", # buildcleaner: keep # "//third_party/webrtc/files/stable/webrtc/api:peer_connection_interface", -======= ->>>>>>> nearby/main "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", diff --git a/internal/platform/implementation/linux/ble_gatt_client.cc b/internal/platform/implementation/linux/ble_gatt_client.cc index 1c876f85..727643f7 100644 --- a/internal/platform/implementation/linux/ble_gatt_client.cc +++ b/internal/platform/implementation/linux/ble_gatt_client.cc @@ -172,62 +172,6 @@ bool GattClient::WriteCharacteristic( return success; } -bool GattClient::SetCharacteristicSubscription( - const api::ble::GattCharacteristic &characteristic, bool enable, - absl::AnyInvocable - on_characteristic_changed_cb) { - LOG(INFO) << __func__ << ": " - << (enable ? "Enabling" : "Disabling") - << " subscription for characteristic '" - << absl::Substitute("$0", characteristic) << "'"; - absl::MutexLock lock(&characteristics_mutex_); - if (characteristics_.count(characteristic) == 0) { - LOG(ERROR) << __func__ << ": Unknown characteristic '" - << absl::Substitute("$0", characteristic) << "'"; - return false; - } - - if (enable) { - auto subbed_chr = gatt_discovery_->GetSubscribedCharacteristic( - peripheral_object_path_, characteristic.service_uuid, - characteristic.uuid, std::move(on_characteristic_changed_cb)); - if (subbed_chr == nullptr) { - LOG(INFO) << __func__ - << ": Failed to get subscribed characteristic client."; - return false; - } - try { - subbed_chr->StartNotify(); - } catch (const sdbus::Error &e) { - DBUS_LOG_METHOD_CALL_ERROR(subbed_chr, "StartNotify", e); - return false; - } - characteristics_[characteristic] = std::move(subbed_chr); - } else if (std::holds_alternative< - std::unique_ptr>( - characteristics_[characteristic])) { - auto chr = gatt_discovery_->GetCharacteristic(peripheral_object_path_, - characteristic.service_uuid, - characteristic.uuid); - if (chr == nullptr) { - LOG(INFO) << __func__ - << ": Failed to get characteristic client for unsubscribe."; - return false; - } - try { - chr->StopNotify(); - } catch (const sdbus::Error &e) { - DBUS_LOG_METHOD_CALL_ERROR(chr, "StopNotify", e); - return false; - } - - characteristics_[characteristic] = std::move(chr); - } - LOG(INFO) << __func__ << ": Subscription update succeeded for characteristic '" - << absl::Substitute("$0", characteristic) << "'"; - return true; -} - void GattClient::Disconnect() { LOG(INFO) << __func__ << ": Disconnecting GATT client for peripheral " diff --git a/internal/platform/implementation/linux/ble_gatt_client.h b/internal/platform/implementation/linux/ble_gatt_client.h index 1f755229..bb41a97b 100644 --- a/internal/platform/implementation/linux/ble_gatt_client.h +++ b/internal/platform/implementation/linux/ble_gatt_client.h @@ -182,14 +182,6 @@ class GattClient : public api::ble::GattClient { absl::string_view value, WriteType type) override ABSL_LOCKS_EXCLUDED(characteristics_mutex_); - // https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic,%20boolean) - // - // Enable or disable notifications/indications for a given characteristic. - bool SetCharacteristicSubscription( - const api::ble::GattCharacteristic &characteristic, bool enable, - absl::AnyInvocable - on_characteristic_changed_cb) override - ABSL_LOCKS_EXCLUDED(characteristics_mutex_); // https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#disconnect() void Disconnect() override; diff --git a/internal/platform/implementation/linux/ble_v2_socket.cc b/internal/platform/implementation/linux/ble_v2_socket.cc index d29791f4..ab3bc725 100644 --- a/internal/platform/implementation/linux/ble_v2_socket.cc +++ b/internal/platform/implementation/linux/ble_v2_socket.cc @@ -242,18 +242,19 @@ void BleV2Socket::SetGattClient( }); // Subscribe to RX characteristic to receive data - bool subscribed = gatt_client_->SetCharacteristicSubscription( - rx_char_, /*enable=*/true, - [this](absl::string_view value) { - if (!IsClosed()) { - ByteArray data(value.data(), value.size()); - input_stream_.ReceiveData(data); - } - }); - if (!subscribed) { - LOG(ERROR) << "Failed to subscribe to RX characteristic"; - } + //bool subscribed = gatt_client_->SetCharacteristicSubscription( + // rx_char_, /*enable=*/true, + // [this](absl::string_view value) { + // if (!IsClosed()) { + // ByteArray data(value.data(), value.size()); + // input_stream_.ReceiveData(data); + // } + // }); + + //if (!subscribed) { + // LOG(ERROR) << "Failed to subscribe to RX characteristic"; + //} LOG(INFO) << "BLE socket configured with GATT client, RX: " << std::string(rx_char.uuid) diff --git a/internal/platform/implementation/linux/device_info.cc b/internal/platform/implementation/linux/device_info.cc index a47e961a..919102e5 100644 --- a/internal/platform/implementation/linux/device_info.cc +++ b/internal/platform/implementation/linux/device_info.cc @@ -93,7 +93,7 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const { } -std::optional DeviceInfo::GetDownloadPath() const { +FilePath DeviceInfo::GetDownloadPath() const { char *dir = getenv("XDG_DOWNLOAD_DIR"); if (dir == nullptr) { return FilePath("/tmp"); @@ -101,7 +101,7 @@ std::optional DeviceInfo::GetDownloadPath() const { return FilePath(std::string(dir)); } -std::optional DeviceInfo::GetLocalAppDataPath() const { +FilePath DeviceInfo::GetLocalAppDataPath(FilePath sub_path) const { char *dir = getenv("XDG_CONFIG_HOME"); if (dir == nullptr) { return FilePath("/tmp"); @@ -109,7 +109,7 @@ std::optional DeviceInfo::GetLocalAppDataPath() const { return FilePath(std::string((std::filesystem::path(std::string(dir)) / "Google Nearby"))); } -std::optional DeviceInfo::GetTemporaryPath() const { +FilePath DeviceInfo::GetTemporaryPath() const { char *dir = getenv("XDG_RUNTIME_PATH"); if (dir == nullptr) { return FilePath("/tmp"); @@ -117,7 +117,7 @@ std::optional DeviceInfo::GetTemporaryPath() const { return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby")); } -std::optional DeviceInfo::GetLogPath() const { +FilePath DeviceInfo::GetLogPath() const { char *dir = getenv("XDG_STATE_HOME"); if (dir == nullptr) { return FilePath("/tmp"); @@ -125,13 +125,6 @@ std::optional DeviceInfo::GetLogPath() const { return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby" / "logs")); } -std::optional DeviceInfo::GetCrashDumpPath() const { - char *dir = getenv("XDG_STATE_HOME"); - if (dir == nullptr) { - return FilePath("/tmp"); - } - return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby" / "crashes")); -} bool DeviceInfo::IsScreenLocked() const { try { diff --git a/internal/platform/implementation/linux/device_info.h b/internal/platform/implementation/linux/device_info.h index fa0913ff..0f0d8acf 100644 --- a/internal/platform/implementation/linux/device_info.h +++ b/internal/platform/implementation/linux/device_info.h @@ -129,14 +129,10 @@ class DeviceInfo final : public api::DeviceInfo { return api::DeviceInfo::OsType::kWindows; // Or ChromeOS? } - std::optional GetDownloadPath() const override; - std::optional GetLocalAppDataPath() const override; - std::optional GetCommonAppDataPath() const override { - return std::nullopt; - }; - std::optional GetTemporaryPath() const override; - std::optional GetLogPath() const override; - std::optional GetCrashDumpPath() const override; + nearby::FilePath GetDownloadPath() const override; + nearby::FilePath GetLocalAppDataPath(nearby::FilePath sub_path) const override; + nearby::FilePath GetTemporaryPath() const override; + nearby::FilePath GetLogPath() const override; bool IsScreenLocked() const override; void RegisterScreenLockedListener( diff --git a/internal/platform/implementation/linux/file_path.cc b/internal/platform/implementation/linux/file_path.cc index 5fb469f4..68fee2d9 100644 --- a/internal/platform/implementation/linux/file_path.cc +++ b/internal/platform/implementation/linux/file_path.cc @@ -56,8 +56,8 @@ std::wstring FilePath::GetDownloadPathInternal(std::wstring parent_folder, auto nearby_path = info.GetDownloadPath(); std::optional download_path = - nearby_path ? std::optional( - std::filesystem::path(nearby_path->ToString())) + !nearby_path.IsEmpty() ? std::optional( + std::filesystem::path(nearby_path.ToString())) : std::nullopt; std::string base_path; diff --git a/internal/platform/implementation/linux/preferences_manager.cc b/internal/platform/implementation/linux/preferences_manager.cc index 9779cefd..1a39ca9b 100644 --- a/internal/platform/implementation/linux/preferences_manager.cc +++ b/internal/platform/implementation/linux/preferences_manager.cc @@ -42,7 +42,7 @@ PreferencesManager::PreferencesManager(absl::string_view file_path) : api::PreferencesManager() { std::optional path = nearby::api::ImplementationPlatform::CreateDeviceInfo() - ->GetLocalAppDataPath(); + ->GetLocalAppDataPath(nearby::FilePath()); if (!path.has_value()) { path = FilePath("/tmp"); }