shill: cellular: Suppress auto-connect when device is not running.

When a cellular device is being disabled, it may disconnect a
connected cellular service. However, shill may try to auto-connect the
service before the service is destroyed. To avoid such a race, this CL
makes a cellular service not auto-connectable when the cellular device
is not running.

BUG=chromium-os:34182
TEST=Tested the following:
1. Build and run unit tests.
2. After connecting to a cellular network, disable the cellular
   technology and verify that shill does not try to auto-connect the
   cellular service while the cellular device is being disabled.

Change-Id: I4ce18dfc416984c607976a183100779b645ebbcb
Reviewed-on: https://gerrit.chromium.org/gerrit/34497
Tested-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
Commit-Ready: Ben Chan <benchan@chromium.org>
diff --git a/cellular_service.h b/cellular_service.h
index 15ef02c..63c9b2f 100644
--- a/cellular_service.h
+++ b/cellular_service.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef SHILL_CELLULAR_SERVICE_
-#define SHILL_CELLULAR_SERVICE_
+#ifndef SHILL_CELLULAR_SERVICE_H_
+#define SHILL_CELLULAR_SERVICE_H_
 
 #include <map>
 #include <string>
@@ -90,7 +90,7 @@
   void SetRoamingState(const std::string &state);
   const std::string &roaming_state() const { return roaming_state_; }
 
-  // Overrride Load and Save from parent Service class.  We will call
+  // Overrides Load and Save from parent Service class.  We will call
   // the parent method.
   virtual bool Load(StoreInterface *storage);
   virtual bool Save(StoreInterface *storage);
@@ -100,6 +100,10 @@
   virtual void SetLastGoodApn(const Stringmap &apn_info);
   virtual void ClearLastGoodApn();
 
+ protected:
+  // Overrides IsAutoConnectable from parent Service class.
+  virtual bool IsAutoConnectable(const char **reason) const;
+
  private:
   friend class CellularServiceTest;
   FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
@@ -108,6 +112,9 @@
   FRIEND_TEST(CellularServiceTest, SetApn);
   FRIEND_TEST(CellularServiceTest, ClearApn);
   FRIEND_TEST(CellularServiceTest, LastGoodApn);
+  FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
+
+  static const char kAutoConnDeviceDisabled[];
 
   void HelpRegisterDerivedStringmap(
       const std::string &name,
@@ -157,4 +164,4 @@
 
 }  // namespace shill
 
-#endif  // SHILL_CELLULAR_SERVICE_
+#endif  // SHILL_CELLULAR_SERVICE_H_