conman:  Stop existing APs at startup with no wired connection.

If an AP was already running when conman starts (e.g. from the 'wifi
restore' call in S50wifi), and Catawampus says to run an access point,
conman would leave it running - even with no wired connection.

Now conman also checks for a working wired connection in order to
leave the AP up.

Change-Id: I00e0561971b15970c28d92dc17794b8623e3b72f
diff --git a/conman/connection_manager.py b/conman/connection_manager.py
index c27ef8d..f290774 100755
--- a/conman/connection_manager.py
+++ b/conman/connection_manager.py
@@ -317,30 +317,35 @@
       for filepath in glob.glob(os.path.join(path, prefix + '*')):
         self._process_file(path, os.path.split(filepath)[-1])
 
-    # Make sure no unwanted APs or clients are running.
-    for wifi in self.wifi:
-      for band in wifi.bands:
-        config = self._wlan_configuration.get(band, None)
-        if config:
-          if config.access_point:
-            # If we have a config and want an AP, we don't want a client.
-            self._stop_wifi(band, False, True)
-          else:
-            # If we have a config but don't want an AP, make sure we aren't
-            # running one.
-            self._stop_wifi(band, True, False)
-          break
-      else:
-        # If we have no config for this radio, neither a client nor an AP should
-        # be running.
-        self._stop_wifi(wifi.bands[0], True, True)
-
     # Now that we've read any existing state, it's okay to let interfaces touch
     # the routing table.
     for ifc in self.interfaces():
       ifc.initialize()
       logging.info('%s initialized', ifc.name)
 
+    # Make sure no unwanted APs or clients are running.
+    for wifi in self.wifi:
+      for band in wifi.bands:
+        config = self._wlan_configuration.get(band, None)
+        if config:
+          if config.access_point and self.bridge.internet():
+            # If we have a config and want an AP, we don't want a client.
+            logging.info('Stopping pre-existing %s client on %s',
+                         band, wifi.name)
+            self._stop_wifi(band, False, True)
+          else:
+            # If we have a config but don't want an AP, make sure we aren't
+            # running one.
+            logging.info('Stopping pre-existing %s AP on %s', band, wifi.name)
+            self._stop_wifi(band, True, False)
+          break
+      else:
+        # If we have no config for this radio, neither a client nor an AP should
+        # be running.
+        logging.info('Stopping pre-existing %s AP and clienton %s',
+                     band, wifi.name)
+        self._stop_wifi(wifi.bands[0], True, True)
+
     self._interface_update_counter = 0
     self._try_wlan_after = {'5': 0, '2.4': 0}