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.h b/cellular.h
index 73eb7f1..ee9683e 100644
--- a/cellular.h
+++ b/cellular.h
@@ -53,9 +53,9 @@
 
   enum ModemState {
     kModemStateUnknown = 0,
-    kModemStateDisabled = 1,
-    kModemStateInitializing = 2,
-    kModemStateLocked = 3,
+    kModemStateInitializing = 1,
+    kModemStateLocked = 2,
+    kModemStateDisabled = 3,
     kModemStateDisabling = 4,
     kModemStateEnabling = 5,
     kModemStateEnabled = 6,
@@ -129,6 +129,8 @@
 
   void set_modem_state(ModemState state) { modem_state_ = state; }
   ModemState modem_state() const { return modem_state_; }
+  bool IsUnderlyingDeviceEnabled() const;
+  static bool IsEnabledModemState(ModemState state);
 
   mobile_provider_db *provider_db() const { return provider_db_; }
 
@@ -173,11 +175,15 @@
                       const Error &error);
   void OnModemStopped(const EnabledStateChangedCallback &callback,
                       const Error &error);
+  void OnConnecting();
   void OnConnected();
   void OnConnectFailed(const Error &error);
   void OnDisconnected();
   void OnDisconnectFailed();
   std::string GetTechnologyFamily(Error *error);
+  void OnModemStateChanged(ModemState old_state,
+                           ModemState new_state,
+                           uint32 reason);
 
  private:
   friend class CellularTest;
@@ -196,6 +202,8 @@
   FRIEND_TEST(CellularTest, ConnectFailure);
   FRIEND_TEST(CellularTest, DisableModem);
   FRIEND_TEST(CellularTest, Disconnect);
+  FRIEND_TEST(CellularTest, ModemStateChangeDisable);
+  FRIEND_TEST(CellularTest, ModemStateChangeEnable);
   FRIEND_TEST(CellularTest, StartConnected);
   FRIEND_TEST(CellularTest, StartCDMARegister);
   FRIEND_TEST(CellularTest, StartGSMRegister);