forked from mirror/chromium
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CrOS MultiDevice] Show notification when Messages pairing is lost.
Once multi-device setup is completed, the "Messages" PWA is installed, but further setup is required before the app can be used. Specifically, the Chromebook needs to be paired with the user's phone via a QR code displayed in the PWA. However, this pairing is broken the PWA is migrated from messages.android.com to messages.google.com (see https://crbug.com/917855. This CL alerts the user that the devices need to be re-paired when this situation arises. Bug: 918943 Change-Id: Ib662edf42ba01320cc12e6f3955b80c390d4493e Reviewed-on: https://chromium-review.googlesource.com/c/1406159 Commit-Queue: Kyle Horimoto <khorimoto@chromium.org> Reviewed-by: Evan Stade <estade@chromium.org> Cr-Commit-Position: refs/heads/master@{#622126}
- Loading branch information
Kyle Horimoto
authored and
Commit Bot
committed
Jan 11, 2019
1 parent
f3fb24a
commit e1a6276
Showing
12 changed files
with
437 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
CANVAS_DIMENSIONS, 36, | ||
MOVE_TO, 31, 4, | ||
H_LINE_TO, 5, | ||
R_ARC_TO, 3, 3, 0, 0, 0, -2.98f, 3, | ||
R_V_LINE_TO, 27, | ||
LINE_TO, 10, 28, | ||
R_H_LINE_TO, 21, | ||
R_CUBIC_TO, 1.65f, 0, 3, -1.35f, 3, -3, | ||
V_LINE_TO, 7, | ||
R_CUBIC_TO, 0, -1.65f, -1.35f, -3, -3, -3, | ||
CLOSE, | ||
MOVE_TO, 9, 20, | ||
R_H_LINE_TO, 12, | ||
R_V_LINE_TO, 3, | ||
H_LINE_TO, 9, | ||
CLOSE, | ||
R_MOVE_TO, 0, -6, | ||
R_H_LINE_TO, 18, | ||
R_V_LINE_TO, 3, | ||
H_LINE_TO, 9, | ||
CLOSE, | ||
R_MOVE_TO, 0, -6, | ||
R_H_LINE_TO, 18, | ||
R_V_LINE_TO, 3, | ||
H_LINE_TO, 9, | ||
CLOSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
chrome/browser/chromeos/android_sms/pairing_lost_notifier.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/chromeos/android_sms/pairing_lost_notifier.h" | ||
|
||
#include "ash/public/cpp/notification_utils.h" | ||
#include "ash/public/cpp/vector_icons/vector_icons.h" | ||
#include "chrome/browser/notifications/notification_display_service.h" | ||
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "chromeos/components/multidevice/logging/logging.h" | ||
#include "chromeos/services/multidevice_setup/public/cpp/android_sms_app_helper_delegate.h" | ||
#include "components/account_id/account_id.h" | ||
#include "components/prefs/pref_registry_simple.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/message_center/public/cpp/notification_types.h" | ||
|
||
namespace chromeos { | ||
|
||
namespace android_sms { | ||
|
||
namespace { | ||
|
||
const char kWasPreviouslySetUpPrefName[] = "android_sms.was_previously_set_up"; | ||
|
||
const char kAndroidSmsNotifierId[] = "ash.android_sms"; | ||
const char kPairingLostNotificationId[] = "android_sms.pairing_lost"; | ||
|
||
} // namespace | ||
|
||
// static | ||
void PairingLostNotifier::RegisterProfilePrefs(PrefRegistrySimple* registry) { | ||
registry->RegisterBooleanPref(kWasPreviouslySetUpPrefName, false); | ||
} | ||
|
||
PairingLostNotifier::PairingLostNotifier( | ||
Profile* profile, | ||
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client, | ||
PrefService* pref_service, | ||
multidevice_setup::AndroidSmsAppHelperDelegate* | ||
android_sms_app_helper_delegate) | ||
: profile_(profile), | ||
multidevice_setup_client_(multidevice_setup_client), | ||
pref_service_(pref_service), | ||
android_sms_app_helper_delegate_(android_sms_app_helper_delegate), | ||
weak_ptr_factory_(this) { | ||
multidevice_setup_client_->AddObserver(this); | ||
HandleMessagesFeatureState(); | ||
} | ||
|
||
PairingLostNotifier::~PairingLostNotifier() { | ||
multidevice_setup_client_->RemoveObserver(this); | ||
} | ||
|
||
void PairingLostNotifier::OnFeatureStatesChanged( | ||
const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap& | ||
feature_states_map) { | ||
HandleMessagesFeatureState(); | ||
} | ||
|
||
void PairingLostNotifier::HandleMessagesFeatureState() { | ||
multidevice_setup::mojom::FeatureState state = | ||
multidevice_setup_client_->GetFeatureStates() | ||
.find(multidevice_setup::mojom::Feature::kMessages) | ||
->second; | ||
|
||
// If Messages is currently enabled or disabled, the user has completed the | ||
// setup process. | ||
if (state == multidevice_setup::mojom::FeatureState::kDisabledByUser || | ||
state == multidevice_setup::mojom::FeatureState::kEnabledByUser) { | ||
HandleSetUpFeatureState(); | ||
return; | ||
} | ||
|
||
// If further setup is not required, there is no need to show a notification. | ||
if (state != multidevice_setup::mojom::FeatureState::kFurtherSetupRequired) | ||
return; | ||
|
||
// The Messages was not previously set up, the notification should not be | ||
// shown. | ||
if (!pref_service_->GetBoolean(kWasPreviouslySetUpPrefName)) | ||
return; | ||
|
||
// Set the preference to false to indicate that the app was not previously set | ||
// up, then show the notification. | ||
pref_service_->SetBoolean(kWasPreviouslySetUpPrefName, false); | ||
ShowPairingLostNotification(); | ||
} | ||
|
||
void PairingLostNotifier::HandleSetUpFeatureState() { | ||
// Store a preference indicating that the feature has been set up. This | ||
// preference will be checked in the future in the case that the phone has | ||
// become unpaired. | ||
pref_service_->SetBoolean(kWasPreviouslySetUpPrefName, true); | ||
|
||
// If the "pairing lost" notification is currently visible, close it. | ||
// Otherwise, the user could be confused that a notification is alerting the | ||
// user to complete a task that has already been completed. | ||
ClosePairingLostNotificationIfVisible(); | ||
} | ||
|
||
void PairingLostNotifier::ShowPairingLostNotification() { | ||
PA_LOG(INFO) << "PairingLostNotifier::ShowPairingLostNotification(): " | ||
<< "Pairing has been lost; displaying notification."; | ||
|
||
NotificationDisplayService::GetForProfile(profile_)->Display( | ||
NotificationHandler::Type::TRANSIENT, | ||
*ash::CreateSystemNotification( | ||
message_center::NotificationType::NOTIFICATION_TYPE_SIMPLE, | ||
kPairingLostNotificationId, | ||
l10n_util::GetStringUTF16( | ||
IDS_ANDROID_MESSAGES_PAIRING_LOST_NOTIFICATION_TITLE), | ||
l10n_util::GetStringUTF16( | ||
IDS_ANDROID_MESSAGES_PAIRING_LOST_NOTIFICATION_MESSAGE), | ||
base::string16() /* display_source */, GURL() /* origin_url */, | ||
message_center::NotifierId( | ||
message_center::NotifierType::SYSTEM_COMPONENT, | ||
kAndroidSmsNotifierId), | ||
{} /* rich_notification_data */, | ||
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>( | ||
base::BindRepeating( | ||
&PairingLostNotifier::OnPairingLostNotificationClick, | ||
weak_ptr_factory_.GetWeakPtr())), | ||
ash::kNotificationMessagesIcon, | ||
message_center::SystemNotificationWarningLevel::NORMAL)); | ||
} | ||
|
||
void PairingLostNotifier::ClosePairingLostNotificationIfVisible() { | ||
PA_LOG(INFO) << "PairingLostNotifier::" | ||
<< "ClosePairingLostNotificationIfVisible(): " | ||
<< "Closing pairing lost notification if visible."; | ||
|
||
NotificationDisplayService::GetForProfile(profile_)->Close( | ||
NotificationHandler::Type::TRANSIENT, kPairingLostNotificationId); | ||
} | ||
|
||
void PairingLostNotifier::OnPairingLostNotificationClick( | ||
base::Optional<int> button_index) { | ||
PA_LOG(INFO) << "PairingLostNotifier::OnPairingLostNotificationClick(): " | ||
<< "Pairing notification clicked; opening PWA."; | ||
|
||
ClosePairingLostNotificationIfVisible(); | ||
android_sms_app_helper_delegate_->SetUpAndLaunchAndroidSmsApp(); | ||
} | ||
|
||
} // namespace android_sms | ||
|
||
} // namespace chromeos |
Oops, something went wrong.