Support policy layer and drivers for Fuchsia WLAN

This changes adds support to all Fuchsia WLAN tests
to use the policy layer by default. It also maintains
the ability to use the drivers by specifying the
association_mechanism in the FuchsiaDevice block
of the ACTS config.

This change also moves utility functions into the objects that they
impact, to reduce the number of code flows. Fuchsia WLAN policy
functions were added to a seperate object, that is then made an attribute
of FuchsiaDevice.

A new configure_wlan flow was added to ensure that the new, complex
wlan configurations required for the policy layer are only invoked
when specifically called, and that they do not interfere with non-wlan
tests.

Bug: None
Test: Ran all affected tests with both policy layer and drivers (where applicable)
Change-Id: I2befd59b5137ee368fe1586009696345044912f4
diff --git a/acts_tests/tests/google/fuchsia/wlan_policy/StartStopClientConnectionsTest.py b/acts_tests/tests/google/fuchsia/wlan_policy/StartStopClientConnectionsTest.py
index 5ca70f4..3f585a2 100644
--- a/acts_tests/tests/google/fuchsia/wlan_policy/StartStopClientConnectionsTest.py
+++ b/acts_tests/tests/google/fuchsia/wlan_policy/StartStopClientConnectionsTest.py
@@ -15,10 +15,9 @@
 #   limitations under the License.
 
 from acts import signals
+from acts.controllers.access_point import setup_ap
 from acts.controllers.ap_lib import hostapd_constants
 from acts.controllers.ap_lib import hostapd_security
-from acts_contrib.test_utils.abstract_devices.utils_lib.wlan_utils import setup_ap
-from acts_contrib.test_utils.abstract_devices.utils_lib.wlan_policy_utils import setup_policy_tests, restore_state, save_network, start_connections, stop_connections
 from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
 from acts.utils import rand_ascii_str
 
@@ -58,32 +57,18 @@
 
         if len(self.fuchsia_devices) < 1:
             raise EnvironmentError("No Fuchsia devices found.")
-        # Save the existing saved networks before we remove them for tests
-        # And remember whether client connections have started
-        self.preexisting_state = setup_policy_tests(self.fuchsia_devices)
+        for fd in self.fuchsia_devices:
+            fd.configure_wlan(association_mechanism='policy',
+                              preserve_saved_networks=True)
 
     def setup_test(self):
         for fd in self.fuchsia_devices:
-            # Set new update listener so that the next test can always get the
-            # most recent udpdate immediately.
-            new_listener_result = fd.wlan_policy_lib.wlanSetNewListener()
-            if new_listener_result.get("error") != None:
-                self.log.warn(
-                    "Error occurred initializing a new update listener for the facade, may"
-                    "cause errors in updates for tests: %s" %
-                    new_listener_result.get("error"))
-
-            resultRemove = fd.wlan_policy_lib.wlanRemoveAllNetworks()
-            if resultRemove.get("error") != None:
+            if not fd.wlan_policy_controller.remove_all_networks():
                 raise EnvironmentError(
-                    "Failed to remove all networks in setup: %s" %
-                    resultRemove.get("error"))
+                    "Failed to remove all networks in setup")
 
     def teardown_class(self):
         self.access_point.stop_all_aps()
-        for fd in self.fuchsia_devices:
-            # Put back the networks that were saved before tests began.
-            restore_state(self.fuchsia_devices, self.preexisting_state)
 
     def connect_and_validate(self, fd, ssid, security_type, expected_response):
         """ Sends a connect request to the device and verifies we get a response
@@ -92,8 +77,8 @@
             connect request, or if we don't get the expected connect response."""
         result_connect = fd.wlan_policy_lib.wlanConnect(ssid, security_type)
         if result_connect.get("error") != None:
-            logging.error("Error occurred requesting a connection: %s" %
-                          result_connect.get("error"))
+            self.log.error("Error occurred requesting a connection: %s" %
+                           result_connect.get("error"))
             raise EnvironmentError("Failed to send connect request")
         response = result_connect.get("result")
         if response != expected_response:
@@ -105,7 +90,7 @@
 
     def test_stop_client_connections_update(self):
         for fd in self.fuchsia_devices:
-            if not stop_connections(fd):
+            if not fd.wlan_policy_controller.stop_client_connections():
                 raise EnvironmentError("Failed to stop client connecions")
 
             # Check that the most recent update says that the device is not
@@ -121,14 +106,14 @@
             if result_update.get("result") != expected_update:
                 self.log.error(
                     "Most recent status update does not indicate client "
-                    "connections have stopped. Expected update: %s\nActual update:"
-                    % (expected_update, result_update))
+                    "connections have stopped. Expected update: %s Actual update: %s"
+                    % (expected_update, result_update.get('result')))
                 raise signals.TestFailure(
                     "Incorrect update after stopping client connections")
 
     def test_start_client_connections_update(self):
         for fd in self.fuchsia_devices:
-            if not start_connections(fd):
+            if not fd.wlan_policy_controller.start_client_connections():
                 raise EnvironmentError("Failed to start client connecions")
 
             # Check that the most recent update says that the device is not
@@ -153,13 +138,13 @@
         # Test that if we turn client connections off, our requests to connect
         # are rejected.
         for fd in self.fuchsia_devices:
-            if not stop_connections(fd):
+            if not fd.wlan_policy_controller.stop_client_connections():
                 raise EnvironmentError("Failed to stop client connecions")
 
             # Save the network, otherwise connecting may fail because the
             # network is not saved instead of client connections being off
-            if not save_network(fd, self.ssid, self.security_type,
-                                self.password):
+            if not fd.wlan_policy_controller.save_network(
+                    self.ssid, self.security_type, password=self.password):
                 raise EnvironmentError("Failed to save network")
             expected_response = "RejectedIncompatibleMode"
             self.connect_and_validate(fd, self.ssid, self.security_type,
@@ -170,24 +155,26 @@
         # and if we turn of client connections the device will disconnect.
         for fd in self.fuchsia_devices:
             # Start client connections and check that we can
-            if not save_network(fd, self.ssid, self.security_type,
-                                self.password):
+            if not fd.wlan_policy_controller.save_network(
+                    self.ssid, self.security_type, password=self.password):
                 raise EnvironmentError("Failed to save network")
-            if not start_connections(fd):
+            if not fd.wlan_policy_controller.start_client_connections():
                 raise EnvironmentError("Failed to start client connections")
 
             expected_response = "Acknowledged"
             self.connect_and_validate(fd, self.ssid, self.security_type,
                                       expected_response)
 
-            if not fd.wait_for_connect(self.ssid, self.security_type):
+            if not fd.wlan_policy_controller.wait_for_connect(
+                    self.ssid, self.security_type):
                 raise signals.TestFailure(
                     "Failed to connect after starting client connections")
 
             # Stop client connections again and check that we disconnect
-            if not stop_connections(fd):
+            if not fd.wlan_policy_controller.stop_client_connections():
                 raise EnvironmentError("Failed to stop client connecions")
-            if not fd.wait_for_disconnect(self.ssid, self.security_type,
-                                          DISCONNECTED, CONNECTION_STOPPED):
+            if not fd.wlan_policy_controller.wait_for_disconnect(
+                    self.ssid, self.security_type, DISCONNECTED,
+                    CONNECTION_STOPPED):
                 raise signals.TestFailure(
                     "Failed to disconnect after client connections stopped")