• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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
17import acts.signals
18import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
19
20from acts.test_decorators import test_tracker_info
21from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
22
23
24class WifiHiddenSSIDTest(WifiBaseTest):
25    """Tests for APIs in Android's WifiManager class.
26
27    Test Bed Requirement:
28    * One Android device
29    * Several Wi-Fi networks visible to the device, including an open Wi-Fi
30      network.
31    """
32    def __init__(self, configs):
33        super().__init__(configs)
34        self.enable_packet_log = True
35
36    def setup_class(self):
37        super().setup_class()
38
39        self.dut = self.android_devices[0]
40
41        if "AccessPoint" in self.user_params:
42            self.legacy_configure_ap_and_start(hidden=True)
43        elif "OpenWrtAP" in self.user_params:
44            self.configure_openwrt_ap_and_start(open_network=True,
45                                                wpa_network=True,
46                                                owe_network=True,
47                                                sae_network=True,
48                                                hidden=True)
49
50        self.open_hidden_2g = self.open_network[0]["2g"]
51        self.open_hidden_5g = self.open_network[0]["5g"]
52        self.wpa_hidden_2g = self.reference_networks[0]["2g"]
53        self.wpa_hidden_5g = self.reference_networks[0]["5g"]
54
55    def setup_test(self):
56        super().setup_test()
57        self.dut.droid.wakeLockAcquireBright()
58        self.dut.droid.wakeUpNow()
59
60    def teardown_test(self):
61        super().teardown_test()
62        self.dut.droid.wakeLockRelease()
63        self.dut.droid.goToSleepNow()
64
65    def teardown_class(self):
66        wutils.reset_wifi(self.dut)
67        if "AccessPoint" in self.user_params:
68            del self.user_params["reference_networks"]
69            del self.user_params["open_network"]
70
71    """Helper Functions"""
72
73    def check_hiddenSSID_in_scan(self, ap_ssid, max_tries=2):
74        """Check if the ap started by wifi tethering is seen in scan results.
75
76        Args:
77            ap_ssid: SSID of the ap we are looking for.
78            max_tries: Number of scans to try.
79        Returns:
80            True: if ap_ssid is found in scan results.
81            False: if ap_ssid is not found in scan results.
82        """
83        for num_tries in range(max_tries):
84            wutils.start_wifi_connection_scan(self.dut)
85            scan_results = self.dut.droid.wifiGetScanResults()
86            match_results = wutils.match_networks(
87                {wutils.WifiEnums.SSID_KEY: ap_ssid}, scan_results)
88            if len(match_results) > 0:
89                return True
90        return False
91
92    def add_hiddenSSID_and_connect(self, hidden_network):
93        """Add the hidden network and connect to it.
94
95        Args:
96            hidden_network: The hidden network config to connect to.
97
98        """
99        wutils.connect_to_wifi_network(self.dut, hidden_network, hidden=True)
100        if not wutils.validate_connection(self.dut):
101            raise signals.TestFailure("Fail to connect to internet on %s" %
102                                       hidden_network)
103
104    """Tests"""
105
106    @test_tracker_info(uuid="d0871f98-6049-4937-a288-ec4a2746c771")
107    def test_connect_to_wpa_hidden_2g(self):
108        """Connect to a WPA, 2G network.
109
110        Steps:
111        1. Add a WPA, 2G hidden network.
112        2. Ensure the network is visible in scan.
113        3. Connect and run ping.
114
115        """
116        self.add_hiddenSSID_and_connect(self.wpa_hidden_2g)
117
118    @test_tracker_info(uuid="c558b31a-549a-4012-9052-275623992187")
119    def test_connect_to_wpa_hidden_5g(self):
120        """Connect to a WPA, 5G hidden  network.
121
122        Steps:
123        1. Add a WPA, 5G hidden network.
124        2. Ensure the network is visible in scan.
125        3. Connect and run ping.
126
127        """
128        self.add_hiddenSSID_and_connect(self.wpa_hidden_5g)
129
130    @test_tracker_info(uuid="cdfce76f-6374-439d-aa1d-e920508269d2")
131    def test_connect_to_open_hidden_2g(self):
132        """Connect to a Open, 2G hidden  network.
133
134        Steps:
135        1. Add a Open, 2G hidden network.
136        2. Ensure the network is visible in scan.
137        3. Connect and run ping.
138
139        """
140        self.add_hiddenSSID_and_connect(self.open_hidden_2g)
141
142    @test_tracker_info(uuid="29ccbae4-4382-4df8-8fc5-00e3104230d0")
143    def test_connect_to_open_hidden_5g(self):
144        """Connect to a Open, 5G hidden  network.
145
146        Steps:
147        1. Add a Open, 5G hidden network.
148        2. Ensure the network is visible in scan.
149        3. Connect and run ping.
150
151        """
152        self.add_hiddenSSID_and_connect(self.open_hidden_5g)
153
154    @test_tracker_info(uuid="62b664df-6397-4360-97bf-a8095c23a878")
155    def test_connect_to_wpa3_owe_hidden_2g(self):
156        """Connect to WPA3 OWE 2G hidden wifi network."""
157        self.add_hiddenSSID_and_connect(self.owe_networks[0]["2g"])
158
159    @test_tracker_info(uuid="dd7b029d-c008-4288-a91c-0820b0b3f29d")
160    def test_connect_to_wpa3_owe_hidden_5g(self):
161        """Connect to WPA3 OWE 5G hidden wifi network."""
162        self.add_hiddenSSID_and_connect(self.owe_networks[0]["5g"])
163
164    @test_tracker_info(uuid="1a9f3ee8-3db0-4f07-a604-66c14a897f94")
165    def test_connect_to_wpa3_sae_hidden_2g(self):
166        """Connect to WPA3 SAE 2G hidden wifi network."""
167        self.add_hiddenSSID_and_connect(self.sae_networks[0]["2g"])
168
169    @test_tracker_info(uuid="6c75618b-9c9b-4eb6-a922-ef1719704a9c")
170    def test_connect_to_wpa3_sae_hidden_5g(self):
171        """Connect to WPA3 SAE 5G hidden wifi network."""
172        self.add_hiddenSSID_and_connect(self.sae_networks[0]["5g"])
173