wifi_test_utils: Send wifi state changed event

Wifi toggle change should wait for wifi state change events (not
supplicant connection change).

Bug: 79263500
Test: Ran `act.py -c softap_cross_onhub.config -tb dut-name -tc
WifiStaApConcurrencyTest` and ensured that toggle wifi state doesn't get
stuck.
Test: Ran 'act.py -c wifi_manager.config -tb dut-name -tc
WifiManagerTest'

Change-Id: I315fe6a76aa8ab7787c79f5ed478afdd61f43290
Merged-In: I315fe6a76aa8ab7787c79f5ed478afdd61f43290
diff --git a/acts/framework/acts/test_utils/wifi/wifi_constants.py b/acts/framework/acts/test_utils/wifi/wifi_constants.py
index d91b454..97f342a 100644
--- a/acts/framework/acts/test_utils/wifi/wifi_constants.py
+++ b/acts/framework/acts/test_utils/wifi/wifi_constants.py
@@ -18,6 +18,7 @@
 WIFI_CONNECTED = "WifiNetworkConnected"
 WIFI_DISCONNECTED = "WifiNetworkDisconnected"
 SUPPLICANT_CON_CHANGED = "SupplicantConnectionChanged"
+WIFI_STATE_CHANGED = "WifiStateChanged"
 WIFI_FORGET_NW_SUCCESS = "WifiManagerForgetNetworkOnSuccess"
 
 # These constants will be used by the ACTS wifi tests.
diff --git a/acts/framework/acts/test_utils/wifi/wifi_test_utils.py b/acts/framework/acts/test_utils/wifi/wifi_test_utils.py
index 7f52fbd..6dc23d6 100755
--- a/acts/framework/acts/test_utils/wifi/wifi_test_utils.py
+++ b/acts/framework/acts/test_utils/wifi/wifi_test_utils.py
@@ -571,14 +571,15 @@
         return
     ad.droid.wifiStartTrackingStateChange()
     ad.log.info("Setting Wi-Fi state to %s.", new_state)
+    ad.ed.clear_all_events()
     # Setting wifi state.
     ad.droid.wifiToggleState(new_state)
     fail_msg = "Failed to set Wi-Fi state to %s on %s." % (new_state,
                                                            ad.serial)
     try:
-        event = ad.ed.pop_event(wifi_constants.SUPPLICANT_CON_CHANGED,
-                                SHORT_TIMEOUT)
-        asserts.assert_equal(event['data']['Connected'], new_state, fail_msg)
+        ad.ed.wait_for_event(wifi_constants.WIFI_STATE_CHANGED,
+                             lambda x: x["data"]["enabled"] == new_state,
+                             SHORT_TIMEOUT)
     except Empty:
         # Supplicant connection event is not always reliable. We double check
         # here and call it a success as long as the new state equals the