blob: e678dc8d7d9131d6616eb522486b889a84d727b4 [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
Roshan Piusd1204442018-11-12 12:20:39 -080040
41# Default timeout used for reboot, toggle WiFi and Airplane mode,
42# for the system to settle down after the operation.
43DEFAULT_TIMEOUT = 10
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -070044PASSPOINT_TIMEOUT = 30
Roshan Piusd1204442018-11-12 12:20:39 -080045
Nate Jiang1ef58c32019-07-15 19:13:26 -070046
Roshan Piusd1204442018-11-12 12:20:39 -080047class WifiNetworkSuggestionTest(WifiBaseTest):
48 """Tests for WifiNetworkSuggestion API surface.
49
50 Test Bed Requirement:
51 * one Android device
52 * Several Wi-Fi networks visible to the device, including an open Wi-Fi
53 network.
54 """
55
Roshan Piusd1204442018-11-12 12:20:39 -080056 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070057 super().setup_class()
58
Roshan Piusd1204442018-11-12 12:20:39 -080059 self.dut = self.android_devices[0]
60 wutils.wifi_test_device_init(self.dut)
Nate Jiang68f3ffa2019-08-07 15:23:49 -070061 req_params = []
Roshan Piusd1204442018-11-12 12:20:39 -080062 opt_param = [
Nate Jiang68f3ffa2019-08-07 15:23:49 -070063 "open_network", "reference_networks", "radius_conf_2g", "radius_conf_5g", "ca_cert",
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -070064 "eap_identity", "eap_password", "hidden_networks", "passpoint_networks"
Roshan Piusd1204442018-11-12 12:20:39 -080065 ]
66 self.unpack_userparams(
67 req_param_names=req_params, opt_param_names=opt_param)
68
69 if "AccessPoint" in self.user_params:
Girish Moturub1e7a5c2019-07-29 13:48:11 -070070 self.legacy_configure_ap_and_start(
71 wpa_network=True, ent_network=True,
72 radius_conf_2g=self.radius_conf_2g,
73 radius_conf_5g=self.radius_conf_5g,)
Roshan Piusd1204442018-11-12 12:20:39 -080074
Girish Moturua069a4a2019-10-23 13:21:42 -070075 if hasattr(self, "reference_networks") and \
76 isinstance(self.reference_networks, list):
77 self.wpa_psk_2g = self.reference_networks[0]["2g"]
78 self.wpa_psk_5g = self.reference_networks[0]["5g"]
79 if hasattr(self, "open_network") and isinstance(self.open_network,list):
Nate Jiang68f3ffa2019-08-07 15:23:49 -070080 self.open_2g = self.open_network[0]["2g"]
81 self.open_5g = self.open_network[0]["5g"]
Girish Moturua069a4a2019-10-23 13:21:42 -070082 if hasattr(self, "ent_networks") and isinstance(self.ent_networks,list):
Nate Jiang68f3ffa2019-08-07 15:23:49 -070083 self.ent_network_2g = self.ent_networks[0]["2g"]
84 self.ent_network_5g = self.ent_networks[0]["5g"]
85 self.config_aka = {
86 Ent.EAP: int(EAP.AKA),
87 WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY],
88 }
89 self.config_ttls = {
90 Ent.EAP: int(EAP.TTLS),
91 Ent.CA_CERT: self.ca_cert,
92 Ent.IDENTITY: self.eap_identity,
93 Ent.PASSWORD: self.eap_password,
94 Ent.PHASE2: int(EapPhase2.MSCHAPV2),
95 WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY],
96 }
Girish Moturua069a4a2019-10-23 13:21:42 -070097 if hasattr(self, "hidden_networks") and \
98 isinstance(self.hidden_networks, list):
99 self.hidden_network = self.hidden_networks[0]
Roshan Piusd1204442018-11-12 12:20:39 -0800100 self.dut.droid.wifiRemoveNetworkSuggestions([])
101
102 def setup_test(self):
103 self.dut.droid.wakeLockAcquireBright()
104 self.dut.droid.wakeUpNow()
Roshan Pius89b22bd2019-01-24 14:12:49 -0800105 self.clear_deleted_ephemeral_networks()
Roshan Piusd1204442018-11-12 12:20:39 -0800106 wutils.wifi_toggle_state(self.dut, True)
Roshan Pius159222c2019-02-07 10:33:32 -0800107 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800108
109 def teardown_test(self):
110 self.dut.droid.wakeLockRelease()
111 self.dut.droid.goToSleepNow()
112 self.dut.droid.wifiRemoveNetworkSuggestions([])
Roshan Piusffc29912019-01-18 13:39:49 -0800113 self.dut.droid.wifiDisconnect()
Roshan Piusd1204442018-11-12 12:20:39 -0800114 wutils.reset_wifi(self.dut)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700115 wutils.wifi_toggle_state(self.dut, False)
Roshan Piusd1204442018-11-12 12:20:39 -0800116 self.dut.ed.clear_all_events()
117
118 def on_fail(self, test_name, begin_time):
119 self.dut.take_bug_report(test_name, begin_time)
120 self.dut.cat_adb_log(test_name, begin_time)
121
122 def teardown_class(self):
123 if "AccessPoint" in self.user_params:
124 del self.user_params["reference_networks"]
125 del self.user_params["open_network"]
126
127 """Helper Functions"""
Roshan Pius3e3bd342019-01-09 13:55:17 -0800128 def set_approved(self, approved):
129 self.dut.log.debug("Setting suggestions from sl4a app "
130 + "approved" if approved else "not approved")
131 self.dut.adb.shell("cmd wifi network-suggestions-set-user-approved"
132 + " " + SL4A_APK_NAME
133 + " " + ("yes" if approved else "no"))
134
135 def is_approved(self):
136 is_approved_str = self.dut.adb.shell(
137 "cmd wifi network-suggestions-has-user-approved"
138 + " " + SL4A_APK_NAME)
139 return True if (is_approved_str == "yes") else False
140
Roshan Pius89b22bd2019-01-24 14:12:49 -0800141 def clear_deleted_ephemeral_networks(self):
142 self.dut.log.debug("Clearing deleted ephemeral networks")
143 self.dut.adb.shell(
144 "cmd wifi clear-deleted-ephemeral-networks")
145
Roshan Piusd1204442018-11-12 12:20:39 -0800146 def add_suggestions_and_ensure_connection(self, network_suggestions,
147 expected_ssid,
148 expect_post_connection_broadcast):
Roshan Pius3702f242019-02-28 09:14:40 -0800149 if expect_post_connection_broadcast is not None:
150 self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange()
151
Roshan Piusd1204442018-11-12 12:20:39 -0800152 self.dut.log.info("Adding network suggestions");
153 asserts.assert_true(
154 self.dut.droid.wifiAddNetworkSuggestions(network_suggestions),
155 "Failed to add suggestions")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800156 # Enable suggestions by the app.
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700157 self.dut.log.debug("Enabling suggestions from test")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800158 self.set_approved(True)
lutina49d3e512019-07-05 14:42:33 +0800159 wutils.start_wifi_connection_scan_and_return_status(self.dut)
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700160 # if suggestion is passpoint wait longer for connection.
161 if "profile" in network_suggestions:
162 time.sleep(PASSPOINT_TIMEOUT)
Roshan Piusd1204442018-11-12 12:20:39 -0800163 wutils.wait_for_connect(self.dut, expected_ssid)
164
165 if expect_post_connection_broadcast is None:
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700166 return
Roshan Piusd1204442018-11-12 12:20:39 -0800167
168 # Check if we expected to get the broadcast.
169 try:
Roshan Piusd1204442018-11-12 12:20:39 -0800170 event = self.dut.ed.pop_event(
171 wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60)
Roshan Piusd1204442018-11-12 12:20:39 -0800172 except queue.Empty:
173 if expect_post_connection_broadcast:
174 raise signals.TestFailure(
175 "Did not receive post connection broadcast")
176 else:
177 if not expect_post_connection_broadcast:
178 raise signals.TestFailure(
179 "Received post connection broadcast")
Roshan Pius3702f242019-02-28 09:14:40 -0800180 finally:
181 self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange()
Roshan Piusff6ca4c2019-03-26 13:53:31 -0700182 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800183
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700184 def remove_suggestions_disconnect_and_ensure_no_connection_back(self,
185 network_suggestions,
186 expected_ssid):
187 # Remove suggestion trigger disconnect and wait for the disconnect.
188 self.dut.log.info("Removing network suggestions")
189 asserts.assert_true(
190 self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions),
191 "Failed to remove suggestions")
192 wutils.wait_for_disconnect(self.dut)
193 self.dut.ed.clear_all_events()
194
195 # Now ensure that we didn't connect back.
196 asserts.assert_false(
197 wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False),
198 "Device should not connect back")
199
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700200 def _test_connect_to_wifi_network_reboot_config_store(self,
201 network_suggestions,
202 wifi_network):
203 """ Test network suggestion with reboot config store
204
205 Args:
206 1. network_suggestions: network suggestions in list to add to the device.
207 2. wifi_network: expected wifi network to connect to
208 """
209
210 self.add_suggestions_and_ensure_connection(
211 network_suggestions, wifi_network[WifiEnums.SSID_KEY], None)
212
213 # Reboot and wait for connection back to the same suggestion.
214 self.dut.reboot()
215 time.sleep(DEFAULT_TIMEOUT)
216
217 wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY])
218
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700219 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
220 network_suggestions, wifi_network[WifiEnums.SSID_KEY])
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700221
Roshan Piusf028bd32018-12-06 15:18:21 -0800222 @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108")
Roshan Piusd1204442018-11-12 12:20:39 -0800223 def test_connect_to_wpa_psk_2g(self):
224 """ Adds a network suggestion and ensure that the device connected.
225
226 Steps:
227 1. Send a network suggestion to the device.
228 2. Wait for the device to connect to it.
229 3. Ensure that we did not receive the post connection broadcast
230 (isAppInteractionRequired = False).
Roshan Piusffc29912019-01-18 13:39:49 -0800231 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800232 """
233 self.add_suggestions_and_ensure_connection(
234 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY],
235 False)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700236
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700237 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
238 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800239
Roshan Piusc6fceca2019-03-22 13:23:58 -0700240 @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43")
241 def test_connect_to_highest_priority(self):
242 """
243 Adds network suggestions and ensures that device connects to
244 the suggestion with the highest priority.
245
246 Steps:
247 1. Send 2 network suggestions to the device (with different priorities).
248 2. Wait for the device to connect to the network with the highest
249 priority.
Nate Jiang172c6902019-09-09 17:54:33 -0700250 3. In-place modify network suggestions with priorities reversed
251 4. Restart wifi, wait for the device to connect to the network with the highest
252 priority.
253 5. Re-add the suggestions with the priorities reversed again.
254 6. Again wait for the device to connect to the network with the highest
Roshan Piusc6fceca2019-03-22 13:23:58 -0700255 priority.
256 """
257 network_suggestion_2g = self.wpa_psk_2g
258 network_suggestion_5g = self.wpa_psk_5g
259
260 # Add suggestions & wait for the connection event.
261 network_suggestion_2g[WifiEnums.PRIORITY] = 5
262 network_suggestion_5g[WifiEnums.PRIORITY] = 2
263 self.add_suggestions_and_ensure_connection(
264 [network_suggestion_2g, network_suggestion_5g],
265 self.wpa_psk_2g[WifiEnums.SSID_KEY],
266 None)
267
Nate Jiang172c6902019-09-09 17:54:33 -0700268 # In-place modify Reverse the priority, should be no disconnect
269 network_suggestion_2g[WifiEnums.PRIORITY] = 2
270 network_suggestion_5g[WifiEnums.PRIORITY] = 5
271 self.dut.log.info("Modifying network suggestions");
272 asserts.assert_true(
273 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g,
274 network_suggestion_5g]),
275 "Failed to add suggestions")
276 wutils.ensure_no_disconnect(self.dut)
277
278 # Disable and re-enable wifi, should connect to higher priority
279 wutils.wifi_toggle_state(self.dut, False)
280 time.sleep(DEFAULT_TIMEOUT)
281 wutils.wifi_toggle_state(self.dut, True)
282 wutils.start_wifi_connection_scan_and_return_status(self.dut)
283 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
284
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700285 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
Nate Jiang0878aef2019-09-16 13:33:26 -0700286 [], self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Piusc6fceca2019-03-22 13:23:58 -0700287
288 # Reverse the priority.
289 # Add suggestions & wait for the connection event.
Nate Jiang172c6902019-09-09 17:54:33 -0700290 network_suggestion_2g[WifiEnums.PRIORITY] = 5
291 network_suggestion_5g[WifiEnums.PRIORITY] = 2
Roshan Piusc6fceca2019-03-22 13:23:58 -0700292 self.add_suggestions_and_ensure_connection(
293 [network_suggestion_2g, network_suggestion_5g],
Nate Jiang0878aef2019-09-16 13:33:26 -0700294 self.wpa_psk_2g[WifiEnums.SSID_KEY],
Roshan Piusc6fceca2019-03-22 13:23:58 -0700295 None)
296
Roshan Piusf028bd32018-12-06 15:18:21 -0800297 @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f")
Roshan Piusd1204442018-11-12 12:20:39 -0800298 def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self):
299 """ Adds a network suggestion and ensure that the device connected.
300
301 Steps:
302 1. Send a network suggestion to the device with
303 isAppInteractionRequired set.
304 2. Wait for the device to connect to it.
305 3. Ensure that we did receive the post connection broadcast
306 (isAppInteractionRequired = True).
Roshan Piusffc29912019-01-18 13:39:49 -0800307 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800308 """
309 network_suggestion = self.wpa_psk_2g
310 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
311 self.add_suggestions_and_ensure_connection(
312 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
313 True)
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700314 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
315 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800316
Roshan Piusf028bd32018-12-06 15:18:21 -0800317 @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710")
Roshan Piusd1204442018-11-12 12:20:39 -0800318 def test_connect_to_wpa_psk_5g_reboot_config_store(self):
319 """
320 Adds a network suggestion and ensure that the device connects to it
321 after reboot.
322
323 Steps:
324 1. Send a network suggestion to the device.
325 2. Wait for the device to connect to it.
326 3. Ensure that we did not receive the post connection broadcast
327 (isAppInteractionRequired = False).
328 4. Reboot the device.
329 5. Wait for the device to connect to back to it.
Roshan Piusffc29912019-01-18 13:39:49 -0800330 6. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800331 """
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700332 self._test_connect_to_wifi_network_reboot_config_store(
333 [self.wpa_psk_5g], self.wpa_psk_5g)
Roshan Piusd1204442018-11-12 12:20:39 -0800334
Girish Moturuc2033ae2019-07-31 09:04:36 -0700335 @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700336 def test_connect_to_wpa_ent_config_aka_reboot_config_store(self):
337 """
338 Adds a network suggestion and ensure that the device connects to it
339 after reboot.
Roshan Piusd1204442018-11-12 12:20:39 -0800340
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700341 Steps:
342 1. Send a Enterprise AKA network suggestion to the device.
343 2. Wait for the device to connect to it.
344 3. Ensure that we did not receive the post connection broadcast.
345 4. Reboot the device.
346 5. Wait for the device to connect to the wifi network.
347 6. Remove suggestions and ensure device doesn't connect back to it.
348 """
349 self._test_connect_to_wifi_network_reboot_config_store(
350 [self.config_aka], self.ent_network_2g)
Roshan Piusd1204442018-11-12 12:20:39 -0800351
Girish Moturuc2033ae2019-07-31 09:04:36 -0700352 @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700353 def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self):
354 """
355 Adds a network suggestion and ensure that the device connects to it
356 after reboot.
Roshan Piusffc29912019-01-18 13:39:49 -0800357
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700358 Steps:
359 1. Send a Enterprise TTLS PAP network suggestion to the device.
360 2. Wait for the device to connect to it.
361 3. Ensure that we did not receive the post connection broadcast.
362 4. Reboot the device.
363 5. Wait for the device to connect to the wifi network.
364 6. Remove suggestions and ensure device doesn't connect back to it.
365 """
366 config = dict(self.config_ttls)
367 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
368
369 self._test_connect_to_wifi_network_reboot_config_store(
370 [config], self.ent_network_2g)
Roshan Piusffc29912019-01-18 13:39:49 -0800371
Roshan Pius3e3bd342019-01-09 13:55:17 -0800372 @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb")
373 def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
374 """
375 Adds a network suggestion and ensure that the device does not
376 connect to it until we approve the app.
377
378 Steps:
379 1. Send a network suggestion to the device with the app not approved.
380 2. Ensure the network is present in scan results, but we don't connect
381 to it.
382 3. Now approve the app.
383 4. Wait for the device to connect to it.
384 """
385 self.dut.log.info("Adding network suggestions");
386 asserts.assert_true(
387 self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
388 "Failed to add suggestions")
389
390 # Disable suggestions by the app.
391 self.set_approved(False)
392
393 # Ensure the app is not approved.
394 asserts.assert_false(
395 self.is_approved(),
396 "Suggestions should be disabled")
397
398 # Start a new scan to trigger auto-join.
399 wutils.start_wifi_connection_scan_and_ensure_network_found(
400 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
401
402 # Ensure we don't connect to the network.
403 asserts.assert_false(
404 wutils.wait_for_connect(
405 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
406 "Should not connect to network suggestions from unapproved app")
407
408 self.dut.log.info("Enabling suggestions from test");
409 # Now Enable suggestions by the app & ensure we connect to the network.
410 self.set_approved(True)
411
412 # Ensure the app is approved.
413 asserts.assert_true(
414 self.is_approved(),
415 "Suggestions should be enabled")
416
417 # Start a new scan to trigger auto-join.
418 wutils.start_wifi_connection_scan_and_ensure_network_found(
419 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
420
421 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Pius89b22bd2019-01-24 14:12:49 -0800422
Roshan Pius3d57f132019-01-28 10:25:18 -0800423 @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800424 def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self):
425 """
426 Adds a network suggestion and ensures that the device does not
427 connect to it after the user forgot the network previously.
428
429 Steps:
430 1. Send a network suggestion to the device with
431 isAppInteractionRequired set.
432 2. Wait for the device to connect to it.
433 3. Ensure that we did receive the post connection broadcast
434 (isAppInteractionRequired = True).
435 4. Simulate user forgetting the network and the device does not
436 connecting back even though the suggestion is active from the app.
437 """
438 network_suggestion = self.wpa_psk_2g
439 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
440 self.add_suggestions_and_ensure_connection(
441 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
442 True)
443
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700444 # Simulate user forgetting the ephemeral network.
Roshan Pius89b22bd2019-01-24 14:12:49 -0800445 self.dut.droid.wifiDisableEphemeralNetwork(
446 self.wpa_psk_2g[WifiEnums.SSID_KEY])
447 wutils.wait_for_disconnect(self.dut)
448 self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
449 self.dut.ed.clear_all_events()
450
451 # Now ensure that we don't connect back even though the suggestion
452 # is still active.
453 asserts.assert_false(
454 wutils.wait_for_connect(self.dut,
455 self.wpa_psk_2g[WifiEnums.SSID_KEY],
456 assert_on_fail=False),
457 "Device should not connect back")
Nate Jiang20af5e82019-08-08 12:45:24 -0700458
459 @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1")
460 def test_connect_to_hidden_network(self):
461 """
462 Adds a network suggestion with hidden SSID config, ensure device can scan
463 and connect to this network.
464
465 Steps:
466 1. Send a hidden network suggestion to the device.
467 2. Wait for the device to connect to it.
468 3. Ensure that we did not receive the post connection broadcast
469 (isAppInteractionRequired = False).
470 4. Remove the suggestions and ensure the device does not connect back.
471 """
472 asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test")
473
474 network_suggestion = self.hidden_network
475 self.add_suggestions_and_ensure_connection(
476 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False)
477 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
478 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700479
Girish Moturua5d28482019-10-23 10:15:37 -0700480 @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700481 def test_connect_to_passpoint_network_with_post_connection_broadcast(self):
482 """ Adds a passpoint network suggestion and ensure that the device connected.
483
484 Steps:
485 1. Send a network suggestion to the device.
486 2. Wait for the device to connect to it.
487 3. Ensure that we did receive the post connection broadcast
488 (isAppInteractionRequired = true).
489 4. Remove the suggestions and ensure the device does not connect back.
490 """
491 asserts.skip_if(not hasattr(self, "passpoint_networks"),
492 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700493 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700494 passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
495 self.add_suggestions_and_ensure_connection([passpoint_config],
496 passpoint_config[WifiEnums.SSID_KEY], True)
497 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
498 [passpoint_config], passpoint_config[WifiEnums.SSID_KEY])
499
Girish Moturua5d28482019-10-23 10:15:37 -0700500 @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700501 def test_connect_to_passpoint_network_reboot_config_store(self):
502 """
503 Adds a passpoint network suggestion and ensure that the device connects to it
504 after reboot.
505
506 Steps:
507 1. Send a network suggestion to the device.
508 2. Wait for the device to connect to it.
509 3. Ensure that we did not receive the post connection broadcast
510 (isAppInteractionRequired = False).
511 4. Reboot the device.
512 5. Wait for the device to connect to back to it.
513 6. Remove the suggestions and ensure the device does not connect back.
514 """
515 asserts.skip_if(not hasattr(self, "passpoint_networks"),
516 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700517 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700518 self._test_connect_to_wifi_network_reboot_config_store([passpoint_config],
519 passpoint_config)
520
Girish Moturua5d28482019-10-23 10:15:37 -0700521 @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700522 def test_fail_to_connect_to_passpoint_network_when_not_approved(self):
523 """
524 Adds a passpoint network suggestion and ensure that the device does not
525 connect to it until we approve the app.
526
527 Steps:
528 1. Send a network suggestion to the device with the app not approved.
529 2. Ensure the network is present in scan results, but we don't connect
530 to it.
531 3. Now approve the app.
532 4. Wait for the device to connect to it.
533 """
534 asserts.skip_if(not hasattr(self, "passpoint_networks"),
535 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700536 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700537 self.dut.log.info("Adding network suggestions")
538 asserts.assert_true(
539 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
540 "Failed to add suggestions")
541
542 # Disable suggestions by the app.
543 self.set_approved(False)
544
545 # Ensure the app is not approved.
546 asserts.assert_false(
547 self.is_approved(),
548 "Suggestions should be disabled")
549
550 # Start a new scan to trigger auto-join.
551 wutils.start_wifi_connection_scan_and_ensure_network_found(
552 self.dut, passpoint_config[WifiEnums.SSID_KEY])
553
554 # Ensure we don't connect to the network.
555 asserts.assert_false(
556 wutils.wait_for_connect(
557 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
558 "Should not connect to network suggestions from unapproved app")
559
560 self.dut.log.info("Enabling suggestions from test");
561 # Now Enable suggestions by the app & ensure we connect to the network.
562 self.set_approved(True)
563
564 # Ensure the app is approved.
565 asserts.assert_true(
566 self.is_approved(),
567 "Suggestions should be enabled")
568
569 # Start a new scan to trigger auto-join.
570 wutils.start_wifi_connection_scan_and_ensure_network_found(
571 self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700572 time.sleep(PASSPOINT_TIMEOUT)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700573 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])