def eap_connect_toggle_wifi(self, config, *args):
        """Connects to an enterprise network, toggles wifi state and ensures
        that the device reconnects.

        This logic expect the enterprise network to have Internet access.

        Args:
            config: A dict representing a wifi enterprise configuration.
            args: args to be passed to |wutils.eap_connect|.

        Returns:
            True if the connection is successful and Internet access works.
        """
        wutils.eap_connect(config, *args)
        ad = args[0]
        wutils.toggle_wifi_and_wait_for_reconnection(ad,
                                                     config,
                                                     num_of_tries=5)
    def connect_to_wifi_network_toggle_wifi_and_run_iperf(self, params):
        """ Connect to the provided network and then toggle wifi mode and wait
        for reconnection to the provided network.

        Logic steps are
        1. Connect to the network.
        2. Turn wifi off.
        3. Turn wifi on.
        4. Wait for connection to the network.
        5. Run iperf traffic.

        Args:
            params: A tuple of network info and AndroidDevice object.
       """
        network, ad = params
        self.connect_to_wifi_network(params)
        wutils.toggle_wifi_and_wait_for_reconnection(
            ad, network, num_of_tries=5)
        self.run_iperf_client(params)
    def test_number_of_softap_clients(self):
        """Test for number of softap clients to be updated correctly

        1. Turn of hotspot
        2. Register softap callback
        3. Let client connect to the hotspot
        4. Register second softap callback
        5. Force client connect/disconnect to hotspot
        6. Unregister second softap callback
        7. Force second client connect to hotspot (if supported)
        8. Turn off hotspot
        9. Verify second softap callback doesn't respond after unresister
        """
        config = wutils.start_softap_and_verify(self, WIFI_CONFIG_APBAND_AUTO)
        # Register callback after softap enabled to avoid unnecessary callback
        # impact the test
        callbackId = self.dut.droid.registerSoftApCallback()
        # Verify clients will update immediately after register callback
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId, 0)
        wutils.wait_for_expected_softap_state(
            self.dut, callbackId, wifi_constants.WIFI_AP_ENABLED_STATE)

        # Force DUTs connect to Network
        wutils.wifi_connect(self.dut_client, config, check_connectivity=False)
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId, 1)

        # Register another callback to verify multi callback clients case
        callbackId_2 = self.dut.droid.registerSoftApCallback()
        # Verify clients will update immediately after register callback
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId_2, 1)
        wutils.wait_for_expected_softap_state(
            self.dut, callbackId_2, wifi_constants.WIFI_AP_ENABLED_STATE)

        # Client Off/On Wifi to verify number of softap clients will be updated
        wutils.toggle_wifi_and_wait_for_reconnection(self.dut_client, config)

        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId, 0)
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId_2, 0)
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId, 1)
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId_2, 1)

        # Unregister callbackId_2 to verify multi callback clients case
        self.dut.droid.unregisterSoftApCallback(callbackId_2)

        if len(self.android_devices) > 2:
            wutils.wifi_connect(self.android_devices[2],
                                config,
                                check_connectivity=False)
            wutils.wait_for_expected_number_of_softap_clients(
                self.dut, callbackId, 2)

        # Turn off softap when clients connected
        wutils.stop_wifi_tethering(self.dut)
        wutils.wait_for_disconnect(self.dut_client)
        if len(self.android_devices) > 2:
            wutils.wait_for_disconnect(self.android_devices[2])

        # Verify client number change back to 0 after softap stop if client
        # doesn't disconnect before softap stop
        wutils.wait_for_expected_softap_state(
            self.dut, callbackId, wifi_constants.WIFI_AP_DISABLING_STATE)
        wutils.wait_for_expected_softap_state(
            self.dut, callbackId, wifi_constants.WIFI_AP_DISABLED_STATE)
        wutils.wait_for_expected_number_of_softap_clients(
            self.dut, callbackId, 0)
        # Unregister callback
        self.dut.droid.unregisterSoftApCallback(callbackId)

        # Check no any callbackId_2 event after unregister
        asserts.assert_equal(
            wutils.get_current_number_of_softap_clients(
                self.dut, callbackId_2), None)