Commit 595f7529 authored by Michael Hansen's avatar Michael Hansen Committed by Commit Bot

[Nearby] Invalidate surfaces on screen lock changes.

Invalidate send and receive surfaces to make sure we start or stop
advertising based on changes to screen lock state.

Bug: b:166174379
Bug: 1119993
Change-Id: Ie7490d888b42e4c4aac783216b54490476f53aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392703
Commit-Queue: Michael Hansen <hansenmichael@google.com>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806767}
parent de24e540
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "ash/public/cpp/session/session_controller.h"
#include "base/barrier_closure.h" #include "base/barrier_closure.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file.h" #include "base/files/file.h"
...@@ -43,7 +44,6 @@ ...@@ -43,7 +44,6 @@
#include "crypto/random.h" #include "crypto/random.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/idle/idle.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -230,6 +230,14 @@ NearbySharingServiceImpl::NearbySharingServiceImpl( ...@@ -230,6 +230,14 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
DCHECK(profile_); DCHECK(profile_);
DCHECK(nearby_connections_manager_); DCHECK(nearby_connections_manager_);
#if defined(OS_CHROMEOS)
auto* session_controller = ash::SessionController::Get();
if (session_controller) {
is_screen_locked_ = session_controller->IsScreenLocked();
session_controller->AddObserver(this);
}
#endif // OS_CHROMEOS
nearby_process_observer_.Add(process_manager_); nearby_process_observer_.Add(process_manager_);
settings_.AddSettingsObserver(settings_receiver_.BindNewPipeAndPassRemote()); settings_.AddSettingsObserver(settings_receiver_.BindNewPipeAndPassRemote());
...@@ -282,6 +290,12 @@ void NearbySharingServiceImpl::Shutdown() { ...@@ -282,6 +290,12 @@ void NearbySharingServiceImpl::Shutdown() {
if (bluetooth_adapter_) if (bluetooth_adapter_)
bluetooth_adapter_->RemoveObserver(this); bluetooth_adapter_->RemoveObserver(this);
#if defined(OS_CHROMEOS)
auto* session_controller = ash::SessionController::Get();
if (session_controller)
session_controller->RemoveObserver(this);
#endif // OS_CHROMEOS
foreground_receive_callbacks_.Clear(); foreground_receive_callbacks_.Clear();
background_receive_callbacks_.Clear(); background_receive_callbacks_.Clear();
foreground_send_transfer_callbacks_.Clear(); foreground_send_transfer_callbacks_.Clear();
...@@ -820,6 +834,13 @@ void NearbySharingServiceImpl::OnEndpointLost(const std::string& endpoint_id) { ...@@ -820,6 +834,13 @@ void NearbySharingServiceImpl::OnEndpointLost(const std::string& endpoint_id) {
NS_LOG(VERBOSE) << __func__ << ": Reported onShareTargetLost"; NS_LOG(VERBOSE) << __func__ << ": Reported onShareTargetLost";
} }
void NearbySharingServiceImpl::OnLockStateChanged(bool locked) {
NS_LOG(VERBOSE) << __func__ << ": Screen lock state changed. (" << locked
<< ")";
is_screen_locked_ = locked;
InvalidateSurfaceState();
}
void NearbySharingServiceImpl::OnEnabledChanged(bool enabled) { void NearbySharingServiceImpl::OnEnabledChanged(bool enabled) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (enabled) { if (enabled) {
...@@ -1120,7 +1141,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() { ...@@ -1120,7 +1141,7 @@ void NearbySharingServiceImpl::InvalidateAdvertisingState() {
} }
// Screen is off. Do no work. // Screen is off. Do no work.
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
StopAdvertising(); StopAdvertising();
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Stopping advertising because the screen is locked."; << ": Stopping advertising because the screen is locked.";
...@@ -1289,7 +1310,7 @@ void NearbySharingServiceImpl::InvalidateScanningState() { ...@@ -1289,7 +1310,7 @@ void NearbySharingServiceImpl::InvalidateScanningState() {
} }
// Screen is off. Do no work. // Screen is off. Do no work.
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
StopScanning(); StopScanning();
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Stopping discovery because the screen is locked."; << ": Stopping discovery because the screen is locked.";
...@@ -1346,7 +1367,7 @@ void NearbySharingServiceImpl::StartScanning() { ...@@ -1346,7 +1367,7 @@ void NearbySharingServiceImpl::StartScanning() {
return; return;
} }
if (ui::CheckIdleStateIsLocked()) { if (is_screen_locked_) {
NS_LOG(VERBOSE) << __func__ NS_LOG(VERBOSE) << __func__
<< ": Failed to scan because the user's screen is locked."; << ": Failed to scan because the user's screen is locked.";
return; return;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ash/public/cpp/session/session_observer.h"
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -57,7 +58,8 @@ class NearbySharingServiceImpl ...@@ -57,7 +58,8 @@ class NearbySharingServiceImpl
public NearbyProcessManager::Observer, public NearbyProcessManager::Observer,
public device::BluetoothAdapter::Observer, public device::BluetoothAdapter::Observer,
public NearbyConnectionsManager::IncomingConnectionListener, public NearbyConnectionsManager::IncomingConnectionListener,
public NearbyConnectionsManager::DiscoveryListener { public NearbyConnectionsManager::DiscoveryListener,
public ash::SessionObserver {
public: public:
explicit NearbySharingServiceImpl( explicit NearbySharingServiceImpl(
PrefService* prefs, PrefService* prefs,
...@@ -132,6 +134,9 @@ class NearbySharingServiceImpl ...@@ -132,6 +134,9 @@ class NearbySharingServiceImpl
void OnEndpointLost(const std::string& endpoint_id) override; void OnEndpointLost(const std::string& endpoint_id) override;
private: private:
// ash::SessionObserver:
void OnLockStateChanged(bool locked) override;
base::ObserverList<TransferUpdateCallback>& GetReceiveCallbacksFromState( base::ObserverList<TransferUpdateCallback>& GetReceiveCallbacksFromState(
ReceiveSurfaceState state); ReceiveSurfaceState state);
bool IsVisibleInBackground(Visibility visibility); bool IsVisibleInBackground(Visibility visibility);
...@@ -316,6 +321,7 @@ class NearbySharingServiceImpl ...@@ -316,6 +321,7 @@ class NearbySharingServiceImpl
std::unique_ptr<NearbyShareCertificateManager> certificate_manager_; std::unique_ptr<NearbyShareCertificateManager> certificate_manager_;
NearbyShareSettings settings_; NearbyShareSettings settings_;
NearbyFileHandler file_handler_; NearbyFileHandler file_handler_;
bool is_screen_locked_ = false;
// A list of service observers. // A list of service observers.
base::ObserverList<NearbySharingService::Observer> observers_; base::ObserverList<NearbySharingService::Observer> observers_;
......
...@@ -6,9 +6,17 @@ ...@@ -6,9 +6,17 @@
#include <utility> #include <utility>
#include "ash/public/cpp/session/session_observer.h"
TestSessionController::TestSessionController() = default; TestSessionController::TestSessionController() = default;
TestSessionController::~TestSessionController() = default; TestSessionController::~TestSessionController() = default;
void TestSessionController::SetScreenLocked(bool locked) {
is_screen_locked_ = locked;
for (auto& observer : observers_)
observer.OnLockStateChanged(locked);
}
void TestSessionController::SetClient(ash::SessionControllerClient* client) {} void TestSessionController::SetClient(ash::SessionControllerClient* client) {}
void TestSessionController::SetSessionInfo(const ash::SessionInfo& info) { void TestSessionController::SetSessionInfo(const ash::SessionInfo& info) {
...@@ -77,11 +85,14 @@ void TestSessionController::RemoveSessionActivationObserverForAccountId( ...@@ -77,11 +85,14 @@ void TestSessionController::RemoveSessionActivationObserverForAccountId(
const AccountId& account_id, const AccountId& account_id,
ash::SessionActivationObserver* observer) {} ash::SessionActivationObserver* observer) {}
void TestSessionController::AddObserver(ash::SessionObserver* observer) {} void TestSessionController::AddObserver(ash::SessionObserver* observer) {
observers_.AddObserver(observer);
}
void TestSessionController::RemoveObserver(ash::SessionObserver* observer) {} void TestSessionController::RemoveObserver(ash::SessionObserver* observer) {
observers_.RemoveObserver(observer);
}
bool TestSessionController::IsScreenLocked() const { bool TestSessionController::IsScreenLocked() const {
NOTIMPLEMENTED(); return is_screen_locked_;
return false;
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/public/cpp/session/session_controller.h" #include "ash/public/cpp/session/session_controller.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/observer_list.h"
#include "base/optional.h" #include "base/optional.h"
// Test implementation of ash's SessionController interface. // Test implementation of ash's SessionController interface.
...@@ -44,6 +45,8 @@ class TestSessionController : public ash::SessionController { ...@@ -44,6 +45,8 @@ class TestSessionController : public ash::SessionController {
return set_user_session_order_count_; return set_user_session_order_count_;
} }
void SetScreenLocked(bool locked);
// ash::SessionController: // ash::SessionController:
void SetClient(ash::SessionControllerClient* client) override; void SetClient(ash::SessionControllerClient* client) override;
void SetSessionInfo(const ash::SessionInfo& info) override; void SetSessionInfo(const ash::SessionInfo& info) override;
...@@ -82,6 +85,8 @@ class TestSessionController : public ash::SessionController { ...@@ -82,6 +85,8 @@ class TestSessionController : public ash::SessionController {
int update_user_session_count_ = 0; int update_user_session_count_ = 0;
int lock_animation_complete_call_count_ = 0; int lock_animation_complete_call_count_ = 0;
int set_user_session_order_count_ = 0; int set_user_session_order_count_ = 0;
bool is_screen_locked_ = false;
base::ObserverList<ash::SessionObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(TestSessionController); DISALLOW_COPY_AND_ASSIGN(TestSessionController);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment