mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Fix DeviceID not changed after logout.
PiperOrigin-RevId: 738836722
This commit is contained in:
committed by
Copybara-Service
parent
70b25b4f8b
commit
57773f9b80
@@ -136,7 +136,6 @@ NearbyShareLocalDeviceDataManagerImpl::NearbyShareLocalDeviceDataManagerImpl(
|
||||
device_info_(device_info),
|
||||
nearby_share_client_(rpc_client_factory->CreateInstance()),
|
||||
nearby_identity_client_(rpc_client_factory->CreateIdentityInstance()),
|
||||
device_id_(GetId()),
|
||||
executor_(context->CreateSequencedTaskRunner()) {}
|
||||
|
||||
NearbyShareLocalDeviceDataManagerImpl::
|
||||
@@ -216,7 +215,7 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadContacts(
|
||||
|
||||
UpdateDeviceRequest request;
|
||||
request.mutable_device()->set_name(
|
||||
absl::StrCat(kDeviceIdPrefix, device_id_));
|
||||
absl::StrCat(kDeviceIdPrefix, GetId()));
|
||||
request.mutable_device()->mutable_contacts()->Add(contacts.begin(),
|
||||
contacts.end());
|
||||
request.mutable_update_mask()->add_paths(
|
||||
@@ -254,7 +253,7 @@ void NearbyShareLocalDeviceDataManagerImpl::PublishDevice(
|
||||
<< certificates.size() << " certificates.";
|
||||
|
||||
PublishDeviceRequest request;
|
||||
request.mutable_device()->set_name(absl::StrCat("devices/", device_id_));
|
||||
request.mutable_device()->set_name(absl::StrCat("devices/", GetId()));
|
||||
LOG(INFO) << __func__
|
||||
<< ": [Call Identity API] PublishDeviceRequest with Device.name: "
|
||||
<< request.device().name();
|
||||
@@ -367,7 +366,7 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadCertificates(
|
||||
}
|
||||
UpdateDeviceRequest request;
|
||||
request.mutable_device()->set_name(
|
||||
absl::StrCat(kDeviceIdPrefix, device_id_));
|
||||
absl::StrCat(kDeviceIdPrefix, GetId()));
|
||||
request.mutable_device()->mutable_public_certificates()->Add(
|
||||
certificates.begin(), certificates.end());
|
||||
request.mutable_update_mask()->add_paths(
|
||||
|
||||
@@ -104,7 +104,6 @@ class NearbyShareLocalDeviceDataManagerImpl
|
||||
std::unique_ptr<nearby::sharing::api::SharingRpcClient> nearby_share_client_;
|
||||
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
|
||||
nearby_identity_client_;
|
||||
const std::string device_id_;
|
||||
std::unique_ptr<TaskRunner> executor_;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/substitute.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
#include "internal/test/fake_account_manager.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
@@ -246,7 +245,7 @@ class NearbyShareLocalDeviceDataManagerImplTest
|
||||
absl::Milliseconds(1000)));
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
nearby::FakePreferenceManager preference_manager_;
|
||||
nearby::FakeAccountManager fake_account_manager_;
|
||||
nearby::FakeDeviceInfo fake_device_info_;
|
||||
@@ -560,6 +559,42 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, PublishDevice_Failure) {
|
||||
EXPECT_FALSE(returned_make_another_call);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareLocalDeviceDataManagerImplTest,
|
||||
PublishDevice_DeviceIdChangedAfterReset) {
|
||||
CreateManager();
|
||||
bool returned_success;
|
||||
PublishDeviceResponse response;
|
||||
|
||||
identity_client()->SetPublishDeviceResponse(
|
||||
absl::StatusOr<PublishDeviceResponse>(response));
|
||||
manager()->PublishDevice(GetTestCertificates(), /*is_second_call=*/true,
|
||||
[&returned_success](
|
||||
bool success, bool make_another_call) {
|
||||
returned_success = success;
|
||||
});
|
||||
|
||||
Sync();
|
||||
EXPECT_TRUE(returned_success);
|
||||
ASSERT_EQ(identity_client()->publish_device_requests().size(), 1);
|
||||
std::string device_id =
|
||||
identity_client()->publish_device_requests().back().device().name();
|
||||
// Reset device ID.
|
||||
preference_manager_.SetString(prefs::kNearbySharingDeviceIdName,
|
||||
std::string());
|
||||
manager()->PublishDevice(
|
||||
GetTestCertificates(), /*is_second_call=*/true,
|
||||
[&returned_success](bool success, bool make_another_call) {
|
||||
returned_success = success;
|
||||
});
|
||||
Sync();
|
||||
EXPECT_TRUE(returned_success);
|
||||
ASSERT_EQ(identity_client()->publish_device_requests().size(), 2);
|
||||
std::string new_device_id =
|
||||
identity_client()->publish_device_requests().back().device().name();
|
||||
|
||||
EXPECT_NE(device_id, new_device_id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user