cellular: Mark an activated service for auto-connect by default.

Mark the auto-connect property of a cellular service as true by default
so that a recently activated service will by default auto-connect.

BUG=chromium:239619
TEST=1. Build and run unit tests.
     2. Activate a new LTE SIM and observe that it auto-connects after
     activation. Verify that the "Automatically connect to this network"
     checkbox is checked in the Settings UI.

Change-Id: I6ab3e91df1f13f208f066047e76415ec990d6d83
Reviewed-on: https://gerrit.chromium.org/gerrit/51361
Commit-Queue: Arman Uguray <armansito@chromium.org>
Reviewed-by: Arman Uguray <armansito@chromium.org>
Tested-by: Arman Uguray <armansito@chromium.org>
diff --git a/cellular.cc b/cellular.cc
index 83c6564..5d1c5c5 100644
--- a/cellular.cc
+++ b/cellular.cc
@@ -409,6 +409,8 @@
   SLOG(Cellular, 2) << __func__ << ": " << GetStateString(state_);
   if (capability_->IsServiceActivationRequired()) {
     if (state_ == kStateEnabled && !service_.get()) {
+      SLOG(Cellular, 2) << "Service activation required. Creating dummy "
+                        << "service.";
       CreateService();
     }
     return;
diff --git a/cellular_capability_universal.cc b/cellular_capability_universal.cc
index 0625195..bfa85ab 100644
--- a/cellular_capability_universal.cc
+++ b/cellular_capability_universal.cc
@@ -644,7 +644,7 @@
   if (!cellular()->service().get())
     return;
   bool activation_required = IsServiceActivationRequired();
-  string activation_state = flimflam::kActivationStateActivated;
+  string activation_state;
   PendingActivationStore::State state =
       modem_info()->pending_activation_store()->GetActivationState(
           PendingActivationStore::kIdentifierICCID,
@@ -655,6 +655,14 @@
     activation_state = flimflam::kActivationStateActivating;
   else if (activation_required)
     activation_state = flimflam::kActivationStateNotActivated;
+  else {
+    activation_state = flimflam::kActivationStateActivated;
+
+    // Mark an activated service for auto-connect by default. Since data from
+    // the user profile will be loaded after the call to OnServiceCreated, this
+    // property will be corrected based on the user data at that time.
+    cellular()->service()->SetAutoConnect(true);
+  }
   cellular()->service()->SetActivationState(activation_state);
   // TODO(benchan): For now, assume the cellular service is activated over
   // a non-cellular network if service activation is required (i.e. a
diff --git a/cellular_capability_universal_unittest.cc b/cellular_capability_universal_unittest.cc
index 02f9e4f..8e4debb 100644
--- a/cellular_capability_universal_unittest.cc
+++ b/cellular_capability_universal_unittest.cc
@@ -1521,11 +1521,13 @@
   EXPECT_CALL(*modem_info_.mock_cellular_operator_info(), GetOLPByMCCMNC(_))
       .WillRepeatedly(Return(&olp));
 
+  service_->SetAutoConnect(false);
   EXPECT_CALL(*service_,
               SetActivationState(flimflam::kActivationStateNotActivated))
       .Times(1);
   capability_->UpdateServiceActivationState();
   Mock::VerifyAndClearExpectations(service_);
+  EXPECT_FALSE(service_->auto_connect());
 
   capability_->mdn_ = "1231231122";
   EXPECT_CALL(*service_,
@@ -1533,7 +1535,9 @@
       .Times(1);
   capability_->UpdateServiceActivationState();
   Mock::VerifyAndClearExpectations(service_);
+  EXPECT_TRUE(service_->auto_connect());
 
+  service_->SetAutoConnect(false);
   capability_->mdn_ = "0000000000";
   capability_->sim_identifier_ = kIccid;
   EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
@@ -1548,6 +1552,7 @@
   capability_->UpdateServiceActivationState();
   Mock::VerifyAndClearExpectations(service_);
   Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
+  EXPECT_FALSE(service_->auto_connect());
 
   EXPECT_CALL(*modem_info_.mock_pending_activation_store(),
               GetActivationState(PendingActivationStore::kIdentifierICCID,
@@ -1558,6 +1563,9 @@
               SetActivationState(flimflam::kActivationStateActivated))
       .Times(1);
   capability_->UpdateServiceActivationState();
+  Mock::VerifyAndClearExpectations(service_);
+  Mock::VerifyAndClearExpectations(modem_info_.mock_pending_activation_store());
+  EXPECT_TRUE(service_->auto_connect());
 }
 
 TEST_F(CellularCapabilityUniversalMainTest, ActivationWaitForRegisterTimeout) {