shill: cellular: Migrate activation paths to use MobileOperatorInfo.

The code paths that determine whether cellular activation is required also
verify that some online portal information is available. This CL migrates this
check to be based off of the new MobileOperatorInfo objects. Before this CL, a
new |CellularOperatorInfo| object was used to make this decision.

BUG=chromium:371630
TEST=- Use pseudomodem to manually create a modem that exposes itself with
         operator id: '310995'
         operator name: ''
         subscription state: 'unknown'
         own: '0000000000'
       and verify that
         $ connectivity show devices
       shows the cellular service is 'not-activated'.
     - Run network_LTEActivate.

Change-Id: I22cecffca1169e8abf25148b367d01520aa171bc
Reviewed-on: https://chromium-review.googlesource.com/200687
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Thieu Le <thieule@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/cellular_capability_universal.cc b/cellular_capability_universal.cc
index 0249d13..919d6ee 100644
--- a/cellular_capability_universal.cc
+++ b/cellular_capability_universal.cc
@@ -903,13 +903,10 @@
 
   // If there is no online payment portal information, it's safer to assume
   // the service does not require activation.
-  if (!modem_info()->cellular_operator_info())
+  if (!cellular()->home_provider_info()->IsMobileNetworkOperatorKnown() ||
+      cellular()->home_provider_info()->olp_list().empty()) {
     return false;
-
-  const CellularOperatorInfo::OLP *olp =
-      modem_info()->cellular_operator_info()->GetOLPByMCCMNC(operator_id_);
-  if (!olp)
-    return false;
+  }
 
   // If the MDN is invalid (i.e. empty or contains only zeros), the service
   // requires activation.
diff --git a/cellular_capability_universal_cdma.cc b/cellular_capability_universal_cdma.cc
index 040249e..3a3546f 100644
--- a/cellular_capability_universal_cdma.cc
+++ b/cellular_capability_universal_cdma.cc
@@ -162,13 +162,10 @@
 bool CellularCapabilityUniversalCDMA::IsServiceActivationRequired() const {
   // If there is no online payment portal information, it's safer to assume
   // the service does not require activation.
-  if (!modem_info()->cellular_operator_info())
+  if (!cellular()->serving_operator_info()->IsMobileNetworkOperatorKnown() ||
+      cellular()->serving_operator_info()->olp_list().empty()) {
     return false;
-
-  const CellularOperatorInfo::OLP *olp =
-      modem_info()->cellular_operator_info()->GetOLPBySID(UintToString(sid_));
-  if (!olp)
-    return false;
+  }
 
   // We could also use the MDN to determine whether or not the service is
   // activated, however, the CDMA ActivatonState property is a more absolute
diff --git a/cellular_capability_universal_cdma_unittest.cc b/cellular_capability_universal_cdma_unittest.cc
index bd57710..fb86542 100644
--- a/cellular_capability_universal_cdma_unittest.cc
+++ b/cellular_capability_universal_cdma_unittest.cc
@@ -374,13 +374,36 @@
 }
 
 TEST_F(CellularCapabilityUniversalCDMAMainTest, IsServiceActivationRequired) {
-  CellularOperatorInfo::OLP olp;
-  EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
-      .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL))
-      .WillRepeatedly(Return(&olp));
+  const vector<MobileOperatorInfo::OnlinePortal> empty_list;
+  const vector<MobileOperatorInfo::OnlinePortal> olp_list {
+    {"some@url", "some_method", "some_post_data"}
+  };
+  SetMockMobileOperatorInfoObjects();
+
   capability_->activation_state_ =
       MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
+  EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(false));
   EXPECT_FALSE(capability_->IsServiceActivationRequired());
+  Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
+
+  capability_->activation_state_ =
+      MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
+  EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_serving_operator_info_, olp_list())
+      .WillRepeatedly(ReturnRef(empty_list));
+  EXPECT_FALSE(capability_->IsServiceActivationRequired());
+  Mock::VerifyAndClearExpectations(mock_serving_operator_info_);
+
+  // These expectations hold for all subsequent tests.
+  EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_serving_operator_info_, olp_list())
+      .WillRepeatedly(ReturnRef(olp_list));
+
+  capability_->activation_state_ =
+      MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED;
   EXPECT_TRUE(capability_->IsServiceActivationRequired());
   capability_->activation_state_ =
       MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING;
@@ -392,9 +415,15 @@
 
 TEST_F(CellularCapabilityUniversalCDMAMainTest,
        UpdateServiceActivationStateProperty) {
-  CellularOperatorInfo::OLP olp;
-  EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPBySID(_))
-      .WillRepeatedly(Return(&olp));
+  const vector<MobileOperatorInfo::OnlinePortal> olp_list {
+    {"some@url", "some_method", "some_post_data"}
+  };
+  SetMockMobileOperatorInfoObjects();
+  EXPECT_CALL(*mock_serving_operator_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_serving_operator_info_, olp_list())
+      .WillRepeatedly(ReturnRef(olp_list));
+
   EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
               GetActivationState(_, _))
       .WillOnce(Return(PendingActivationStore::kStatePending))
diff --git a/cellular_capability_universal_unittest.cc b/cellular_capability_universal_unittest.cc
index bae614d..98c988d 100644
--- a/cellular_capability_universal_unittest.cc
+++ b/cellular_capability_universal_unittest.cc
@@ -1657,13 +1657,17 @@
 
 TEST_F(CellularCapabilityUniversalMainTest, UpdateServiceActivationState) {
   const char kIccid[] = "1234567";
+  const vector<MobileOperatorInfo::OnlinePortal> olp_list {
+    {"some@url", "some_method", "some_post_data"}
+  };
   capability_->subscription_state_ =
       CellularCapabilityUniversal::kSubscriptionStateUnprovisioned;
   cellular_->set_sim_identifier("");
   cellular_->set_mdn("0000000000");
-  CellularOperatorInfo::OLP olp;
-  EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
-      .WillRepeatedly(Return(&olp));
+  EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_home_provider_info_, olp_list())
+      .WillRepeatedly(ReturnRef(olp_list));
 
   service_->SetAutoConnect(false);
   EXPECT_CALL(*service_, SetActivationState(kActivationStateNotActivated))
@@ -1956,6 +1960,11 @@
 }
 
 TEST_F(CellularCapabilityUniversalMainTest, IsServiceActivationRequired) {
+  const vector<MobileOperatorInfo::OnlinePortal> empty_list;
+  const vector<MobileOperatorInfo::OnlinePortal> olp_list {
+    {"some@url", "some_method", "some_post_data"}
+  };
+
   capability_->subscription_state_ =
       CellularCapabilityUniversal::kSubscriptionStateProvisioned;
   EXPECT_FALSE(capability_->IsServiceActivationRequired());
@@ -1969,11 +1978,23 @@
   cellular_->set_mdn("0000000000");
   EXPECT_FALSE(capability_->IsServiceActivationRequired());
 
-  CellularOperatorInfo::OLP olp;
-  EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
-      .WillOnce(Return((const CellularOperatorInfo::OLP *)NULL))
-      .WillRepeatedly(Return(&olp));
+  EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(false));
   EXPECT_FALSE(capability_->IsServiceActivationRequired());
+  Mock::VerifyAndClearExpectations(mock_home_provider_info_);
+
+  EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_home_provider_info_, olp_list())
+      .WillRepeatedly(ReturnRef(empty_list));
+  EXPECT_FALSE(capability_->IsServiceActivationRequired());
+  Mock::VerifyAndClearExpectations(mock_home_provider_info_);
+
+  // Set expectations for all subsequent cases.
+  EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_home_provider_info_, olp_list())
+      .WillRepeatedly(ReturnRef(olp_list));
 
   cellular_->set_mdn("");
   EXPECT_TRUE(capability_->IsServiceActivationRequired());
diff --git a/cellular_unittest.cc b/cellular_unittest.cc
index 968271f..f1e4a60 100644
--- a/cellular_unittest.cc
+++ b/cellular_unittest.cc
@@ -1267,13 +1267,23 @@
 }
 
 TEST_F(CellularTest, HandleNewRegistrationStateForServiceRequiringActivation) {
+  const vector<MobileOperatorInfo::OnlinePortal> olp_list {
+    {"some@url", "some_method", "some_post_data"}
+  };
+
   SetCellularType(Cellular::kTypeUniversal);
+  SetMockMobileOperatorInfoObjects();
+  // Service gets created in this test, so set defaults.
+  mock_home_provider_info_->SetEmptyDefaultsForProperties();
 
   // Service activation is needed
   device_->set_mdn("0000000000");
-  CellularOperatorInfo::OLP olp;
-  EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
-      .WillRepeatedly(Return(&olp));
+  // |CellularCapabilityUniversal| expects the |olp_list| from
+  // |cellular->home_provider_info()|.
+  EXPECT_CALL(*mock_home_provider_info_, IsMobileNetworkOperatorKnown())
+      .WillRepeatedly(Return(true));
+  EXPECT_CALL(*mock_home_provider_info_, olp_list())
+      .WillRepeatedly(ReturnRef(olp_list));
   EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
               GetActivationState(_,_))
       .WillRepeatedly(Return(PendingActivationStore::kStateUnknown));