mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
finished merge with upstream
This commit is contained in:
@@ -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
|
||||
|
||||
+2
-1
@@ -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"],
|
||||
|
||||
@@ -92,10 +92,6 @@ constexpr auto kMediumMaxAllowedReadBytes =
|
||||
// Disable/Enable refactor of BLE/L2CAP in Nearby Connections SDK.
|
||||
constexpr auto kRefactorBleL2cap =
|
||||
flags::Flag<bool>(kConfigPackage, "45737079", false);
|
||||
// Enable/Disable usage of shared CBPeripheralManager for GATT and L2CAP
|
||||
// servers.
|
||||
constexpr auto kEnableSharedPeripheralManager =
|
||||
flags::Flag<bool>(kConfigPackage, "45770787", false);
|
||||
// Set the safe-to-disconnect version.
|
||||
// 0. Disabled all. 1. safe-to-disconnect 2. reserved 3.
|
||||
// auto-reconnect(deprecated)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -172,62 +172,6 @@ bool GattClient::WriteCharacteristic(
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GattClient::SetCharacteristicSubscription(
|
||||
const api::ble::GattCharacteristic &characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
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<bluez::SubscribedGattCharacteristicClient>>(
|
||||
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 "
|
||||
|
||||
@@ -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<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) override
|
||||
ABSL_LOCKS_EXCLUDED(characteristics_mutex_);
|
||||
|
||||
// https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html#disconnect()
|
||||
void Disconnect() override;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -93,7 +93,7 @@ api::DeviceInfo::DeviceType DeviceInfo::GetDeviceType() const {
|
||||
}
|
||||
|
||||
|
||||
std::optional<FilePath> 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<FilePath> DeviceInfo::GetDownloadPath() const {
|
||||
return FilePath(std::string(dir));
|
||||
}
|
||||
|
||||
std::optional<FilePath> 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<FilePath> DeviceInfo::GetLocalAppDataPath() const {
|
||||
return FilePath(std::string((std::filesystem::path(std::string(dir)) / "Google Nearby")));
|
||||
}
|
||||
|
||||
std::optional<FilePath> 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<FilePath> DeviceInfo::GetTemporaryPath() const {
|
||||
return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby"));
|
||||
}
|
||||
|
||||
std::optional<FilePath> 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<FilePath> DeviceInfo::GetLogPath() const {
|
||||
return FilePath(std::string(std::filesystem::path(std::string(dir)) / "Google Nearby" / "logs"));
|
||||
}
|
||||
|
||||
std::optional<FilePath> 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 {
|
||||
|
||||
@@ -129,14 +129,10 @@ class DeviceInfo final : public api::DeviceInfo {
|
||||
return api::DeviceInfo::OsType::kWindows; // Or ChromeOS?
|
||||
}
|
||||
|
||||
std::optional<nearby::FilePath> GetDownloadPath() const override;
|
||||
std::optional<nearby::FilePath> GetLocalAppDataPath() const override;
|
||||
std::optional<nearby::FilePath> GetCommonAppDataPath() const override {
|
||||
return std::nullopt;
|
||||
};
|
||||
std::optional<nearby::FilePath> GetTemporaryPath() const override;
|
||||
std::optional<nearby::FilePath> GetLogPath() const override;
|
||||
std::optional<nearby::FilePath> 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(
|
||||
|
||||
@@ -56,8 +56,8 @@ std::wstring FilePath::GetDownloadPathInternal(std::wstring parent_folder,
|
||||
auto nearby_path = info.GetDownloadPath();
|
||||
|
||||
std::optional<std::filesystem::path> download_path =
|
||||
nearby_path ? std::optional<std::filesystem::path>(
|
||||
std::filesystem::path(nearby_path->ToString()))
|
||||
!nearby_path.IsEmpty() ? std::optional<std::filesystem::path>(
|
||||
std::filesystem::path(nearby_path.ToString()))
|
||||
: std::nullopt;
|
||||
|
||||
std::string base_path;
|
||||
|
||||
@@ -42,7 +42,7 @@ PreferencesManager::PreferencesManager(absl::string_view file_path)
|
||||
: api::PreferencesManager() {
|
||||
std::optional<FilePath> path =
|
||||
nearby::api::ImplementationPlatform::CreateDeviceInfo()
|
||||
->GetLocalAppDataPath();
|
||||
->GetLocalAppDataPath(nearby::FilePath());
|
||||
if (!path.has_value()) {
|
||||
path = FilePath("/tmp");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user