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/device.h b/device.h
index cd84a2a..3a6d6e8 100644
--- a/device.h
+++ b/device.h
@@ -62,6 +62,12 @@
   void SetEnabledPersistent(bool enable,
                             Error *error, const ResultCallback &callback);
 
+  // Returns true if the underlying device reports that it is already enabled.
+  // Used when the device is registered with the Manager, so that shill can
+  // sync its state/ with the true state of the device. The default is to
+  // report false.
+  virtual bool IsUnderlyingDeviceEnabled() const;
+
   // TODO(gauravsh): We do not really need this since technology() can be used
   //                 to get a device's technology for direct comparison.
   // Base method always returns false.
@@ -144,6 +150,7 @@
   DeviceAdaptorInterface *adaptor() const { return adaptor_.get(); }
 
  protected:
+  FRIEND_TEST(CellularTest, ModemStateChangeDisable);
   FRIEND_TEST(DeviceTest, AcquireIPConfig);
   FRIEND_TEST(DeviceTest, DestroyIPConfig);
   FRIEND_TEST(DeviceTest, DestroyIPConfigNULL);