Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 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 | |
| 17 | import itertools |
| 18 | import pprint |
| 19 | import queue |
| 20 | import time |
| 21 | |
| 22 | import acts.base_test |
| 23 | import acts.signals as signals |
| 24 | import acts.test_utils.wifi.wifi_test_utils as wutils |
| 25 | import acts.utils |
| 26 | |
| 27 | from acts import asserts |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 28 | from acts.controllers.android_device import SL4A_APK_NAME |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 29 | from acts.test_decorators import test_tracker_info |
| 30 | from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest |
| 31 | from acts.test_utils.wifi import wifi_constants |
| 32 | |
| 33 | WifiEnums = wutils.WifiEnums |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 34 | # EAP Macros |
| 35 | EAP = WifiEnums.Eap |
| 36 | EapPhase2 = WifiEnums.EapPhase2 |
| 37 | # Enterprise Config Macros |
| 38 | Ent = WifiEnums.Enterprise |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 39 | ATT = 2 |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 40 | |
| 41 | # Default timeout used for reboot, toggle WiFi and Airplane mode, |
| 42 | # for the system to settle down after the operation. |
| 43 | DEFAULT_TIMEOUT = 10 |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 44 | PASSPOINT_TIMEOUT = 30 |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 45 | |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 46 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 47 | class WifiNetworkSuggestionTest(WifiBaseTest): |
| 48 | """Tests for WifiNetworkSuggestion API surface. |
| 49 | |
| 50 | Test Bed Requirement: |
| 51 | * one Android device |
| 52 | * Several Wi-Fi networks visible to the device, including an open Wi-Fi |
| 53 | network. |
| 54 | """ |
| 55 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 56 | def setup_class(self): |
Xianyuan Jia | 168103b | 2019-09-06 12:22:52 -0700 | [diff] [blame] | 57 | super().setup_class() |
| 58 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 59 | self.dut = self.android_devices[0] |
| 60 | wutils.wifi_test_device_init(self.dut) |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 61 | req_params = [] |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 62 | opt_param = [ |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 63 | "open_network", "reference_networks", "radius_conf_2g", "radius_conf_5g", "ca_cert", |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 64 | "eap_identity", "eap_password", "hidden_networks", "passpoint_networks" |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 65 | ] |
| 66 | self.unpack_userparams( |
| 67 | req_param_names=req_params, opt_param_names=opt_param) |
| 68 | |
| 69 | if "AccessPoint" in self.user_params: |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 70 | self.legacy_configure_ap_and_start( |
| 71 | wpa_network=True, ent_network=True, |
| 72 | radius_conf_2g=self.radius_conf_2g, |
| 73 | radius_conf_5g=self.radius_conf_5g,) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 74 | |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 75 | if hasattr(self, "reference_networks") and \ |
| 76 | isinstance(self.reference_networks, list): |
| 77 | self.wpa_psk_2g = self.reference_networks[0]["2g"] |
| 78 | self.wpa_psk_5g = self.reference_networks[0]["5g"] |
| 79 | if hasattr(self, "open_network") and isinstance(self.open_network,list): |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 80 | self.open_2g = self.open_network[0]["2g"] |
| 81 | self.open_5g = self.open_network[0]["5g"] |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 82 | if hasattr(self, "ent_networks") and isinstance(self.ent_networks,list): |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 83 | self.ent_network_2g = self.ent_networks[0]["2g"] |
| 84 | self.ent_network_5g = self.ent_networks[0]["5g"] |
| 85 | self.config_aka = { |
| 86 | Ent.EAP: int(EAP.AKA), |
| 87 | WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY], |
| 88 | } |
| 89 | self.config_ttls = { |
| 90 | Ent.EAP: int(EAP.TTLS), |
| 91 | Ent.CA_CERT: self.ca_cert, |
| 92 | Ent.IDENTITY: self.eap_identity, |
| 93 | Ent.PASSWORD: self.eap_password, |
| 94 | Ent.PHASE2: int(EapPhase2.MSCHAPV2), |
| 95 | WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY], |
| 96 | } |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 97 | if hasattr(self, "hidden_networks") and \ |
| 98 | isinstance(self.hidden_networks, list): |
| 99 | self.hidden_network = self.hidden_networks[0] |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 100 | self.dut.droid.wifiRemoveNetworkSuggestions([]) |
| 101 | |
| 102 | def setup_test(self): |
| 103 | self.dut.droid.wakeLockAcquireBright() |
| 104 | self.dut.droid.wakeUpNow() |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 105 | self.clear_deleted_ephemeral_networks() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 106 | wutils.wifi_toggle_state(self.dut, True) |
Roshan Pius | 159222c | 2019-02-07 10:33:32 -0800 | [diff] [blame] | 107 | self.dut.ed.clear_all_events() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 108 | |
| 109 | def teardown_test(self): |
| 110 | self.dut.droid.wakeLockRelease() |
| 111 | self.dut.droid.goToSleepNow() |
| 112 | self.dut.droid.wifiRemoveNetworkSuggestions([]) |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 113 | self.dut.droid.wifiDisconnect() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 114 | wutils.reset_wifi(self.dut) |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 115 | wutils.wifi_toggle_state(self.dut, False) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 116 | self.dut.ed.clear_all_events() |
| 117 | |
| 118 | def on_fail(self, test_name, begin_time): |
| 119 | self.dut.take_bug_report(test_name, begin_time) |
| 120 | self.dut.cat_adb_log(test_name, begin_time) |
| 121 | |
| 122 | def teardown_class(self): |
| 123 | if "AccessPoint" in self.user_params: |
| 124 | del self.user_params["reference_networks"] |
| 125 | del self.user_params["open_network"] |
| 126 | |
| 127 | """Helper Functions""" |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 128 | def set_approved(self, approved): |
| 129 | self.dut.log.debug("Setting suggestions from sl4a app " |
| 130 | + "approved" if approved else "not approved") |
| 131 | self.dut.adb.shell("cmd wifi network-suggestions-set-user-approved" |
| 132 | + " " + SL4A_APK_NAME |
| 133 | + " " + ("yes" if approved else "no")) |
| 134 | |
| 135 | def is_approved(self): |
| 136 | is_approved_str = self.dut.adb.shell( |
| 137 | "cmd wifi network-suggestions-has-user-approved" |
| 138 | + " " + SL4A_APK_NAME) |
| 139 | return True if (is_approved_str == "yes") else False |
| 140 | |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 141 | def clear_deleted_ephemeral_networks(self): |
| 142 | self.dut.log.debug("Clearing deleted ephemeral networks") |
| 143 | self.dut.adb.shell( |
| 144 | "cmd wifi clear-deleted-ephemeral-networks") |
| 145 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 146 | def add_suggestions_and_ensure_connection(self, network_suggestions, |
| 147 | expected_ssid, |
| 148 | expect_post_connection_broadcast): |
Roshan Pius | 3702f24 | 2019-02-28 09:14:40 -0800 | [diff] [blame] | 149 | if expect_post_connection_broadcast is not None: |
| 150 | self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange() |
| 151 | |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 152 | self.dut.log.info("Adding network suggestions") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 153 | asserts.assert_true( |
| 154 | self.dut.droid.wifiAddNetworkSuggestions(network_suggestions), |
| 155 | "Failed to add suggestions") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 156 | # Enable suggestions by the app. |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 157 | self.dut.log.debug("Enabling suggestions from test") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 158 | self.set_approved(True) |
lutina | 49d3e51 | 2019-07-05 14:42:33 +0800 | [diff] [blame] | 159 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 160 | # if suggestion is passpoint wait longer for connection. |
| 161 | if "profile" in network_suggestions: |
| 162 | time.sleep(PASSPOINT_TIMEOUT) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 163 | wutils.wait_for_connect(self.dut, expected_ssid) |
| 164 | |
| 165 | if expect_post_connection_broadcast is None: |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 166 | return |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 167 | |
| 168 | # Check if we expected to get the broadcast. |
| 169 | try: |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 170 | event = self.dut.ed.pop_event( |
| 171 | wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 172 | except queue.Empty: |
| 173 | if expect_post_connection_broadcast: |
| 174 | raise signals.TestFailure( |
| 175 | "Did not receive post connection broadcast") |
| 176 | else: |
| 177 | if not expect_post_connection_broadcast: |
| 178 | raise signals.TestFailure( |
| 179 | "Received post connection broadcast") |
Roshan Pius | 3702f24 | 2019-02-28 09:14:40 -0800 | [diff] [blame] | 180 | finally: |
| 181 | self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange() |
Roshan Pius | ff6ca4c | 2019-03-26 13:53:31 -0700 | [diff] [blame] | 182 | self.dut.ed.clear_all_events() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 183 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 184 | def remove_suggestions_disconnect_and_ensure_no_connection_back(self, |
| 185 | network_suggestions, |
| 186 | expected_ssid): |
| 187 | # Remove suggestion trigger disconnect and wait for the disconnect. |
| 188 | self.dut.log.info("Removing network suggestions") |
| 189 | asserts.assert_true( |
| 190 | self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions), |
| 191 | "Failed to remove suggestions") |
| 192 | wutils.wait_for_disconnect(self.dut) |
| 193 | self.dut.ed.clear_all_events() |
| 194 | |
| 195 | # Now ensure that we didn't connect back. |
| 196 | asserts.assert_false( |
| 197 | wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False), |
| 198 | "Device should not connect back") |
| 199 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 200 | def _test_connect_to_wifi_network_reboot_config_store(self, |
| 201 | network_suggestions, |
| 202 | wifi_network): |
| 203 | """ Test network suggestion with reboot config store |
| 204 | |
| 205 | Args: |
| 206 | 1. network_suggestions: network suggestions in list to add to the device. |
| 207 | 2. wifi_network: expected wifi network to connect to |
| 208 | """ |
| 209 | |
| 210 | self.add_suggestions_and_ensure_connection( |
| 211 | network_suggestions, wifi_network[WifiEnums.SSID_KEY], None) |
| 212 | |
| 213 | # Reboot and wait for connection back to the same suggestion. |
| 214 | self.dut.reboot() |
| 215 | time.sleep(DEFAULT_TIMEOUT) |
| 216 | |
| 217 | wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY]) |
| 218 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 219 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 220 | network_suggestions, wifi_network[WifiEnums.SSID_KEY]) |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 221 | |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 222 | # Reboot with empty suggestion, verify user approval is kept. |
| 223 | self.dut.reboot() |
| 224 | time.sleep(DEFAULT_TIMEOUT) |
| 225 | asserts.assert_true(self.is_approved(), "User approval should be kept") |
| 226 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 227 | @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 228 | def test_connect_to_wpa_psk_2g(self): |
| 229 | """ Adds a network suggestion and ensure that the device connected. |
| 230 | |
| 231 | Steps: |
| 232 | 1. Send a network suggestion to the device. |
| 233 | 2. Wait for the device to connect to it. |
| 234 | 3. Ensure that we did not receive the post connection broadcast |
| 235 | (isAppInteractionRequired = False). |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 236 | 4. Remove the suggestions and ensure the device does not connect back. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 237 | """ |
| 238 | self.add_suggestions_and_ensure_connection( |
| 239 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 240 | False) |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 241 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 242 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 243 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 244 | |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 245 | @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43") |
| 246 | def test_connect_to_highest_priority(self): |
| 247 | """ |
| 248 | Adds network suggestions and ensures that device connects to |
| 249 | the suggestion with the highest priority. |
| 250 | |
| 251 | Steps: |
| 252 | 1. Send 2 network suggestions to the device (with different priorities). |
| 253 | 2. Wait for the device to connect to the network with the highest |
| 254 | priority. |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 255 | 3. In-place modify network suggestions with priorities reversed |
| 256 | 4. Restart wifi, wait for the device to connect to the network with the highest |
| 257 | priority. |
| 258 | 5. Re-add the suggestions with the priorities reversed again. |
| 259 | 6. Again wait for the device to connect to the network with the highest |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 260 | priority. |
| 261 | """ |
| 262 | network_suggestion_2g = self.wpa_psk_2g |
| 263 | network_suggestion_5g = self.wpa_psk_5g |
| 264 | |
| 265 | # Add suggestions & wait for the connection event. |
| 266 | network_suggestion_2g[WifiEnums.PRIORITY] = 5 |
| 267 | network_suggestion_5g[WifiEnums.PRIORITY] = 2 |
| 268 | self.add_suggestions_and_ensure_connection( |
| 269 | [network_suggestion_2g, network_suggestion_5g], |
| 270 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 271 | None) |
| 272 | |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 273 | # In-place modify Reverse the priority, should be no disconnect |
| 274 | network_suggestion_2g[WifiEnums.PRIORITY] = 2 |
| 275 | network_suggestion_5g[WifiEnums.PRIORITY] = 5 |
| 276 | self.dut.log.info("Modifying network suggestions"); |
| 277 | asserts.assert_true( |
| 278 | self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g, |
| 279 | network_suggestion_5g]), |
| 280 | "Failed to add suggestions") |
| 281 | wutils.ensure_no_disconnect(self.dut) |
| 282 | |
| 283 | # Disable and re-enable wifi, should connect to higher priority |
| 284 | wutils.wifi_toggle_state(self.dut, False) |
| 285 | time.sleep(DEFAULT_TIMEOUT) |
| 286 | wutils.wifi_toggle_state(self.dut, True) |
| 287 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
| 288 | wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 289 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 290 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
Nate Jiang | 0878aef | 2019-09-16 13:33:26 -0700 | [diff] [blame] | 291 | [], self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 292 | |
| 293 | # Reverse the priority. |
| 294 | # Add suggestions & wait for the connection event. |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 295 | network_suggestion_2g[WifiEnums.PRIORITY] = 5 |
| 296 | network_suggestion_5g[WifiEnums.PRIORITY] = 2 |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 297 | self.add_suggestions_and_ensure_connection( |
| 298 | [network_suggestion_2g, network_suggestion_5g], |
Nate Jiang | 0878aef | 2019-09-16 13:33:26 -0700 | [diff] [blame] | 299 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 300 | None) |
| 301 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 302 | @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 303 | def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self): |
| 304 | """ Adds a network suggestion and ensure that the device connected. |
| 305 | |
| 306 | Steps: |
| 307 | 1. Send a network suggestion to the device with |
| 308 | isAppInteractionRequired set. |
| 309 | 2. Wait for the device to connect to it. |
| 310 | 3. Ensure that we did receive the post connection broadcast |
| 311 | (isAppInteractionRequired = True). |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 312 | 4. Remove the suggestions and ensure the device does not connect back. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 313 | """ |
| 314 | network_suggestion = self.wpa_psk_2g |
| 315 | network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
| 316 | self.add_suggestions_and_ensure_connection( |
| 317 | [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 318 | True) |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 319 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 320 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 321 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 322 | @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 323 | def test_connect_to_wpa_psk_5g_reboot_config_store(self): |
| 324 | """ |
| 325 | Adds a network suggestion and ensure that the device connects to it |
| 326 | after reboot. |
| 327 | |
| 328 | Steps: |
| 329 | 1. Send a network suggestion to the device. |
| 330 | 2. Wait for the device to connect to it. |
| 331 | 3. Ensure that we did not receive the post connection broadcast |
| 332 | (isAppInteractionRequired = False). |
| 333 | 4. Reboot the device. |
| 334 | 5. Wait for the device to connect to back to it. |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 335 | 6. Remove the suggestions and ensure the device does not connect back. |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 336 | 7. Reboot the device again, ensure user approval is kept |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 337 | """ |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 338 | self._test_connect_to_wifi_network_reboot_config_store( |
| 339 | [self.wpa_psk_5g], self.wpa_psk_5g) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 340 | |
Girish Moturu | c2033ae | 2019-07-31 09:04:36 -0700 | [diff] [blame] | 341 | @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31") |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 342 | def test_connect_to_wpa_ent_config_aka_reboot_config_store(self): |
| 343 | """ |
| 344 | Adds a network suggestion and ensure that the device connects to it |
| 345 | after reboot. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 346 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 347 | Steps: |
| 348 | 1. Send a Enterprise AKA network suggestion to the device. |
| 349 | 2. Wait for the device to connect to it. |
| 350 | 3. Ensure that we did not receive the post connection broadcast. |
| 351 | 4. Reboot the device. |
| 352 | 5. Wait for the device to connect to the wifi network. |
| 353 | 6. Remove suggestions and ensure device doesn't connect back to it. |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 354 | 7. Reboot the device again, ensure user approval is kept |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 355 | """ |
| 356 | self._test_connect_to_wifi_network_reboot_config_store( |
| 357 | [self.config_aka], self.ent_network_2g) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 358 | |
Girish Moturu | c2033ae | 2019-07-31 09:04:36 -0700 | [diff] [blame] | 359 | @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d") |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 360 | def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self): |
| 361 | """ |
| 362 | Adds a network suggestion and ensure that the device connects to it |
| 363 | after reboot. |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 364 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 365 | Steps: |
| 366 | 1. Send a Enterprise TTLS PAP network suggestion to the device. |
| 367 | 2. Wait for the device to connect to it. |
| 368 | 3. Ensure that we did not receive the post connection broadcast. |
| 369 | 4. Reboot the device. |
| 370 | 5. Wait for the device to connect to the wifi network. |
| 371 | 6. Remove suggestions and ensure device doesn't connect back to it. |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 372 | 7. Reboot the device again, ensure user approval is kept |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 373 | """ |
| 374 | config = dict(self.config_ttls) |
| 375 | config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value |
| 376 | |
| 377 | self._test_connect_to_wifi_network_reboot_config_store( |
| 378 | [config], self.ent_network_2g) |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 379 | |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 380 | @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb") |
| 381 | def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self): |
| 382 | """ |
| 383 | Adds a network suggestion and ensure that the device does not |
| 384 | connect to it until we approve the app. |
| 385 | |
| 386 | Steps: |
| 387 | 1. Send a network suggestion to the device with the app not approved. |
| 388 | 2. Ensure the network is present in scan results, but we don't connect |
| 389 | to it. |
| 390 | 3. Now approve the app. |
| 391 | 4. Wait for the device to connect to it. |
| 392 | """ |
| 393 | self.dut.log.info("Adding network suggestions"); |
| 394 | asserts.assert_true( |
| 395 | self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]), |
| 396 | "Failed to add suggestions") |
| 397 | |
| 398 | # Disable suggestions by the app. |
| 399 | self.set_approved(False) |
| 400 | |
| 401 | # Ensure the app is not approved. |
| 402 | asserts.assert_false( |
| 403 | self.is_approved(), |
| 404 | "Suggestions should be disabled") |
| 405 | |
| 406 | # Start a new scan to trigger auto-join. |
| 407 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 408 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 409 | |
| 410 | # Ensure we don't connect to the network. |
| 411 | asserts.assert_false( |
| 412 | wutils.wait_for_connect( |
| 413 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 414 | "Should not connect to network suggestions from unapproved app") |
| 415 | |
| 416 | self.dut.log.info("Enabling suggestions from test"); |
| 417 | # Now Enable suggestions by the app & ensure we connect to the network. |
| 418 | self.set_approved(True) |
| 419 | |
| 420 | # Ensure the app is approved. |
| 421 | asserts.assert_true( |
| 422 | self.is_approved(), |
| 423 | "Suggestions should be enabled") |
| 424 | |
| 425 | # Start a new scan to trigger auto-join. |
| 426 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 427 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 428 | |
| 429 | wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 430 | |
Roshan Pius | 3d57f13 | 2019-01-28 10:25:18 -0800 | [diff] [blame] | 431 | @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c") |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 432 | def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self): |
| 433 | """ |
| 434 | Adds a network suggestion and ensures that the device does not |
| 435 | connect to it after the user forgot the network previously. |
| 436 | |
| 437 | Steps: |
| 438 | 1. Send a network suggestion to the device with |
| 439 | isAppInteractionRequired set. |
| 440 | 2. Wait for the device to connect to it. |
| 441 | 3. Ensure that we did receive the post connection broadcast |
| 442 | (isAppInteractionRequired = True). |
| 443 | 4. Simulate user forgetting the network and the device does not |
| 444 | connecting back even though the suggestion is active from the app. |
| 445 | """ |
| 446 | network_suggestion = self.wpa_psk_2g |
| 447 | network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
| 448 | self.add_suggestions_and_ensure_connection( |
| 449 | [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 450 | True) |
| 451 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 452 | # Simulate user forgetting the ephemeral network. |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 453 | self.dut.droid.wifiDisableEphemeralNetwork( |
| 454 | self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
| 455 | wutils.wait_for_disconnect(self.dut) |
| 456 | self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g) |
| 457 | self.dut.ed.clear_all_events() |
| 458 | |
| 459 | # Now ensure that we don't connect back even though the suggestion |
| 460 | # is still active. |
| 461 | asserts.assert_false( |
| 462 | wutils.wait_for_connect(self.dut, |
| 463 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 464 | assert_on_fail=False), |
| 465 | "Device should not connect back") |
Nate Jiang | 20af5e8 | 2019-08-08 12:45:24 -0700 | [diff] [blame] | 466 | |
| 467 | @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1") |
| 468 | def test_connect_to_hidden_network(self): |
| 469 | """ |
| 470 | Adds a network suggestion with hidden SSID config, ensure device can scan |
| 471 | and connect to this network. |
| 472 | |
| 473 | Steps: |
| 474 | 1. Send a hidden network suggestion to the device. |
| 475 | 2. Wait for the device to connect to it. |
| 476 | 3. Ensure that we did not receive the post connection broadcast |
| 477 | (isAppInteractionRequired = False). |
| 478 | 4. Remove the suggestions and ensure the device does not connect back. |
| 479 | """ |
| 480 | asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test") |
| 481 | |
| 482 | network_suggestion = self.hidden_network |
| 483 | self.add_suggestions_and_ensure_connection( |
| 484 | [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False) |
| 485 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 486 | [network_suggestion], network_suggestion[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 487 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 488 | @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 489 | def test_connect_to_passpoint_network_with_post_connection_broadcast(self): |
| 490 | """ Adds a passpoint network suggestion and ensure that the device connected. |
| 491 | |
| 492 | Steps: |
| 493 | 1. Send a network suggestion to the device. |
| 494 | 2. Wait for the device to connect to it. |
| 495 | 3. Ensure that we did receive the post connection broadcast |
| 496 | (isAppInteractionRequired = true). |
| 497 | 4. Remove the suggestions and ensure the device does not connect back. |
| 498 | """ |
| 499 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 500 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 501 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 502 | passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
| 503 | self.add_suggestions_and_ensure_connection([passpoint_config], |
| 504 | passpoint_config[WifiEnums.SSID_KEY], True) |
| 505 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 506 | [passpoint_config], passpoint_config[WifiEnums.SSID_KEY]) |
| 507 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 508 | @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 509 | def test_connect_to_passpoint_network_reboot_config_store(self): |
| 510 | """ |
| 511 | Adds a passpoint network suggestion and ensure that the device connects to it |
| 512 | after reboot. |
| 513 | |
| 514 | Steps: |
| 515 | 1. Send a network suggestion to the device. |
| 516 | 2. Wait for the device to connect to it. |
| 517 | 3. Ensure that we did not receive the post connection broadcast |
| 518 | (isAppInteractionRequired = False). |
| 519 | 4. Reboot the device. |
| 520 | 5. Wait for the device to connect to back to it. |
| 521 | 6. Remove the suggestions and ensure the device does not connect back. |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 522 | 7. Reboot the device again, ensure user approval is kept |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 523 | """ |
| 524 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 525 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 526 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 527 | self._test_connect_to_wifi_network_reboot_config_store([passpoint_config], |
| 528 | passpoint_config) |
| 529 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 530 | @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 531 | def test_fail_to_connect_to_passpoint_network_when_not_approved(self): |
| 532 | """ |
| 533 | Adds a passpoint network suggestion and ensure that the device does not |
| 534 | connect to it until we approve the app. |
| 535 | |
| 536 | Steps: |
| 537 | 1. Send a network suggestion to the device with the app not approved. |
| 538 | 2. Ensure the network is present in scan results, but we don't connect |
| 539 | to it. |
| 540 | 3. Now approve the app. |
| 541 | 4. Wait for the device to connect to it. |
| 542 | """ |
| 543 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 544 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 545 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 546 | self.dut.log.info("Adding network suggestions") |
| 547 | asserts.assert_true( |
| 548 | self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]), |
| 549 | "Failed to add suggestions") |
| 550 | |
| 551 | # Disable suggestions by the app. |
| 552 | self.set_approved(False) |
| 553 | |
| 554 | # Ensure the app is not approved. |
| 555 | asserts.assert_false( |
| 556 | self.is_approved(), |
| 557 | "Suggestions should be disabled") |
| 558 | |
| 559 | # Start a new scan to trigger auto-join. |
| 560 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 561 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
| 562 | |
| 563 | # Ensure we don't connect to the network. |
| 564 | asserts.assert_false( |
| 565 | wutils.wait_for_connect( |
| 566 | self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 567 | "Should not connect to network suggestions from unapproved app") |
| 568 | |
| 569 | self.dut.log.info("Enabling suggestions from test"); |
| 570 | # Now Enable suggestions by the app & ensure we connect to the network. |
| 571 | self.set_approved(True) |
| 572 | |
| 573 | # Ensure the app is approved. |
| 574 | asserts.assert_true( |
| 575 | self.is_approved(), |
| 576 | "Suggestions should be enabled") |
| 577 | |
| 578 | # Start a new scan to trigger auto-join. |
| 579 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 580 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 581 | time.sleep(PASSPOINT_TIMEOUT) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 582 | wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 583 | |
| 584 | @test_tracker_info(uuid="") |
| 585 | def test_initial_auto_join_on_network_suggestion(self): |
| 586 | """ |
| 587 | Add a network suggestion with enableAutojoin bit set to false, ensure the device doesn't |
| 588 | auto connect to this network |
| 589 | |
| 590 | Steps: |
| 591 | 1. Create a network suggestion. |
| 592 | 2. Set EnableAutojoin to false. |
| 593 | 3. Add this suggestion |
| 594 | 4. Ensure device doesn't connect to his network |
| 595 | """ |
Girish Moturu | 2155dc1 | 2020-01-21 15:16:17 -0800 | [diff] [blame^] | 596 | network_suggestion = self.wpa_psk_5g |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 597 | # Set suggestion auto join initial to false. |
| 598 | network_suggestion["enableAutojoin"] = False |
| 599 | self.dut.log.info("Adding network suggestions") |
| 600 | asserts.assert_true( |
| 601 | self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]), |
| 602 | "Failed to add suggestions") |
| 603 | # Enable suggestions by the app. |
| 604 | self.dut.log.debug("Enabling suggestions from test") |
| 605 | self.set_approved(True) |
| 606 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
| 607 | asserts.assert_false( |
| 608 | wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY], |
| 609 | assert_on_fail=False), "Device should not connect.") |
| 610 | |
| 611 | @test_tracker_info(uuid="") |
| 612 | def test_user_override_auto_join_on_network_suggestion(self): |
| 613 | """ |
| 614 | Add a network suggestion, user change the auto join to false, ensure the device doesn't |
| 615 | auto connect to this network |
| 616 | |
| 617 | Steps: |
| 618 | 1. Create a network suggestion. |
| 619 | 2. Add this suggestion, and ensure we connect to this network |
| 620 | 3. Simulate user change the auto join to false. |
| 621 | 4. Toggle the Wifi off and on |
| 622 | 4. Ensure device doesn't connect to his network |
| 623 | """ |
Girish Moturu | 2155dc1 | 2020-01-21 15:16:17 -0800 | [diff] [blame^] | 624 | network_suggestion = self.wpa_psk_5g |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 625 | self.add_suggestions_and_ensure_connection([network_suggestion], |
| 626 | network_suggestion[WifiEnums.SSID_KEY], False) |
| 627 | wifi_info = self.dut.droid.wifiGetConnectionInfo() |
| 628 | self.dut.log.info(wifi_info) |
| 629 | network_id = wifi_info[WifiEnums.NETID_KEY] |
| 630 | # Simulate user disable auto join through Settings. |
| 631 | self.dut.log.info("Disable auto join on suggestion") |
| 632 | self.dut.droid.wifiEnableAutojoin(network_id, False) |
| 633 | wutils.wifi_toggle_state(self.dut, False) |
| 634 | wutils.wifi_toggle_state(self.dut, True) |
| 635 | asserts.assert_false( |
| 636 | wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY], |
| 637 | assert_on_fail=False), "Device should not connect.") |