Skip to content

Commit

Permalink
[CrOS Cellular] Handle connection failures due to locked SIMs
Browse files Browse the repository at this point in the history
This CL updates NetworkConnectionHandlerImpl to check whether the
network to be connected is locked. If it is, it fails and returns a "SIM
locked" error. Additionally, this CL handles that error by showing a
notification.

(cherry picked from commit 2ef76a4)

Bug: 1197374
Change-Id: Ib57cddefee0f37a0dde3ac5da84bbe882255e920
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2816444
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Azeem Arshad <azeemarshad@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#871357}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2820514
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Kyle Horimoto <khorimoto@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/4472@{#15}
Cr-Branched-From: 3d60439-refs/heads/master@{#870763}
  • Loading branch information
Kyle Horimoto authored and Chromium LUCI CQ committed Apr 12, 2021
1 parent 4d49a0b commit df8f0a3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
5 changes: 4 additions & 1 deletion chrome/browser/ui/ash/network/network_state_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ std::u16string GetConnectErrorString(const std::string& error_name) {
return l10n_util::GetStringUTF16(
IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
}
if (error_name == NetworkConnectionHandler::kErrorSimLocked)
return l10n_util::GetStringUTF16(IDS_NETWORK_LIST_SIM_CARD_LOCKED);
return std::u16string();
}

Expand Down Expand Up @@ -111,7 +113,8 @@ bool ShouldConnectFailedNotificationBeShown(const std::string& error_name,
if (error_name != NetworkConnectionHandler::kErrorConnectFailed &&
error_name != NetworkConnectionHandler::kErrorNotFound &&
error_name != NetworkConnectionHandler::kErrorConfigureFailed &&
error_name != NetworkConnectionHandler::kErrorCertLoadTimeout) {
error_name != NetworkConnectionHandler::kErrorCertLoadTimeout &&
error_name != NetworkConnectionHandler::kErrorSimLocked) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions chromeos/network/network_connection_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const char NetworkConnectionHandler::kErrorCellularOutOfCredits[] =
"cellular-out-of-credits";
const char NetworkConnectionHandler::kErrorESimProfileIssue[] =
"esim-profile-issue";
const char NetworkConnectionHandler::kErrorSimLocked[] = "sim-locked";

NetworkConnectionHandler::NetworkConnectionHandler()
: tether_delegate_(nullptr) {}
Expand Down
4 changes: 4 additions & 0 deletions chromeos/network/network_connection_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkConnectionHandler {
// Error occurred while trying to perform an operation with an eSIM profile.
static const char kErrorESimProfileIssue[];

// Failed due to a connection attempt to a cellular network with a locked SIM.
// The SIM must be unlocked before a connection can succeed.
static const char kErrorSimLocked[];

class COMPONENT_EXPORT(CHROMEOS_NETWORK) TetherDelegate {
public:
using StringErrorCallback =
Expand Down
29 changes: 22 additions & 7 deletions chromeos/network/network_connection_handler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "chromeos/dbus/shill/shill_service_client.h"
#include "chromeos/login/login_state/login_state.h"
#include "chromeos/network/cellular_esim_connection_handler.h"
#include "chromeos/network/cellular_utils.h"
#include "chromeos/network/client_cert_resolver.h"
#include "chromeos/network/client_cert_util.h"
#include "chromeos/network/device_state.h"
Expand Down Expand Up @@ -314,13 +315,27 @@ void NetworkConnectionHandlerImpl::ConnectToNetwork(
return;
}

// eSIM networks are Cellular networks with an associated EID. Note that
// |cellular_esim_connection_handler_| is expected to be null if the flag is
// disabled.
if (cellular_esim_connection_handler_ &&
NetworkTypePattern::Cellular().MatchesType(network->type()) &&
!network->eid().empty() && !network->connectable()) {
is_non_connectable_esim_network = true;
if (NetworkTypePattern::Cellular().MatchesType(network->type())) {
const DeviceState* cellular_device =
network_state_handler_->GetDeviceState(network->device_path());

// If the SIM is active and the active SIM is locked, we are attempting to
// connect to a locked SIM. A SIM must be unlocked before a connection can
// succeed.
if (cellular_device && IsSimPrimary(network->iccid(), cellular_device) &&
cellular_device->IsSimLocked()) {
InvokeConnectErrorCallback(service_path, std::move(error_callback),
kErrorSimLocked);
return;
}

// eSIM networks are Cellular networks with an associated EID. Note that
// |cellular_esim_connection_handler_| is expected to be null if the flag
// is disabled.
if (cellular_esim_connection_handler_ && !network->eid().empty() &&
!network->connectable()) {
is_non_connectable_esim_network = true;
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions chromeos/network/network_connection_handler_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ class NetworkConnectionHandlerImplTest : public testing::Test {
base::RunLoop().RunUntilIdle();
}

void SetCellularSimLocked() {
// Simulate a locked SIM.
base::Value sim_lock_status(base::Value::Type::DICTIONARY);
sim_lock_status.SetKey(shill::kSIMLockTypeProperty,
base::Value(shill::kSIMLockPin));
helper_.device_test()->SetDeviceProperty(
kTestCellularDevicePath, shill::kSIMLockStatusProperty,
std::move(sim_lock_status), /*notify_changed=*/true);

// Set the cellular service to be the active profile.
base::Value::ListStorage sim_slot_infos;
base::Value slot_info_item(base::Value::Type::DICTIONARY);
slot_info_item.SetKey(shill::kSIMSlotInfoICCID, base::Value(kTestIccid));
slot_info_item.SetBoolKey(shill::kSIMSlotInfoPrimary, true);
sim_slot_infos.push_back(std::move(slot_info_item));
helper_.device_test()->SetDeviceProperty(
kTestCellularDevicePath, shill::kSIMSlotInfoProperty,
base::Value(sim_slot_infos), /*notify_changed=*/true);

base::RunLoop().RunUntilIdle();
}

void AddNonConnectablePSimService() {
AddCellularDevice();

Expand Down Expand Up @@ -934,6 +956,14 @@ TEST_F(NetworkConnectionHandlerImplTest, PSimProfile_OutOfCredits) {
GetResultAndReset());
}

TEST_F(NetworkConnectionHandlerImplTest, SimLocked) {
AddNonConnectablePSimService();
SetCellularSimLocked();
SetCellularServiceConnectable();
Connect(kTestCellularServicePath);
EXPECT_EQ(NetworkConnectionHandler::kErrorSimLocked, GetResultAndReset());
}

TEST_F(NetworkConnectionHandlerImplTest, ESimProfile_AlreadyConnectable) {
AddCellularServiceWithESimProfile();

Expand Down

0 comments on commit df8f0a3

Please sign in to comment.