mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Merge pull request #2307 from ChenWangG:patch-1
PiperOrigin-RevId: 612604370
This commit is contained in:
@@ -147,7 +147,10 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
|
||||
|
||||
// TODO(hais): update this after ble_v2 refactor.
|
||||
if (api::ImplementationPlatform::GetCurrentOS() ==
|
||||
api::OSName::kChromeOS) {
|
||||
api::OSName::kChromeOS &&
|
||||
!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kEnableBleV2)) {
|
||||
if (ble_medium_.StartLegacyAdvertising(
|
||||
service_id, local_endpoint_id,
|
||||
advertising_options.fast_advertisement_service_uuid)) {
|
||||
@@ -221,7 +224,9 @@ Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
|
||||
if (client->GetClientId() == bluetooth_classic_advertiser_client_id_) {
|
||||
bluetooth_medium_.TurnOffDiscoverability();
|
||||
// TODO(hais): update this after ble_v2 refactor.
|
||||
if (api::ImplementationPlatform::GetCurrentOS() == api::OSName::kChromeOS) {
|
||||
if (api::ImplementationPlatform::GetCurrentOS() == api::OSName::kChromeOS &&
|
||||
!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
|
||||
ble_medium_.StopLegacyAdvertising(client->GetAdvertisingServiceId());
|
||||
}
|
||||
bluetooth_classic_advertiser_client_id_ = 0;
|
||||
@@ -981,7 +986,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
|
||||
if (ble_v2_medium !=
|
||||
location::nearby::proto::connections::UNKNOWN_MEDIUM) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "P2pClusterPcpHandler::StartDiscoveryImpl: Ble added.";
|
||||
<< "P2pClusterPcpHandler::StartDiscoveryImpl: Ble v2 added.";
|
||||
mediums_started_successfully.push_back(ble_v2_medium);
|
||||
}
|
||||
} else {
|
||||
@@ -1340,7 +1345,10 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
|
||||
web_rtc_state) != Medium::UNKNOWN_MEDIUM) {
|
||||
// TODO(hais): update this after ble_v2 refactor.
|
||||
if (api::ImplementationPlatform::GetCurrentOS() ==
|
||||
api::OSName::kChromeOS) {
|
||||
api::OSName::kChromeOS &&
|
||||
!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kEnableBleV2)) {
|
||||
if (ble_medium_.StartLegacyAdvertising(
|
||||
std::string(service_id), std::string(local_endpoint_id),
|
||||
advertising_options.fast_advertisement_service_uuid)) {
|
||||
@@ -1902,8 +1910,9 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
// request comes in very quickly. BLE allows connecting over BLE itself, as
|
||||
// well as advertising the Bluetooth MAC address to allow connecting over
|
||||
// Bluetooth Classic.
|
||||
NEARBY_LOGS(INFO) << "P2pClusterPcpHandler::StartBleAdvertising: service_id="
|
||||
<< service_id << " : start";
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "P2pClusterPcpHandler::StartBleV2Advertising: service_id="
|
||||
<< service_id << " : start";
|
||||
if (!ble_v2_medium_.IsAcceptingConnections(service_id)) {
|
||||
if (!bluetooth_radio_.Enable() ||
|
||||
!ble_v2_medium_.StartAcceptingConnections(
|
||||
@@ -1913,7 +1922,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
client, local_endpoint_info.AsStringView(),
|
||||
NearbyDevice::Type::kConnectionsDevice))) {
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "In StartBleAdvertising("
|
||||
<< "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " failed to start accepting for incoming BLE connections to "
|
||||
@@ -1922,7 +1931,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
return location::nearby::proto::connections::UNKNOWN_MEDIUM;
|
||||
}
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "In StartBleAdvertising("
|
||||
<< "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " started accepting for incoming BLE connections to service_id="
|
||||
@@ -1944,7 +1953,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
this, client, local_endpoint_info.AsStringView(),
|
||||
NearbyDevice::Type::kConnectionsDevice))) {
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "In BT StartBleAdvertising("
|
||||
<< "In BT StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " failed to start accepting for incoming BLE connections to "
|
||||
@@ -1954,7 +1963,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
return location::nearby::proto::connections::UNKNOWN_MEDIUM;
|
||||
}
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "In BT StartBleAdvertising("
|
||||
<< "In BT StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " started accepting for incoming BLE connections to service_id="
|
||||
@@ -1962,7 +1971,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
}
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << "In StartBleAdvertising("
|
||||
NEARBY_LOGS(INFO) << "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " start to generate BleAdvertisement with service_id="
|
||||
@@ -1991,7 +2000,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
/*uwb_address=*/ByteArray{}, web_rtc_state));
|
||||
}
|
||||
if (advertisement_bytes.Empty()) {
|
||||
NEARBY_LOGS(WARNING) << "In StartBleAdvertising("
|
||||
NEARBY_LOGS(WARNING) << "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " failed to create an advertisement.";
|
||||
@@ -1999,7 +2008,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
return location::nearby::proto::connections::UNKNOWN_MEDIUM;
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << "In StartBleAdvertising("
|
||||
NEARBY_LOGS(INFO) << "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " generated BleAdvertisement with service_id="
|
||||
@@ -2009,7 +2018,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
service_id, advertisement_bytes, power_level,
|
||||
!advertising_options.fast_advertisement_service_uuid.empty())) {
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "In StartBleAdvertising("
|
||||
<< "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " couldn't start BLE Advertising with BleAdvertisement "
|
||||
@@ -2017,7 +2026,7 @@ Medium P2pClusterPcpHandler::StartBleV2Advertising(
|
||||
ble_v2_medium_.StopAcceptingConnections(service_id);
|
||||
return location::nearby::proto::connections::UNKNOWN_MEDIUM;
|
||||
}
|
||||
NEARBY_LOGS(INFO) << "In startBleAdvertising("
|
||||
NEARBY_LOGS(INFO) << "In StartBleV2Advertising("
|
||||
<< absl::BytesToHexString(local_endpoint_info.data())
|
||||
<< "), client=" << client->GetClientId()
|
||||
<< " started BLE Advertising with BleAdvertisement "
|
||||
@@ -2042,12 +2051,13 @@ Medium P2pClusterPcpHandler::StartBleV2Scanning(
|
||||
client),
|
||||
})) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "In StartBleScanning(), client=" << client->GetClientId()
|
||||
<< "In StartBleV2Scanning(), client=" << client->GetClientId()
|
||||
<< " started scanning for BLE advertisements for service_id="
|
||||
<< service_id;
|
||||
return location::nearby::proto::connections::BLE;
|
||||
}
|
||||
NEARBY_LOGS(INFO) << "In StartBleScanning(), client=" << client->GetClientId()
|
||||
NEARBY_LOGS(INFO) << "In StartBleV2Scanning(), client="
|
||||
<< client->GetClientId()
|
||||
<< " couldn't start scanning on BLE for service_id="
|
||||
<< service_id;
|
||||
|
||||
@@ -2067,7 +2077,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl(
|
||||
client->GetCancellationFlag(endpoint->endpoint_id));
|
||||
if (!ble_socket.IsValid()) {
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "In BleConnectImpl(), failed to connect to BLE device "
|
||||
<< "In BleV2ConnectImpl(), failed to connect to BLE device "
|
||||
<< absl::BytesToHexString(peripheral.GetId().data())
|
||||
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
|
||||
return BasePcpHandler::ConnectImplResult{
|
||||
|
||||
@@ -57,8 +57,9 @@ class AccountManager {
|
||||
// |login_success_callback| is called when the login succeeded. Account
|
||||
// information is passed to callback.
|
||||
// |login_failure_callback| is called when the login fails.
|
||||
virtual void Login(absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void()> login_failure_callback) = 0;
|
||||
virtual void Login(
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) = 0;
|
||||
|
||||
// Logs out current active account. |logout_callback| is called when logout is
|
||||
// completed.
|
||||
|
||||
@@ -33,7 +33,7 @@ std::optional<AccountManager::Account> FakeAccountManager::GetCurrentAccount() {
|
||||
|
||||
void FakeAccountManager::Login(
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void()> login_failure_callback) {
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) {
|
||||
if (account_.has_value()) {
|
||||
login_success_callback(*account_);
|
||||
UpdateCurrentUser(account_->id);
|
||||
@@ -41,7 +41,7 @@ void FakeAccountManager::Login(
|
||||
return;
|
||||
}
|
||||
|
||||
login_failure_callback();
|
||||
login_failure_callback(absl::InternalError("No account."));
|
||||
}
|
||||
|
||||
void FakeAccountManager::Logout(
|
||||
|
||||
@@ -35,8 +35,9 @@ class FakeAccountManager : public AccountManager {
|
||||
|
||||
std::optional<Account> GetCurrentAccount() override;
|
||||
|
||||
void Login(absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void()> login_failure_callback) override;
|
||||
void Login(
|
||||
absl::AnyInvocable<void(Account)> login_success_callback,
|
||||
absl::AnyInvocable<void(absl::Status)> login_failure_callback) override;
|
||||
|
||||
void Logout(absl::AnyInvocable<void(absl::Status)> logout_callback) override;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
This directory contains Rust implementation of Nearby Presence.
|
||||
@@ -117,7 +117,7 @@ class NearbyShareCertificateManagerImplTest
|
||||
fake_account_manager_.SetAccount(account);
|
||||
|
||||
fake_account_manager_.Login([](AccountManager::Account account) {},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
|
||||
NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_);
|
||||
NearbyShareCertificateStorageImpl::Factory::SetFactoryForTesting(
|
||||
|
||||
@@ -4452,7 +4452,7 @@ TEST_F(NearbySharingServiceImplTest, ObserveAccountLoginAndLogout) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_CALL(account_observer, OnLogoutSucceeded(kTestAccountId)).Times(1);
|
||||
absl::Notification logout_notification;
|
||||
@@ -4483,7 +4483,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
EXPECT_TRUE(service_->GetSettings()->GetIsAnalyticsEnabled());
|
||||
@@ -4527,7 +4527,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
|
||||
@@ -4554,7 +4554,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldNotResetOnboarding) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
EXPECT_FALSE(service_->GetSettings()->IsOnboardingComplete());
|
||||
@@ -4580,7 +4580,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldNotResetOnboarding) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login2_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login2_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
EXPECT_TRUE(service_->GetSettings()->IsOnboardingComplete());
|
||||
@@ -4613,7 +4613,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
|
||||
@@ -4640,7 +4640,7 @@ TEST_F(NearbySharingServiceImplTest, LogoutShouldSetValidVisibility) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
login2_notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(login2_notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
FakeTaskRunner::WaitForRunningTasksWithTimeout(kTaskWaitTimeout);
|
||||
|
||||
@@ -4684,7 +4684,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutNoStopRunningSurfaces) {
|
||||
EXPECT_EQ(account.id, kTestAccountId);
|
||||
notification.Notify();
|
||||
},
|
||||
[]() {});
|
||||
[](absl::Status status) {});
|
||||
ASSERT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsDiscovering());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user