shill: cellular: Unify UpdateStorageIdentifier.
Before this CL, |CellularService::SetStorageIdentifier| was called from
different code paths in three of the capabilities. This CL unifies these code
paths to be triggered when the ServingOperator is determined in |Cellular|.
BUG=chromium:352243
TEST=- Manually test that sensible storage identifiers are used for different
operators, and that they are persistent across service reboots.
- Run shill unit-tests.
Change-Id: I5837465589667e4d4feb75eeeeeb6f793fb5450a
Reviewed-on: https://chromium-review.googlesource.com/197602
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
diff --git a/cellular.cc b/cellular.cc
index bbeb124..4182d9d 100644
--- a/cellular.cc
+++ b/cellular.cc
@@ -134,6 +134,7 @@
sim_present_(false),
prl_version_(0),
modem_info_(modem_info),
+ type_(type),
proxy_factory_(proxy_factory),
ppp_device_factory_(PPPDeviceFactory::GetInstance()),
allow_roaming_(false),
@@ -622,7 +623,48 @@
CHECK(!service_.get());
service_ = new CellularService(modem_info_, this);
capability_->OnServiceCreated();
+
+ // Storage identifier must be set only once, and before registering the
+ // service with the manager, since we key off of this identifier to
+ // determine the profile to load.
+ // TODO(pprabhu) Make profile matching more robust (crbug.com/369755)
+ string service_id;
+ if (home_provider_info_->IsMobileNetworkOperatorKnown() &&
+ !home_provider_info_->uuid().empty()){
+ service_id = home_provider_info_->uuid();
+ } else if (serving_operator_info_->IsMobileNetworkOperatorKnown() &&
+ !serving_operator_info_->uuid().empty()) {
+ service_id = serving_operator_info_->uuid();
+ } else {
+ switch (type_) {
+ case kTypeGSM:
+ case kTypeUniversal:
+ if (!sim_identifier().empty()) {
+ service_id = sim_identifier();
+ }
+ break;
+
+ case kTypeCDMA:
+ case kTypeUniversalCDMA:
+ if (!meid().empty()) {
+ service_id = meid();
+ }
+ break;
+
+ default:
+ NOTREACHED();
+ }
+ }
+
+ if (!service_id.empty()) {
+ string storage_id = base::StringPrintf(
+ "%s_%s_%s",
+ kTypeCellular, address().c_str(), service_id.c_str());
+ service()->SetStorageIdentifier(storage_id);
+ }
+
manager()->RegisterService(service_);
+
// We might have missed a property update because the service wasn't created
// ealier.
UpdateScanning();