Roll forward to cl/314549634

Change-Id: I4d1e7eacd5fa4078a094571ad6d5f51e422535ff
This commit is contained in:
Himanshu Jaju
2020-06-03 11:18:32 -07:00
committed by Alexey Polyudov
parent ae1c427b99
commit cffbc04508
92 changed files with 3804 additions and 697 deletions
+37 -22
View File
@@ -2,7 +2,7 @@
#include <string>
#include "platform_v2/impl/g3/medium_environment.h"
#include "platform_v2/base/medium_environment.h"
namespace location {
namespace nearby {
@@ -11,15 +11,22 @@ namespace g3 {
BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter)
: adapter_(*adapter) {}
BluetoothAdapter::~BluetoothAdapter() { SetStatus(Status::kDisabled); }
std::string BluetoothDevice::GetName() const { return adapter_.GetName(); }
bool BluetoothAdapter::SetStatus(Status status) ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(&mutex_);
enabled_ = (status == Status::kEnabled);
RunOnCallbackThread([this]() {
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this);
});
bool BluetoothAdapter::SetStatus(Status status) {
BluetoothAdapter::ScanMode mode;
bool enabled = status == Status::kEnabled;
std::string name;
{
absl::MutexLock lock(&mutex_);
enabled_ = enabled;
name = name_;
mode = mode_;
}
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this, device_, name, enabled, mode);
return true;
}
@@ -34,13 +41,17 @@ BluetoothAdapter::ScanMode BluetoothAdapter::GetScanMode() const {
}
bool BluetoothAdapter::SetScanMode(BluetoothAdapter::ScanMode mode) {
absl::MutexLock lock(&mutex_);
if (enabled_) return false;
mode_ = mode;
RunOnCallbackThread([this]() {
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this);
});
bool enabled;
std::string name;
{
absl::MutexLock lock(&mutex_);
mode_ = mode;
name = name_;
enabled = enabled_;
}
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this, device_, std::move(name), enabled,
mode);
return true;
}
@@ -50,13 +61,17 @@ std::string BluetoothAdapter::GetName() const {
}
bool BluetoothAdapter::SetName(absl::string_view name) {
absl::MutexLock lock(&mutex_);
if (enabled_) return false;
name_ = name;
RunOnCallbackThread([this]() {
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this);
});
BluetoothAdapter::ScanMode mode;
bool enabled;
{
absl::MutexLock lock(&mutex_);
name_ = name;
enabled = enabled_;
mode = mode_;
}
auto& env = MediumEnvironment::Instance();
env.OnBluetoothAdapterChangedState(*this, device_, std::string(name), enabled,
mode);
return true;
}