blob: f75e462d5a58c68a64beb88dec307a320ad914ec [file] [log] [blame]
Roshan Piusd1204442018-11-12 12:20:39 -08001#!/usr/bin/env python3.4
2#
3# Copyright 2018 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import itertools
18import pprint
19import queue
20import time
21
22import acts.base_test
23import acts.signals as signals
24import acts.test_utils.wifi.wifi_test_utils as wutils
25import acts.utils
26
27from acts import asserts
Roshan Pius3e3bd342019-01-09 13:55:17 -080028from acts.controllers.android_device import SL4A_APK_NAME
Roshan Piusd1204442018-11-12 12:20:39 -080029from acts.test_decorators import test_tracker_info
30from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
31from acts.test_utils.wifi import wifi_constants
32
33WifiEnums = wutils.WifiEnums
Girish Moturub1e7a5c2019-07-29 13:48:11 -070034# EAP Macros
35EAP = WifiEnums.Eap
36EapPhase2 = WifiEnums.EapPhase2
37# Enterprise Config Macros
38Ent = WifiEnums.Enterprise
Girish Moturua069a4a2019-10-23 13:21:42 -070039ATT = 2
Nate Jiang8b2b4b82020-03-13 13:49:07 -070040# Suggestion network Macros
41Untrusted = "untrusted"
42AutoJoin = "enableAutojoin"
43# Network request Macros
44ClearCapabilities = "ClearCapabilities"
45TransportType = "TransportType"
46
Roshan Piusd1204442018-11-12 12:20:39 -080047
48# Default timeout used for reboot, toggle WiFi and Airplane mode,
49# for the system to settle down after the operation.
50DEFAULT_TIMEOUT = 10
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -070051PASSPOINT_TIMEOUT = 30
Roshan Piusd1204442018-11-12 12:20:39 -080052
Nate Jiang1ef58c32019-07-15 19:13:26 -070053
Roshan Piusd1204442018-11-12 12:20:39 -080054class 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 Piusd1204442018-11-12 12:20:39 -080063 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070064 super().setup_class()
65
Roshan Piusd1204442018-11-12 12:20:39 -080066 self.dut = self.android_devices[0]
67 wutils.wifi_test_device_init(self.dut)
Nate Jiang68f3ffa2019-08-07 15:23:49 -070068 req_params = []
Roshan Piusd1204442018-11-12 12:20:39 -080069 opt_param = [
Nate Jiang68f3ffa2019-08-07 15:23:49 -070070 "open_network", "reference_networks", "radius_conf_2g", "radius_conf_5g", "ca_cert",
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -070071 "eap_identity", "eap_password", "hidden_networks", "passpoint_networks"
Roshan Piusd1204442018-11-12 12:20:39 -080072 ]
73 self.unpack_userparams(
74 req_param_names=req_params, opt_param_names=opt_param)
75
76 if "AccessPoint" in self.user_params:
Girish Moturub1e7a5c2019-07-29 13:48:11 -070077 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 Piusd1204442018-11-12 12:20:39 -080081
Girish Moturua069a4a2019-10-23 13:21:42 -070082 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 Jiang68f3ffa2019-08-07 15:23:49 -070087 self.open_2g = self.open_network[0]["2g"]
88 self.open_5g = self.open_network[0]["5g"]
Girish Moturua069a4a2019-10-23 13:21:42 -070089 if hasattr(self, "ent_networks") and isinstance(self.ent_networks,list):
Nate Jiang68f3ffa2019-08-07 15:23:49 -070090 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 Moturu7e30c782020-02-05 12:37:06 -080095 "carrierId": str(self.dut.droid.telephonyGetSimCarrierId()),
Nate Jiang68f3ffa2019-08-07 15:23:49 -070096 }
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 Moturua069a4a2019-10-23 13:21:42 -0700105 if hasattr(self, "hidden_networks") and \
106 isinstance(self.hidden_networks, list):
107 self.hidden_network = self.hidden_networks[0]
Roshan Piusd1204442018-11-12 12:20:39 -0800108 self.dut.droid.wifiRemoveNetworkSuggestions([])
109
110 def setup_test(self):
111 self.dut.droid.wakeLockAcquireBright()
112 self.dut.droid.wakeUpNow()
Nate(Qiang) Jiangd3424642020-03-02 19:52:59 -0800113 self.clear_user_disabled_networks()
Roshan Piusd1204442018-11-12 12:20:39 -0800114 wutils.wifi_toggle_state(self.dut, True)
Roshan Pius159222c2019-02-07 10:33:32 -0800115 self.dut.ed.clear_all_events()
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800116 self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId()))
Roshan Piusd1204442018-11-12 12:20:39 -0800117
118 def teardown_test(self):
119 self.dut.droid.wakeLockRelease()
120 self.dut.droid.goToSleepNow()
121 self.dut.droid.wifiRemoveNetworkSuggestions([])
Roshan Piusffc29912019-01-18 13:39:49 -0800122 self.dut.droid.wifiDisconnect()
Roshan Piusd1204442018-11-12 12:20:39 -0800123 wutils.reset_wifi(self.dut)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700124 wutils.wifi_toggle_state(self.dut, False)
Roshan Piusd1204442018-11-12 12:20:39 -0800125 self.dut.ed.clear_all_events()
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800126 self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId()))
Roshan Piusd1204442018-11-12 12:20:39 -0800127
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 Pius3e3bd342019-01-09 13:55:17 -0800138 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) Jiangacaf8892020-01-29 14:04:12 -0800151 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) Jiangd3424642020-03-02 19:52:59 -0800169 def clear_user_disabled_networks(self):
170 self.dut.log.debug("Clearing user disabled networks")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800171 self.dut.adb.shell(
Nate(Qiang) Jiangd3424642020-03-02 19:52:59 -0800172 "cmd wifi clear-user-disabled-networks")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800173
Roshan Piusd1204442018-11-12 12:20:39 -0800174 def add_suggestions_and_ensure_connection(self, network_suggestions,
175 expected_ssid,
176 expect_post_connection_broadcast):
Roshan Pius3702f242019-02-28 09:14:40 -0800177 if expect_post_connection_broadcast is not None:
178 self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange()
179
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800180 self.dut.log.info("Adding network suggestions")
Roshan Piusd1204442018-11-12 12:20:39 -0800181 asserts.assert_true(
182 self.dut.droid.wifiAddNetworkSuggestions(network_suggestions),
183 "Failed to add suggestions")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800184 # Enable suggestions by the app.
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700185 self.dut.log.debug("Enabling suggestions from test")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800186 self.set_approved(True)
lutina49d3e512019-07-05 14:42:33 +0800187 wutils.start_wifi_connection_scan_and_return_status(self.dut)
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700188 # if suggestion is passpoint wait longer for connection.
189 if "profile" in network_suggestions:
190 time.sleep(PASSPOINT_TIMEOUT)
Roshan Piusd1204442018-11-12 12:20:39 -0800191 wutils.wait_for_connect(self.dut, expected_ssid)
192
193 if expect_post_connection_broadcast is None:
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700194 return
Roshan Piusd1204442018-11-12 12:20:39 -0800195
196 # Check if we expected to get the broadcast.
197 try:
Roshan Piusd1204442018-11-12 12:20:39 -0800198 event = self.dut.ed.pop_event(
199 wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60)
Roshan Piusd1204442018-11-12 12:20:39 -0800200 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 Pius3702f242019-02-28 09:14:40 -0800208 finally:
209 self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange()
Roshan Piusff6ca4c2019-03-26 13:53:31 -0700210 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800211
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700212 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 Moturub1e7a5c2019-07-29 13:48:11 -0700228 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 Jiang68f3ffa2019-08-07 15:23:49 -0700247 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
248 network_suggestions, wifi_network[WifiEnums.SSID_KEY])
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700249
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800250 # 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 Piusf028bd32018-12-06 15:18:21 -0800255 @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108")
Roshan Piusd1204442018-11-12 12:20:39 -0800256 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 Piusffc29912019-01-18 13:39:49 -0800264 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800265 """
266 self.add_suggestions_and_ensure_connection(
267 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY],
268 False)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700269
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700270 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
271 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800272
Roshan Piusc6fceca2019-03-22 13:23:58 -0700273 @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43")
274 def test_connect_to_highest_priority(self):
275 """
276 Adds network suggestions and ensures that device connects to
277 the suggestion with the highest priority.
278
279 Steps:
280 1. Send 2 network suggestions to the device (with different priorities).
281 2. Wait for the device to connect to the network with the highest
282 priority.
Nate Jiang172c6902019-09-09 17:54:33 -0700283 3. In-place modify network suggestions with priorities reversed
284 4. Restart wifi, wait for the device to connect to the network with the highest
285 priority.
286 5. Re-add the suggestions with the priorities reversed again.
287 6. Again wait for the device to connect to the network with the highest
Roshan Piusc6fceca2019-03-22 13:23:58 -0700288 priority.
289 """
290 network_suggestion_2g = self.wpa_psk_2g
291 network_suggestion_5g = self.wpa_psk_5g
292
293 # Add suggestions & wait for the connection event.
294 network_suggestion_2g[WifiEnums.PRIORITY] = 5
295 network_suggestion_5g[WifiEnums.PRIORITY] = 2
296 self.add_suggestions_and_ensure_connection(
297 [network_suggestion_2g, network_suggestion_5g],
298 self.wpa_psk_2g[WifiEnums.SSID_KEY],
299 None)
300
Nate Jiang172c6902019-09-09 17:54:33 -0700301 # In-place modify Reverse the priority, should be no disconnect
302 network_suggestion_2g[WifiEnums.PRIORITY] = 2
303 network_suggestion_5g[WifiEnums.PRIORITY] = 5
304 self.dut.log.info("Modifying network suggestions");
305 asserts.assert_true(
306 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g,
307 network_suggestion_5g]),
308 "Failed to add suggestions")
309 wutils.ensure_no_disconnect(self.dut)
310
311 # Disable and re-enable wifi, should connect to higher priority
312 wutils.wifi_toggle_state(self.dut, False)
313 time.sleep(DEFAULT_TIMEOUT)
314 wutils.wifi_toggle_state(self.dut, True)
315 wutils.start_wifi_connection_scan_and_return_status(self.dut)
316 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
317
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700318 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
Nate Jiang0878aef2019-09-16 13:33:26 -0700319 [], self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Piusc6fceca2019-03-22 13:23:58 -0700320
321 # Reverse the priority.
322 # Add suggestions & wait for the connection event.
Nate Jiang172c6902019-09-09 17:54:33 -0700323 network_suggestion_2g[WifiEnums.PRIORITY] = 5
324 network_suggestion_5g[WifiEnums.PRIORITY] = 2
Roshan Piusc6fceca2019-03-22 13:23:58 -0700325 self.add_suggestions_and_ensure_connection(
326 [network_suggestion_2g, network_suggestion_5g],
Nate Jiang0878aef2019-09-16 13:33:26 -0700327 self.wpa_psk_2g[WifiEnums.SSID_KEY],
Roshan Piusc6fceca2019-03-22 13:23:58 -0700328 None)
329
Roshan Piusf028bd32018-12-06 15:18:21 -0800330 @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f")
Roshan Piusd1204442018-11-12 12:20:39 -0800331 def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self):
332 """ Adds a network suggestion and ensure that the device connected.
333
334 Steps:
335 1. Send a network suggestion to the device with
336 isAppInteractionRequired set.
337 2. Wait for the device to connect to it.
338 3. Ensure that we did receive the post connection broadcast
339 (isAppInteractionRequired = True).
Roshan Piusffc29912019-01-18 13:39:49 -0800340 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800341 """
342 network_suggestion = self.wpa_psk_2g
343 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
344 self.add_suggestions_and_ensure_connection(
345 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
346 True)
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700347 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
348 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800349
Roshan Piusf028bd32018-12-06 15:18:21 -0800350 @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710")
Roshan Piusd1204442018-11-12 12:20:39 -0800351 def test_connect_to_wpa_psk_5g_reboot_config_store(self):
352 """
353 Adds a network suggestion and ensure that the device connects to it
354 after reboot.
355
356 Steps:
357 1. Send a network suggestion to the device.
358 2. Wait for the device to connect to it.
359 3. Ensure that we did not receive the post connection broadcast
360 (isAppInteractionRequired = False).
361 4. Reboot the device.
362 5. Wait for the device to connect to back to it.
Roshan Piusffc29912019-01-18 13:39:49 -0800363 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800364 7. Reboot the device again, ensure user approval is kept
Roshan Piusd1204442018-11-12 12:20:39 -0800365 """
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700366 self._test_connect_to_wifi_network_reboot_config_store(
367 [self.wpa_psk_5g], self.wpa_psk_5g)
Roshan Piusd1204442018-11-12 12:20:39 -0800368
Girish Moturuc2033ae2019-07-31 09:04:36 -0700369 @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700370 def test_connect_to_wpa_ent_config_aka_reboot_config_store(self):
371 """
372 Adds a network suggestion and ensure that the device connects to it
373 after reboot.
Roshan Piusd1204442018-11-12 12:20:39 -0800374
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700375 Steps:
376 1. Send a Enterprise AKA network suggestion to the device.
377 2. Wait for the device to connect to it.
378 3. Ensure that we did not receive the post connection broadcast.
379 4. Reboot the device.
380 5. Wait for the device to connect to the wifi network.
381 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800382 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700383 """
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800384 if "carrierId" in self.config_aka:
385 self.set_carrier_approved(self.config_aka["carrierId"], True)
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700386 self._test_connect_to_wifi_network_reboot_config_store(
387 [self.config_aka], self.ent_network_2g)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800388 if "carrierId" in self.config_aka:
389 self.clear_carrier_approved(self.config_aka["carrierId"])
Roshan Piusd1204442018-11-12 12:20:39 -0800390
Girish Moturuc2033ae2019-07-31 09:04:36 -0700391 @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700392 def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self):
393 """
394 Adds a network suggestion and ensure that the device connects to it
395 after reboot.
Roshan Piusffc29912019-01-18 13:39:49 -0800396
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700397 Steps:
398 1. Send a Enterprise TTLS PAP network suggestion to the device.
399 2. Wait for the device to connect to it.
400 3. Ensure that we did not receive the post connection broadcast.
401 4. Reboot the device.
402 5. Wait for the device to connect to the wifi network.
403 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800404 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700405 """
406 config = dict(self.config_ttls)
407 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
408
409 self._test_connect_to_wifi_network_reboot_config_store(
410 [config], self.ent_network_2g)
Roshan Piusffc29912019-01-18 13:39:49 -0800411
Roshan Pius3e3bd342019-01-09 13:55:17 -0800412 @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb")
413 def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
414 """
415 Adds a network suggestion and ensure that the device does not
416 connect to it until we approve the app.
417
418 Steps:
419 1. Send a network suggestion to the device with the app not approved.
420 2. Ensure the network is present in scan results, but we don't connect
421 to it.
422 3. Now approve the app.
423 4. Wait for the device to connect to it.
424 """
425 self.dut.log.info("Adding network suggestions");
426 asserts.assert_true(
427 self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
428 "Failed to add suggestions")
429
430 # Disable suggestions by the app.
431 self.set_approved(False)
432
433 # Ensure the app is not approved.
434 asserts.assert_false(
435 self.is_approved(),
436 "Suggestions should be disabled")
437
438 # Start a new scan to trigger auto-join.
439 wutils.start_wifi_connection_scan_and_ensure_network_found(
440 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
441
442 # Ensure we don't connect to the network.
443 asserts.assert_false(
444 wutils.wait_for_connect(
445 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
446 "Should not connect to network suggestions from unapproved app")
447
448 self.dut.log.info("Enabling suggestions from test");
449 # Now Enable suggestions by the app & ensure we connect to the network.
450 self.set_approved(True)
451
452 # Ensure the app is approved.
453 asserts.assert_true(
454 self.is_approved(),
455 "Suggestions should be enabled")
456
457 # Start a new scan to trigger auto-join.
458 wutils.start_wifi_connection_scan_and_ensure_network_found(
459 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
460
461 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Pius89b22bd2019-01-24 14:12:49 -0800462
Roshan Pius3d57f132019-01-28 10:25:18 -0800463 @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800464 def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self):
465 """
466 Adds a network suggestion and ensures that the device does not
467 connect to it after the user forgot the network previously.
468
469 Steps:
470 1. Send a network suggestion to the device with
471 isAppInteractionRequired set.
472 2. Wait for the device to connect to it.
473 3. Ensure that we did receive the post connection broadcast
474 (isAppInteractionRequired = True).
475 4. Simulate user forgetting the network and the device does not
476 connecting back even though the suggestion is active from the app.
477 """
478 network_suggestion = self.wpa_psk_2g
479 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
480 self.add_suggestions_and_ensure_connection(
481 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
482 True)
483
Nate(Qiang) Jiangd3424642020-03-02 19:52:59 -0800484 # Simulate user disconnect the network.
485 self.dut.droid.wifiUserDisconnectNetwork(
Roshan Pius89b22bd2019-01-24 14:12:49 -0800486 self.wpa_psk_2g[WifiEnums.SSID_KEY])
487 wutils.wait_for_disconnect(self.dut)
488 self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
489 self.dut.ed.clear_all_events()
490
491 # Now ensure that we don't connect back even though the suggestion
492 # is still active.
493 asserts.assert_false(
494 wutils.wait_for_connect(self.dut,
495 self.wpa_psk_2g[WifiEnums.SSID_KEY],
496 assert_on_fail=False),
497 "Device should not connect back")
Nate Jiang20af5e82019-08-08 12:45:24 -0700498
499 @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1")
500 def test_connect_to_hidden_network(self):
501 """
502 Adds a network suggestion with hidden SSID config, ensure device can scan
503 and connect to this network.
504
505 Steps:
506 1. Send a hidden network suggestion to the device.
507 2. Wait for the device to connect to it.
508 3. Ensure that we did not receive the post connection broadcast
509 (isAppInteractionRequired = False).
510 4. Remove the suggestions and ensure the device does not connect back.
511 """
512 asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test")
513
514 network_suggestion = self.hidden_network
515 self.add_suggestions_and_ensure_connection(
516 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False)
517 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
518 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700519
Girish Moturua5d28482019-10-23 10:15:37 -0700520 @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700521 def test_connect_to_passpoint_network_with_post_connection_broadcast(self):
522 """ Adds a passpoint network suggestion and ensure that the device connected.
523
524 Steps:
525 1. Send a network suggestion to the device.
526 2. Wait for the device to connect to it.
527 3. Ensure that we did receive the post connection broadcast
528 (isAppInteractionRequired = true).
529 4. Remove the suggestions and ensure the device does not connect back.
530 """
531 asserts.skip_if(not hasattr(self, "passpoint_networks"),
532 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700533 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700534 passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800535 if "carrierId" in passpoint_config:
536 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700537 self.add_suggestions_and_ensure_connection([passpoint_config],
538 passpoint_config[WifiEnums.SSID_KEY], True)
539 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
540 [passpoint_config], passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800541 if "carrierId" in passpoint_config:
542 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700543
Girish Moturua5d28482019-10-23 10:15:37 -0700544 @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700545 def test_connect_to_passpoint_network_reboot_config_store(self):
546 """
547 Adds a passpoint network suggestion and ensure that the device connects to it
548 after reboot.
549
550 Steps:
551 1. Send a network suggestion to the device.
552 2. Wait for the device to connect to it.
553 3. Ensure that we did not receive the post connection broadcast
554 (isAppInteractionRequired = False).
555 4. Reboot the device.
556 5. Wait for the device to connect to back to it.
557 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800558 7. Reboot the device again, ensure user approval is kept
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700559 """
560 asserts.skip_if(not hasattr(self, "passpoint_networks"),
561 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700562 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800563 if "carrierId" in passpoint_config:
564 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700565 self._test_connect_to_wifi_network_reboot_config_store([passpoint_config],
566 passpoint_config)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800567 if "carrierId" in passpoint_config:
568 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700569
Girish Moturua5d28482019-10-23 10:15:37 -0700570 @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700571 def test_fail_to_connect_to_passpoint_network_when_not_approved(self):
572 """
573 Adds a passpoint network suggestion and ensure that the device does not
574 connect to it until we approve the app.
575
576 Steps:
577 1. Send a network suggestion to the device with the app not approved.
578 2. Ensure the network is present in scan results, but we don't connect
579 to it.
580 3. Now approve the app.
581 4. Wait for the device to connect to it.
582 """
583 asserts.skip_if(not hasattr(self, "passpoint_networks"),
584 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700585 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang647afb92020-02-06 13:44:14 -0800586 if "carrierId" in passpoint_config:
587 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700588 self.dut.log.info("Adding network suggestions")
589 asserts.assert_true(
590 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
591 "Failed to add suggestions")
592
593 # Disable suggestions by the app.
594 self.set_approved(False)
595
596 # Ensure the app is not approved.
597 asserts.assert_false(
598 self.is_approved(),
599 "Suggestions should be disabled")
600
601 # Start a new scan to trigger auto-join.
602 wutils.start_wifi_connection_scan_and_ensure_network_found(
603 self.dut, passpoint_config[WifiEnums.SSID_KEY])
604
605 # Ensure we don't connect to the network.
606 asserts.assert_false(
607 wutils.wait_for_connect(
608 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
609 "Should not connect to network suggestions from unapproved app")
610
611 self.dut.log.info("Enabling suggestions from test");
612 # Now Enable suggestions by the app & ensure we connect to the network.
613 self.set_approved(True)
614
615 # Ensure the app is approved.
616 asserts.assert_true(
617 self.is_approved(),
618 "Suggestions should be enabled")
619
620 # Start a new scan to trigger auto-join.
621 wutils.start_wifi_connection_scan_and_ensure_network_found(
622 self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700623 time.sleep(PASSPOINT_TIMEOUT)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700624 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang647afb92020-02-06 13:44:14 -0800625 if "carrierId" in passpoint_config:
626 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800627
Girish Moturu7e30c782020-02-05 12:37:06 -0800628 @test_tracker_info(uuid="cf624cda-4d25-42f1-80eb-6c717fb08338")
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800629 def test_fail_to_connect_to_passpoint_network_when_imsi_protection_exemption_not_approved(self):
630 """
631 Adds a passpoint network suggestion using SIM credential without IMSI privacy protection.
632 Before user approves the exemption, ensure that the device does noconnect to it until we
633 approve the carrier exemption.
634
635 Steps:
636 1. Send a network suggestion to the device with IMSI protection exemption not approved.
637 2. Ensure the network is present in scan results, but we don't connect
638 to it.
639 3. Now approve the carrier.
640 4. Wait for the device to connect to it.
641 """
642 asserts.skip_if(not hasattr(self, "passpoint_networks"),
643 "No passpoint networks, skip this test")
644 passpoint_config = self.passpoint_networks[ATT]
645 asserts.skip_if("carrierId" not in passpoint_config,
646 "Not a SIM based passpoint network, skip this test")
647
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800648 # Ensure the carrier is not approved.
649 asserts.assert_false(
650 self.is_carrier_approved(passpoint_config["carrierId"]),
651 "Carrier shouldn't be approved")
652
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800653 self.dut.log.info("Adding network suggestions")
654 asserts.assert_true(
655 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
656 "Failed to add suggestions")
657
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800658 # Start a new scan to trigger auto-join.
659 wutils.start_wifi_connection_scan_and_ensure_network_found(
660 self.dut, passpoint_config[WifiEnums.SSID_KEY])
661
662 # Ensure we don't connect to the network.
663 asserts.assert_false(
664 wutils.wait_for_connect(
665 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
666 "Should not connect to network suggestions from unapproved app")
667
668 self.dut.log.info("Enabling suggestions from test")
669 # Now approve IMSI protection exemption by carrier & ensure we connect to the network.
670 self.set_carrier_approved(passpoint_config["carrierId"], True)
671
672 # Ensure the carrier is approved.
673 asserts.assert_true(
674 self.is_carrier_approved(passpoint_config["carrierId"]),
675 "Carrier should be approved")
676
677 # Start a new scan to trigger auto-join.
678 wutils.start_wifi_connection_scan_and_ensure_network_found(
679 self.dut, passpoint_config[WifiEnums.SSID_KEY])
680 time.sleep(PASSPOINT_TIMEOUT)
681 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
682 self.clear_carrier_approved(passpoint_config["carrierId"])
683
Girish Moturu31f58f22020-01-30 18:54:40 -0800684 @test_tracker_info(uuid="e35f99c8-78a4-4b96-9258-f9834b6ddd33")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800685 def test_initial_auto_join_on_network_suggestion(self):
686 """
687 Add a network suggestion with enableAutojoin bit set to false, ensure the device doesn't
688 auto connect to this network
689
690 Steps:
691 1. Create a network suggestion.
692 2. Set EnableAutojoin to false.
693 3. Add this suggestion
694 4. Ensure device doesn't connect to his network
695 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800696 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800697 # Set suggestion auto join initial to false.
Nate Jiang8b2b4b82020-03-13 13:49:07 -0700698 network_suggestion[AutoJoin] = False
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800699 self.dut.log.info("Adding network suggestions")
700 asserts.assert_true(
701 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]),
702 "Failed to add suggestions")
703 # Enable suggestions by the app.
704 self.dut.log.debug("Enabling suggestions from test")
705 self.set_approved(True)
706 wutils.start_wifi_connection_scan_and_return_status(self.dut)
707 asserts.assert_false(
708 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
709 assert_on_fail=False), "Device should not connect.")
710
Girish Moturu31f58f22020-01-30 18:54:40 -0800711 @test_tracker_info(uuid="ff4e451f-a380-4ff5-a5c2-dd9b1633d5e5")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800712 def test_user_override_auto_join_on_network_suggestion(self):
713 """
714 Add a network suggestion, user change the auto join to false, ensure the device doesn't
715 auto connect to this network
716
717 Steps:
718 1. Create a network suggestion.
719 2. Add this suggestion, and ensure we connect to this network
720 3. Simulate user change the auto join to false.
721 4. Toggle the Wifi off and on
722 4. Ensure device doesn't connect to his network
723 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800724 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800725 self.add_suggestions_and_ensure_connection([network_suggestion],
726 network_suggestion[WifiEnums.SSID_KEY], False)
727 wifi_info = self.dut.droid.wifiGetConnectionInfo()
728 self.dut.log.info(wifi_info)
729 network_id = wifi_info[WifiEnums.NETID_KEY]
730 # Simulate user disable auto join through Settings.
731 self.dut.log.info("Disable auto join on suggestion")
732 self.dut.droid.wifiEnableAutojoin(network_id, False)
733 wutils.wifi_toggle_state(self.dut, False)
734 wutils.wifi_toggle_state(self.dut, True)
735 asserts.assert_false(
736 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
737 assert_on_fail=False), "Device should not connect.")
Nate Jiang8b2b4b82020-03-13 13:49:07 -0700738
739 @test_tracker_info(uuid="")
740 def test_untrusted_suggestion_without_untrusted_request(self):
741 """
742 Add an untrusted network suggestion, when no untrusted request, will not connect to it.
743 Steps:
744 1. Create a untrusted network suggestion.
745 2. Add this suggestion, and ensure device do not connect to this network
746 3. Request untrusted network and ensure device connect to this network
747 """
748 network_suggestion = self.open_5g
749 network_suggestion[Untrusted] = True
750 self.dut.log.info("Adding network suggestions")
751 asserts.assert_true(
752 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]),
753 "Failed to add suggestions")
754 # Start a new scan to trigger auto-join.
755 wutils.start_wifi_connection_scan_and_ensure_network_found(
756 self.dut, network_suggestion[WifiEnums.SSID_KEY])
757
758 # Ensure we don't connect to the network.
759 asserts.assert_false(
760 wutils.wait_for_connect(
761 self.dut, network_suggestion[WifiEnums.SSID_KEY], assert_on_fail=False),
762 "Should not connect to untrusted network suggestions with no request")
763 network_request = {ClearCapabilities: True, TransportType: 1}
764 req_key = self.dut.droid.connectivityRequestNetwork(network_request)
765
766 # Start a new scan to trigger auto-join.
767 wutils.start_wifi_connection_scan_and_ensure_network_found(
768 self.dut, network_suggestion[WifiEnums.SSID_KEY])
769
770 wutils.wait_for_connect(
771 self.dut, network_suggestion[WifiEnums.SSID_KEY], assert_on_fail=False)
772
773 self.dut.droid.connectivityUnregisterNetworkCallback(req_key)
774