Commit 058824a6 authored by Azeem Arshad's avatar Azeem Arshad Committed by Commit Bot

[AndroidSms] Start connection on unlock.

This CL modifies android sms service and connection
manager so that a startConnection message is sent to the
service worker when device is unlocked. This makes sure
the service worker reconnects and continues to receive
messages after being woken up from sleep.

Bug: 1150178
Change-Id: Ie524db4d3714f08ecbbf5a39d573b20712db55b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553183Reviewed-by: default avatarJon Mann <jonmann@chromium.org>
Commit-Queue: Azeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830256}
parent 3e8af4b6
......@@ -67,13 +67,18 @@ void AndroidSmsService::Shutdown() {
}
void AndroidSmsService::OnSessionStateChanged() {
// At most one ConnectionManager should be created.
if (connection_manager_)
// ConnectionManager should not be created for blocked sessions.
if (session_manager::SessionManager::Get()->IsUserSessionBlocked()) {
return;
}
// ConnectionManager should not be created for blocked sessions.
if (session_manager::SessionManager::Get()->IsUserSessionBlocked())
// Start Connection if connection manager already exists.
// This ensures that the service worker connects again and
// continues to receive messages after unlock.
if (connection_manager_) {
connection_manager_->StartConnection();
return;
}
std::unique_ptr<ConnectionEstablisher> connection_establisher;
connection_establisher = std::make_unique<FcmConnectionEstablisher>(
......
......@@ -66,6 +66,18 @@ ConnectionManager::~ConnectionManager() {
GetCurrentServiceWorkerContext()->RemoveObserver(this);
}
void ConnectionManager::StartConnection() {
if (!enabled_pwa_url_) {
return;
}
PA_LOG(INFO) << "ConnectionManager::StartConnection(): Establishing "
<< "connection to PWA at " << *enabled_pwa_url_ << ".";
connection_establisher_->EstablishConnection(
*enabled_pwa_url_,
ConnectionEstablisher::ConnectionMode::kStartConnection,
GetCurrentServiceWorkerContext());
}
void ConnectionManager::OnVersionActivated(int64_t version_id,
const GURL& scope) {
if (!enabled_pwa_url_ || !scope.EqualsIgnoringRef(*enabled_pwa_url_))
......@@ -146,13 +158,8 @@ void ConnectionManager::UpdateConnectionStatus() {
if (!enabled_pwa_url_)
return;
PA_LOG(INFO) << "ConnectionManager::UpdateConnectionStatus(): Establishing "
<< "connection to PWA at " << *enabled_pwa_url_ << ".";
GetCurrentServiceWorkerContext()->AddObserver(this);
connection_establisher_->EstablishConnection(
*enabled_pwa_url_,
ConnectionEstablisher::ConnectionMode::kStartConnection,
GetCurrentServiceWorkerContext());
StartConnection();
}
base::Optional<GURL> ConnectionManager::GenerateEnabledPwaUrl() {
......
......@@ -54,6 +54,9 @@ class ConnectionManager
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
~ConnectionManager() override;
// Sends a start connection message to the service worker.
void StartConnection();
private:
friend class ConnectionManagerTest;
......
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