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