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 |
Nate Jiang | 8b2b4b8 | 2020-03-13 13:49:07 -0700 | [diff] [blame] | 40 | # Suggestion network Macros |
| 41 | Untrusted = "untrusted" |
| 42 | AutoJoin = "enableAutojoin" |
| 43 | # Network request Macros |
| 44 | ClearCapabilities = "ClearCapabilities" |
| 45 | TransportType = "TransportType" |
| 46 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 47 | |
| 48 | # Default timeout used for reboot, toggle WiFi and Airplane mode, |
| 49 | # for the system to settle down after the operation. |
| 50 | DEFAULT_TIMEOUT = 10 |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 51 | PASSPOINT_TIMEOUT = 30 |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 52 | |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 53 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 54 | class WifiNetworkSuggestionTest(WifiBaseTest): |
| 55 | """Tests for WifiNetworkSuggestion API surface. |
| 56 | |
| 57 | Test Bed Requirement: |
| 58 | * one Android device |
| 59 | * Several Wi-Fi networks visible to the device, including an open Wi-Fi |
| 60 | network. |
| 61 | """ |
| 62 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 63 | def setup_class(self): |
Xianyuan Jia | 168103b | 2019-09-06 12:22:52 -0700 | [diff] [blame] | 64 | super().setup_class() |
| 65 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 66 | self.dut = self.android_devices[0] |
| 67 | wutils.wifi_test_device_init(self.dut) |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 68 | req_params = [] |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 69 | opt_param = [ |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 70 | "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] | 71 | "eap_identity", "eap_password", "hidden_networks", "passpoint_networks" |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 72 | ] |
| 73 | self.unpack_userparams( |
| 74 | req_param_names=req_params, opt_param_names=opt_param) |
| 75 | |
| 76 | if "AccessPoint" in self.user_params: |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 77 | self.legacy_configure_ap_and_start( |
| 78 | wpa_network=True, ent_network=True, |
| 79 | radius_conf_2g=self.radius_conf_2g, |
| 80 | radius_conf_5g=self.radius_conf_5g,) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 81 | |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 82 | if hasattr(self, "reference_networks") and \ |
| 83 | isinstance(self.reference_networks, list): |
| 84 | self.wpa_psk_2g = self.reference_networks[0]["2g"] |
| 85 | self.wpa_psk_5g = self.reference_networks[0]["5g"] |
| 86 | if hasattr(self, "open_network") and isinstance(self.open_network,list): |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 87 | self.open_2g = self.open_network[0]["2g"] |
| 88 | self.open_5g = self.open_network[0]["5g"] |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 89 | if hasattr(self, "ent_networks") and isinstance(self.ent_networks,list): |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 90 | self.ent_network_2g = self.ent_networks[0]["2g"] |
| 91 | self.ent_network_5g = self.ent_networks[0]["5g"] |
| 92 | self.config_aka = { |
| 93 | Ent.EAP: int(EAP.AKA), |
| 94 | WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY], |
Girish Moturu | 7e30c78 | 2020-02-05 12:37:06 -0800 | [diff] [blame] | 95 | "carrierId": str(self.dut.droid.telephonyGetSimCarrierId()), |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 96 | } |
| 97 | self.config_ttls = { |
| 98 | Ent.EAP: int(EAP.TTLS), |
| 99 | Ent.CA_CERT: self.ca_cert, |
| 100 | Ent.IDENTITY: self.eap_identity, |
| 101 | Ent.PASSWORD: self.eap_password, |
| 102 | Ent.PHASE2: int(EapPhase2.MSCHAPV2), |
| 103 | WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY], |
| 104 | } |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 105 | if hasattr(self, "hidden_networks") and \ |
| 106 | isinstance(self.hidden_networks, list): |
| 107 | self.hidden_network = self.hidden_networks[0] |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 108 | self.dut.droid.wifiRemoveNetworkSuggestions([]) |
| 109 | |
| 110 | def setup_test(self): |
| 111 | self.dut.droid.wakeLockAcquireBright() |
| 112 | self.dut.droid.wakeUpNow() |
Nate(Qiang) Jiang | d342464 | 2020-03-02 19:52:59 -0800 | [diff] [blame] | 113 | self.clear_user_disabled_networks() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 114 | wutils.wifi_toggle_state(self.dut, True) |
Roshan Pius | 159222c | 2019-02-07 10:33:32 -0800 | [diff] [blame] | 115 | self.dut.ed.clear_all_events() |
Nate(Qiang) Jiang | 92251a6 | 2020-02-28 10:13:30 -0800 | [diff] [blame] | 116 | self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId())) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 117 | |
| 118 | def teardown_test(self): |
| 119 | self.dut.droid.wakeLockRelease() |
| 120 | self.dut.droid.goToSleepNow() |
| 121 | self.dut.droid.wifiRemoveNetworkSuggestions([]) |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 122 | self.dut.droid.wifiDisconnect() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 123 | wutils.reset_wifi(self.dut) |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 124 | wutils.wifi_toggle_state(self.dut, False) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 125 | self.dut.ed.clear_all_events() |
Nate(Qiang) Jiang | 92251a6 | 2020-02-28 10:13:30 -0800 | [diff] [blame] | 126 | self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId())) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 127 | |
| 128 | def on_fail(self, test_name, begin_time): |
| 129 | self.dut.take_bug_report(test_name, begin_time) |
| 130 | self.dut.cat_adb_log(test_name, begin_time) |
| 131 | |
| 132 | def teardown_class(self): |
| 133 | if "AccessPoint" in self.user_params: |
| 134 | del self.user_params["reference_networks"] |
| 135 | del self.user_params["open_network"] |
| 136 | |
| 137 | """Helper Functions""" |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 138 | def set_approved(self, approved): |
| 139 | self.dut.log.debug("Setting suggestions from sl4a app " |
| 140 | + "approved" if approved else "not approved") |
| 141 | self.dut.adb.shell("cmd wifi network-suggestions-set-user-approved" |
| 142 | + " " + SL4A_APK_NAME |
| 143 | + " " + ("yes" if approved else "no")) |
| 144 | |
| 145 | def is_approved(self): |
| 146 | is_approved_str = self.dut.adb.shell( |
| 147 | "cmd wifi network-suggestions-has-user-approved" |
| 148 | + " " + SL4A_APK_NAME) |
| 149 | return True if (is_approved_str == "yes") else False |
| 150 | |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 151 | def set_carrier_approved(self, carrier_id, approved): |
| 152 | self.dut.log.debug(("Setting IMSI protection exemption for carrier: " + carrier_id |
| 153 | + "approved" if approved else "not approved")) |
| 154 | self.dut.adb.shell("cmd wifi imsi-protection-exemption-set-user-approved-for-carrier" |
| 155 | + " " + carrier_id |
| 156 | + " " + ("yes" if approved else "no")) |
| 157 | |
| 158 | def is_carrier_approved(self, carrier_id): |
| 159 | is_approved_str = self.dut.adb.shell( |
| 160 | "cmd wifi imsi-protection-exemption-has-user-approved-for-carrier" |
| 161 | + " " + carrier_id) |
| 162 | return True if (is_approved_str == "yes") else False |
| 163 | |
| 164 | def clear_carrier_approved(self, carrier_id): |
| 165 | self.dut.adb.shell( |
| 166 | "cmd wifi imsi-protection-exemption-clear-user-approved-for-carrier" |
| 167 | + " " + carrier_id) |
| 168 | |
Nate(Qiang) Jiang | d342464 | 2020-03-02 19:52:59 -0800 | [diff] [blame] | 169 | def clear_user_disabled_networks(self): |
| 170 | self.dut.log.debug("Clearing user disabled networks") |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 171 | self.dut.adb.shell( |
Nate(Qiang) Jiang | d342464 | 2020-03-02 19:52:59 -0800 | [diff] [blame] | 172 | "cmd wifi clear-user-disabled-networks") |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 173 | |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 174 | def add_suggestions_and_ensure_connection(self, network_suggestions, |
| 175 | expected_ssid, |
| 176 | expect_post_connection_broadcast): |
Roshan Pius | 3702f24 | 2019-02-28 09:14:40 -0800 | [diff] [blame] | 177 | if expect_post_connection_broadcast is not None: |
| 178 | self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange() |
| 179 | |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 180 | self.dut.log.info("Adding network suggestions") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 181 | asserts.assert_true( |
| 182 | self.dut.droid.wifiAddNetworkSuggestions(network_suggestions), |
| 183 | "Failed to add suggestions") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 184 | # Enable suggestions by the app. |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 185 | self.dut.log.debug("Enabling suggestions from test") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 186 | self.set_approved(True) |
lutina | 49d3e51 | 2019-07-05 14:42:33 +0800 | [diff] [blame] | 187 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 188 | # if suggestion is passpoint wait longer for connection. |
| 189 | if "profile" in network_suggestions: |
| 190 | time.sleep(PASSPOINT_TIMEOUT) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 191 | wutils.wait_for_connect(self.dut, expected_ssid) |
| 192 | |
| 193 | if expect_post_connection_broadcast is None: |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 194 | return |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 195 | |
| 196 | # Check if we expected to get the broadcast. |
| 197 | try: |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 198 | event = self.dut.ed.pop_event( |
| 199 | wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 200 | except queue.Empty: |
| 201 | if expect_post_connection_broadcast: |
| 202 | raise signals.TestFailure( |
| 203 | "Did not receive post connection broadcast") |
| 204 | else: |
| 205 | if not expect_post_connection_broadcast: |
| 206 | raise signals.TestFailure( |
| 207 | "Received post connection broadcast") |
Roshan Pius | 3702f24 | 2019-02-28 09:14:40 -0800 | [diff] [blame] | 208 | finally: |
| 209 | self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange() |
Roshan Pius | ff6ca4c | 2019-03-26 13:53:31 -0700 | [diff] [blame] | 210 | self.dut.ed.clear_all_events() |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 211 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 212 | def remove_suggestions_disconnect_and_ensure_no_connection_back(self, |
| 213 | network_suggestions, |
| 214 | expected_ssid): |
| 215 | # Remove suggestion trigger disconnect and wait for the disconnect. |
| 216 | self.dut.log.info("Removing network suggestions") |
| 217 | asserts.assert_true( |
| 218 | self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions), |
| 219 | "Failed to remove suggestions") |
| 220 | wutils.wait_for_disconnect(self.dut) |
| 221 | self.dut.ed.clear_all_events() |
| 222 | |
| 223 | # Now ensure that we didn't connect back. |
| 224 | asserts.assert_false( |
| 225 | wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False), |
| 226 | "Device should not connect back") |
| 227 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 228 | def _test_connect_to_wifi_network_reboot_config_store(self, |
| 229 | network_suggestions, |
| 230 | wifi_network): |
| 231 | """ Test network suggestion with reboot config store |
| 232 | |
| 233 | Args: |
| 234 | 1. network_suggestions: network suggestions in list to add to the device. |
| 235 | 2. wifi_network: expected wifi network to connect to |
| 236 | """ |
| 237 | |
| 238 | self.add_suggestions_and_ensure_connection( |
| 239 | network_suggestions, wifi_network[WifiEnums.SSID_KEY], None) |
| 240 | |
| 241 | # Reboot and wait for connection back to the same suggestion. |
| 242 | self.dut.reboot() |
| 243 | time.sleep(DEFAULT_TIMEOUT) |
| 244 | |
| 245 | wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY]) |
| 246 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 247 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 248 | network_suggestions, wifi_network[WifiEnums.SSID_KEY]) |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 249 | |
Nate(Qiang) Jiang | 8a62e37 | 2019-12-19 11:04:05 -0800 | [diff] [blame] | 250 | # Reboot with empty suggestion, verify user approval is kept. |
| 251 | self.dut.reboot() |
| 252 | time.sleep(DEFAULT_TIMEOUT) |
| 253 | asserts.assert_true(self.is_approved(), "User approval should be kept") |
| 254 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 255 | @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 256 | def test_connect_to_wpa_psk_2g(self): |
| 257 | """ Adds a network suggestion and ensure that the device connected. |
| 258 | |
| 259 | Steps: |
| 260 | 1. Send a network suggestion to the device. |
| 261 | 2. Wait for the device to connect to it. |
| 262 | 3. Ensure that we did not receive the post connection broadcast |
| 263 | (isAppInteractionRequired = False). |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 264 | 4. Remove the suggestions and ensure the device does not connect back. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 265 | """ |
| 266 | self.add_suggestions_and_ensure_connection( |
| 267 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 268 | False) |
Nate Jiang | 1ef58c3 | 2019-07-15 19:13:26 -0700 | [diff] [blame] | 269 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 270 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 271 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 272 | |
Girish Moturu | 10c6b2c | 2020-04-08 09:28:48 -0700 | [diff] [blame^] | 273 | @test_tracker_info(uuid="b2df6ebe-9c5b-4e84-906a-e76f96fcef56") |
Roshan Pius | 67e7c51 | 2020-04-07 14:40:18 -0700 | [diff] [blame] | 274 | def test_connect_to_wpa_psk_2g_with_screen_off(self): |
| 275 | """ Adds a network suggestion and ensure that the device connected |
| 276 | when the screen is off. |
| 277 | |
| 278 | Steps: |
| 279 | 1. Send an invalid suggestion to the device (Needed for PNO scan to start). |
| 280 | 2. Toggle screen off. |
| 281 | 3. Send a valid network suggestion to the device. |
| 282 | 4. Wait for the device to connect to it. |
| 283 | 5. Ensure that we did not receive the post connection broadcast |
| 284 | (isAppInteractionRequired = False). |
| 285 | 6. Remove the suggestions and ensure the device does not connect back. |
| 286 | """ |
| 287 | invalid_suggestion = self.wpa_psk_5g |
| 288 | network_ssid = invalid_suggestion.pop(WifiEnums.SSID_KEY) |
| 289 | invalid_suggestion[WifiEnums.SSID_KEY] = network_ssid + "blah" |
| 290 | |
| 291 | self.dut.log.info("Adding invalid suggestions") |
| 292 | asserts.assert_true( |
| 293 | self.dut.droid.wifiAddNetworkSuggestions([invalid_suggestion]), |
| 294 | "Failed to add suggestions") |
| 295 | |
| 296 | # Approve suggestions by the app. |
| 297 | self.set_approved(True) |
| 298 | |
| 299 | # Turn screen off to ensure PNO kicks-in. |
| 300 | self.dut.droid.wakeLockRelease() |
| 301 | self.dut.droid.goToSleepNow() |
| 302 | time.sleep(10) |
| 303 | |
| 304 | # Add valid suggestions & ensure we restart PNO and connect to it. |
| 305 | self.add_suggestions_and_ensure_connection( |
| 306 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 307 | False) |
| 308 | |
| 309 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 310 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
| 311 | |
Girish Moturu | 10c6b2c | 2020-04-08 09:28:48 -0700 | [diff] [blame^] | 312 | @test_tracker_info(uuid="f18bf994-ef3b-45d6-aba0-dd6338b07979") |
Roshan Pius | 55fb7c4 | 2020-04-03 14:47:18 -0700 | [diff] [blame] | 313 | def test_connect_to_wpa_psk_2g_modify_meteredness(self): |
| 314 | """ Adds a network suggestion and ensure that the device connected. |
| 315 | Change the meteredness of the network after the connection. |
| 316 | |
| 317 | Steps: |
| 318 | 1. Send a network suggestion to the device. |
| 319 | 2. Wait for the device to connect to it. |
| 320 | 3. Ensure that we did not receive the post connection broadcast |
| 321 | (isAppInteractionRequired = False). |
| 322 | 4. Mark the network suggestion metered. |
| 323 | 5. Ensure that the device disconnected and reconnected back to the |
| 324 | suggestion. |
| 325 | 6. Mark the network suggestion unmetered. |
| 326 | 7. Ensure that the device did not disconnect. |
| 327 | 8. Remove the suggestions and ensure the device does not connect back. |
| 328 | """ |
| 329 | self.add_suggestions_and_ensure_connection( |
| 330 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 331 | False) |
| 332 | |
| 333 | mod_suggestion = self.wpa_psk_2g |
| 334 | |
| 335 | # Mark the network metered. |
| 336 | self.dut.log.debug("Marking suggestion as metered") |
| 337 | mod_suggestion[WifiEnums.IS_SUGGESTION_METERED] = True |
| 338 | asserts.assert_true( |
| 339 | self.dut.droid.wifiAddNetworkSuggestions([mod_suggestion]), |
| 340 | "Failed to add suggestions") |
| 341 | # Wait for disconnect. |
| 342 | wutils.wait_for_disconnect(self.dut) |
| 343 | self.dut.log.info("Disconnected from network %s", mod_suggestion) |
| 344 | self.dut.ed.clear_all_events() |
| 345 | # Wait for reconnect. |
| 346 | wutils.wait_for_connect(self.dut, mod_suggestion[WifiEnums.SSID_KEY]) |
| 347 | |
| 348 | # Mark the network unmetered. |
| 349 | self.dut.log.debug("Marking suggestion as unmetered") |
| 350 | mod_suggestion[WifiEnums.IS_SUGGESTION_METERED] = False |
| 351 | asserts.assert_true( |
| 352 | self.dut.droid.wifiAddNetworkSuggestions([mod_suggestion]), |
| 353 | "Failed to add suggestions") |
| 354 | # Ensure there is no disconnect. |
| 355 | wutils.ensure_no_disconnect(self.dut) |
| 356 | self.dut.ed.clear_all_events() |
| 357 | |
| 358 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 359 | [mod_suggestion], mod_suggestion[WifiEnums.SSID_KEY]) |
| 360 | |
| 361 | |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 362 | @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43") |
| 363 | def test_connect_to_highest_priority(self): |
| 364 | """ |
| 365 | Adds network suggestions and ensures that device connects to |
| 366 | the suggestion with the highest priority. |
| 367 | |
| 368 | Steps: |
| 369 | 1. Send 2 network suggestions to the device (with different priorities). |
| 370 | 2. Wait for the device to connect to the network with the highest |
| 371 | priority. |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 372 | 3. In-place modify network suggestions with priorities reversed |
| 373 | 4. Restart wifi, wait for the device to connect to the network with the highest |
| 374 | priority. |
| 375 | 5. Re-add the suggestions with the priorities reversed again. |
| 376 | 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] | 377 | priority. |
| 378 | """ |
| 379 | network_suggestion_2g = self.wpa_psk_2g |
| 380 | network_suggestion_5g = self.wpa_psk_5g |
| 381 | |
| 382 | # Add suggestions & wait for the connection event. |
| 383 | network_suggestion_2g[WifiEnums.PRIORITY] = 5 |
| 384 | network_suggestion_5g[WifiEnums.PRIORITY] = 2 |
| 385 | self.add_suggestions_and_ensure_connection( |
| 386 | [network_suggestion_2g, network_suggestion_5g], |
| 387 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 388 | None) |
| 389 | |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 390 | # In-place modify Reverse the priority, should be no disconnect |
| 391 | network_suggestion_2g[WifiEnums.PRIORITY] = 2 |
| 392 | network_suggestion_5g[WifiEnums.PRIORITY] = 5 |
Roshan Pius | 67e7c51 | 2020-04-07 14:40:18 -0700 | [diff] [blame] | 393 | self.dut.log.info("Modifying network suggestions") |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 394 | asserts.assert_true( |
| 395 | self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g, |
| 396 | network_suggestion_5g]), |
| 397 | "Failed to add suggestions") |
| 398 | wutils.ensure_no_disconnect(self.dut) |
| 399 | |
| 400 | # Disable and re-enable wifi, should connect to higher priority |
| 401 | wutils.wifi_toggle_state(self.dut, False) |
| 402 | time.sleep(DEFAULT_TIMEOUT) |
| 403 | wutils.wifi_toggle_state(self.dut, True) |
| 404 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
| 405 | wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 406 | |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 407 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
Nate Jiang | 0878aef | 2019-09-16 13:33:26 -0700 | [diff] [blame] | 408 | [], self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 409 | |
| 410 | # Reverse the priority. |
| 411 | # Add suggestions & wait for the connection event. |
Nate Jiang | 172c690 | 2019-09-09 17:54:33 -0700 | [diff] [blame] | 412 | network_suggestion_2g[WifiEnums.PRIORITY] = 5 |
| 413 | network_suggestion_5g[WifiEnums.PRIORITY] = 2 |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 414 | self.add_suggestions_and_ensure_connection( |
| 415 | [network_suggestion_2g, network_suggestion_5g], |
Nate Jiang | 0878aef | 2019-09-16 13:33:26 -0700 | [diff] [blame] | 416 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
Roshan Pius | c6fceca | 2019-03-22 13:23:58 -0700 | [diff] [blame] | 417 | None) |
| 418 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 419 | @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 420 | def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self): |
| 421 | """ Adds a network suggestion and ensure that the device connected. |
| 422 | |
| 423 | Steps: |
| 424 | 1. Send a network suggestion to the device with |
| 425 | isAppInteractionRequired set. |
| 426 | 2. Wait for the device to connect to it. |
| 427 | 3. Ensure that we did receive the post connection broadcast |
| 428 | (isAppInteractionRequired = True). |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 429 | 4. Remove the suggestions and ensure the device does not connect back. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 430 | """ |
| 431 | network_suggestion = self.wpa_psk_2g |
| 432 | network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
| 433 | self.add_suggestions_and_ensure_connection( |
| 434 | [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 435 | True) |
Nate Jiang | 68f3ffa | 2019-08-07 15:23:49 -0700 | [diff] [blame] | 436 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 437 | [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 438 | |
Roshan Pius | f028bd3 | 2018-12-06 15:18:21 -0800 | [diff] [blame] | 439 | @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710") |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 440 | def test_connect_to_wpa_psk_5g_reboot_config_store(self): |
| 441 | """ |
| 442 | Adds a network suggestion and ensure that the device connects to it |
| 443 | after reboot. |
| 444 | |
| 445 | Steps: |
| 446 | 1. Send a network suggestion to the device. |
| 447 | 2. Wait for the device to connect to it. |
| 448 | 3. Ensure that we did not receive the post connection broadcast |
| 449 | (isAppInteractionRequired = False). |
| 450 | 4. Reboot the device. |
| 451 | 5. Wait for the device to connect to back to it. |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 452 | 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] | 453 | 7. Reboot the device again, ensure user approval is kept |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 454 | """ |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 455 | self._test_connect_to_wifi_network_reboot_config_store( |
| 456 | [self.wpa_psk_5g], self.wpa_psk_5g) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 457 | |
Girish Moturu | c2033ae | 2019-07-31 09:04:36 -0700 | [diff] [blame] | 458 | @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31") |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 459 | def test_connect_to_wpa_ent_config_aka_reboot_config_store(self): |
| 460 | """ |
| 461 | Adds a network suggestion and ensure that the device connects to it |
| 462 | after reboot. |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 463 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 464 | Steps: |
| 465 | 1. Send a Enterprise AKA network suggestion to the device. |
| 466 | 2. Wait for the device to connect to it. |
| 467 | 3. Ensure that we did not receive the post connection broadcast. |
| 468 | 4. Reboot the device. |
| 469 | 5. Wait for the device to connect to the wifi network. |
| 470 | 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] | 471 | 7. Reboot the device again, ensure user approval is kept |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 472 | """ |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 473 | if "carrierId" in self.config_aka: |
| 474 | self.set_carrier_approved(self.config_aka["carrierId"], True) |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 475 | self._test_connect_to_wifi_network_reboot_config_store( |
| 476 | [self.config_aka], self.ent_network_2g) |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 477 | if "carrierId" in self.config_aka: |
| 478 | self.clear_carrier_approved(self.config_aka["carrierId"]) |
Roshan Pius | d120444 | 2018-11-12 12:20:39 -0800 | [diff] [blame] | 479 | |
Girish Moturu | c2033ae | 2019-07-31 09:04:36 -0700 | [diff] [blame] | 480 | @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d") |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 481 | def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self): |
| 482 | """ |
| 483 | Adds a network suggestion and ensure that the device connects to it |
| 484 | after reboot. |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 485 | |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 486 | Steps: |
| 487 | 1. Send a Enterprise TTLS PAP network suggestion to the device. |
| 488 | 2. Wait for the device to connect to it. |
| 489 | 3. Ensure that we did not receive the post connection broadcast. |
| 490 | 4. Reboot the device. |
| 491 | 5. Wait for the device to connect to the wifi network. |
| 492 | 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] | 493 | 7. Reboot the device again, ensure user approval is kept |
Girish Moturu | b1e7a5c | 2019-07-29 13:48:11 -0700 | [diff] [blame] | 494 | """ |
| 495 | config = dict(self.config_ttls) |
| 496 | config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value |
| 497 | |
| 498 | self._test_connect_to_wifi_network_reboot_config_store( |
| 499 | [config], self.ent_network_2g) |
Roshan Pius | ffc2991 | 2019-01-18 13:39:49 -0800 | [diff] [blame] | 500 | |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 501 | @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb") |
| 502 | def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self): |
| 503 | """ |
| 504 | Adds a network suggestion and ensure that the device does not |
| 505 | connect to it until we approve the app. |
| 506 | |
| 507 | Steps: |
| 508 | 1. Send a network suggestion to the device with the app not approved. |
| 509 | 2. Ensure the network is present in scan results, but we don't connect |
| 510 | to it. |
| 511 | 3. Now approve the app. |
| 512 | 4. Wait for the device to connect to it. |
| 513 | """ |
Roshan Pius | 67e7c51 | 2020-04-07 14:40:18 -0700 | [diff] [blame] | 514 | self.dut.log.info("Adding network suggestions") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 515 | asserts.assert_true( |
| 516 | self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]), |
| 517 | "Failed to add suggestions") |
| 518 | |
| 519 | # Disable suggestions by the app. |
| 520 | self.set_approved(False) |
| 521 | |
| 522 | # Ensure the app is not approved. |
| 523 | asserts.assert_false( |
| 524 | self.is_approved(), |
| 525 | "Suggestions should be disabled") |
| 526 | |
| 527 | # Start a new scan to trigger auto-join. |
| 528 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 529 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 530 | |
| 531 | # Ensure we don't connect to the network. |
| 532 | asserts.assert_false( |
| 533 | wutils.wait_for_connect( |
| 534 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 535 | "Should not connect to network suggestions from unapproved app") |
| 536 | |
Roshan Pius | 67e7c51 | 2020-04-07 14:40:18 -0700 | [diff] [blame] | 537 | self.dut.log.info("Enabling suggestions from test") |
Roshan Pius | 3e3bd34 | 2019-01-09 13:55:17 -0800 | [diff] [blame] | 538 | # Now Enable suggestions by the app & ensure we connect to the network. |
| 539 | self.set_approved(True) |
| 540 | |
| 541 | # Ensure the app is approved. |
| 542 | asserts.assert_true( |
| 543 | self.is_approved(), |
| 544 | "Suggestions should be enabled") |
| 545 | |
| 546 | # Start a new scan to trigger auto-join. |
| 547 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 548 | self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY]) |
| 549 | |
| 550 | 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] | 551 | |
Roshan Pius | 3d57f13 | 2019-01-28 10:25:18 -0800 | [diff] [blame] | 552 | @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c") |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 553 | def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self): |
| 554 | """ |
| 555 | Adds a network suggestion and ensures that the device does not |
| 556 | connect to it after the user forgot the network previously. |
| 557 | |
| 558 | Steps: |
| 559 | 1. Send a network suggestion to the device with |
| 560 | isAppInteractionRequired set. |
| 561 | 2. Wait for the device to connect to it. |
| 562 | 3. Ensure that we did receive the post connection broadcast |
| 563 | (isAppInteractionRequired = True). |
| 564 | 4. Simulate user forgetting the network and the device does not |
| 565 | connecting back even though the suggestion is active from the app. |
| 566 | """ |
| 567 | network_suggestion = self.wpa_psk_2g |
| 568 | network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
| 569 | self.add_suggestions_and_ensure_connection( |
| 570 | [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 571 | True) |
| 572 | |
Nate(Qiang) Jiang | d342464 | 2020-03-02 19:52:59 -0800 | [diff] [blame] | 573 | # Simulate user disconnect the network. |
| 574 | self.dut.droid.wifiUserDisconnectNetwork( |
Roshan Pius | 89b22bd | 2019-01-24 14:12:49 -0800 | [diff] [blame] | 575 | self.wpa_psk_2g[WifiEnums.SSID_KEY]) |
| 576 | wutils.wait_for_disconnect(self.dut) |
| 577 | self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g) |
| 578 | self.dut.ed.clear_all_events() |
| 579 | |
| 580 | # Now ensure that we don't connect back even though the suggestion |
| 581 | # is still active. |
| 582 | asserts.assert_false( |
| 583 | wutils.wait_for_connect(self.dut, |
| 584 | self.wpa_psk_2g[WifiEnums.SSID_KEY], |
| 585 | assert_on_fail=False), |
| 586 | "Device should not connect back") |
Nate Jiang | 20af5e8 | 2019-08-08 12:45:24 -0700 | [diff] [blame] | 587 | |
| 588 | @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1") |
| 589 | def test_connect_to_hidden_network(self): |
| 590 | """ |
| 591 | Adds a network suggestion with hidden SSID config, ensure device can scan |
| 592 | and connect to this network. |
| 593 | |
| 594 | Steps: |
| 595 | 1. Send a hidden network suggestion to the device. |
| 596 | 2. Wait for the device to connect to it. |
| 597 | 3. Ensure that we did not receive the post connection broadcast |
| 598 | (isAppInteractionRequired = False). |
| 599 | 4. Remove the suggestions and ensure the device does not connect back. |
| 600 | """ |
| 601 | asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test") |
| 602 | |
| 603 | network_suggestion = self.hidden_network |
| 604 | self.add_suggestions_and_ensure_connection( |
| 605 | [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False) |
| 606 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 607 | [network_suggestion], network_suggestion[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 608 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 609 | @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 610 | def test_connect_to_passpoint_network_with_post_connection_broadcast(self): |
| 611 | """ Adds a passpoint network suggestion and ensure that the device connected. |
| 612 | |
| 613 | Steps: |
| 614 | 1. Send a network suggestion to the device. |
| 615 | 2. Wait for the device to connect to it. |
| 616 | 3. Ensure that we did receive the post connection broadcast |
| 617 | (isAppInteractionRequired = true). |
| 618 | 4. Remove the suggestions and ensure the device does not connect back. |
| 619 | """ |
| 620 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 621 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 622 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 623 | passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 624 | if "carrierId" in passpoint_config: |
| 625 | self.set_carrier_approved(passpoint_config["carrierId"], True) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 626 | self.add_suggestions_and_ensure_connection([passpoint_config], |
| 627 | passpoint_config[WifiEnums.SSID_KEY], True) |
| 628 | self.remove_suggestions_disconnect_and_ensure_no_connection_back( |
| 629 | [passpoint_config], passpoint_config[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 630 | if "carrierId" in passpoint_config: |
| 631 | self.clear_carrier_approved(passpoint_config["carrierId"]) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 632 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 633 | @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 634 | def test_connect_to_passpoint_network_reboot_config_store(self): |
| 635 | """ |
| 636 | Adds a passpoint network suggestion and ensure that the device connects to it |
| 637 | after reboot. |
| 638 | |
| 639 | Steps: |
| 640 | 1. Send a network suggestion to the device. |
| 641 | 2. Wait for the device to connect to it. |
| 642 | 3. Ensure that we did not receive the post connection broadcast |
| 643 | (isAppInteractionRequired = False). |
| 644 | 4. Reboot the device. |
| 645 | 5. Wait for the device to connect to back to it. |
| 646 | 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] | 647 | 7. Reboot the device again, ensure user approval is kept |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 648 | """ |
| 649 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 650 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 651 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 652 | if "carrierId" in passpoint_config: |
| 653 | self.set_carrier_approved(passpoint_config["carrierId"], True) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 654 | self._test_connect_to_wifi_network_reboot_config_store([passpoint_config], |
| 655 | passpoint_config) |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 656 | if "carrierId" in passpoint_config: |
| 657 | self.clear_carrier_approved(passpoint_config["carrierId"]) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 658 | |
Girish Moturu | a5d2848 | 2019-10-23 10:15:37 -0700 | [diff] [blame] | 659 | @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 660 | def test_fail_to_connect_to_passpoint_network_when_not_approved(self): |
| 661 | """ |
| 662 | Adds a passpoint network suggestion and ensure that the device does not |
| 663 | connect to it until we approve the app. |
| 664 | |
| 665 | Steps: |
| 666 | 1. Send a network suggestion to the device with the app not approved. |
| 667 | 2. Ensure the network is present in scan results, but we don't connect |
| 668 | to it. |
| 669 | 3. Now approve the app. |
| 670 | 4. Wait for the device to connect to it. |
| 671 | """ |
| 672 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 673 | "No passpoint networks, skip this test") |
Girish Moturu | a069a4a | 2019-10-23 13:21:42 -0700 | [diff] [blame] | 674 | passpoint_config = self.passpoint_networks[ATT] |
Nate(Qiang) Jiang | 647afb9 | 2020-02-06 13:44:14 -0800 | [diff] [blame] | 675 | if "carrierId" in passpoint_config: |
| 676 | self.set_carrier_approved(passpoint_config["carrierId"], True) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 677 | self.dut.log.info("Adding network suggestions") |
| 678 | asserts.assert_true( |
| 679 | self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]), |
| 680 | "Failed to add suggestions") |
| 681 | |
| 682 | # Disable suggestions by the app. |
| 683 | self.set_approved(False) |
| 684 | |
| 685 | # Ensure the app is not approved. |
| 686 | asserts.assert_false( |
| 687 | self.is_approved(), |
| 688 | "Suggestions should be disabled") |
| 689 | |
| 690 | # Start a new scan to trigger auto-join. |
| 691 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 692 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
| 693 | |
| 694 | # Ensure we don't connect to the network. |
| 695 | asserts.assert_false( |
| 696 | wutils.wait_for_connect( |
| 697 | self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 698 | "Should not connect to network suggestions from unapproved app") |
| 699 | |
Roshan Pius | 67e7c51 | 2020-04-07 14:40:18 -0700 | [diff] [blame] | 700 | self.dut.log.info("Enabling suggestions from test") |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 701 | # Now Enable suggestions by the app & ensure we connect to the network. |
| 702 | self.set_approved(True) |
| 703 | |
| 704 | # Ensure the app is approved. |
| 705 | asserts.assert_true( |
| 706 | self.is_approved(), |
| 707 | "Suggestions should be enabled") |
| 708 | |
| 709 | # Start a new scan to trigger auto-join. |
| 710 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 711 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | 051b814 | 2019-11-01 17:23:33 -0700 | [diff] [blame] | 712 | time.sleep(PASSPOINT_TIMEOUT) |
Nate(Qiang) Jiang | 5558215 | 2019-10-07 12:13:47 -0700 | [diff] [blame] | 713 | wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
Nate(Qiang) Jiang | 647afb9 | 2020-02-06 13:44:14 -0800 | [diff] [blame] | 714 | if "carrierId" in passpoint_config: |
| 715 | self.clear_carrier_approved(passpoint_config["carrierId"]) |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 716 | |
Girish Moturu | 7e30c78 | 2020-02-05 12:37:06 -0800 | [diff] [blame] | 717 | @test_tracker_info(uuid="cf624cda-4d25-42f1-80eb-6c717fb08338") |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 718 | def test_fail_to_connect_to_passpoint_network_when_imsi_protection_exemption_not_approved(self): |
| 719 | """ |
| 720 | Adds a passpoint network suggestion using SIM credential without IMSI privacy protection. |
| 721 | Before user approves the exemption, ensure that the device does noconnect to it until we |
| 722 | approve the carrier exemption. |
| 723 | |
| 724 | Steps: |
| 725 | 1. Send a network suggestion to the device with IMSI protection exemption not approved. |
| 726 | 2. Ensure the network is present in scan results, but we don't connect |
| 727 | to it. |
| 728 | 3. Now approve the carrier. |
| 729 | 4. Wait for the device to connect to it. |
| 730 | """ |
| 731 | asserts.skip_if(not hasattr(self, "passpoint_networks"), |
| 732 | "No passpoint networks, skip this test") |
| 733 | passpoint_config = self.passpoint_networks[ATT] |
| 734 | asserts.skip_if("carrierId" not in passpoint_config, |
| 735 | "Not a SIM based passpoint network, skip this test") |
| 736 | |
Nate(Qiang) Jiang | 92251a6 | 2020-02-28 10:13:30 -0800 | [diff] [blame] | 737 | # Ensure the carrier is not approved. |
| 738 | asserts.assert_false( |
| 739 | self.is_carrier_approved(passpoint_config["carrierId"]), |
| 740 | "Carrier shouldn't be approved") |
| 741 | |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 742 | self.dut.log.info("Adding network suggestions") |
| 743 | asserts.assert_true( |
| 744 | self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]), |
| 745 | "Failed to add suggestions") |
| 746 | |
Nate(Qiang) Jiang | acaf889 | 2020-01-29 14:04:12 -0800 | [diff] [blame] | 747 | # Start a new scan to trigger auto-join. |
| 748 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 749 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
| 750 | |
| 751 | # Ensure we don't connect to the network. |
| 752 | asserts.assert_false( |
| 753 | wutils.wait_for_connect( |
| 754 | self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 755 | "Should not connect to network suggestions from unapproved app") |
| 756 | |
| 757 | self.dut.log.info("Enabling suggestions from test") |
| 758 | # Now approve IMSI protection exemption by carrier & ensure we connect to the network. |
| 759 | self.set_carrier_approved(passpoint_config["carrierId"], True) |
| 760 | |
| 761 | # Ensure the carrier is approved. |
| 762 | asserts.assert_true( |
| 763 | self.is_carrier_approved(passpoint_config["carrierId"]), |
| 764 | "Carrier should be approved") |
| 765 | |
| 766 | # Start a new scan to trigger auto-join. |
| 767 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 768 | self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
| 769 | time.sleep(PASSPOINT_TIMEOUT) |
| 770 | wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY]) |
| 771 | self.clear_carrier_approved(passpoint_config["carrierId"]) |
| 772 | |
Girish Moturu | 31f58f2 | 2020-01-30 18:54:40 -0800 | [diff] [blame] | 773 | @test_tracker_info(uuid="e35f99c8-78a4-4b96-9258-f9834b6ddd33") |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 774 | def test_initial_auto_join_on_network_suggestion(self): |
| 775 | """ |
| 776 | Add a network suggestion with enableAutojoin bit set to false, ensure the device doesn't |
| 777 | auto connect to this network |
| 778 | |
| 779 | Steps: |
| 780 | 1. Create a network suggestion. |
| 781 | 2. Set EnableAutojoin to false. |
| 782 | 3. Add this suggestion |
| 783 | 4. Ensure device doesn't connect to his network |
| 784 | """ |
Girish Moturu | 2155dc1 | 2020-01-21 15:16:17 -0800 | [diff] [blame] | 785 | network_suggestion = self.wpa_psk_5g |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 786 | # Set suggestion auto join initial to false. |
Nate Jiang | 8b2b4b8 | 2020-03-13 13:49:07 -0700 | [diff] [blame] | 787 | network_suggestion[AutoJoin] = False |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 788 | self.dut.log.info("Adding network suggestions") |
| 789 | asserts.assert_true( |
| 790 | self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]), |
| 791 | "Failed to add suggestions") |
| 792 | # Enable suggestions by the app. |
| 793 | self.dut.log.debug("Enabling suggestions from test") |
| 794 | self.set_approved(True) |
| 795 | wutils.start_wifi_connection_scan_and_return_status(self.dut) |
| 796 | asserts.assert_false( |
| 797 | wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY], |
| 798 | assert_on_fail=False), "Device should not connect.") |
| 799 | |
Girish Moturu | 31f58f2 | 2020-01-30 18:54:40 -0800 | [diff] [blame] | 800 | @test_tracker_info(uuid="ff4e451f-a380-4ff5-a5c2-dd9b1633d5e5") |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 801 | def test_user_override_auto_join_on_network_suggestion(self): |
| 802 | """ |
| 803 | Add a network suggestion, user change the auto join to false, ensure the device doesn't |
| 804 | auto connect to this network |
| 805 | |
| 806 | Steps: |
| 807 | 1. Create a network suggestion. |
| 808 | 2. Add this suggestion, and ensure we connect to this network |
| 809 | 3. Simulate user change the auto join to false. |
| 810 | 4. Toggle the Wifi off and on |
| 811 | 4. Ensure device doesn't connect to his network |
| 812 | """ |
Girish Moturu | 2155dc1 | 2020-01-21 15:16:17 -0800 | [diff] [blame] | 813 | network_suggestion = self.wpa_psk_5g |
Nate(Qiang) Jiang | e7a400e | 2020-01-16 17:27:23 -0800 | [diff] [blame] | 814 | self.add_suggestions_and_ensure_connection([network_suggestion], |
| 815 | network_suggestion[WifiEnums.SSID_KEY], False) |
| 816 | wifi_info = self.dut.droid.wifiGetConnectionInfo() |
| 817 | self.dut.log.info(wifi_info) |
| 818 | network_id = wifi_info[WifiEnums.NETID_KEY] |
| 819 | # Simulate user disable auto join through Settings. |
| 820 | self.dut.log.info("Disable auto join on suggestion") |
| 821 | self.dut.droid.wifiEnableAutojoin(network_id, False) |
| 822 | wutils.wifi_toggle_state(self.dut, False) |
| 823 | wutils.wifi_toggle_state(self.dut, True) |
| 824 | asserts.assert_false( |
| 825 | wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY], |
| 826 | assert_on_fail=False), "Device should not connect.") |
Nate Jiang | 8b2b4b8 | 2020-03-13 13:49:07 -0700 | [diff] [blame] | 827 | |
Girish Moturu | 10c6b2c | 2020-04-08 09:28:48 -0700 | [diff] [blame^] | 828 | @test_tracker_info(uuid="32201b1c-76a0-46dc-9983-2cd24312a783") |
Nate Jiang | 8b2b4b8 | 2020-03-13 13:49:07 -0700 | [diff] [blame] | 829 | def test_untrusted_suggestion_without_untrusted_request(self): |
| 830 | """ |
| 831 | Add an untrusted network suggestion, when no untrusted request, will not connect to it. |
| 832 | Steps: |
| 833 | 1. Create a untrusted network suggestion. |
| 834 | 2. Add this suggestion, and ensure device do not connect to this network |
| 835 | 3. Request untrusted network and ensure device connect to this network |
| 836 | """ |
| 837 | network_suggestion = self.open_5g |
| 838 | network_suggestion[Untrusted] = True |
| 839 | self.dut.log.info("Adding network suggestions") |
| 840 | asserts.assert_true( |
| 841 | self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]), |
| 842 | "Failed to add suggestions") |
| 843 | # Start a new scan to trigger auto-join. |
| 844 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 845 | self.dut, network_suggestion[WifiEnums.SSID_KEY]) |
| 846 | |
| 847 | # Ensure we don't connect to the network. |
| 848 | asserts.assert_false( |
| 849 | wutils.wait_for_connect( |
| 850 | self.dut, network_suggestion[WifiEnums.SSID_KEY], assert_on_fail=False), |
| 851 | "Should not connect to untrusted network suggestions with no request") |
| 852 | network_request = {ClearCapabilities: True, TransportType: 1} |
| 853 | req_key = self.dut.droid.connectivityRequestNetwork(network_request) |
| 854 | |
| 855 | # Start a new scan to trigger auto-join. |
| 856 | wutils.start_wifi_connection_scan_and_ensure_network_found( |
| 857 | self.dut, network_suggestion[WifiEnums.SSID_KEY]) |
| 858 | |
| 859 | wutils.wait_for_connect( |
| 860 | self.dut, network_suggestion[WifiEnums.SSID_KEY], assert_on_fail=False) |
| 861 | |
| 862 | self.dut.droid.connectivityUnregisterNetworkCallback(req_key) |
| 863 | |