0

Reland "[CrOS Cellular] Make the SIM Profile name consistent across all UIs"

This is a reland of commit 7df4589fcf

The original commit modified the quick settings view to display cellular
name inline with os settings. The newly added code in
network_list_item_view failed the address sanitizer test and this reland
should fix that.

Bug: b/267515202
Change-Id: I0edfe27b7ff2d8d28cfa9bb8ae56ce336f02ccd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4832633
Reviewed-by: Jason Zhang <jiajunz@google.com>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Commit-Queue: Nikhil Nayunigari <nikhilcn@google.com>
Cr-Commit-Position: refs/heads/main@{#1191091}
This commit is contained in:
Nikhil Nayunigari
2023-09-01 00:39:31 +00:00
committed by Chromium LUCI CQ
parent b398170e0b
commit 79c6e89568
9 changed files with 85 additions and 0 deletions

@ -3466,6 +3466,12 @@ Turning on battery saver to increase your battery life.
<message name="IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATING" desc="Message for the network list when activating a network.">
<ph name="NAME">$1<ex>YBH Cellular</ex></ph>: Activating...
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATING_WITH_NICK_NAME" desc="Message for the network list when activating a network.">
<ph name="NAME">$1<ex>YBH Cellular</ex></ph> · <ph name="SERVICE_PROVIDER">$2<ex>T-Mobile</ex></ph>: Activating...
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_LIST_ITEM_TITLE" desc="Label for a network shown in a list in settings and oobe displaying its name and subtitle.">
<ph name="NETWORK_NAME">$1<ex>My Verizon eSIM</ex></ph> · <ph name="SERVICE_PROVIDER">$2<ex>Verizon Wireless</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED" desc="Description in status area or network list when no network is connected.">
No network
</message>

@ -0,0 +1 @@
ff333162066bcfa02d5798be88dba2ba9c7dbc92

@ -0,0 +1 @@
ff333162066bcfa02d5798be88dba2ba9c7dbc92

@ -29,10 +29,24 @@ std::u16string NetworkListItemView::GetLabel() {
ActivationStateType activation_state =
network_properties_->type_state->get_cellular()->activation_state;
if (activation_state == ActivationStateType::kActivating) {
if (network_properties_->type_state->get_cellular()->has_nick_name) {
return l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATING_WITH_NICK_NAME,
base::UTF8ToUTF16(network_properties_->name),
base::UTF8ToUTF16(network_properties_->type_state->get_cellular()
->network_operator));
}
return l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_LIST_ACTIVATING,
base::UTF8ToUTF16(network_properties_->name));
}
if (network_properties_->type_state->get_cellular()->has_nick_name) {
return l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_LIST_ITEM_TITLE,
base::UTF8ToUTF16(network_properties_->name),
base::UTF8ToUTF16(network_properties_->type_state->get_cellular()
->network_operator));
}
}
// Otherwise just show the network name or 'Ethernet'.
if (network_properties_->type == NetworkType::kEthernet)

@ -601,6 +601,8 @@ export class OncMojo {
simLockEnabled: false,
simLocked: false,
simLockType: '',
hasNickName: false,
networkOperator: '',
};
break;
case NetworkType.kEthernet:

@ -59,6 +59,22 @@ absl::optional<std::string> GetESimProfileName(
return absl::nullopt;
}
absl::optional<CellularESimProfile> GetMatchedESimProfile(
CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state) {
std::vector<CellularESimProfile> profiles =
cellular_esim_profile_handler->GetESimProfiles();
for (const auto& profile : profiles) {
if (profile.eid() != network_state->eid() ||
profile.iccid() != network_state->iccid()) {
continue;
}
return profile;
}
return absl::nullopt;
}
std::string GetNetworkName(
CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state) {
@ -73,4 +89,33 @@ std::string GetNetworkName(
return network_state->name();
}
bool HasNickName(CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state) {
DCHECK(network_state);
if (!cellular_esim_profile_handler) {
return false;
}
absl::optional<CellularESimProfile> profile =
GetMatchedESimProfile(cellular_esim_profile_handler, network_state);
if (profile.has_value() && !profile.value().nickname().empty()) {
return true;
}
return false;
}
std::string GetServiceProvider(
CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state) {
DCHECK(network_state);
if (!cellular_esim_profile_handler) {
return "";
}
absl::optional<CellularESimProfile> profile =
GetMatchedESimProfile(cellular_esim_profile_handler, network_state);
if (profile.has_value()) {
return base::UTF16ToUTF8(profile.value().service_provider());
}
return "";
}
} // namespace ash::network_name_util

@ -34,6 +34,14 @@ std::string GetNetworkName(
CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state);
COMPONENT_EXPORT(CHROMEOS_NETWORK)
bool HasNickName(CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state);
COMPONENT_EXPORT(CHROMEOS_NETWORK)
std::string GetServiceProvider(
CellularESimProfileHandler* cellular_esim_profile_handler,
const NetworkState* network_state);
} // namespace network_name_util
} // namespace ash

@ -469,6 +469,10 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(
cellular->sim_locked = sim_is_primary && cellular_device->IsSimLocked();
if (sim_is_primary)
cellular->sim_lock_type = cellular_device->sim_lock_type();
cellular->has_nick_name = network_name_util::HasNickName(
cellular_esim_profile_handler, network);
cellular->network_operator = network_name_util::GetServiceProvider(
cellular_esim_profile_handler, network);
result->type_state =
mojom::NetworkTypeStateProperties::NewCellular(std::move(cellular));
break;

@ -219,6 +219,10 @@ struct CellularStateProperties {
// String representing the SIM lock type. This will be empty when the SIM
// is unlocked.
string sim_lock_type;
// True when a SIM has a custom name.
bool has_nick_name = false;
// String representing the network operator.
string network_operator;
};
struct EthernetStateProperties {