mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Remove unknown files from PAYLOAD_TRANSFER offline frame
PiperOrigin-RevId: 625500482
This commit is contained in:
committed by
Copybara-Service
parent
e5279bfd49
commit
486b4bfaca
+1
-4
@@ -58,19 +58,17 @@ cc_library(
|
||||
deps = [
|
||||
":connection_types",
|
||||
"//internal/crypto_cros",
|
||||
"//internal/interop:authentication_status",
|
||||
"//internal/network:url",
|
||||
"//sharing/common:compatible_u8_string",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/base",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
"//sharing/proto:share_cc_proto",
|
||||
"//sharing/proto:wire_format_cc_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/strings:str_format",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_absl//absl/types:span",
|
||||
],
|
||||
)
|
||||
@@ -326,7 +324,6 @@ cc_test(
|
||||
"//internal/network:types",
|
||||
"//internal/network:url",
|
||||
"//internal/platform/implementation:account_manager",
|
||||
"//internal/platform/implementation:types",
|
||||
"//internal/platform/implementation/g3", # fixdeps: keep
|
||||
"//internal/test",
|
||||
"//proto:sharing_enums_cc_proto",
|
||||
|
||||
@@ -315,6 +315,28 @@ void FakeNearbyConnectionsManager::SetCustomSavePath(
|
||||
custom_save_path_ = custom_save_path;
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
FakeNearbyConnectionsManager::GetUnknownFilePathsToDelete() {
|
||||
return file_paths_to_delete_;
|
||||
}
|
||||
|
||||
void FakeNearbyConnectionsManager::ClearUnknownFilePathsToDelete() {
|
||||
file_paths_to_delete_.clear();
|
||||
}
|
||||
|
||||
void FakeNearbyConnectionsManager::AddUnknownFilePathsToDeleteForTesting(
|
||||
std::filesystem::path file_path) {
|
||||
file_paths_to_delete_.insert(file_path);
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
FakeNearbyConnectionsManager::GetAndClearUnknownFilePathsToDelete() {
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete =
|
||||
file_paths_to_delete_;
|
||||
file_paths_to_delete_.clear();
|
||||
return file_paths_to_delete;
|
||||
}
|
||||
|
||||
std::string FakeNearbyConnectionsManager::Dump() const { return ""; }
|
||||
|
||||
} // namespace sharing
|
||||
|
||||
@@ -75,6 +75,11 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
absl::string_view endpoint_id) override;
|
||||
void UpgradeBandwidth(absl::string_view endpoint_id) override;
|
||||
void SetCustomSavePath(absl::string_view custom_save_path) override;
|
||||
absl::flat_hash_set<std::filesystem::path> GetUnknownFilePathsToDelete()
|
||||
override;
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetAndClearUnknownFilePathsToDelete() override;
|
||||
void ClearUnknownFilePathsToDelete() override;
|
||||
|
||||
// Testing methods
|
||||
void SetRawAuthenticationToken(absl::string_view endpoint_id,
|
||||
@@ -135,6 +140,8 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
return !incoming_payloads_.empty();
|
||||
}
|
||||
|
||||
void AddUnknownFilePathsToDeleteForTesting(std::filesystem::path file_path);
|
||||
|
||||
private:
|
||||
void HandleStartAdvertisingCallback(ConnectionsStatus status);
|
||||
void HandleStopAdvertisingCallback(ConnectionsStatus status);
|
||||
@@ -172,7 +179,7 @@ class FakeNearbyConnectionsManager : public NearbyConnectionsManager {
|
||||
std::map<int64_t, std::unique_ptr<Payload>> incoming_payloads_
|
||||
ABSL_GUARDED_BY(incoming_payloads_mutex_);
|
||||
std::map<int64_t, std::filesystem::path> registered_payload_paths_;
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete_;
|
||||
std::string Dump() const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
@@ -162,6 +163,17 @@ class NearbyConnectionsManager {
|
||||
// Sets a custom save path.
|
||||
virtual void SetCustomSavePath(absl::string_view custom_save_path) = 0;
|
||||
|
||||
// Gets the file paths to delete.
|
||||
virtual absl::flat_hash_set<std::filesystem::path>
|
||||
GetUnknownFilePathsToDelete() = 0;
|
||||
|
||||
// Deletes the file paths to delete.
|
||||
virtual void ClearUnknownFilePathsToDelete() = 0;
|
||||
|
||||
// Gets the file paths to delete and clear the hash set.
|
||||
virtual absl::flat_hash_set<std::filesystem::path>
|
||||
GetAndClearUnknownFilePathsToDelete() = 0;
|
||||
|
||||
// Dump internal state for debugging purposes.
|
||||
virtual std::string Dump() const = 0;
|
||||
};
|
||||
|
||||
@@ -136,8 +136,7 @@ std::string MediumSelectionToString(const MediumSelection& mediums) {
|
||||
} // namespace
|
||||
|
||||
NearbyConnectionsManagerImpl::NearbyConnectionsManagerImpl(
|
||||
Context* context,
|
||||
ConnectivityManager& connectivity_manager,
|
||||
Context* context, ConnectivityManager& connectivity_manager,
|
||||
nearby::DeviceInfo& device_info,
|
||||
std::unique_ptr<NearbyConnectionsService> nearby_connections_service)
|
||||
: context_(context),
|
||||
@@ -489,8 +488,7 @@ void NearbyConnectionsManagerImpl::Send(
|
||||
|
||||
if (transfer_managers_.contains(endpoint_id) && payload->content.is_file()) {
|
||||
NL_LOG(INFO) << __func__ << ": Send payload " << payload->id << " to "
|
||||
<< endpoint_id
|
||||
<< " to transfer manager. payload is file: "
|
||||
<< endpoint_id << " to transfer manager. payload is file: "
|
||||
<< payload->content.is_file() << ", is bytes "
|
||||
<< payload->content.is_bytes();
|
||||
transfer_managers_.at(endpoint_id)
|
||||
@@ -831,6 +829,17 @@ void NearbyConnectionsManagerImpl::OnPayloadTransferUpdate(
|
||||
|
||||
if (payload_it->second.content.type != PayloadContent::Type::kBytes) {
|
||||
NL_LOG(WARNING) << "Received unknown payload of file type. Cancelling.";
|
||||
if (!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
sharing::config_package_nearby::nearby_sharing_feature::
|
||||
kDeleteUnexpectedReceivedFile)) {
|
||||
// if we get kFile and have file_path, delete the file path.
|
||||
if (payload_it->second.content.type == PayloadContent::Type::kFile) {
|
||||
auto file_path = payload_it->second.content.file_payload.file.path;
|
||||
NL_LOG(WARNING) << __func__
|
||||
<< ": Payload is Type::kFile type. Removing.";
|
||||
file_paths_to_delete_.insert(file_path);
|
||||
}
|
||||
}
|
||||
nearby_connections_service_->CancelPayload(kServiceId, payload_it->first,
|
||||
[](Status status) {});
|
||||
return;
|
||||
@@ -898,6 +907,31 @@ void NearbyConnectionsManagerImpl::SetCustomSavePath(
|
||||
});
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
NearbyConnectionsManagerImpl::GetUnknownFilePathsToDelete() {
|
||||
MutexLock lock(&mutex_);
|
||||
return file_paths_to_delete_;
|
||||
}
|
||||
|
||||
void NearbyConnectionsManagerImpl::ClearUnknownFilePathsToDelete() {
|
||||
MutexLock lock(&mutex_);
|
||||
file_paths_to_delete_.clear();
|
||||
}
|
||||
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
NearbyConnectionsManagerImpl::GetAndClearUnknownFilePathsToDelete() {
|
||||
MutexLock lock(&mutex_);
|
||||
auto file_paths_to_delete = file_paths_to_delete_;
|
||||
file_paths_to_delete_.clear();
|
||||
return file_paths_to_delete;
|
||||
}
|
||||
|
||||
void NearbyConnectionsManagerImpl::AddUnknownFilePathsToDeleteForTesting(
|
||||
std::filesystem::path file_path) {
|
||||
MutexLock lock(&mutex_);
|
||||
file_paths_to_delete_.insert(file_path);
|
||||
}
|
||||
|
||||
std::string NearbyConnectionsManagerImpl::Dump() const {
|
||||
return nearby_connections_service_->Dump();
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ namespace sharing {
|
||||
class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
public:
|
||||
explicit NearbyConnectionsManagerImpl(
|
||||
Context* context,
|
||||
nearby::ConnectivityManager& connectivity_manager,
|
||||
Context* context, nearby::ConnectivityManager& connectivity_manager,
|
||||
nearby::DeviceInfo& device_info,
|
||||
std::unique_ptr<NearbyConnectionsService> nearby_connections_service);
|
||||
~NearbyConnectionsManagerImpl() override;
|
||||
@@ -85,12 +84,20 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
absl::string_view endpoint_id) override;
|
||||
void UpgradeBandwidth(absl::string_view endpoint_id) override;
|
||||
void SetCustomSavePath(absl::string_view custom_save_path) override;
|
||||
absl::flat_hash_set<std::filesystem::path> GetUnknownFilePathsToDelete()
|
||||
override;
|
||||
absl::flat_hash_set<std::filesystem::path>
|
||||
GetAndClearUnknownFilePathsToDelete() override;
|
||||
void ClearUnknownFilePathsToDelete() override;
|
||||
|
||||
std::string Dump() const override;
|
||||
|
||||
NearbyConnectionsService* GetNearbyConnectionsService() const {
|
||||
return nearby_connections_service_.get();
|
||||
}
|
||||
|
||||
void AddUnknownFilePathsToDeleteForTesting(std::filesystem::path file_path);
|
||||
|
||||
private:
|
||||
// EndpointDiscoveryListener:
|
||||
void OnEndpointFound(absl::string_view endpoint_id,
|
||||
@@ -176,6 +183,10 @@ class NearbyConnectionsManagerImpl : public NearbyConnectionsManager {
|
||||
// Avoid calling to disconnect on an endpoint multiple times.
|
||||
absl::flat_hash_set<std::string> disconnecting_endpoints_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
|
||||
// A set of file paths to delete.
|
||||
absl::flat_hash_set<std::filesystem::path> file_paths_to_delete_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace {
|
||||
using ::nearby::sharing::proto::DataUsage;
|
||||
using ::testing::ElementsAre;
|
||||
using ::testing::FieldsAre;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
constexpr char kServiceId[] = "NearbySharing";
|
||||
constexpr Strategy kStrategy = Strategy::kP2pPointToPoint;
|
||||
@@ -95,6 +96,8 @@ void InitializeTemporaryFile(std::filesystem::path& file) {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace NearbyConnectionsManagerUnitTests {
|
||||
|
||||
class MockDiscoveryListener
|
||||
: public NearbyConnectionsManager::DiscoveryListener {
|
||||
public:
|
||||
@@ -1731,5 +1734,41 @@ TEST_F(NearbyConnectionsManagerImplTest,
|
||||
notification.WaitForNotificationWithTimeout(kSynchronizationTimeOut));
|
||||
}
|
||||
|
||||
TEST_F(NearbyConnectionsManagerImplTest, UnknownFilePathsToDelete) {
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
auto unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDelete();
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test3.txt");
|
||||
|
||||
// Test if we get copy of container.
|
||||
EXPECT_NE(unknown_file_paths.size(), 3);
|
||||
EXPECT_EQ(unknown_file_paths.size(), 2);
|
||||
EXPECT_EQ(nearby_connections_manager_->GetUnknownFilePathsToDelete().size(),
|
||||
3);
|
||||
unknown_file_paths =
|
||||
nearby_connections_manager_->GetUnknownFilePathsToDelete();
|
||||
EXPECT_THAT(unknown_file_paths,
|
||||
UnorderedElementsAre("test1.txt", "test2.txt", "test3.txt"));
|
||||
nearby_connections_manager_->ClearUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(nearby_connections_manager_->GetUnknownFilePathsToDelete().size(),
|
||||
0);
|
||||
|
||||
// Test GetAndClearUnknownFilePathsToDelete
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
unknown_file_paths =
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(unknown_file_paths.size(), 2);
|
||||
EXPECT_EQ(nearby_connections_manager_->GetUnknownFilePathsToDelete().size(),
|
||||
0);
|
||||
}
|
||||
|
||||
} // namespace NearbyConnectionsManagerUnitTests
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
@@ -279,8 +279,7 @@ void NearbySharingServiceImpl::Shutdown(
|
||||
foreground_receive_callbacks_.Clear();
|
||||
background_receive_callbacks_.Clear();
|
||||
|
||||
device_info_.UnregisterScreenLockedListener(
|
||||
kScreenStateListenerName);
|
||||
device_info_.UnregisterScreenLockedListener(kScreenStateListenerName);
|
||||
|
||||
settings_->RemoveSettingsObserver(this);
|
||||
|
||||
@@ -1160,8 +1159,7 @@ std::string NearbySharingServiceImpl::Dump() const {
|
||||
sstream << " IsSendingFile: " << IsSendingFile() << std::endl;
|
||||
sstream << " IsReceivingFile: " << IsReceivingFile() << std::endl;
|
||||
|
||||
sstream << " IsScreenLocked: " << device_info_.IsScreenLocked()
|
||||
<< std::endl;
|
||||
sstream << " IsScreenLocked: " << device_info_.IsScreenLocked() << std::endl;
|
||||
sstream << " IsBluetoothPresent: " << IsBluetoothPresent() << std::endl;
|
||||
sstream << " IsBluetoothPowered: " << IsBluetoothPowered() << std::endl;
|
||||
sstream << " IsExtendedAdvertisingSupported: "
|
||||
@@ -3972,7 +3970,6 @@ std::optional<ShareTarget> NearbySharingServiceImpl::CreateShareTarget(
|
||||
absl::string_view endpoint_id, const Advertisement& advertisement,
|
||||
std::optional<NearbyShareDecryptedPublicCertificate> certificate,
|
||||
bool is_incoming) {
|
||||
|
||||
if (!advertisement.device_name() && !certificate.has_value()) {
|
||||
NL_VLOG(1) << __func__
|
||||
<< ": Failed to retrieve public certificate for contact "
|
||||
@@ -4115,9 +4112,8 @@ bool NearbySharingServiceImpl::OnIncomingPayloadsComplete(
|
||||
|
||||
connection->SetDisconnectionListener([&, share_target_id]() {
|
||||
RunOnNearbySharingServiceThread(
|
||||
"disconnection_listener", [&, share_target_id]() {
|
||||
UnregisterShareTarget(share_target_id);
|
||||
});
|
||||
"disconnection_listener",
|
||||
[&, share_target_id]() { UnregisterShareTarget(share_target_id); });
|
||||
});
|
||||
|
||||
if (!update_file_paths_in_progress_) {
|
||||
@@ -4241,6 +4237,17 @@ void NearbySharingServiceImpl::RemoveIncomingPayloads(
|
||||
NL_LOG(INFO) << __func__ << ": Cleaning up payloads due to transfer failure";
|
||||
nearby_connections_manager_->ClearIncomingPayloads();
|
||||
std::vector<std::filesystem::path> files_for_deletion;
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_sharing_feature::
|
||||
kDeleteUnexpectedReceivedFile)) {
|
||||
auto file_paths_to_delete =
|
||||
nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
for (auto it = file_paths_to_delete.begin();
|
||||
it != file_paths_to_delete.end(); ++it) {
|
||||
NL_VLOG(1) << __func__ << ": Has unknown file path to delete.";
|
||||
files_for_deletion.push_back(*it);
|
||||
}
|
||||
}
|
||||
for (const auto& file : share_target.file_attachments) {
|
||||
if (!file.file_path().has_value()) continue;
|
||||
auto file_path = *file.file_path();
|
||||
|
||||
@@ -88,6 +88,7 @@ class NearbyShareContactManager;
|
||||
|
||||
namespace NearbySharingServiceUnitTests {
|
||||
class NearbySharingServiceImplTest_CreateShareTarget_Test;
|
||||
class NearbySharingServiceImplTest_RemoveIncomingPayloads_Test;
|
||||
};
|
||||
|
||||
// All methods should be called from the same sequence that created the service.
|
||||
@@ -103,6 +104,8 @@ class NearbySharingServiceImpl
|
||||
public NearbyConnectionsManager::DiscoveryListener {
|
||||
FRIEND_TEST(NearbySharingServiceUnitTests::NearbySharingServiceImplTest,
|
||||
CreateShareTarget);
|
||||
FRIEND_TEST(NearbySharingServiceUnitTests::NearbySharingServiceImplTest,
|
||||
RemoveIncomingPayloads);
|
||||
|
||||
public:
|
||||
NearbySharingServiceImpl(
|
||||
|
||||
@@ -110,6 +110,7 @@ using ::nearby::sharing::service::proto::V1Frame;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::ReturnRef;
|
||||
using ::testing::UnorderedElementsAre;
|
||||
|
||||
class MockTransferUpdateCallback : public TransferUpdateCallback {
|
||||
public:
|
||||
@@ -362,9 +363,8 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
&contact_manager_factory_);
|
||||
NearbyShareCertificateManagerImpl::Factory::SetFactoryForTesting(
|
||||
&certificate_manager_factory_);
|
||||
AccountManagerImpl::Factory::SetFactoryForTesting([]() {
|
||||
return std::make_unique<FakeAccountManager>();
|
||||
});
|
||||
AccountManagerImpl::Factory::SetFactoryForTesting(
|
||||
[]() { return std::make_unique<FakeAccountManager>(); });
|
||||
nearby_fast_initiation_factory_ =
|
||||
std::make_unique<FakeNearbyFastInitiation::Factory>();
|
||||
NearbyFastInitiationImpl::Factory::SetFactoryForTesting(
|
||||
@@ -1197,9 +1197,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
std::filesystem::temp_directory_path(), size);
|
||||
}
|
||||
|
||||
void ResetDiskSpace() {
|
||||
fake_device_info_.ResetDiskSpace();
|
||||
}
|
||||
void ResetDiskSpace() { fake_device_info_.ResetDiskSpace(); }
|
||||
|
||||
protected:
|
||||
FakeNearbyShareLocalDeviceDataManager* local_device_data_manager() {
|
||||
@@ -1212,9 +1210,7 @@ class NearbySharingServiceImplTest : public testing::Test {
|
||||
return certificate_manager_factory_.instances().back();
|
||||
}
|
||||
|
||||
FakeAccountManager& account_manager() {
|
||||
return fake_account_manager_;
|
||||
}
|
||||
FakeAccountManager& account_manager() { return fake_account_manager_; }
|
||||
|
||||
std::filesystem::path CreateTestFile(absl::string_view name,
|
||||
const std::vector<uint8_t>& content) {
|
||||
@@ -1907,7 +1903,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
::nearby::AccountManager::Account account;
|
||||
account.id = kTestAccountId;
|
||||
account_manager().SetAccount(account);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -1962,7 +1959,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
DataUsageChangedRegisterReceiveSurfaceRestartsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingDataUsageName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingDataUsageName,
|
||||
static_cast<int>(DataUsage::OFFLINE_DATA_USAGE));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -1973,7 +1971,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(DataUsage::OFFLINE_DATA_USAGE,
|
||||
fake_nearby_connections_manager_->advertising_data_usage());
|
||||
|
||||
preference_manager().SetInteger(prefs::kNearbySharingDataUsageName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingDataUsageName,
|
||||
static_cast<int>(DataUsage::ONLINE_DATA_USAGE));
|
||||
FlushTesting();
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
@@ -1985,7 +1984,8 @@ TEST_F(
|
||||
NearbySharingServiceImplTest,
|
||||
UnregisterForegroundReceiveSurfaceVisibilityAllContactsRestartAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
|
||||
@@ -2160,7 +2160,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2173,7 +2174,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceNoOneVisibilityNotAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2187,7 +2189,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceVisibilityToNoOneStopsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2196,7 +2199,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED));
|
||||
FlushTesting();
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
@@ -2206,7 +2210,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceVisibilityToSelectedStartsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2216,7 +2221,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->is_shutdown());
|
||||
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
@@ -2225,7 +2231,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2238,7 +2245,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2251,7 +2259,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceAllContactsVisibilityIsAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2264,7 +2273,8 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceAllContactsVisibilityNotAdvertising) {
|
||||
SetConnectionType(ConnectionType::kWifi);
|
||||
preference_manager().SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -4690,6 +4700,40 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
UnregisterReceiveSurface(&callback);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, RemoveIncomingPayloads) {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_sharing_feature::
|
||||
kDeleteUnexpectedReceivedFile,
|
||||
true);
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
auto unknown_file_paths_to_delete =
|
||||
fake_nearby_connections_manager_->GetUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(unknown_file_paths_to_delete.size(), 2);
|
||||
EXPECT_THAT(unknown_file_paths_to_delete,
|
||||
UnorderedElementsAre("test1.txt", "test2.txt"));
|
||||
ShareTarget share_target;
|
||||
share_target.is_incoming = true;
|
||||
service_->RemoveIncomingPayloads(share_target);
|
||||
EXPECT_EQ(
|
||||
fake_nearby_connections_manager_->GetUnknownFilePathsToDelete().size(),
|
||||
0);
|
||||
|
||||
// Test GetAndClearUnknownFilePathsToDelete
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test1.txt");
|
||||
fake_nearby_connections_manager_->AddUnknownFilePathsToDeleteForTesting(
|
||||
"test2.txt");
|
||||
unknown_file_paths_to_delete =
|
||||
fake_nearby_connections_manager_->GetAndClearUnknownFilePathsToDelete();
|
||||
EXPECT_EQ(unknown_file_paths_to_delete.size(), 2);
|
||||
EXPECT_EQ(
|
||||
fake_nearby_connections_manager_->GetUnknownFilePathsToDelete().size(),
|
||||
0);
|
||||
}
|
||||
|
||||
} // namespace NearbySharingServiceUnitTests
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user