1#!/usr/bin/python3.4
2#
3#   Copyright 2017 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17from acts import asserts
18from acts.test_utils.wifi import wifi_test_utils as wutils
19from acts.test_utils.wifi.aware import aware_const as aconsts
20from acts.test_utils.wifi.aware import aware_test_utils as autils
21from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
22
23
24class NonConcurrencyTest(AwareBaseTest):
25  """Tests lack of concurrency scenarios Wi-Fi Aware with WFD (p2p) and
26  SoftAP
27
28  Note: these tests should be modified if the concurrency behavior changes!"""
29
30  SERVICE_NAME = "GoogleTestXYZ"
31  TETHER_SSID = "GoogleTestSoftApXYZ"
32
33  def __init__(self, controllers):
34    AwareBaseTest.__init__(self, controllers)
35
36  def teardown_test(self):
37    AwareBaseTest.teardown_test(self)
38    for ad in self.android_devices:
39      ad.droid.wifiP2pClose()
40
41  def run_aware_then_incompat_service(self, is_p2p):
42    """Run test to validate that a running Aware session terminates when an
43    Aware-incompatible service is started.
44
45    Args:
46      is_p2p: True for p2p, False for SoftAP
47    """
48    dut = self.android_devices[0]
49
50    # start Aware
51    id = dut.droid.wifiAwareAttach()
52    autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
53
54    # start other service
55    if is_p2p:
56      dut.droid.wifiP2pInitialize()
57    else:
58      wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)
59
60    # expect an announcement about Aware non-availability
61    autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
62
63    # local clean-up
64    if not is_p2p:
65      wutils.stop_wifi_tethering(dut)
66
67  def run_incompat_service_then_aware(self, is_p2p):
68    """Validate that if an Aware-incompatible service is already up then any
69    Aware operation fails"""
70    dut = self.android_devices[0]
71
72    # start other service
73    if is_p2p:
74      dut.droid.wifiP2pInitialize()
75    else:
76      wutils.start_wifi_tethering(dut, self.TETHER_SSID, password=None)
77
78    # expect an announcement about Aware non-availability
79    autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
80
81    # try starting anyway (expect failure)
82    dut.droid.wifiAwareAttach()
83    autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
84
85    # stop other service
86    if is_p2p:
87      dut.droid.wifiP2pClose()
88    else:
89      wutils.stop_wifi_tethering(dut)
90
91    # expect an announcement about Aware availability
92    autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
93
94    # try starting Aware
95    dut.droid.wifiAwareAttach()
96    autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
97
98  ##########################################################################
99
100  def test_run_p2p_then_aware(self):
101    """Validate that if p2p is already up then any Aware operation fails"""
102    self.run_incompat_service_then_aware(is_p2p=True)
103
104  def test_run_aware_then_p2p(self):
105    """Validate that a running Aware session terminates when p2p is started"""
106    self.run_aware_then_incompat_service(is_p2p=True)
107
108  def test_run_softap_then_aware(self):
109    """Validate that if SoftAp is already up then any Aware operation fails"""
110    self.run_incompat_service_then_aware(is_p2p=False)
111
112  def test_run_aware_then_softap(self):
113    """Validate that a running Aware session terminates when softAp is
114    started"""
115    self.run_aware_then_incompat_service(is_p2p=False)
116