shill: Refactor SIM lock status properties into the GSM delegate.

BUG=chromium-os:18735
TEST=unit tests (old and new)

Change-Id: I829eb6cee67cb1ab418cf16a32c2195e3446a22b
Reviewed-on: https://gerrit.chromium.org/gerrit/11765
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Jason Glasgow <jglasgow@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/cellular_capability_gsm.cc b/cellular_capability_gsm.cc
index b7969d3..7296bf9 100644
--- a/cellular_capability_gsm.cc
+++ b/cellular_capability_gsm.cc
@@ -13,8 +13,10 @@
 
 #include "shill/cellular.h"
 #include "shill/cellular_service.h"
+#include "shill/property_accessor.h"
 #include "shill/proxy_factory.h"
 
+using std::make_pair;
 using std::string;
 
 namespace shill {
@@ -29,6 +31,8 @@
 const char CellularCapabilityGSM::kPhoneNumber[] = "*99#";
 const char CellularCapabilityGSM::kPropertyAccessTechnology[] =
     "AccessTechnology";
+const char CellularCapabilityGSM::kPropertyUnlockRequired[] = "UnlockRequired";
+const char CellularCapabilityGSM::kPropertyUnlockRetries[] = "UnlockRetries";
 
 CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular)
     : CellularCapability(cellular),
@@ -44,9 +48,30 @@
                                  &found_networks_);
   store->RegisterConstBool(flimflam::kScanningProperty, &scanning_);
   store->RegisterUint16(flimflam::kScanIntervalProperty, &scan_interval_);
+  HelpRegisterDerivedStrIntPair(flimflam::kSIMLockStatusProperty,
+                                &CellularCapabilityGSM::SimLockStatusToProperty,
+                                NULL);
 }
 
-void CellularCapabilityGSM::InitProxies() {
+StrIntPair CellularCapabilityGSM::SimLockStatusToProperty(Error */*error*/) {
+  return StrIntPair(make_pair(flimflam::kSIMLockTypeProperty,
+                              sim_lock_status_.lock_type),
+                    make_pair(flimflam::kSIMLockRetriesLeftProperty,
+                              sim_lock_status_.retries_left));
+}
+
+void CellularCapabilityGSM::HelpRegisterDerivedStrIntPair(
+    const string &name,
+    StrIntPair(CellularCapabilityGSM::*get)(Error *),
+    void(CellularCapabilityGSM::*set)(const StrIntPair &, Error *)) {
+  cellular()->mutable_store()->RegisterDerivedStrIntPair(
+      name,
+      StrIntPairAccessor(
+          new CustomAccessor<CellularCapabilityGSM, StrIntPair>(
+              this, get, set)));
+}
+
+void CellularCapabilityGSM::OnStart() {
   VLOG(2) << __func__;
   card_proxy_.reset(
       proxy_factory()->CreateModemGSMCardProxy(this,
@@ -58,6 +83,12 @@
                                                   cellular()->dbus_owner()));
 }
 
+void CellularCapabilityGSM::OnStop() {
+  VLOG(2) << __func__;
+  card_proxy_.reset();
+  network_proxy_.reset();
+}
+
 void CellularCapabilityGSM::UpdateStatus(const DBusPropertiesMap &properties) {
   string imsi;
   if (DBusProperties::GetString(properties, "imsi", &imsi)) {
@@ -395,6 +426,10 @@
                                 &access_technology)) {
     SetAccessTechnology(access_technology);
   }
+  DBusProperties::GetString(
+      properties, kPropertyUnlockRequired, &sim_lock_status_.lock_type);
+  DBusProperties::GetUint32(
+      properties, kPropertyUnlockRetries, &sim_lock_status_.retries_left);
 }
 
 void CellularCapabilityGSM::OnServiceCreated() {