finished merge with upstream

This commit is contained in:
Lasan Mahaliyana
2026-06-13 22:02:21 +05:30
parent c34efc75f8
commit c20d7affc4
11 changed files with 31 additions and 105 deletions
@@ -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");
}