Skip to content

Commit

Permalink
[CrOS Cellular] Add service count at login for pSIM and eSIM.
Browse files Browse the repository at this point in the history
When user logs in, the number of pSIM networks available and eSIM
profiles is logged.

(cherry picked from commit 0a1984b)

Bug: 1183573, 1184848
Change-Id: Ifd00d68a6db2d016525489c298c54143d736d93a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2718540
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: Steven Holte <holte@chromium.org>
Reviewed-by: Azeem Arshad <azeemarshad@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#860087}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2738701
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/branch-heads/4430@{#148}
Cr-Branched-From: e5ce7dc-refs/heads/master@{#857950}
  • Loading branch information
Regan Hsu authored and Chromium LUCI CQ committed Mar 5, 2021
1 parent a6f6fda commit 33cb4e1
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
33 changes: 33 additions & 0 deletions chromeos/network/cellular_metrics_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void CellularMetricsLogger::NetworkListChanged() {
void CellularMetricsLogger::OnInitializationTimeout() {
CheckForActivationStateMetric();
CheckForCellularUsageCountMetric();
CheckForCellularServiceCountMetric();
}

void CellularMetricsLogger::LoggedInStateChanged() {
Expand All @@ -161,6 +162,11 @@ void CellularMetricsLogger::LoggedInStateChanged() {
// the user logs in.
is_activation_state_logged_ = false;
CheckForActivationStateMetric();

// This flag ensures that the service count is only logged once when
// the user logs in.
is_service_count_logged_ = false;
CheckForCellularServiceCountMetric();
}

void CellularMetricsLogger::NetworkConnectionStateChanged(
Expand Down Expand Up @@ -285,6 +291,33 @@ void CellularMetricsLogger::CheckForActivationStateMetric() {
is_activation_state_logged_ = true;
}

void CellularMetricsLogger::CheckForCellularServiceCountMetric() {
if (!is_cellular_available_ || is_service_count_logged_ ||
!CellularMetricsLogger::IsLoggedInUserOwnerOrRegular()) {
return;
}

NetworkStateHandler::NetworkStateList network_list;
network_state_handler_->GetVisibleNetworkListByType(
NetworkTypePattern::Cellular(), &network_list);

size_t psim_networks = 0;
size_t esim_profiles = 0;

for (const auto* network : network_list) {
if (!network->eid().empty())
esim_profiles++;
else
psim_networks++;
}

UMA_HISTOGRAM_COUNTS_100("Network.Cellular.PSim.ServiceAtLogin.Count",
psim_networks);
UMA_HISTOGRAM_COUNTS_100("Network.Cellular.ESim.ServiceAtLogin.Count",
esim_profiles);
is_service_count_logged_ = true;
}

void CellularMetricsLogger::CheckForCellularUsageCountMetric() {
if (!is_cellular_available_)
return;
Expand Down
9 changes: 9 additions & 0 deletions chromeos/network/cellular_metrics_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) CellularMetricsLogger

private:
friend class CellularMetricsLoggerTest;
FRIEND_TEST_ALL_PREFIXES(CellularMetricsLoggerTest,
CellularServiceAtLoginTest);
FRIEND_TEST_ALL_PREFIXES(CellularMetricsLoggerTest, CellularUsageCountTest);
FRIEND_TEST_ALL_PREFIXES(CellularMetricsLoggerTest,
CellularUsageCountDongleTest);
Expand Down Expand Up @@ -152,6 +154,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) CellularMetricsLogger
// when usage state changes.
void CheckForCellularUsageCountMetric();

// Tracks how many eSIM profiles are installed on the device and how many pSIM
// networks are available on the device if |is_service_count_logged_| is true.
void CheckForCellularServiceCountMetric();

// Returns the ConnectionInfo for given |cellular_network_guid|.
ConnectionInfo* GetConnectionInfoForCellularNetwork(
const std::string& cellular_network_guid);
Expand Down Expand Up @@ -181,6 +187,9 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) CellularMetricsLogger
// session.
bool is_activation_state_logged_ = false;

// Tracks whether service count is already logged for this session.
bool is_service_count_logged_ = false;

// Stores connection information for all cellular networks.
base::flat_map<std::string, std::unique_ptr<ConnectionInfo>>
guid_to_connection_info_map_;
Expand Down
42 changes: 42 additions & 0 deletions chromeos/network/cellular_metrics_logger_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const char kTestEthServicePath[] = "/service/eth0";
const char kPSimUsageCountHistogram[] = "Network.Cellular.PSim.Usage.Count";
const char kESimUsageCountHistogram[] = "Network.Cellular.ESim.Usage.Count";

const char kPSimServiceAtLoginHistogram[] =
"Network.Cellular.PSim.ServiceAtLogin.Count";
const char kESimServiceAtLoginHistogram[] =
"Network.Cellular.ESim.ServiceAtLogin.Count";

const char kActivationStatusAtLoginHistogram[] =
"Network.Cellular.Activation.StatusAtLogin";
const char kTimeToConnectedHistogram[] =
Expand Down Expand Up @@ -125,6 +130,43 @@ class CellularMetricsLoggerTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(CellularMetricsLoggerTest);
};

TEST_F(CellularMetricsLoggerTest, CellularServiceAtLoginTest) {
base::HistogramTester histogram_tester;

// Should defer logging when there are no cellular networks.
LoginState::Get()->SetLoggedInState(
LoginState::LoggedInState::LOGGED_IN_ACTIVE,
LoginState::LoggedInUserType::LOGGED_IN_USER_OWNER);
histogram_tester.ExpectTotalCount(kESimServiceAtLoginHistogram, 0);
histogram_tester.ExpectTotalCount(kPSimServiceAtLoginHistogram, 0);

// Should wait until initialization timeout before logging status.
InitCellular();
histogram_tester.ExpectTotalCount(kESimServiceAtLoginHistogram, 0);
histogram_tester.ExpectTotalCount(kPSimServiceAtLoginHistogram, 0);
task_environment_.FastForwardBy(
CellularMetricsLogger::kInitializationTimeout);
histogram_tester.ExpectTotalCount(kESimServiceAtLoginHistogram, 1);
histogram_tester.ExpectTotalCount(kPSimServiceAtLoginHistogram, 1);

// Should log immediately when networks are already initialized.
LoginState::Get()->SetLoggedInState(
LoginState::LoggedInState::LOGGED_IN_NONE,
LoginState::LoggedInUserType::LOGGED_IN_USER_NONE);
LoginState::Get()->SetLoggedInState(
LoginState::LoggedInState::LOGGED_IN_ACTIVE,
LoginState::LoggedInUserType::LOGGED_IN_USER_OWNER);
histogram_tester.ExpectTotalCount(kESimServiceAtLoginHistogram, 2);
histogram_tester.ExpectTotalCount(kPSimServiceAtLoginHistogram, 2);

// Should not log when the logged in user is neither owner nor regular.
LoginState::Get()->SetLoggedInState(
LoginState::LoggedInState::LOGGED_IN_ACTIVE,
LoginState::LoggedInUserType::LOGGED_IN_USER_KIOSK_APP);
histogram_tester.ExpectTotalCount(kESimServiceAtLoginHistogram, 2);
histogram_tester.ExpectTotalCount(kPSimServiceAtLoginHistogram, 2);
}

TEST_F(CellularMetricsLoggerTest, CellularUsageCountTest) {
InitEthernet();
InitCellular();
Expand Down
22 changes: 21 additions & 1 deletion tools/metrics/histograms/histograms_xml/network/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,23 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<histogram name="Network.Cellular.Connection.TimeToConnected" units="ms"
expires_after="2021-06-30">
<owner>azeemarshad@chromium.org</owner>
<owner>cros-system-services-networking@google.com</owner>
<owner>cros-connectivity@google.com</owner>
<summary>
Tracks the amount fo time taken between when cellular device starts and
finishes connecting.
</summary>
</histogram>

<histogram name="Network.Cellular.ESim.ServiceAtLogin.Count" units="units"
expires_after="2022-03-01">
<owner>azeemarshad@chromium.org</owner>
<owner>cros-connectivit@google.com</owner>
<summary>
Tracks how many eSIM profiles are installed on the devices after a primary
user login.
</summary>
</histogram>

<histogram name="Network.Cellular.ESim.Usage.Count" enum="NetworkCellularUsage"
expires_after="2022-03-01">
<owner>azeemarshad@chromium.org</owner>
Expand All @@ -128,6 +138,16 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>

<histogram name="Network.Cellular.PSim.ServiceAtLogin.Count" units="units"
expires_after="2022-03-01">
<owner>azeemarshad@chromium.org</owner>
<owner>cros-system-services-networking@google.com</owner>
<summary>
Tracks how many pSIM networks are available on the device after a primary
user login.
</summary>
</histogram>

<histogram name="Network.Cellular.PSim.Usage.Count" enum="NetworkCellularUsage"
expires_after="2022-03-01">
<owner>azeemarshad@chromium.org</owner>
Expand Down

0 comments on commit 33cb4e1

Please sign in to comment.