blob: 49c5bf8fe9e8d5dd1e8c4f16023ed825d921c812 [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
44
Nate Jiang1ef58c32019-07-15 19:13:26 -070045
Roshan Piusd1204442018-11-12 12:20:39 -080046class WifiNetworkSuggestionTest(WifiBaseTest):
47 """Tests for WifiNetworkSuggestion API surface.
48
49 Test Bed Requirement:
50 * one Android device
51 * Several Wi-Fi networks visible to the device, including an open Wi-Fi
52 network.
53 """
54
Roshan Piusd1204442018-11-12 12:20:39 -080055 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070056 super().setup_class()
57
Roshan Piusd1204442018-11-12 12:20:39 -080058 self.dut = self.android_devices[0]
59 wutils.wifi_test_device_init(self.dut)
Nate Jiang68f3ffa2019-08-07 15:23:49 -070060 req_params = []
Roshan Piusd1204442018-11-12 12:20:39 -080061 opt_param = [
Nate Jiang68f3ffa2019-08-07 15:23:49 -070062 "open_network", "reference_networks", "radius_conf_2g", "radius_conf_5g", "ca_cert",
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -070063 "eap_identity", "eap_password", "hidden_networks", "passpoint_networks"
Roshan Piusd1204442018-11-12 12:20:39 -080064 ]
65 self.unpack_userparams(
66 req_param_names=req_params, opt_param_names=opt_param)
67
68 if "AccessPoint" in self.user_params:
Girish Moturub1e7a5c2019-07-29 13:48:11 -070069 self.legacy_configure_ap_and_start(
70 wpa_network=True, ent_network=True,
71 radius_conf_2g=self.radius_conf_2g,
72 radius_conf_5g=self.radius_conf_5g,)
Roshan Piusd1204442018-11-12 12:20:39 -080073
Girish Moturua069a4a2019-10-23 13:21:42 -070074 if hasattr(self, "reference_networks") and \
75 isinstance(self.reference_networks, list):
76 self.wpa_psk_2g = self.reference_networks[0]["2g"]
77 self.wpa_psk_5g = self.reference_networks[0]["5g"]
78 if hasattr(self, "open_network") and isinstance(self.open_network,list):
Nate Jiang68f3ffa2019-08-07 15:23:49 -070079 self.open_2g = self.open_network[0]["2g"]
80 self.open_5g = self.open_network[0]["5g"]
Girish Moturua069a4a2019-10-23 13:21:42 -070081 if hasattr(self, "ent_networks") and isinstance(self.ent_networks,list):
Nate Jiang68f3ffa2019-08-07 15:23:49 -070082 self.ent_network_2g = self.ent_networks[0]["2g"]
83 self.ent_network_5g = self.ent_networks[0]["5g"]
84 self.config_aka = {
85 Ent.EAP: int(EAP.AKA),
86 WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY],
87 }
88 self.config_ttls = {
89 Ent.EAP: int(EAP.TTLS),
90 Ent.CA_CERT: self.ca_cert,
91 Ent.IDENTITY: self.eap_identity,
92 Ent.PASSWORD: self.eap_password,
93 Ent.PHASE2: int(EapPhase2.MSCHAPV2),
94 WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY],
95 }
Girish Moturua069a4a2019-10-23 13:21:42 -070096 if hasattr(self, "hidden_networks") and \
97 isinstance(self.hidden_networks, list):
98 self.hidden_network = self.hidden_networks[0]
Roshan Piusd1204442018-11-12 12:20:39 -080099 self.dut.droid.wifiRemoveNetworkSuggestions([])
100
101 def setup_test(self):
102 self.dut.droid.wakeLockAcquireBright()
103 self.dut.droid.wakeUpNow()
Roshan Pius89b22bd2019-01-24 14:12:49 -0800104 self.clear_deleted_ephemeral_networks()
Roshan Piusd1204442018-11-12 12:20:39 -0800105 wutils.wifi_toggle_state(self.dut, True)
Roshan Pius159222c2019-02-07 10:33:32 -0800106 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800107
108 def teardown_test(self):
109 self.dut.droid.wakeLockRelease()
110 self.dut.droid.goToSleepNow()
111 self.dut.droid.wifiRemoveNetworkSuggestions([])
Roshan Piusffc29912019-01-18 13:39:49 -0800112 self.dut.droid.wifiDisconnect()
Roshan Piusd1204442018-11-12 12:20:39 -0800113 wutils.reset_wifi(self.dut)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700114 wutils.wifi_toggle_state(self.dut, False)
Roshan Piusd1204442018-11-12 12:20:39 -0800115 self.dut.ed.clear_all_events()
116
117 def on_fail(self, test_name, begin_time):
118 self.dut.take_bug_report(test_name, begin_time)
119 self.dut.cat_adb_log(test_name, begin_time)
120
121 def teardown_class(self):
122 if "AccessPoint" in self.user_params:
123 del self.user_params["reference_networks"]
124 del self.user_params["open_network"]
125
126 """Helper Functions"""
Roshan Pius3e3bd342019-01-09 13:55:17 -0800127 def set_approved(self, approved):
128 self.dut.log.debug("Setting suggestions from sl4a app "
129 + "approved" if approved else "not approved")
130 self.dut.adb.shell("cmd wifi network-suggestions-set-user-approved"
131 + " " + SL4A_APK_NAME
132 + " " + ("yes" if approved else "no"))
133
134 def is_approved(self):
135 is_approved_str = self.dut.adb.shell(
136 "cmd wifi network-suggestions-has-user-approved"
137 + " " + SL4A_APK_NAME)
138 return True if (is_approved_str == "yes") else False
139
Roshan Pius89b22bd2019-01-24 14:12:49 -0800140 def clear_deleted_ephemeral_networks(self):
141 self.dut.log.debug("Clearing deleted ephemeral networks")
142 self.dut.adb.shell(
143 "cmd wifi clear-deleted-ephemeral-networks")
144
Roshan Piusd1204442018-11-12 12:20:39 -0800145 def add_suggestions_and_ensure_connection(self, network_suggestions,
146 expected_ssid,
147 expect_post_connection_broadcast):
Roshan Pius3702f242019-02-28 09:14:40 -0800148 if expect_post_connection_broadcast is not None:
149 self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange()
150
Roshan Piusd1204442018-11-12 12:20:39 -0800151 self.dut.log.info("Adding network suggestions");
152 asserts.assert_true(
153 self.dut.droid.wifiAddNetworkSuggestions(network_suggestions),
154 "Failed to add suggestions")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800155 # Enable suggestions by the app.
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700156 self.dut.log.debug("Enabling suggestions from test")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800157 self.set_approved(True)
lutina49d3e512019-07-05 14:42:33 +0800158 wutils.start_wifi_connection_scan_and_return_status(self.dut)
Roshan Piusd1204442018-11-12 12:20:39 -0800159 wutils.wait_for_connect(self.dut, expected_ssid)
160
161 if expect_post_connection_broadcast is None:
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700162 return
Roshan Piusd1204442018-11-12 12:20:39 -0800163
164 # Check if we expected to get the broadcast.
165 try:
Roshan Piusd1204442018-11-12 12:20:39 -0800166 event = self.dut.ed.pop_event(
167 wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60)
Roshan Piusd1204442018-11-12 12:20:39 -0800168 except queue.Empty:
169 if expect_post_connection_broadcast:
170 raise signals.TestFailure(
171 "Did not receive post connection broadcast")
172 else:
173 if not expect_post_connection_broadcast:
174 raise signals.TestFailure(
175 "Received post connection broadcast")
Roshan Pius3702f242019-02-28 09:14:40 -0800176 finally:
177 self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange()
Roshan Piusff6ca4c2019-03-26 13:53:31 -0700178 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800179
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700180 def remove_suggestions_disconnect_and_ensure_no_connection_back(self,
181 network_suggestions,
182 expected_ssid):
183 # Remove suggestion trigger disconnect and wait for the disconnect.
184 self.dut.log.info("Removing network suggestions")
185 asserts.assert_true(
186 self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions),
187 "Failed to remove suggestions")
188 wutils.wait_for_disconnect(self.dut)
189 self.dut.ed.clear_all_events()
190
191 # Now ensure that we didn't connect back.
192 asserts.assert_false(
193 wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False),
194 "Device should not connect back")
195
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700196 def _test_connect_to_wifi_network_reboot_config_store(self,
197 network_suggestions,
198 wifi_network):
199 """ Test network suggestion with reboot config store
200
201 Args:
202 1. network_suggestions: network suggestions in list to add to the device.
203 2. wifi_network: expected wifi network to connect to
204 """
205
206 self.add_suggestions_and_ensure_connection(
207 network_suggestions, wifi_network[WifiEnums.SSID_KEY], None)
208
209 # Reboot and wait for connection back to the same suggestion.
210 self.dut.reboot()
211 time.sleep(DEFAULT_TIMEOUT)
212
213 wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY])
214
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700215 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
216 network_suggestions, wifi_network[WifiEnums.SSID_KEY])
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700217
Roshan Piusf028bd32018-12-06 15:18:21 -0800218 @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108")
Roshan Piusd1204442018-11-12 12:20:39 -0800219 def test_connect_to_wpa_psk_2g(self):
220 """ Adds a network suggestion and ensure that the device connected.
221
222 Steps:
223 1. Send a network suggestion to the device.
224 2. Wait for the device to connect to it.
225 3. Ensure that we did not receive the post connection broadcast
226 (isAppInteractionRequired = False).
Roshan Piusffc29912019-01-18 13:39:49 -0800227 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800228 """
229 self.add_suggestions_and_ensure_connection(
230 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY],
231 False)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700232
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700233 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
234 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800235
Roshan Piusc6fceca2019-03-22 13:23:58 -0700236 @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43")
237 def test_connect_to_highest_priority(self):
238 """
239 Adds network suggestions and ensures that device connects to
240 the suggestion with the highest priority.
241
242 Steps:
243 1. Send 2 network suggestions to the device (with different priorities).
244 2. Wait for the device to connect to the network with the highest
245 priority.
Nate Jiang172c6902019-09-09 17:54:33 -0700246 3. In-place modify network suggestions with priorities reversed
247 4. Restart wifi, wait for the device to connect to the network with the highest
248 priority.
249 5. Re-add the suggestions with the priorities reversed again.
250 6. Again wait for the device to connect to the network with the highest
Roshan Piusc6fceca2019-03-22 13:23:58 -0700251 priority.
252 """
253 network_suggestion_2g = self.wpa_psk_2g
254 network_suggestion_5g = self.wpa_psk_5g
255
256 # Add suggestions & wait for the connection event.
257 network_suggestion_2g[WifiEnums.PRIORITY] = 5
258 network_suggestion_5g[WifiEnums.PRIORITY] = 2
259 self.add_suggestions_and_ensure_connection(
260 [network_suggestion_2g, network_suggestion_5g],
261 self.wpa_psk_2g[WifiEnums.SSID_KEY],
262 None)
263
Nate Jiang172c6902019-09-09 17:54:33 -0700264 # In-place modify Reverse the priority, should be no disconnect
265 network_suggestion_2g[WifiEnums.PRIORITY] = 2
266 network_suggestion_5g[WifiEnums.PRIORITY] = 5
267 self.dut.log.info("Modifying network suggestions");
268 asserts.assert_true(
269 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g,
270 network_suggestion_5g]),
271 "Failed to add suggestions")
272 wutils.ensure_no_disconnect(self.dut)
273
274 # Disable and re-enable wifi, should connect to higher priority
275 wutils.wifi_toggle_state(self.dut, False)
276 time.sleep(DEFAULT_TIMEOUT)
277 wutils.wifi_toggle_state(self.dut, True)
278 wutils.start_wifi_connection_scan_and_return_status(self.dut)
279 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
280
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700281 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
Nate Jiang0878aef2019-09-16 13:33:26 -0700282 [], self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Piusc6fceca2019-03-22 13:23:58 -0700283
284 # Reverse the priority.
285 # Add suggestions & wait for the connection event.
Nate Jiang172c6902019-09-09 17:54:33 -0700286 network_suggestion_2g[WifiEnums.PRIORITY] = 5
287 network_suggestion_5g[WifiEnums.PRIORITY] = 2
Roshan Piusc6fceca2019-03-22 13:23:58 -0700288 self.add_suggestions_and_ensure_connection(
289 [network_suggestion_2g, network_suggestion_5g],
Nate Jiang0878aef2019-09-16 13:33:26 -0700290 self.wpa_psk_2g[WifiEnums.SSID_KEY],
Roshan Piusc6fceca2019-03-22 13:23:58 -0700291 None)
292
Roshan Piusf028bd32018-12-06 15:18:21 -0800293 @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f")
Roshan Piusd1204442018-11-12 12:20:39 -0800294 def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self):
295 """ Adds a network suggestion and ensure that the device connected.
296
297 Steps:
298 1. Send a network suggestion to the device with
299 isAppInteractionRequired set.
300 2. Wait for the device to connect to it.
301 3. Ensure that we did receive the post connection broadcast
302 (isAppInteractionRequired = True).
Roshan Piusffc29912019-01-18 13:39:49 -0800303 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800304 """
305 network_suggestion = self.wpa_psk_2g
306 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
307 self.add_suggestions_and_ensure_connection(
308 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
309 True)
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700310 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
311 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800312
Roshan Piusf028bd32018-12-06 15:18:21 -0800313 @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710")
Roshan Piusd1204442018-11-12 12:20:39 -0800314 def test_connect_to_wpa_psk_5g_reboot_config_store(self):
315 """
316 Adds a network suggestion and ensure that the device connects to it
317 after reboot.
318
319 Steps:
320 1. Send a network suggestion to the device.
321 2. Wait for the device to connect to it.
322 3. Ensure that we did not receive the post connection broadcast
323 (isAppInteractionRequired = False).
324 4. Reboot the device.
325 5. Wait for the device to connect to back to it.
Roshan Piusffc29912019-01-18 13:39:49 -0800326 6. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800327 """
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700328 self._test_connect_to_wifi_network_reboot_config_store(
329 [self.wpa_psk_5g], self.wpa_psk_5g)
Roshan Piusd1204442018-11-12 12:20:39 -0800330
Girish Moturuc2033ae2019-07-31 09:04:36 -0700331 @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700332 def test_connect_to_wpa_ent_config_aka_reboot_config_store(self):
333 """
334 Adds a network suggestion and ensure that the device connects to it
335 after reboot.
Roshan Piusd1204442018-11-12 12:20:39 -0800336
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700337 Steps:
338 1. Send a Enterprise AKA network suggestion to the device.
339 2. Wait for the device to connect to it.
340 3. Ensure that we did not receive the post connection broadcast.
341 4. Reboot the device.
342 5. Wait for the device to connect to the wifi network.
343 6. Remove suggestions and ensure device doesn't connect back to it.
344 """
345 self._test_connect_to_wifi_network_reboot_config_store(
346 [self.config_aka], self.ent_network_2g)
Roshan Piusd1204442018-11-12 12:20:39 -0800347
Girish Moturuc2033ae2019-07-31 09:04:36 -0700348 @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700349 def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self):
350 """
351 Adds a network suggestion and ensure that the device connects to it
352 after reboot.
Roshan Piusffc29912019-01-18 13:39:49 -0800353
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700354 Steps:
355 1. Send a Enterprise TTLS PAP network suggestion to the device.
356 2. Wait for the device to connect to it.
357 3. Ensure that we did not receive the post connection broadcast.
358 4. Reboot the device.
359 5. Wait for the device to connect to the wifi network.
360 6. Remove suggestions and ensure device doesn't connect back to it.
361 """
362 config = dict(self.config_ttls)
363 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
364
365 self._test_connect_to_wifi_network_reboot_config_store(
366 [config], self.ent_network_2g)
Roshan Piusffc29912019-01-18 13:39:49 -0800367
Roshan Pius3e3bd342019-01-09 13:55:17 -0800368 @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb")
369 def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
370 """
371 Adds a network suggestion and ensure that the device does not
372 connect to it until we approve the app.
373
374 Steps:
375 1. Send a network suggestion to the device with the app not approved.
376 2. Ensure the network is present in scan results, but we don't connect
377 to it.
378 3. Now approve the app.
379 4. Wait for the device to connect to it.
380 """
381 self.dut.log.info("Adding network suggestions");
382 asserts.assert_true(
383 self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
384 "Failed to add suggestions")
385
386 # Disable suggestions by the app.
387 self.set_approved(False)
388
389 # Ensure the app is not approved.
390 asserts.assert_false(
391 self.is_approved(),
392 "Suggestions should be disabled")
393
394 # Start a new scan to trigger auto-join.
395 wutils.start_wifi_connection_scan_and_ensure_network_found(
396 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
397
398 # Ensure we don't connect to the network.
399 asserts.assert_false(
400 wutils.wait_for_connect(
401 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
402 "Should not connect to network suggestions from unapproved app")
403
404 self.dut.log.info("Enabling suggestions from test");
405 # Now Enable suggestions by the app & ensure we connect to the network.
406 self.set_approved(True)
407
408 # Ensure the app is approved.
409 asserts.assert_true(
410 self.is_approved(),
411 "Suggestions should be enabled")
412
413 # Start a new scan to trigger auto-join.
414 wutils.start_wifi_connection_scan_and_ensure_network_found(
415 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
416
417 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Pius89b22bd2019-01-24 14:12:49 -0800418
Roshan Pius3d57f132019-01-28 10:25:18 -0800419 @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800420 def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self):
421 """
422 Adds a network suggestion and ensures that the device does not
423 connect to it after the user forgot the network previously.
424
425 Steps:
426 1. Send a network suggestion to the device with
427 isAppInteractionRequired set.
428 2. Wait for the device to connect to it.
429 3. Ensure that we did receive the post connection broadcast
430 (isAppInteractionRequired = True).
431 4. Simulate user forgetting the network and the device does not
432 connecting back even though the suggestion is active from the app.
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)
439
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700440 # Simulate user forgetting the ephemeral network.
Roshan Pius89b22bd2019-01-24 14:12:49 -0800441 self.dut.droid.wifiDisableEphemeralNetwork(
442 self.wpa_psk_2g[WifiEnums.SSID_KEY])
443 wutils.wait_for_disconnect(self.dut)
444 self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
445 self.dut.ed.clear_all_events()
446
447 # Now ensure that we don't connect back even though the suggestion
448 # is still active.
449 asserts.assert_false(
450 wutils.wait_for_connect(self.dut,
451 self.wpa_psk_2g[WifiEnums.SSID_KEY],
452 assert_on_fail=False),
453 "Device should not connect back")
Nate Jiang20af5e82019-08-08 12:45:24 -0700454
455 @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1")
456 def test_connect_to_hidden_network(self):
457 """
458 Adds a network suggestion with hidden SSID config, ensure device can scan
459 and connect to this network.
460
461 Steps:
462 1. Send a hidden network suggestion to the device.
463 2. Wait for the device to connect to it.
464 3. Ensure that we did not receive the post connection broadcast
465 (isAppInteractionRequired = False).
466 4. Remove the suggestions and ensure the device does not connect back.
467 """
468 asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test")
469
470 network_suggestion = self.hidden_network
471 self.add_suggestions_and_ensure_connection(
472 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False)
473 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
474 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700475
Girish Moturua5d28482019-10-23 10:15:37 -0700476 @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700477 def test_connect_to_passpoint_network_with_post_connection_broadcast(self):
478 """ Adds a passpoint network suggestion and ensure that the device connected.
479
480 Steps:
481 1. Send a network suggestion to the device.
482 2. Wait for the device to connect to it.
483 3. Ensure that we did receive the post connection broadcast
484 (isAppInteractionRequired = true).
485 4. Remove the suggestions and ensure the device does not connect back.
486 """
487 asserts.skip_if(not hasattr(self, "passpoint_networks"),
488 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700489 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700490 passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
491 self.add_suggestions_and_ensure_connection([passpoint_config],
492 passpoint_config[WifiEnums.SSID_KEY], True)
493 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
494 [passpoint_config], passpoint_config[WifiEnums.SSID_KEY])
495
Girish Moturua5d28482019-10-23 10:15:37 -0700496 @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700497 def test_connect_to_passpoint_network_reboot_config_store(self):
498 """
499 Adds a passpoint network suggestion and ensure that the device connects to it
500 after reboot.
501
502 Steps:
503 1. Send a network suggestion to the device.
504 2. Wait for the device to connect to it.
505 3. Ensure that we did not receive the post connection broadcast
506 (isAppInteractionRequired = False).
507 4. Reboot the device.
508 5. Wait for the device to connect to back to it.
509 6. Remove the suggestions and ensure the device does not connect back.
510 """
511 asserts.skip_if(not hasattr(self, "passpoint_networks"),
512 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700513 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700514 self._test_connect_to_wifi_network_reboot_config_store([passpoint_config],
515 passpoint_config)
516
Girish Moturua5d28482019-10-23 10:15:37 -0700517 @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700518 def test_fail_to_connect_to_passpoint_network_when_not_approved(self):
519 """
520 Adds a passpoint network suggestion and ensure that the device does not
521 connect to it until we approve the app.
522
523 Steps:
524 1. Send a network suggestion to the device with the app not approved.
525 2. Ensure the network is present in scan results, but we don't connect
526 to it.
527 3. Now approve the app.
528 4. Wait for the device to connect to it.
529 """
530 asserts.skip_if(not hasattr(self, "passpoint_networks"),
531 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700532 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700533 self.dut.log.info("Adding network suggestions")
534 asserts.assert_true(
535 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
536 "Failed to add suggestions")
537
538 # Disable suggestions by the app.
539 self.set_approved(False)
540
541 # Ensure the app is not approved.
542 asserts.assert_false(
543 self.is_approved(),
544 "Suggestions should be disabled")
545
546 # Start a new scan to trigger auto-join.
547 wutils.start_wifi_connection_scan_and_ensure_network_found(
548 self.dut, passpoint_config[WifiEnums.SSID_KEY])
549
550 # Ensure we don't connect to the network.
551 asserts.assert_false(
552 wutils.wait_for_connect(
553 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
554 "Should not connect to network suggestions from unapproved app")
555
556 self.dut.log.info("Enabling suggestions from test");
557 # Now Enable suggestions by the app & ensure we connect to the network.
558 self.set_approved(True)
559
560 # Ensure the app is approved.
561 asserts.assert_true(
562 self.is_approved(),
563 "Suggestions should be enabled")
564
565 # Start a new scan to trigger auto-join.
566 wutils.start_wifi_connection_scan_and_ensure_network_found(
567 self.dut, passpoint_config[WifiEnums.SSID_KEY])
568
569 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
570