shill: Handle modem state changes reported by modem-manager.

Also, adjust correctly to initial state reported by
modem-manager. This involved some adjustments to the
StartModem path, e.g., to make the MM Enable operation
conditional on whether the current modem state is not
already Enabled. Other streamlining done for the StartModem
path includes:

- eliminating the GetModemStatus call in the GSM
  case. All the needed information (such as IMSI)
  is obtained in later calls.
- making the Register call conditional on the modem
  not already being registered.

I added a couple of unit tests to check responses to
state changes, but many more tests could be created.

BUG=chromium-os:19962
TEST=Testing includes running mm-enable and
mm-disable while the modem is in the disabled, enabled,
registered, and connected states, and making sure that
shill updates its own state appropriately, and that the
UI properly reflects the new state.  Also ran mm-connect
and mm-disconnect to see that the UI (and shill) respond
correctly to connect and disconnect events. Similarly,
started up shill while modem started out in these various
states.

Tested only using MM classic API. Code is in place to make
this work for the MM1 API, but I haven't tried testing while
the new modem manager is running.

Change-Id: I4f276bee62b64e8f1260a39f18c3c2a5de8d2798
Reviewed-on: https://gerrit.chromium.org/gerrit/20517
Commit-Ready: Eric Shienbrood <ers@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Tested-by: Eric Shienbrood <ers@chromium.org>
diff --git a/cellular_capability_classic.h b/cellular_capability_classic.h
index 8778a7c..4e62020 100644
--- a/cellular_capability_classic.h
+++ b/cellular_capability_classic.h
@@ -14,6 +14,7 @@
 #include <base/memory/weak_ptr.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
+#include "shill/cellular.h"
 #include "shill/cellular_capability.h"
 #include "shill/dbus_properties.h"
 #include "shill/modem_proxy_interface.h"
@@ -26,6 +27,19 @@
 class EventDispatcher;
 class ProxyFactory;
 
+enum ModemClassicState {
+  kModemClassicStateUnknown = 0,
+  kModemClassicStateDisabled = 10,
+  kModemClassicStateDisabling = 20,
+  kModemClassicStateEnabling = 30,
+  kModemClassicStateEnabled = 40,
+  kModemClassicStateSearching = 50,
+  kModemClassicStateRegistered = 60,
+  kModemClassicStateDisconnecting = 70,
+  kModemClassicStateConnecting = 80,
+  kModemClassicStateConnected = 90,
+};
+
 // CellularCapabilityClassic handles modems using the
 // org.chromium.ModemManager DBUS interface.
 class CellularCapabilityClassic : public CellularCapability {
@@ -35,6 +49,7 @@
   static const char kConnectPropertyApnPassword[];
   static const char kConnectPropertyHomeOnly[];
   static const char kConnectPropertyPhoneNumber[];
+  static const char kModemPropertyEnabled[];
 
   // |cellular| is the parent Cellular device.
   CellularCapabilityClassic(Cellular *cellular, ProxyFactory *proxy_factory);
@@ -67,6 +82,11 @@
 
   virtual void Scan(Error *error, const ResultCallback &callback);
 
+  virtual void OnDBusPropertiesChanged(
+      const std::string &interface,
+      const DBusPropertiesMap &properties,
+      const std::vector<std::string> &invalidated_properties);
+
  protected:
   // The following five methods are only ever called as
   // callbacks (from the main loop), which is why they
@@ -122,6 +142,8 @@
   FRIEND_TEST(CellularTest, Connect);
   FRIEND_TEST(CellularTest, ConnectFailure);
   FRIEND_TEST(CellularTest, Disconnect);
+  FRIEND_TEST(CellularTest, ModemStateChangeEnable);
+  FRIEND_TEST(CellularTest, ModemStateChangeDisable);
 
   void HelpRegisterDerivedBool(
       const std::string &name,