Skip to content

Commit

Permalink
[CrOS Network] Show reset euicc notification
Browse files Browse the repository at this point in the history
This CL implements showing a system notification when reset euicc is
completed.

Bug: 1231305
Change-Id: I063a8e9a6ac7567793ab6fd40acff8dedc066d97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3203012
Reviewed-by: Azeem Arshad <azeemarshad@chromium.org>
Reviewed-by: Anqing Zhao <anqing@chromium.org>
Commit-Queue: Jason Zhang <jiajunz@google.com>
Cr-Commit-Position: refs/heads/main@{#930739}
  • Loading branch information
Jason Zhang authored and Chromium LUCI CQ committed Oct 12, 2021
1 parent e66d345 commit 5c91240
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ash/ash_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,12 @@ This file contains the strings for ash.
<message name="IDS_ASH_NETWORK_CELLULAR_SETUP_NOTIFICATION_MESSAGE" desc="Message displayed in the system notification shown post-OOBE if a user has no activated mobile networks.">
Tap to complete set up
</message>
<message name="IDS_ASH_NETWORK_RESET_EUICC_NOTIFICATION_TITLE" desc="Title used for the system notification shown when the reset euicc operation is initiated.">
eSIM connection unavailable
</message>
<message name="IDS_ASH_NETWORK_RESET_EUICC_NOTIFICATION_MESSAGE" desc="Message displayed in the system notification shown when the reset euicc operation is initiated.">
Your administrator has removed all eSIM profiles. Contact your administrator for more info.
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_DISCONNECTED_LABEL" desc="The label text used when network is not connected. [CHAR_LIMIT=14]">
Not connected
</message>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79228bebb6a5d609393df1218a8f393c05d72a81
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7e55cb34a65f3d50948987c050973264a7168ec0
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,35 @@

#include <utility>

#include "ash/public/cpp/notification_utils.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/syslog_logging.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/notifications/system_notification_helper.h"
#include "chromeos/dbus/hermes/hermes_euicc_client.h"
#include "chromeos/network/cellular_inhibitor.h"
#include "chromeos/network/cellular_utils.h"
#include "chromeos/network/network_handler.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#include "ui/message_center/public/cpp/notification.h"

namespace policy {

namespace {

constexpr char kNotifierESimPolicy[] = "policy.esim-policy";

} // namespace

// static
const char DeviceCommandResetEuiccJob::kResetEuiccNotificationId[] =
"cros_reset_euicc";

DeviceCommandResetEuiccJob::DeviceCommandResetEuiccJob()
: DeviceCommandResetEuiccJob(
chromeos::NetworkHandler::Get()->cellular_inhibitor()) {}
Expand Down Expand Up @@ -50,8 +66,7 @@ void DeviceCommandResetEuiccJob::RunImpl(CallbackWithResult succeeded_callback,
return;
}

// TODO(crbug.com/1231305) Trigger a notification if an eSIM network is
// active.
ShowResetEuiccNotification();
SYSLOG(INFO) << "Executing EUICC reset memory remote command";
cellular_inhibitor_->InhibitCellularScanning(
chromeos::CellularInhibitor::InhibitReason::kResettingEuiccMemory,
Expand Down Expand Up @@ -106,4 +121,24 @@ void DeviceCommandResetEuiccJob::RunResultCallback(
base::BindOnce(std::move(callback), /*result_payload=*/nullptr));
}

void DeviceCommandResetEuiccJob::ShowResetEuiccNotification() {
std::unique_ptr<message_center::Notification> notification =
ash::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE, kResetEuiccNotificationId,
l10n_util::GetStringUTF16(
IDS_ASH_NETWORK_RESET_EUICC_NOTIFICATION_TITLE),
l10n_util::GetStringUTF16(
IDS_ASH_NETWORK_RESET_EUICC_NOTIFICATION_MESSAGE),
/*display_source=*/std::u16string(), /*origin_url=*/GURL(),
message_center::NotifierId(
message_center::NotifierType::SYSTEM_COMPONENT,
kNotifierESimPolicy),
message_center::RichNotificationData(),
base::MakeRefCounted<message_center::HandleNotificationClickDelegate>(
base::DoNothingAs<void()>()),
/*small_image=*/gfx::VectorIcon(),
message_center::SystemNotificationWarningLevel::NORMAL);
SystemNotificationHelper::GetInstance()->Display(*notification);
}

} // namespace policy
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DeviceCommandResetEuiccJob : public RemoteCommandJob {
static std::unique_ptr<DeviceCommandResetEuiccJob> CreateForTesting(
chromeos::CellularInhibitor* cellular_inhbitor);

static const char kResetEuiccNotificationId[];

// RemoteCommandJob:
enterprise_management::RemoteCommand_Type GetType() const override;

Expand All @@ -58,6 +60,7 @@ class DeviceCommandResetEuiccJob : public RemoteCommandJob {
std::unique_ptr<chromeos::CellularInhibitor::InhibitLock> inhibit_lock,
chromeos::HermesResponseStatus status);
void RunResultCallback(CallbackWithResult callback);
void ShowResetEuiccNotification();

chromeos::CellularInhibitor* const cellular_inhibitor_;
base::WeakPtrFactory<DeviceCommandResetEuiccJob> weak_ptr_factory_{this};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "chrome/browser/ash/policy/remote_commands/device_command_reset_euicc_job.h"

#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/system_notification_helper.h"
#include "chrome/test/base/chrome_ash_test_base.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/dbus/hermes/hermes_clients.h"
#include "chromeos/dbus/hermes/hermes_euicc_client.h"
#include "chromeos/dbus/hermes/hermes_manager_client.h"
Expand All @@ -13,6 +16,7 @@
#include "chromeos/network/network_state_test_helper.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/public/cpp/notification.h"

namespace policy {

Expand Down Expand Up @@ -109,6 +113,10 @@ class DeviceCommandResetEuiccJobTest : public ChromeAshTestBase {

TEST_F(DeviceCommandResetEuiccJobTest, ResetEuicc) {
base::RunLoop run_loop;
TestingBrowserProcess::GetGlobal()->SetSystemNotificationHelper(
std::make_unique<SystemNotificationHelper>());
NotificationDisplayServiceTester tester(/*profile=*/nullptr);

std::unique_ptr<RemoteCommandJob> job = CreateResetEuiccJob(test_start_time_);
EXPECT_TRUE(
job->Run(base::Time::Now(), base::TimeTicks::Now(),
Expand All @@ -117,10 +125,16 @@ TEST_F(DeviceCommandResetEuiccJobTest, ResetEuicc) {
RemoteCommandJob::Status::SUCCEEDED,
/*expected_profile_count=*/0)));
run_loop.Run();
// Verify that the notification should be displayed.
EXPECT_TRUE(tester.GetNotification(
DeviceCommandResetEuiccJob::kResetEuiccNotificationId));
}

TEST_F(DeviceCommandResetEuiccJobTest, ResetEuiccInhibitFailure) {
chromeos::ShillManagerClient::Get()->GetTestInterface()->ClearDevices();
TestingBrowserProcess::GetGlobal()->SetSystemNotificationHelper(
std::make_unique<SystemNotificationHelper>());
NotificationDisplayServiceTester tester(/*profile=*/nullptr);
base::RunLoop run_loop;
std::unique_ptr<RemoteCommandJob> job = CreateResetEuiccJob(test_start_time_);
EXPECT_TRUE(
Expand All @@ -130,6 +144,9 @@ TEST_F(DeviceCommandResetEuiccJobTest, ResetEuiccInhibitFailure) {
RemoteCommandJob::Status::FAILED,
/*expected_profile_count=*/2)));
run_loop.Run();
// Verify that the notification should be displayed.
EXPECT_TRUE(tester.GetNotification(
DeviceCommandResetEuiccJob::kResetEuiccNotificationId));
}

} // namespace policy

0 comments on commit 5c91240

Please sign in to comment.