shill: cellular: Migrate |ParseScanResult| to use MobileOperatorInfo.
|CellularCapabilityUniversal::ParseScanResult| and
|CellularCapabilityGSM::ParseScanResult| were the last uses of
|mobile_provider_db|. This CL migrates these function to use the new
|MobileOperatorInfo| objects. With this, we no longer depend on
mobile_provider_db.
BUG=chromium:371630
TEST=- Test a user initiated scan request works correctly on e362, Gobi3K UMTS.
- Test that user initiated scan works correctly when the operator name is
not available from the modem. This situation can be simulated as follows:
$ run_pseudomodem.py &
$ connectivity show devices
Verify that the 'Cellular.FoundNetworks' is absent from
/device/pseudomodem0
$ dbus-send --system --dest=org.freedesktop.ModemManager1 \
/org/freedesktop/ModemManager1/SIM/0 \
org.freedesktop.DBus.Properties.Set \
string:'org.freedesktop.ModemManager1.Sim' \
string:'OperatorName' variant:string:''
$ dbus-send --system --dest=org.freedesktop.ModemManager1 \
/org/freedesktop/ModemManager1/Modem/0 \
org.freedesktop.DBus.Properties.Set \
string:'org.freedesktop.ModemManager1.Modem.Modem3gpp' \
string:'OperatorName' variant:string:''
$ dbus-send --system --dest=org.chromium.flimflam \
/device/pseudomodem0 org.chromium.flimflam.Device.ProposeScan
Verify that the 'Cellular.FoundNetworks' is present and has the
'long_name' populated.
Change-Id: I340217acb700eb1c8253c88c1b75851880033160
Reviewed-on: https://chromium-review.googlesource.com/200681
Reviewed-by: Thieu Le <thieule@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/cellular_capability_gsm.cc b/cellular_capability_gsm.cc
index 2e0cac2..2640430 100644
--- a/cellular_capability_gsm.cc
+++ b/cellular_capability_gsm.cc
@@ -53,12 +53,15 @@
ModemInfo *modem_info)
: CellularCapabilityClassic(cellular, proxy_factory, modem_info),
weak_ptr_factory_(this),
+ mobile_operator_info_(new MobileOperatorInfo(cellular->dispatcher(),
+ "ParseScanResult")),
registration_state_(MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN),
access_technology_(MM_MODEM_GSM_ACCESS_TECH_UNKNOWN),
home_provider_info_(NULL),
get_imsi_retries_(0),
get_imsi_retry_delay_milliseconds_(kGetIMSIRetryDelayMilliseconds) {
SLOG(Cellular, 2) << "Cellular capability constructed: GSM";
+ mobile_operator_info_->Init();
HelpRegisterConstDerivedKeyValueStore(
kSIMLockStatusProperty, &CellularCapabilityGSM::SimLockStatusToProperty);
this->cellular()->set_scanning_supported(true);
@@ -582,15 +585,11 @@
if ((!ContainsKey(parsed, kLongNameProperty) ||
parsed[kLongNameProperty].empty()) &&
ContainsKey(parsed, kNetworkIdProperty)) {
- mobile_provider *provider =
- mobile_provider_lookup_by_network(
- modem_info()->provider_db(),
- parsed[kNetworkIdProperty].c_str());
- if (provider) {
- const char *long_name = mobile_provider_get_name(provider);
- if (long_name && *long_name) {
- parsed[kLongNameProperty] = long_name;
- }
+ mobile_operator_info_->Reset();
+ mobile_operator_info_->UpdateMCCMNC(parsed[kNetworkIdProperty]);
+ if (mobile_operator_info_->IsMobileNetworkOperatorKnown() &&
+ !mobile_operator_info_->operator_name().empty()) {
+ parsed[kLongNameProperty] = mobile_operator_info_->operator_name();
}
}
return parsed;
diff --git a/cellular_capability_gsm.h b/cellular_capability_gsm.h
index 96447c3..fe313da 100644
--- a/cellular_capability_gsm.h
+++ b/cellular_capability_gsm.h
@@ -202,6 +202,10 @@
scoped_ptr<ModemGSMCardProxyInterface> card_proxy_;
scoped_ptr<ModemGSMNetworkProxyInterface> network_proxy_;
base::WeakPtrFactory<CellularCapabilityGSM> weak_ptr_factory_;
+ // Used to enrich information about the network operator in |ParseScanResult|.
+ // TODO(pprabhu) Instead instantiate a local |MobileOperatorInfo| instance
+ // once the context has been separated out. (crbug.com/363874)
+ scoped_ptr<MobileOperatorInfo> mobile_operator_info_;
uint32 registration_state_;
uint32 access_technology_;
diff --git a/cellular_capability_gsm_unittest.cc b/cellular_capability_gsm_unittest.cc
index 8f1d6fa..e654e03 100644
--- a/cellular_capability_gsm_unittest.cc
+++ b/cellular_capability_gsm_unittest.cc
@@ -572,14 +572,26 @@
}
TEST_F(CellularCapabilityGSMTest, ParseScanResultProviderLookup) {
- InitProviderDB();
- static const char kID[] = "310210";
+ static const char kID[] = "10001";
+ const string kLongName = "TestNetworkLongName";
+ // Replace the |MobileOperatorInfo| used by |ParseScanResult| by a mock.
+ auto *mock_mobile_operator_info = new MockMobileOperatorInfo(
+ &dispatcher_,
+ "MockParseScanResult");
+ capability_->mobile_operator_info_.reset(mock_mobile_operator_info);
+
+ mock_mobile_operator_info->SetEmptyDefaultsForProperties();
+ EXPECT_CALL(*mock_mobile_operator_info, UpdateMCCMNC(kID));
+ EXPECT_CALL(*mock_mobile_operator_info, IsMobileNetworkOperatorKnown()).
+ WillOnce(Return(true));
+ EXPECT_CALL(*mock_mobile_operator_info, operator_name()).
+ WillRepeatedly(ReturnRef(kLongName));
GSMScanResult result;
result[CellularCapabilityGSM::kNetworkPropertyID] = kID;
Stringmap parsed = capability_->ParseScanResult(result);
EXPECT_EQ(2, parsed.size());
EXPECT_EQ(kID, parsed[kNetworkIdProperty]);
- EXPECT_EQ("T-Mobile", parsed[kLongNameProperty]);
+ EXPECT_EQ(kLongName, parsed[kLongNameProperty]);
}
TEST_F(CellularCapabilityGSMTest, SetAccessTechnology) {
diff --git a/cellular_capability_universal.cc b/cellular_capability_universal.cc
index f4356db..61484d3 100644
--- a/cellular_capability_universal.cc
+++ b/cellular_capability_universal.cc
@@ -132,6 +132,8 @@
ProxyFactory *proxy_factory,
ModemInfo *modem_info)
: CellularCapability(cellular, proxy_factory, modem_info),
+ mobile_operator_info_(new MobileOperatorInfo(cellular->dispatcher(),
+ "ParseScanResult")),
weak_ptr_factory_(this),
registration_state_(MM_MODEM_3GPP_REGISTRATION_STATE_UNKNOWN),
current_capabilities_(MM_MODEM_CAPABILITY_NONE),
@@ -145,6 +147,7 @@
registration_dropped_update_timeout_milliseconds_(
kRegistrationDroppedUpdateTimeoutMilliseconds) {
SLOG(Cellular, 2) << "Cellular capability constructed: Universal";
+ mobile_operator_info_->Init();
HelpRegisterConstDerivedKeyValueStore(
kSIMLockStatusProperty,
&CellularCapabilityUniversal::SimLockStatusToProperty);
@@ -1128,15 +1131,11 @@
if ((!ContainsKey(parsed, kLongNameProperty) ||
parsed[kLongNameProperty].empty()) &&
ContainsKey(parsed, kNetworkIdProperty)) {
- mobile_provider *provider =
- mobile_provider_lookup_by_network(
- modem_info()->provider_db(),
- parsed[kNetworkIdProperty].c_str());
- if (provider) {
- const char *long_name = mobile_provider_get_name(provider);
- if (long_name && *long_name) {
- parsed[kLongNameProperty] = long_name;
- }
+ mobile_operator_info_->Reset();
+ mobile_operator_info_->UpdateMCCMNC(parsed[kNetworkIdProperty]);
+ if (mobile_operator_info_->IsMobileNetworkOperatorKnown() &&
+ !mobile_operator_info_->operator_name().empty()) {
+ parsed[kLongNameProperty] = mobile_operator_info_->operator_name();
}
}
return parsed;
diff --git a/cellular_capability_universal.h b/cellular_capability_universal.h
index af2c874..1a2efff 100644
--- a/cellular_capability_universal.h
+++ b/cellular_capability_universal.h
@@ -399,6 +399,10 @@
scoped_ptr<mm1::ModemProxyInterface> modem_proxy_;
scoped_ptr<mm1::ModemSimpleProxyInterface> modem_simple_proxy_;
scoped_ptr<mm1::SimProxyInterface> sim_proxy_;
+ // Used to enrich information about the network operator in |ParseScanResult|.
+ // TODO(pprabhu) Instead instantiate a local |MobileOperatorInfo| instance
+ // once the context has been separated out. (crbug.com/363874)
+ scoped_ptr<MobileOperatorInfo> mobile_operator_info_;
base::WeakPtrFactory<CellularCapabilityUniversal> weak_ptr_factory_;