• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
16import queue
17import time
18
19from acts import asserts
20from acts import utils
21from acts.test_decorators import test_tracker_info
22from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
23from acts_contrib.test_utils.wifi.aware import aware_const as aconsts
24from acts_contrib.test_utils.wifi.aware import aware_test_utils as autils
25from acts_contrib.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
26
27
28class AttachTest(AwareBaseTest):
29    @test_tracker_info(uuid="cdafd1e0-bcf5-4fe8-ae32-f55483db9925")
30    def test_attach(self):
31        """Functional test case / Attach test cases / attach
32
33    Validates that attaching to the Wi-Fi Aware service works (receive
34    the expected callback).
35    """
36        dut = self.android_devices[0]
37        dut.droid.wifiAwareAttach(False)
38        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
39        autils.fail_on_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
40
41    @test_tracker_info(uuid="82f2a8bc-a62b-49c2-ac8a-fe8460010ba2")
42    def test_attach_with_identity(self):
43        """Functional test case / Attach test cases / attach with identity callback
44
45    Validates that attaching to the Wi-Fi Aware service works (receive
46    the expected callbacks).
47    """
48        dut = self.android_devices[0]
49        dut.droid.wifiAwareAttach(True)
50        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
51        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
52
53    @test_tracker_info(uuid="d2714d14-f330-47d4-b8e9-ee4d5e5b7ea0")
54    def test_attach_multiple_sessions(self):
55        """Functional test case / Attach test cases / multiple attach sessions
56
57    Validates that when creating multiple attach sessions each can be
58    configured independently as to whether or not to receive an identity
59    callback.
60    """
61        dut = self.android_devices[0]
62
63        # Create 3 attach sessions: 2 without identity callback, 1 with
64        id1 = dut.droid.wifiAwareAttach(False, None, True)
65        time.sleep(10)  # to make sure all calls and callbacks are done
66        id2 = dut.droid.wifiAwareAttach(True, None, True)
67        time.sleep(10)  # to make sure all calls and callbacks are done
68        id3 = dut.droid.wifiAwareAttach(False, None, True)
69        dut.log.info('id1=%d, id2=%d, id3=%d', id1, id2, id3)
70
71        # Attach session 1: wait for attach, should not get identity
72        autils.wait_for_event(
73            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id1))
74        autils.fail_on_event(
75            dut,
76            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id1))
77
78        # Attach session 2: wait for attach and for identity callback
79        autils.wait_for_event(
80            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id2))
81        autils.wait_for_event(
82            dut,
83            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id2))
84
85        # Attach session 3: wait for attach, should not get identity
86        autils.wait_for_event(
87            dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id3))
88        autils.fail_on_event(
89            dut,
90            autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id3))
91
92    @test_tracker_info(uuid="b8ea4d02-ae23-42a7-a85e-def52932c858")
93    def test_attach_with_no_wifi(self):
94        """Function test case / Attach test cases / attempt to attach with wifi off
95
96    Validates that if trying to attach with Wi-Fi disabled will receive the
97    expected failure callback. As a side-effect also validates that the
98    broadcast for Aware unavailable is received.
99    """
100        dut = self.android_devices[0]
101        wutils.wifi_toggle_state(dut, False)
102        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
103        dut.droid.wifiAwareAttach()
104        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
105
106    @test_tracker_info(uuid="7dcc4530-c936-4447-9d22-a7c5b315e2ce")
107    def test_attach_with_doze(self):
108        """Function test case / Attach test cases / attempt to attach with doze on
109
110    Validates that if trying to attach with device in doze mode will receive the
111    expected failure callback. As a side-effect also validates that the
112    broadcast for Aware unavailable is received.
113    """
114        dut = self.android_devices[0]
115        asserts.assert_true(utils.enable_doze(dut), "Can't enable doze")
116        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
117        dut.droid.wifiAwareAttach()
118        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
119        asserts.assert_true(utils.disable_doze(dut), "Can't disable doze")
120        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
121
122    @test_tracker_info(uuid="2574fd01-8974-4dd0-aeb8-a7194461140e")
123    def test_attach_with_location_off(self):
124        """Function test case / Attach test cases / attempt to attach with location
125    mode off.
126
127    Validates that if trying to attach with device location mode off will
128    receive the expected failure callback. As a side-effect also validates that
129    the broadcast for Aware unavailable is received.
130    """
131        dut = self.android_devices[0]
132        asserts.skip_if(dut.droid.isSdkAtLeastT(),
133                        "From T build Aware will not be disabled due to location off")
134        utils.set_location_service(dut, False)
135        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
136        dut.droid.wifiAwareAttach()
137        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)
138        utils.set_location_service(dut, True)
139        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
140
141    @test_tracker_info(uuid="7ffde8e7-a010-4b77-97f5-959f263b5249")
142    def test_attach_apm_toggle_attach_again(self):
143        """Validates that enabling Airplane mode while Aware is on resets it
144    correctly, and allows it to be re-enabled when Airplane mode is then
145    disabled."""
146        dut = self.android_devices[0]
147
148        # enable Aware (attach)
149        dut.droid.wifiAwareAttach()
150        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
151
152        # enable airplane mode
153        utils.force_airplane_mode(dut, True)
154        # APM has a race condition between tear down the NAN Iface and change the Wifi State.
155        try:
156            dut.ed.pop_event(aconsts.BROADCAST_WIFI_AWARE_AVAILABLE, autils.EVENT_TIMEOUT)
157        except queue.Empty:
158            dut.log.info('Wifi State changes before Interface is torn down')
159        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)
160
161        # wait a few seconds and disable airplane mode
162        time.sleep(10)
163        utils.force_airplane_mode(dut, False)
164        autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)
165
166        # try enabling Aware again (attach)
167        dut.droid.wifiAwareAttach()
168        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
169