[CrOS Cellular] Add extra logging to eSIM-related classes

Add logging to eSIM-related classes to output SIM slot EID statuses and
available EUICCs to aid in debugging eSIM section not showing.

Bug: b:295977916
Test: None needed since only logs added
Change-Id: I53fd963ffb0ccbc159819a608a9e54fdeea549f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4912751
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Auto-Submit: Gordon Seto <gordonseto@google.com>
Commit-Queue: Gordon Seto <gordonseto@google.com>
Cr-Commit-Position: refs/heads/main@{#1215618}
diff --git a/chromeos/ash/components/network/BUILD.gn b/chromeos/ash/components/network/BUILD.gn
index 0300f171..5f03593 100644
--- a/chromeos/ash/components/network/BUILD.gn
+++ b/chromeos/ash/components/network/BUILD.gn
@@ -16,6 +16,7 @@
     "//ash/components/arc:prefs",
     "//ash/constants",
     "//base",
+    "//chromeos/ash/components/cryptohome",
     "//chromeos/ash/components/dbus/hermes",
     "//chromeos/ash/components/dbus/shill",
     "//chromeos/ash/components/feature_usage",
diff --git a/chromeos/ash/components/network/DEPS b/chromeos/ash/components/network/DEPS
index 88d53d77..d96f33e 100644
--- a/chromeos/ash/components/network/DEPS
+++ b/chromeos/ash/components/network/DEPS
@@ -12,6 +12,7 @@
   "+chromeos/ash/services/network_config/public",
   "+chromeos/ash/services/cellular_setup/public",
   "+chromeos/components/onc",
+  "+chromeos/ash/components/cryptohome",
   "+chromeos/dbus",
   "+chromeos/services/network_config/public",
   "+chromeos/test",
diff --git a/chromeos/ash/components/network/cellular_utils.cc b/chromeos/ash/components/network/cellular_utils.cc
index 978b647..a49cf33 100644
--- a/chromeos/ash/components/network/cellular_utils.cc
+++ b/chromeos/ash/components/network/cellular_utils.cc
@@ -12,6 +12,7 @@
 #include "base/strings/strcat.h"
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
+#include "chromeos/ash/components/cryptohome/system_salt_getter.h"
 #include "chromeos/ash/components/dbus/hermes/hermes_euicc_client.h"
 #include "chromeos/ash/components/dbus/hermes/hermes_manager_client.h"
 #include "chromeos/ash/components/dbus/hermes/hermes_profile_client.h"
@@ -19,6 +20,7 @@
 #include "chromeos/ash/components/network/network_handler.h"
 #include "chromeos/ash/components/network/network_profile.h"
 #include "chromeos/ash/components/network/network_profile_handler.h"
+#include "crypto/sha2.h"
 
 namespace ash {
 
@@ -33,6 +35,16 @@
 
 namespace {
 const char kNonShillCellularNetworkPathPrefix[] = "/non-shill-cellular/";
+
+std::string GetLogSafeEid(const std::string& eid) {
+  const SystemSaltGetter::RawSalt* salt = SystemSaltGetter::Get()->GetRawSalt();
+  if (!salt) {
+    return std::string();
+  }
+  return crypto::SHA256HashString(
+      eid + SystemSaltGetter::ConvertRawSaltToHexString(*salt));
+}
+
 }  // namespace
 
 base::flat_set<dbus::ObjectPath> GetProfilePathsFromEuicc(
@@ -101,12 +113,18 @@
 
 const base::flat_map<int32_t, std::string> GetESimSlotToEidMap() {
   base::flat_map<int32_t, std::string> esim_slot_to_eid;
-  for (auto& euicc_path : HermesManagerClient::Get()->GetAvailableEuiccs()) {
+  const std::vector<dbus::ObjectPath>& available_euiccs =
+      HermesManagerClient::Get()->GetAvailableEuiccs();
+  VLOG(1) << "GetESimSlotToEidMap(): Num available EUICCs: "
+          << available_euiccs.size();
+  for (auto& euicc_path : available_euiccs) {
     HermesEuiccClient::Properties* properties =
         HermesEuiccClient::Get()->GetProperties(euicc_path);
     int32_t slot_id = properties->physical_slot().value();
     std::string eid = properties->eid().value();
     esim_slot_to_eid.emplace(slot_id, eid);
+    VLOG(1) << "EUICC: " << euicc_path.value() << ", slot id: " << slot_id
+            << ", eid: " << GetLogSafeEid(eid);
   }
   return esim_slot_to_eid;
 }
@@ -132,8 +150,12 @@
       GetESimSlotToEidMap();
 
   DeviceState::CellularSIMSlotInfos sim_slot_infos = device->GetSimSlotInfos();
+  VLOG(1) << "GetSimSlotInfosWithUpdatedEid(): Num SIM slot infos: "
+          << sim_slot_infos.size();
   for (auto& sim_slot_info : sim_slot_infos) {
     const std::string shill_provided_eid = sim_slot_info.eid;
+    VLOG(1) << "SIM slot id: " << sim_slot_info.slot_id
+            << ", Shill provided eid: " << GetLogSafeEid(shill_provided_eid);
 
     // If there is no associated |slot_id| in the map, the SIM slot info refers
     // to a pSIM, and the Hermes provided data is irrelevant.
diff --git a/chromeos/ash/services/cellular_setup/esim_manager.cc b/chromeos/ash/services/cellular_setup/esim_manager.cc
index 23a0a34..6309f7e2 100644
--- a/chromeos/ash/services/cellular_setup/esim_manager.cc
+++ b/chromeos/ash/services/cellular_setup/esim_manager.cc
@@ -95,6 +95,8 @@
 
 void ESimManager::GetAvailableEuiccs(GetAvailableEuiccsCallback callback) {
   std::vector<mojo::PendingRemote<mojom::Euicc>> euicc_list;
+  NET_LOG(DEBUG) << "GetAvailableEuiccs(): Num available_euiccs_: "
+                 << available_euiccs_.size();
   for (auto const& euicc : available_euiccs_)
     euicc_list.push_back(euicc->CreateRemote());
   std::move(callback).Run(std::move(euicc_list));
@@ -179,6 +181,7 @@
        euicc_it != available_euiccs_.end();) {
     if (new_euicc_paths.find((*euicc_it)->path()) == new_euicc_paths.end()) {
       removed = true;
+      NET_LOG(DEBUG) << "Removing EUICC: " << (*euicc_it)->path().value();
       euicc_it = available_euiccs_.erase(euicc_it);
     } else {
       euicc_it++;
@@ -191,6 +194,7 @@
   Euicc* euicc_info = GetEuiccFromPath(euicc_path);
   if (euicc_info)
     return false;
+  NET_LOG(DEBUG) << "Creating EUICC: " << euicc_path.value();
   available_euiccs_.push_back(std::make_unique<Euicc>(euicc_path, this));
   return true;
 }