Merge "[WifiRoamingTest] Fix test_roaming_fail_psk_2g" into sc-dev
diff --git a/acts_tests/tests/google/wifi/WifiEnterpriseTest.py b/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
index 2cb3f28..3eee55b 100644
--- a/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
+++ b/acts_tests/tests/google/wifi/WifiEnterpriseTest.py
@@ -155,6 +155,7 @@
         self.dut.droid.wifiStopTrackingStateChange()
         # Turn off airplane mode
         acts.utils.force_airplane_mode(self.dut, False)
+        wutils.set_attns(self.attenuators, "default")
 
     """Helper Functions"""
 
diff --git a/acts_tests/tests/google/wifi/WifiManagerTest.py b/acts_tests/tests/google/wifi/WifiManagerTest.py
index 719d2ca..8bd4225 100644
--- a/acts_tests/tests/google/wifi/WifiManagerTest.py
+++ b/acts_tests/tests/google/wifi/WifiManagerTest.py
@@ -108,6 +108,10 @@
             wutils.stop_wifi_tethering(self.dut)
         for ad in self.android_devices:
             wutils.reset_wifi(ad)
+        self.log.debug("Toggling Airplane mode OFF")
+        asserts.assert_true(
+            acts.utils.force_airplane_mode(self.dut, False),
+            "Can not turn airplane mode off: %s" % self.dut.serial)
 
     def teardown_class(self):
         if "AccessPoint" in self.user_params:
@@ -744,6 +748,36 @@
         self.turn_location_on_and_scan_toggle_on()
         self.helper_reconnect_toggle_airplane()
 
+    @test_tracker_info(uuid="52b89a47-f260-4343-922d-fbeb4d8d2b63")
+    def test_reconnect_toggle_wifi_on_with_airplane_on(self):
+        """Connect to multiple networks, turn on airplane mode, turn on wifi,
+        then reconnect a previously connected network.
+
+        Steps:
+        1. Connect to a 2GHz network.
+        2. Connect to a 5GHz network.
+        3. Turn ON Airplane mode.
+        4. Turn ON WiFi.
+        5. Reconnect to the a previously connected network.
+        """
+        connect_2g_data = self.get_connection_data(self.dut, self.wpapsk_2g)
+        connect_5g_data = self.get_connection_data(self.dut, self.wpapsk_5g)
+        self.log.debug("Toggling Airplane mode ON")
+        asserts.assert_true(
+            acts.utils.force_airplane_mode(self.dut, True),
+            "Can not turn on airplane mode on: %s" % self.dut.serial)
+        self.log.debug("Toggling wifi ON")
+        wutils.wifi_toggle_state(self.dut, True)
+        time.sleep(DEFAULT_TIMEOUT)
+        reconnect_to = self.get_enabled_network(connect_2g_data,
+                                                connect_5g_data)
+        reconnect = self.connect_to_wifi_network_with_id(
+            reconnect_to[WifiEnums.NETID_KEY],
+            reconnect_to[WifiEnums.SSID_KEY])
+        if not reconnect:
+            raise signals.TestFailure("Device did not connect to the correct"
+                                      " network after toggling WiFi.")
+
     @test_tracker_info(uuid="3d041c12-05e2-46a7-ab9b-e3f60cc735db")
     def test_reboot_configstore_reconnect(self):
         """Connect to multiple networks, reboot then reconnect to previously
diff --git a/acts_tests/tests/google/wifi/aware/functional/DataPathTest.py b/acts_tests/tests/google/wifi/aware/functional/DataPathTest.py
index 44a9f38..c28468a 100644
--- a/acts_tests/tests/google/wifi/aware/functional/DataPathTest.py
+++ b/acts_tests/tests/google/wifi/aware/functional/DataPathTest.py
@@ -117,7 +117,7 @@
             p2_config = self.create_config(ptype)
             if not pub_on_both_same:
                 p2_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = (
-                    p2_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] + "-XYZXYZ")
+                        p2_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] + "-XYZXYZ")
             s_dut.droid.wifiAwarePublish(s_id, p2_config)
             autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
 
@@ -178,11 +178,11 @@
     """
         (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub,
          peer_id_on_pub) = self.set_up_discovery(
-             ptype,
-             stype,
-             use_peer_id,
-             pub_on_both=pub_on_both,
-             pub_on_both_same=pub_on_both_same)
+            ptype,
+            stype,
+            use_peer_id,
+            pub_on_both=pub_on_both,
+            pub_on_both_same=pub_on_both_same)
 
         passphrase = None
         pmk = None
@@ -481,8 +481,8 @@
     """
         (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub,
          peer_id_on_pub) = self.set_up_discovery(
-             aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE,
-             True)
+            aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE,
+            True)
 
         if pub_mismatch:
             peer_id_on_pub = peer_id_on_pub - 1
@@ -1752,12 +1752,12 @@
         if use_ib:
             (resp_req_key, init_req_key, resp_aware_if, init_aware_if,
              resp_ipv6, init_ipv6) = autils.create_ib_ndp(
-                 resp_dut, init_dut,
-                 autils.create_discovery_config(
-                     "GoogleTestXyz", aconsts.PUBLISH_TYPE_UNSOLICITED),
-                 autils.create_discovery_config(
-                     "GoogleTestXyz", aconsts.SUBSCRIBE_TYPE_PASSIVE),
-                 self.device_startup_offset)
+                resp_dut, init_dut,
+                autils.create_discovery_config(
+                    "GoogleTestXyz", aconsts.PUBLISH_TYPE_UNSOLICITED),
+                autils.create_discovery_config(
+                    "GoogleTestXyz", aconsts.SUBSCRIBE_TYPE_PASSIVE),
+                self.device_startup_offset)
         else:
             (init_req_key, resp_req_key, init_aware_if, resp_aware_if,
              init_ipv6, resp_ipv6) = autils.create_oob_ndp(init_dut, resp_dut)
@@ -1852,7 +1852,7 @@
 
         (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub,
          peer_id_on_pub) = self.set_up_discovery(
-             aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE, True)
+            aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE, True)
 
         p_id2, p_mac = autils.attach_with_identity(p_dut)
         s_id2, s_mac = autils.attach_with_identity(s_dut)
@@ -2034,10 +2034,10 @@
                 resp_interface, "NDP interfaces don't match on Sub/other")
 
             asserts.assert_equal(pub_ipv6, resp_ipv6
-                                 if inits_on_same_dut else init_ipv6,
+            if inits_on_same_dut else init_ipv6,
                                  "NDP IPv6 don't match on Pub/other")
             asserts.assert_equal(sub_ipv6, init_ipv6
-                                 if inits_on_same_dut else resp_ipv6,
+            if inits_on_same_dut else resp_ipv6,
                                  "NDP IPv6 don't match on Sub/other")
         else:
             asserts.assert_false(
@@ -2221,8 +2221,8 @@
 
             (init_req_key, resp_req_key, init_aware_if, resp_aware_if,
              init_ipv6, resp_ipv6) = autils.create_oob_ndp_on_sessions(
-                 duts[i], duts[peer_device], ids[i], macs[i], ids[peer_device],
-                 macs[peer_device])
+                duts[i], duts[peer_device], ids[i], macs[i], ids[peer_device],
+                macs[peer_device])
 
             reqs[i].append(init_req_key)
             reqs[peer_device].append(resp_req_key)
@@ -2246,3 +2246,110 @@
                 "ifs": ifs,
                 "ipv6s": ipv6s
             })
+
+    @test_tracker_info(uuid="")
+    def test_ndp_initiate_from_both_sides_with_accepts_any_responder(self):
+        """Validate when two device both try to initiate a connection to each other, both NDP can be
+        formed.
+
+        1. Device A and B both publish and file accept any request.
+        2. Device A and B both subscribe to the peer
+        3. When get a discovery match file a network request to the peer
+        4. Wait for NDP setup finish.
+        """
+        asserts.skip_if(
+            self.android_devices[0]
+            .aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES] < 2
+            or self.android_devices[1]
+            .aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES] < 2,
+            "DUTs do not support enough NDIs.")
+        ptype = aconsts.PUBLISH_TYPE_UNSOLICITED
+        stype = aconsts.SUBSCRIBE_TYPE_PASSIVE
+        dut1 = self.android_devices[0]
+        dut2 = self.android_devices[1]
+
+        # Publisher+Subscriber: attach and wait for confirmation
+        dut1_id = dut1.droid.wifiAwareAttach()
+        autils.wait_for_event(dut1, aconsts.EVENT_CB_ON_ATTACHED)
+        time.sleep(self.device_startup_offset)
+        dut2_id = dut2.droid.wifiAwareAttach()
+        autils.wait_for_event(dut2, aconsts.EVENT_CB_ON_ATTACHED)
+
+        # Publisher: start publish and wait for confirmation
+        dut1_p_disc_id = dut1.droid.wifiAwarePublish(dut1_id, self.create_config(ptype))
+        autils.wait_for_event(dut1, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
+
+        dut2_p_disc_id = dut2.droid.wifiAwarePublish(dut2_id, self.create_config(ptype))
+        autils.wait_for_event(dut2, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
+
+        # Publisher: file an accept any NetworkRequest
+        dut1_p_req_key = self.request_network(
+            dut1,
+            dut1.droid.wifiAwareCreateNetworkSpecifier(
+                dut1_p_disc_id, None, self.PASSPHRASE, None))
+
+        dut2_p_req_key = self.request_network(
+            dut2,
+            dut2.droid.wifiAwareCreateNetworkSpecifier(
+                dut2_p_disc_id, None, self.PASSPHRASE, None))
+
+        # Subscriber: start subscribe and wait for discovery match
+        dut2_s_disc_id = dut2.droid.wifiAwareSubscribe(dut2_id, self.create_config(stype))
+        autils.wait_for_event(dut2, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
+
+        dut1_s_disc_id = dut1.droid.wifiAwareSubscribe(dut1_id, self.create_config(stype))
+        autils.wait_for_event(dut1, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
+
+        discovery_event = autils.wait_for_event(
+            dut2, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
+        dut2_peer_id_on_sub = discovery_event["data"][
+            aconsts.SESSION_CB_KEY_PEER_ID]
+
+        discovery_event = autils.wait_for_event(
+            dut1, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
+        dut1_peer_id_on_sub = discovery_event["data"][
+            aconsts.SESSION_CB_KEY_PEER_ID]
+
+        # Subscriber: file a NetworkRequest with peer Id
+        dut2_s_req_key = self.request_network(
+            dut2,
+            dut2.droid.wifiAwareCreateNetworkSpecifier(
+                dut2_s_disc_id, dut2_peer_id_on_sub, self.PASSPHRASE, None))
+
+        # Avoid publisher and subscriber requests are handled in the same NDP
+        time.sleep(1)
+
+        dut1_s_req_key = self.request_network(
+            dut1,
+            dut1.droid.wifiAwareCreateNetworkSpecifier(
+                dut1_s_disc_id, dut1_peer_id_on_sub, self.PASSPHRASE, None))
+
+        # Publisher+Subscriber: wait and check the network callback.
+        autils.wait_for_event_with_keys(
+            dut1, cconsts.EVENT_NETWORK_CALLBACK,
+            autils.EVENT_NDP_TIMEOUT,
+            (cconsts.NETWORK_CB_KEY_EVENT,
+             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
+            (cconsts.NETWORK_CB_KEY_ID, dut1_p_req_key))
+
+        autils.wait_for_event_with_keys(
+            dut2, cconsts.EVENT_NETWORK_CALLBACK,
+            autils.EVENT_NDP_TIMEOUT,
+            (cconsts.NETWORK_CB_KEY_EVENT,
+             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
+            (cconsts.NETWORK_CB_KEY_ID, dut2_s_req_key))
+
+        autils.wait_for_event_with_keys(
+            dut2, cconsts.EVENT_NETWORK_CALLBACK,
+            autils.EVENT_NDP_TIMEOUT,
+            (cconsts.NETWORK_CB_KEY_EVENT,
+             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
+            (cconsts.NETWORK_CB_KEY_ID, dut2_p_req_key))
+
+        autils.wait_for_event_with_keys(
+            dut1, cconsts.EVENT_NETWORK_CALLBACK,
+            autils.EVENT_NDP_TIMEOUT,
+            (cconsts.NETWORK_CB_KEY_EVENT,
+             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
+            (cconsts.NETWORK_CB_KEY_ID, dut1_s_req_key))
+