mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove open()-related and unused code.
PiperOrigin-RevId: 671851469
This commit is contained in:
committed by
Copybara-Service
parent
a8cd7d0b3d
commit
e36398b124
@@ -247,7 +247,6 @@ cc_library(
|
||||
"nearby_connections_stream_buffer_manager.cc",
|
||||
"nearby_share_profile_info_provider_impl.cc",
|
||||
"nearby_sharing_service.cc",
|
||||
"nearby_sharing_service_extension.cc",
|
||||
"nearby_sharing_service_factory.cc",
|
||||
"nearby_sharing_service_impl.cc",
|
||||
"nearby_sharing_settings.cc",
|
||||
|
||||
@@ -159,17 +159,6 @@ bool FakeNearbySharingService::DidLocalUserCancelTransfer(
|
||||
return false;
|
||||
}
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
void FakeNearbySharingService::Open(
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) {
|
||||
status_codes_callback(StatusCodes::kOk);
|
||||
}
|
||||
|
||||
// Copies text to cache/clipboard.
|
||||
void FakeNearbySharingService::CopyText(absl::string_view text) {}
|
||||
|
||||
std::string FakeNearbySharingService::Dump() const { return ""; }
|
||||
|
||||
NearbyShareSettings* FakeNearbySharingService::GetSettings() { return nullptr; }
|
||||
|
||||
@@ -108,15 +108,6 @@ class FakeNearbySharingService : public NearbySharingService {
|
||||
// |share_target|.
|
||||
bool DidLocalUserCancelTransfer(int64_t share_target_id) override;
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
void Open(ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback)
|
||||
override;
|
||||
|
||||
// Copies text to cache/clipboard.
|
||||
void CopyText(absl::string_view text) override;
|
||||
|
||||
std::string Dump() const override;
|
||||
|
||||
NearbyShareSettings* GetSettings() override;
|
||||
|
||||
@@ -28,7 +28,6 @@ cc_library(
|
||||
"sharing_platform.h",
|
||||
"sharing_rpc_client.h",
|
||||
"sharing_rpc_notifier.h",
|
||||
"shell.h",
|
||||
"system_info.h",
|
||||
"wifi_adapter.h",
|
||||
],
|
||||
@@ -67,7 +66,6 @@ cc_library(
|
||||
"mock_network_monitor.h",
|
||||
"mock_public_certificate_db.h",
|
||||
"mock_sharing_platform.h",
|
||||
"mock_shell.h",
|
||||
"mock_system_info.h",
|
||||
"mock_wifi_adapter.h",
|
||||
],
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/device_info.h"
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
@@ -36,7 +35,6 @@
|
||||
#include "sharing/internal/api/public_certificate_database.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/api/sharing_rpc_client.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/system_info.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
|
||||
@@ -69,24 +67,12 @@ class MockSharingPlatform : public SharingPlatform {
|
||||
MOCK_METHOD(nearby::sharing::api::WifiAdapter&, GetWifiAdapter, (),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, LaunchDefaultBrowserFromURL,
|
||||
(absl::string_view url,
|
||||
std::function<void(absl::Status)> callback),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(nearby::api::Shell&, GetShell, (), (override));
|
||||
|
||||
MOCK_METHOD(nearby::api::FastInitBleBeacon&, GetFastInitBleBeacon, (),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(nearby::api::FastInitiationManager&, GetFastInitiationManager, (),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, CopyText,
|
||||
(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(std::unique_ptr<nearby::api::SystemInfo>, CreateSystemInfo, (),
|
||||
(override));
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2024 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_
|
||||
|
||||
#include <filesystem> // NOLINT
|
||||
#include <functional>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
|
||||
namespace nearby::sharing::api {
|
||||
|
||||
class MockShell : public nearby::api::Shell {
|
||||
public:
|
||||
MockShell() = default;
|
||||
MockShell(const MockShell&) = delete;
|
||||
MockShell& operator=(const MockShell&) = delete;
|
||||
~MockShell() override = default;
|
||||
|
||||
MOCK_METHOD(void, Open,
|
||||
(const std::filesystem::path& path,
|
||||
std::function<void(absl::Status)> callback),
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing::api
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_
|
||||
@@ -44,10 +44,6 @@ class MockWifiAdapter : public nearby::sharing::api::WifiAdapter {
|
||||
MOCK_METHOD(void, AddObserver, (Observer * observer), (override));
|
||||
MOCK_METHOD(void, RemoveObserver, (Observer * observer), (override));
|
||||
MOCK_METHOD(bool, HasObserver, (Observer * observer), (override));
|
||||
MOCK_METHOD(void, JoinNetwork,
|
||||
(absl::string_view ssid, absl::string_view password,
|
||||
std::function<void(absl::Status)> callback),
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing::api
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/api/public_certificate_database.h"
|
||||
#include "sharing/internal/api/sharing_rpc_client.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/system_info.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
|
||||
@@ -65,25 +64,10 @@ class SharingPlatform {
|
||||
|
||||
virtual WifiAdapter& GetWifiAdapter() = 0;
|
||||
|
||||
virtual void LaunchDefaultBrowserFromURL(
|
||||
absl::string_view url, std::function<void(absl::Status)> callback) = 0;
|
||||
|
||||
virtual nearby::api::Shell& GetShell() = 0;
|
||||
|
||||
virtual nearby::api::FastInitBleBeacon& GetFastInitBleBeacon() = 0;
|
||||
|
||||
virtual nearby::api::FastInitiationManager& GetFastInitiationManager() = 0;
|
||||
|
||||
// Make calls to OS to copy text to clipboard
|
||||
//
|
||||
// @param text is a text to copy to clipboard.
|
||||
// @param callback
|
||||
//
|
||||
// If it is successfully copied, callback provided is executed with
|
||||
// absl::OkStatus. Otherwise, absl::InternalError.
|
||||
virtual void CopyText(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) = 0;
|
||||
|
||||
// Creates system information class. SystemInfo provides APIs to access
|
||||
// system information.
|
||||
virtual std::unique_ptr<nearby::api::SystemInfo> CreateSystemInfo() = 0;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHELL_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHELL_H_
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
// Shell defines interfaces to interact with platform core features.
|
||||
class Shell {
|
||||
public:
|
||||
virtual ~Shell() = default;
|
||||
|
||||
// Opens the |path| file or folder with default application. if |path|
|
||||
// is a directory, will open the folder by explore, otherwise it will
|
||||
// try to open the file with application supports it. |callback| is called
|
||||
// when the open operation completed, and absl::StatusCodes::kOk returned
|
||||
// only when open the path successfully.
|
||||
virtual void Open(const std::filesystem::path& path,
|
||||
std::function<void(absl::Status)> callback) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHELL_H_
|
||||
@@ -78,10 +78,6 @@ class WifiAdapter {
|
||||
virtual void AddObserver(Observer* observer) = 0;
|
||||
virtual void RemoveObserver(Observer* observer) = 0;
|
||||
virtual bool HasObserver(Observer* observer) = 0;
|
||||
|
||||
// Requests to join a Wi-Fi network.
|
||||
virtual void JoinNetwork(absl::string_view ssid, absl::string_view password,
|
||||
std::function<void(absl::Status)> callback) = 0;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
||||
@@ -20,15 +20,11 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "internal/platform/timer.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/fast_initiation_manager.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
|
||||
@@ -46,27 +42,16 @@ class Context {
|
||||
virtual Clock* GetClock() const = 0;
|
||||
virtual std::unique_ptr<Timer> CreateTimer() = 0;
|
||||
|
||||
// Opens a URL by calling the platform API. The platform API should run
|
||||
// in async mode. However, the callback might be called before
|
||||
// this function returns, for example if the URL has an error.
|
||||
// |url| is the URL to open. |callback| is called when the platform API
|
||||
// completes. absl::StatusCode::kOk is returned when the URL opens
|
||||
// successfully.
|
||||
virtual void OpenUrl(const nearby::network::Url& url,
|
||||
std::function<void(absl::Status)> callback) = 0;
|
||||
virtual ConnectivityManager* GetConnectivityManager() const = 0;
|
||||
virtual sharing::api::BluetoothAdapter& GetBluetoothAdapter() const = 0;
|
||||
virtual sharing::api::WifiAdapter& GetWifiAdapter() const = 0;
|
||||
virtual api::FastInitiationManager& GetFastInitiationManager() const = 0;
|
||||
virtual std::unique_ptr<TaskRunner> CreateSequencedTaskRunner() const = 0;
|
||||
virtual void CopyText(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) = 0;
|
||||
|
||||
// Creates task runner concurrently. |concurrent_count| is the maximum
|
||||
// count of tasks running at the same time.
|
||||
virtual std::unique_ptr<TaskRunner> CreateConcurrentTaskRunner(
|
||||
uint32_t concurrent_count) const = 0;
|
||||
virtual api::Shell& GetShell() const = 0;
|
||||
|
||||
// Provides the API to retrieve TaskRunner to run a task globally.
|
||||
virtual TaskRunner* GetTaskRunner() = 0;
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/clock_impl.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
@@ -32,7 +29,6 @@
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/fast_initiation_manager.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/connectivity_manager_impl.h"
|
||||
@@ -53,11 +49,6 @@ std::unique_ptr<Timer> ContextImpl::CreateTimer() {
|
||||
return std::make_unique<TimerImpl>();
|
||||
}
|
||||
|
||||
void ContextImpl::OpenUrl(const nearby::network::Url& url,
|
||||
std::function<void(absl::Status)> callback) {
|
||||
platform_.LaunchDefaultBrowserFromURL(url.GetUrlPath(), std::move(callback));
|
||||
}
|
||||
|
||||
ConnectivityManager* ContextImpl::GetConnectivityManager() const {
|
||||
return connectivity_manager_.get();
|
||||
}
|
||||
@@ -86,15 +77,6 @@ std::unique_ptr<TaskRunner> ContextImpl::CreateConcurrentTaskRunner(
|
||||
return task_runner;
|
||||
}
|
||||
|
||||
api::Shell& ContextImpl::GetShell() const {
|
||||
return platform_.GetShell();
|
||||
}
|
||||
|
||||
void ContextImpl::CopyText(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) {
|
||||
platform_.CopyText(text, callback);
|
||||
}
|
||||
|
||||
TaskRunner* ContextImpl::GetTaskRunner() {
|
||||
return &platform_.GetDefaultTaskRunner();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/fast_initiation_manager.h"
|
||||
#include "sharing/internal/api/sharing_platform.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
@@ -43,8 +42,6 @@ class ContextImpl : public Context {
|
||||
|
||||
Clock* GetClock() const override;
|
||||
std::unique_ptr<Timer> CreateTimer() override;
|
||||
void OpenUrl(const nearby::network::Url& url,
|
||||
std::function<void(absl::Status)> callback) override;
|
||||
ConnectivityManager* GetConnectivityManager() const override;
|
||||
sharing::api::BluetoothAdapter& GetBluetoothAdapter() const override;
|
||||
sharing::api::WifiAdapter& GetWifiAdapter() const override;
|
||||
@@ -52,9 +49,6 @@ class ContextImpl : public Context {
|
||||
std::unique_ptr<TaskRunner> CreateSequencedTaskRunner() const override;
|
||||
std::unique_ptr<TaskRunner> CreateConcurrentTaskRunner(
|
||||
uint32_t concurrent_count) const override;
|
||||
api::Shell& GetShell() const override;
|
||||
void CopyText(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) override;
|
||||
TaskRunner* GetTaskRunner() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -31,7 +31,6 @@ cc_library(
|
||||
"fake_network_monitor.h",
|
||||
"fake_preference_manager.h",
|
||||
"fake_public_certificate_db.h",
|
||||
"fake_shell.h",
|
||||
"fake_wifi_adapter.h",
|
||||
"fake_wifi_adapter_observer.h",
|
||||
],
|
||||
@@ -66,7 +65,6 @@ cc_test(
|
||||
"fake_connectivity_manager_test.cc",
|
||||
"fake_context_test.cc",
|
||||
"fake_fast_initiation_manager_test.cc",
|
||||
"fake_shell_test.cc",
|
||||
"fake_wifi_adapter_test.cc",
|
||||
],
|
||||
shard_count = 8,
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "internal/platform/timer.h"
|
||||
@@ -31,13 +28,11 @@
|
||||
#include "internal/test/fake_timer.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/fast_initiation_manager.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_bluetooth_adapter.h"
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_fast_initiation_manager.h"
|
||||
#include "sharing/internal/test/fake_shell.h"
|
||||
#include "sharing/internal/test/fake_wifi_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -49,7 +44,6 @@ FakeContext::FakeContext()
|
||||
fake_wifi_adapter_(std::make_unique<FakeWifiAdapter>()),
|
||||
fake_fast_initiation_manager_(
|
||||
std::make_unique<FakeFastInitiationManager>()),
|
||||
fake_shell_(std::make_unique<FakeShell>()),
|
||||
executor_(std::make_unique<FakeTaskRunner>(fake_clock_.get(), 5)) {}
|
||||
|
||||
Clock* FakeContext::GetClock() const { return fake_clock_.get(); }
|
||||
@@ -58,20 +52,6 @@ std::unique_ptr<Timer> FakeContext::CreateTimer() {
|
||||
return std::make_unique<FakeTimer>(fake_clock_.get());
|
||||
}
|
||||
|
||||
void FakeContext::OpenUrl(const nearby::network::Url& url,
|
||||
std::function<void(absl::Status)> callback) {
|
||||
// OpenUrl is an interface that depends on platform API. In a mock method, it
|
||||
// returns OK to avoid breaking test cases in the Nearby Sharing SDK.
|
||||
std::move(callback)(absl::OkStatus());
|
||||
}
|
||||
|
||||
void FakeContext::CopyText(const absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) {
|
||||
// CopyText is an interface that depends on platform API. In a mock method, it
|
||||
// returns OK to avoid breaking test cases in the Nearby Sharing SDK.
|
||||
std::move(callback)(absl::OkStatus());
|
||||
}
|
||||
|
||||
ConnectivityManager* FakeContext::GetConnectivityManager() const {
|
||||
return fake_connectivity_manager_.get();
|
||||
}
|
||||
@@ -101,8 +81,6 @@ std::unique_ptr<TaskRunner> FakeContext::CreateConcurrentTaskRunner(
|
||||
return task_runner;
|
||||
}
|
||||
|
||||
api::Shell& FakeContext::GetShell() const { return *fake_shell_; }
|
||||
|
||||
TaskRunner* FakeContext::GetTaskRunner() { return executor_.get(); }
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -20,23 +20,18 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "internal/platform/clock.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "internal/platform/timer.h"
|
||||
#include "internal/test/fake_clock.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/fast_initiation_manager.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/internal/test/fake_bluetooth_adapter.h"
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_fast_initiation_manager.h"
|
||||
#include "sharing/internal/test/fake_shell.h"
|
||||
#include "sharing/internal/test/fake_wifi_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -48,8 +43,6 @@ class FakeContext : public Context {
|
||||
|
||||
Clock* GetClock() const override;
|
||||
std::unique_ptr<Timer> CreateTimer() override;
|
||||
void OpenUrl(const nearby::network::Url& url,
|
||||
std::function<void(absl::Status)> callback) override;
|
||||
ConnectivityManager* GetConnectivityManager() const override;
|
||||
sharing::api::BluetoothAdapter& GetBluetoothAdapter() const override;
|
||||
sharing::api::WifiAdapter& GetWifiAdapter() const override;
|
||||
@@ -57,9 +50,6 @@ class FakeContext : public Context {
|
||||
std::unique_ptr<TaskRunner> CreateSequencedTaskRunner() const override;
|
||||
std::unique_ptr<TaskRunner> CreateConcurrentTaskRunner(
|
||||
uint32_t concurrent_count) const override;
|
||||
api::Shell& GetShell() const override;
|
||||
void CopyText(absl::string_view text,
|
||||
std::function<void(absl::Status)> callback) override;
|
||||
TaskRunner* GetTaskRunner() override;
|
||||
|
||||
FakeClock* fake_clock() const { return fake_clock_.get(); }
|
||||
@@ -75,7 +65,6 @@ class FakeContext : public Context {
|
||||
FakeFastInitiationManager* fake_fast_initiation_manager() const {
|
||||
return fake_fast_initiation_manager_.get();
|
||||
}
|
||||
FakeShell* fake_shell() const { return fake_shell_.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<FakeClock> fake_clock_;
|
||||
@@ -83,7 +72,6 @@ class FakeContext : public Context {
|
||||
std::unique_ptr<FakeBluetoothAdapter> fake_bluetooth_adapter_;
|
||||
std::unique_ptr<FakeWifiAdapter> fake_wifi_adapter_;
|
||||
std::unique_ptr<FakeFastInitiationManager> fake_fast_initiation_manager_;
|
||||
std::unique_ptr<FakeShell> fake_shell_;
|
||||
std::unique_ptr<TaskRunner> executor_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_SHELL_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_SHELL_H_
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <functional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "sharing/internal/api/shell.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class FakeShell : public api::Shell {
|
||||
public:
|
||||
FakeShell() = default;
|
||||
|
||||
// Open file by application. The mock method doesn't use the path
|
||||
// parameter. The callback result is controlled by return_error_.
|
||||
void Open(const std::filesystem::path& path,
|
||||
std::function<void(absl::Status)> callback) override {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
NL_LOG(WARNING) << "the path " << path << " is not existed.";
|
||||
}
|
||||
|
||||
if (return_error_) {
|
||||
std::move(callback)(absl::UnknownError(absl::StrCat("error code:", 12)));
|
||||
return;
|
||||
}
|
||||
|
||||
std::move(callback)(absl::OkStatus());
|
||||
}
|
||||
|
||||
// Mock methods.
|
||||
void set_return_error(bool return_error) { return_error_ = return_error; }
|
||||
|
||||
private:
|
||||
bool return_error_ = false;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_SHELL_H_
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sharing/internal/test/fake_shell.h"
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/status/status.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace {
|
||||
|
||||
TEST(FakeShell, Open) {
|
||||
FakeShell shell;
|
||||
absl::Status result;
|
||||
shell.Open(std::filesystem::temp_directory_path(),
|
||||
[&](absl::Status status) { result = status; });
|
||||
EXPECT_TRUE(result.ok());
|
||||
}
|
||||
|
||||
TEST(FakeShell, OpenFailed) {
|
||||
FakeShell shell;
|
||||
shell.set_return_error(true);
|
||||
absl::Status result;
|
||||
shell.Open("c:\\windows", [&](absl::Status status) { result = status; });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace nearby
|
||||
@@ -68,11 +68,6 @@ class FakeWifiAdapter : public sharing::api::WifiAdapter {
|
||||
return observer_list_.HasObserver(observer);
|
||||
}
|
||||
|
||||
void JoinNetwork(absl::string_view ssid, absl::string_view password,
|
||||
std::function<void(absl::Status)> callback) override {
|
||||
callback(absl::OkStatus());
|
||||
}
|
||||
|
||||
// Mock OS Wi-Fi adapter presence state changed events
|
||||
void ReceivedAdapterPresentChangedFromOs(bool present) {
|
||||
num_present_received_ += 1;
|
||||
|
||||
@@ -240,21 +240,6 @@ class NearbySharingService {
|
||||
// |share_target|.
|
||||
virtual bool DidLocalUserCancelTransfer(int64_t share_target_id) = 0;
|
||||
|
||||
// Opens attachments in |attachment_container| from the remote |share_target|.
|
||||
// If |attachment_container| is null, or the container is empty, the status
|
||||
// code will be set to kInvalidArgument.
|
||||
virtual void Open(
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) = 0;
|
||||
|
||||
// Copies text to cache/clipboard.
|
||||
virtual void CopyText(absl::string_view text) = 0;
|
||||
|
||||
// Persists and joins the Wi-Fi network.
|
||||
virtual void JoinWifiNetwork(absl::string_view ssid,
|
||||
absl::string_view password) = 0;
|
||||
|
||||
// Checks to make sure visibility setting is valid and updates the service's
|
||||
// visibility if so.
|
||||
virtual void SetVisibility(
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
// Copyright 2023 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "sharing/nearby_sharing_service_extension.h"
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <string>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
|
||||
namespace {
|
||||
using ::nearby::sharing::service::proto::FileMetadata;
|
||||
using ::nearby::sharing::service::proto::TextMetadata;
|
||||
using StatusCodes = ::nearby::sharing::NearbySharingService::StatusCodes;
|
||||
} // namespace
|
||||
|
||||
NearbySharingService::StatusCodes NearbySharingServiceExtension::Open(
|
||||
const AttachmentContainer& container) {
|
||||
if (!container.HasAttachments()) {
|
||||
return StatusCodes::kInvalidArgument;
|
||||
}
|
||||
|
||||
if (!container.GetFileAttachments().empty() &&
|
||||
!container.GetTextAttachments().empty()) {
|
||||
NL_LOG(ERROR)
|
||||
<< __func__
|
||||
<< ": Text attachments and file attachments can't come together.";
|
||||
return StatusCodes::kError;
|
||||
}
|
||||
|
||||
if (container.GetTextAttachments().size() == 1) {
|
||||
const TextAttachment& text_attachment = container.GetTextAttachments()[0];
|
||||
|
||||
switch (text_attachment.type()) {
|
||||
case TextMetadata::TEXT: {
|
||||
CopyText(text_attachment.text_body());
|
||||
break;
|
||||
}
|
||||
case TextMetadata::URL: {
|
||||
OpenUrl(*nearby::network::Url::Create(text_attachment.text_body()));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// Copy text for all other text types.
|
||||
CopyText(text_attachment.text_title());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return StatusCodes::kOk;
|
||||
}
|
||||
|
||||
if (container.GetTextAttachments().size() > 1) {
|
||||
NL_LOG(ERROR) << __func__
|
||||
<< ": Multiple text attachments are not supported currently.";
|
||||
return StatusCodes::kError;
|
||||
}
|
||||
|
||||
if (container.GetWifiCredentialsAttachments().size() == 1) {
|
||||
const WifiCredentialsAttachment& wifi_credentials_attachment =
|
||||
container.GetWifiCredentialsAttachments()[0];
|
||||
JoinWifiNetwork(wifi_credentials_attachment.ssid(),
|
||||
wifi_credentials_attachment.password());
|
||||
return StatusCodes::kOk;
|
||||
}
|
||||
|
||||
if (container.GetWifiCredentialsAttachments().size() > 1) {
|
||||
NL_LOG(ERROR) << __func__
|
||||
<< ": Multiple WiFi credentials attachments are not "
|
||||
"supported currently.";
|
||||
return StatusCodes::kError;
|
||||
}
|
||||
|
||||
const FileAttachment& file_attachment = container.GetFileAttachments()[0];
|
||||
|
||||
if ((container.GetFileAttachments().size() > 1) ||
|
||||
((file_attachment.type() != FileMetadata::AUDIO) &&
|
||||
(file_attachment.type() != FileMetadata::VIDEO) &&
|
||||
(file_attachment.type() != FileMetadata::IMAGE))) {
|
||||
// Opens download folder.
|
||||
NearbySharingService::StatusCodes status_codes = StatusCodes::kOk;
|
||||
absl::Notification notification;
|
||||
context_->GetShell().Open(
|
||||
std::filesystem::u8path(settings_->GetCustomSavePath()),
|
||||
[&status_codes, ¬ification](absl::Status status) {
|
||||
if (!status.ok()) {
|
||||
NL_LOG(ERROR)
|
||||
<< "Failed to open download folder with error message:"
|
||||
<< status;
|
||||
status_codes = StatusCodes::kError;
|
||||
} else {
|
||||
status_codes = StatusCodes::kOk;
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
notification.WaitForNotification();
|
||||
return status_codes;
|
||||
}
|
||||
|
||||
// Opens the file with default application.
|
||||
std::filesystem::path file_path;
|
||||
if (file_attachment.file_path().has_value()) {
|
||||
file_path = *file_attachment.file_path();
|
||||
} else {
|
||||
file_path =
|
||||
std::filesystem::u8path(settings_->GetCustomSavePath()) /
|
||||
// NOLINTNEXTLINE cannot build without the new string creation
|
||||
std::filesystem::u8path(std::string(file_attachment.file_name()));
|
||||
}
|
||||
|
||||
NearbySharingService::StatusCodes status_codes = StatusCodes::kOk;
|
||||
absl::Notification notification;
|
||||
context_->GetShell().Open(
|
||||
file_path, [file_name = file_attachment.file_name(), &status_codes,
|
||||
¬ification](absl::Status status) {
|
||||
if (!status.ok()) {
|
||||
NL_LOG(ERROR) << "Failed to open file " << file_name;
|
||||
status_codes = StatusCodes::kError;
|
||||
} else {
|
||||
status_codes = StatusCodes::kOk;
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
notification.WaitForNotification();
|
||||
return status_codes;
|
||||
}
|
||||
|
||||
// Opens an url target on a browser instance.
|
||||
void NearbySharingServiceExtension::OpenUrl(const ::nearby::network::Url& url) {
|
||||
absl::Notification notification;
|
||||
context_->OpenUrl(url, [url, ¬ification](absl::Status status) {
|
||||
if (!status.ok()) {
|
||||
NL_LOG(ERROR) << "Failed to open URL " << url.GetUrlPath()
|
||||
<< " with error " << status.message();
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
notification.WaitForNotification();
|
||||
}
|
||||
|
||||
// Copies text to cache/clipboard.
|
||||
void NearbySharingServiceExtension::CopyText(absl::string_view text) {
|
||||
absl::Notification notification;
|
||||
context_->CopyText(
|
||||
text, [text = std::string(text), ¬ification](absl::Status status) {
|
||||
if (!status.ok()) {
|
||||
NL_LOG(ERROR) << "Failed to copy text " << text << " with error "
|
||||
<< status.message();
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
notification.WaitForNotification();
|
||||
}
|
||||
|
||||
// Persists and joins the Wi-Fi network.
|
||||
void NearbySharingServiceExtension::JoinWifiNetwork(
|
||||
absl::string_view ssid, absl::string_view password) {
|
||||
absl::Notification notification;
|
||||
context_->GetWifiAdapter().JoinNetwork(
|
||||
ssid, password,
|
||||
[ssid = std::string(ssid), ¬ification](absl::Status status) {
|
||||
if (!status.ok()) {
|
||||
NL_LOG(ERROR) << "Failed to join network " << ssid << " with error "
|
||||
<< status.message();
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
notification.WaitForNotification();
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
@@ -17,40 +17,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/network/url.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/nearby_sharing_settings.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
|
||||
class NearbySharingServiceExtension {
|
||||
public:
|
||||
NearbySharingServiceExtension(Context* context, NearbyShareSettings* settings)
|
||||
: context_(context), settings_(settings) {}
|
||||
|
||||
// Opens attachments from the remote |share_target|.
|
||||
NearbySharingService::StatusCodes Open(const AttachmentContainer& container);
|
||||
|
||||
// Copies text to cache/clipboard.
|
||||
void CopyText(absl::string_view text);
|
||||
|
||||
// Persists and joins the Wi-Fi network.
|
||||
void JoinWifiNetwork(absl::string_view ssid, absl::string_view password);
|
||||
NearbySharingServiceExtension() = default;
|
||||
|
||||
// Returns the QR Code Url.
|
||||
std::string GetQrCodeUrl() const { return qr_code_url_; }
|
||||
|
||||
private:
|
||||
// Opens an url target on a browser instance.
|
||||
void OpenUrl(const ::nearby::network::Url& url);
|
||||
|
||||
Context* context_ = nullptr;
|
||||
NearbyShareSettings* settings_ = nullptr;
|
||||
|
||||
// The qr code url for the current session containing the Sender Public Key.
|
||||
std::string qr_code_url_ = "https://near.by/qrcode";
|
||||
};
|
||||
|
||||
@@ -14,168 +14,30 @@
|
||||
|
||||
#include "sharing/nearby_sharing_service_extension.h"
|
||||
|
||||
#include <filesystem> // NOLINT(build/c++17)
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/test/fake_device_info.h"
|
||||
#include "sharing/attachment_container.h"
|
||||
#include "sharing/file_attachment.h"
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
#include "sharing/internal/test/fake_preference_manager.h"
|
||||
#include "sharing/internal/test/fake_shell.h"
|
||||
#include "sharing/local_device_data/fake_nearby_share_local_device_data_manager.h"
|
||||
#include "sharing/nearby_sharing_service.h"
|
||||
#include "sharing/nearby_sharing_settings.h"
|
||||
#include "sharing/proto/wire_format.pb.h"
|
||||
#include "sharing/text_attachment.h"
|
||||
#include "sharing/wifi_credentials_attachment.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace {
|
||||
|
||||
using StatusCodes = NearbySharingService::StatusCodes;
|
||||
using ::nearby::sharing::service::proto::FileMetadata;
|
||||
using ::nearby::sharing::service::proto::TextMetadata;
|
||||
|
||||
class NearbySharingServiceExtensionTest : public ::testing::Test {
|
||||
public:
|
||||
NearbySharingServiceExtensionTest() = default;
|
||||
|
||||
void SetUp() override {
|
||||
service_extension_ = std::make_unique<NearbySharingServiceExtension>(
|
||||
&context_, &nearby_share_settings_);
|
||||
service_extension_ = std::make_unique<NearbySharingServiceExtension>();
|
||||
}
|
||||
|
||||
NearbySharingServiceExtension* service_extension() {
|
||||
return service_extension_.get();
|
||||
}
|
||||
|
||||
FakeContext* context() { return &context_; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<NearbySharingServiceExtension> service_extension_;
|
||||
nearby::FakeDeviceInfo device_info_;
|
||||
nearby::FakePreferenceManager preference_manager_;
|
||||
FakeContext context_;
|
||||
FakeNearbyShareLocalDeviceDataManager local_device_data_manager_{"test"};
|
||||
NearbyShareSettings nearby_share_settings_{&context_, context_.GetClock(),
|
||||
device_info_, preference_manager_,
|
||||
&local_device_data_manager_};
|
||||
};
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenEmptyAttachments) {
|
||||
StatusCodes status_codes = service_extension()->Open(AttachmentContainer());
|
||||
EXPECT_EQ(status_codes, StatusCodes::kInvalidArgument);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenBothFileAndTextAttachments) {
|
||||
AttachmentContainer container;
|
||||
container.AddTextAttachment(
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title", "mime"));
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.g1"));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kError);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenOneTextAttachment) {
|
||||
AttachmentContainer container;
|
||||
container.AddTextAttachment(
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title", "mime"));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenMoreThanOneTextAttachments) {
|
||||
AttachmentContainer container;
|
||||
container.AddTextAttachment(
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title1", "mime"));
|
||||
container.AddTextAttachment(
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title2", "mime"));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kError);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenUrlAttacchment) {
|
||||
AttachmentContainer container;
|
||||
container.AddTextAttachment(TextAttachment(
|
||||
TextMetadata::URL, "http://www.google.com", std::nullopt, std::nullopt));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenTextAddressAttacchment) {
|
||||
AttachmentContainer container;
|
||||
container.AddTextAttachment(TextAttachment(TextMetadata::ADDRESS, "body",
|
||||
std::nullopt, std::nullopt));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenWifiAttacchment) {
|
||||
AttachmentContainer container;
|
||||
container.AddWifiCredentialsAttachment(WifiCredentialsAttachment(
|
||||
"ssid", service::proto::WifiCredentialsMetadata::WPA_PSK));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenMultipleWifiAttacchments) {
|
||||
AttachmentContainer container;
|
||||
container.AddWifiCredentialsAttachment(WifiCredentialsAttachment(
|
||||
"ssid1", service::proto::WifiCredentialsMetadata::WPA_PSK));
|
||||
container.AddWifiCredentialsAttachment(WifiCredentialsAttachment(
|
||||
"ssid2", service::proto::WifiCredentialsMetadata::WPA_PSK));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kError);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenOneFileAttacchment) {
|
||||
AttachmentContainer container;
|
||||
container.AddFileAttachment(FileAttachment(
|
||||
/*id=*/1234, /*size=*/1000, /*file_name=*/"test.png",
|
||||
/*mime_type=*/"image", /*type=*/FileMetadata::IMAGE));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenUseDownloadFolder) {
|
||||
AttachmentContainer container;
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.g1"));
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.g2"));
|
||||
StatusCodes status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
FakeShell& shell = *context()->fake_shell();
|
||||
shell.set_return_error(true);
|
||||
status_codes = service_extension()->Open(container);
|
||||
EXPECT_NE(status_codes, StatusCodes::kOk);
|
||||
shell.set_return_error(false);
|
||||
status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, OpenUseDefaultApplication) {
|
||||
AttachmentContainer container;
|
||||
NearbySharingService::StatusCodes status_codes;
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.jpg"));
|
||||
status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.wav"));
|
||||
status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
container.AddFileAttachment(
|
||||
FileAttachment(std::filesystem::temp_directory_path() / "test.wmv"));
|
||||
status_codes = service_extension()->Open(container);
|
||||
EXPECT_EQ(status_codes, StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceExtensionTest, GetQrCodeUrl) {
|
||||
EXPECT_EQ(service_extension()->GetQrCodeUrl(), "https://near.by/qrcode");
|
||||
}
|
||||
|
||||
@@ -223,8 +223,7 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
settings_(std::make_unique<NearbyShareSettings>(
|
||||
context_, context_->GetClock(), device_info_, preference_manager_,
|
||||
local_device_data_manager_.get(), analytics_recorder_.get())),
|
||||
service_extension_(std::make_unique<NearbySharingServiceExtension>(
|
||||
context_, settings_.get())),
|
||||
service_extension_(std::make_unique<NearbySharingServiceExtension>()),
|
||||
file_handler_(sharing_platform),
|
||||
app_info_(sharing_platform.CreateAppInfo()) {
|
||||
NL_DCHECK(nearby_connections_manager_);
|
||||
@@ -988,41 +987,6 @@ bool NearbySharingServiceImpl::DidLocalUserCancelTransfer(
|
||||
share_target_id);
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::Open(
|
||||
ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback) {
|
||||
RunOnAnyThread(
|
||||
"api_open", [this, share_target = std::move(share_target),
|
||||
attachment_container = std::move(attachment_container),
|
||||
status_codes_callback = std::move(status_codes_callback)]() {
|
||||
if (!attachment_container || !attachment_container->HasAttachments()) {
|
||||
status_codes_callback(StatusCodes::kInvalidArgument);
|
||||
return;
|
||||
}
|
||||
NL_LOG(INFO) << __func__ << ": Open is called for share_target: "
|
||||
<< share_target.ToString();
|
||||
// Log analytics event of opening received attachments.
|
||||
analytics_recorder_->NewOpenReceivedAttachments(*attachment_container,
|
||||
/*session_id=*/0);
|
||||
status_codes_callback(service_extension_->Open(*attachment_container));
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::CopyText(absl::string_view text) {
|
||||
RunOnAnyThread("api_copy_text", [this, text = std::string(text)]() {
|
||||
service_extension_->CopyText(text);
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::JoinWifiNetwork(absl::string_view ssid,
|
||||
absl::string_view password) {
|
||||
RunOnAnyThread("api_join_wifi_network", [this, ssid = std::string(ssid),
|
||||
password = std::string(password)]() {
|
||||
service_extension_->JoinWifiNetwork(ssid, password);
|
||||
});
|
||||
}
|
||||
|
||||
void NearbySharingServiceImpl::SetVisibility(
|
||||
proto::DeviceVisibility visibility, absl::Duration expiration,
|
||||
absl::AnyInvocable<void(StatusCodes status_code) &&> callback) {
|
||||
|
||||
@@ -164,13 +164,6 @@ class NearbySharingServiceImpl
|
||||
std::function<void(StatusCodes status_codes)>
|
||||
status_codes_callback) override;
|
||||
bool DidLocalUserCancelTransfer(int64_t share_target_id) override;
|
||||
void Open(ShareTarget share_target,
|
||||
std::unique_ptr<AttachmentContainer> attachment_container,
|
||||
std::function<void(StatusCodes status_codes)> status_codes_callback)
|
||||
override;
|
||||
void CopyText(absl::string_view text) override;
|
||||
void JoinWifiNetwork(absl::string_view ssid,
|
||||
absl::string_view password) override;
|
||||
void SetVisibility(
|
||||
proto::DeviceVisibility visibility, absl::Duration expiration,
|
||||
absl::AnyInvocable<void(StatusCodes status_code) &&> callback) override;
|
||||
|
||||
@@ -4237,37 +4237,6 @@ TEST_F(NearbySharingServiceImplTest, RetryDiscoveredEndpointsDownloadLimit) {
|
||||
service_.reset();
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, OpenSharedTarget) {
|
||||
ShareTarget share_target;
|
||||
auto container = std::make_unique<AttachmentContainer>();
|
||||
container->AddTextAttachment(
|
||||
TextAttachment(TextMetadata::TEXT, "body", "title", "mime"));
|
||||
NearbySharingService::StatusCodes result;
|
||||
absl::Notification notification;
|
||||
service_->Open(share_target, std::move(container),
|
||||
[&](NearbySharingService::StatusCodes status_code) {
|
||||
result = status_code;
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
ASSERT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kOk);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest, OpenSharedTargetWithEmptyAttachments) {
|
||||
ShareTarget share_target;
|
||||
NearbySharingService::StatusCodes result;
|
||||
absl::Notification notification;
|
||||
service_->Open(share_target, std::make_unique<AttachmentContainer>(),
|
||||
[&](NearbySharingService::StatusCodes status_code) {
|
||||
result = status_code;
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
ASSERT_TRUE(notification.WaitForNotificationWithTimeout(kWaitTimeout));
|
||||
EXPECT_EQ(result, NearbySharingService::StatusCodes::kInvalidArgument);
|
||||
}
|
||||
|
||||
TEST_F(NearbySharingServiceImplTest,
|
||||
ScreenLockedRegisterReceiveSurfaceNotAdvertising) {
|
||||
SetScreenLocked(true);
|
||||
|
||||
Reference in New Issue
Block a user