blob: d398f53153c468d68522b625b59091031ecfaa7c [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
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800141 def set_carrier_approved(self, carrier_id, approved):
142 self.dut.log.debug(("Setting IMSI protection exemption for carrier: " + carrier_id
143 + "approved" if approved else "not approved"))
144 self.dut.adb.shell("cmd wifi imsi-protection-exemption-set-user-approved-for-carrier"
145 + " " + carrier_id
146 + " " + ("yes" if approved else "no"))
147
148 def is_carrier_approved(self, carrier_id):
149 is_approved_str = self.dut.adb.shell(
150 "cmd wifi imsi-protection-exemption-has-user-approved-for-carrier"
151 + " " + carrier_id)
152 return True if (is_approved_str == "yes") else False
153
154 def clear_carrier_approved(self, carrier_id):
155 self.dut.adb.shell(
156 "cmd wifi imsi-protection-exemption-clear-user-approved-for-carrier"
157 + " " + carrier_id)
158
Roshan Pius89b22bd2019-01-24 14:12:49 -0800159 def clear_deleted_ephemeral_networks(self):
160 self.dut.log.debug("Clearing deleted ephemeral networks")
161 self.dut.adb.shell(
162 "cmd wifi clear-deleted-ephemeral-networks")
163
Roshan Piusd1204442018-11-12 12:20:39 -0800164 def add_suggestions_and_ensure_connection(self, network_suggestions,
165 expected_ssid,
166 expect_post_connection_broadcast):
Roshan Pius3702f242019-02-28 09:14:40 -0800167 if expect_post_connection_broadcast is not None:
168 self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange()
169
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800170 self.dut.log.info("Adding network suggestions")
Roshan Piusd1204442018-11-12 12:20:39 -0800171 asserts.assert_true(
172 self.dut.droid.wifiAddNetworkSuggestions(network_suggestions),
173 "Failed to add suggestions")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800174 # Enable suggestions by the app.
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700175 self.dut.log.debug("Enabling suggestions from test")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800176 self.set_approved(True)
lutina49d3e512019-07-05 14:42:33 +0800177 wutils.start_wifi_connection_scan_and_return_status(self.dut)
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700178 # if suggestion is passpoint wait longer for connection.
179 if "profile" in network_suggestions:
180 time.sleep(PASSPOINT_TIMEOUT)
Roshan Piusd1204442018-11-12 12:20:39 -0800181 wutils.wait_for_connect(self.dut, expected_ssid)
182
183 if expect_post_connection_broadcast is None:
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700184 return
Roshan Piusd1204442018-11-12 12:20:39 -0800185
186 # Check if we expected to get the broadcast.
187 try:
Roshan Piusd1204442018-11-12 12:20:39 -0800188 event = self.dut.ed.pop_event(
189 wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60)
Roshan Piusd1204442018-11-12 12:20:39 -0800190 except queue.Empty:
191 if expect_post_connection_broadcast:
192 raise signals.TestFailure(
193 "Did not receive post connection broadcast")
194 else:
195 if not expect_post_connection_broadcast:
196 raise signals.TestFailure(
197 "Received post connection broadcast")
Roshan Pius3702f242019-02-28 09:14:40 -0800198 finally:
199 self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange()
Roshan Piusff6ca4c2019-03-26 13:53:31 -0700200 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800201
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700202 def remove_suggestions_disconnect_and_ensure_no_connection_back(self,
203 network_suggestions,
204 expected_ssid):
205 # Remove suggestion trigger disconnect and wait for the disconnect.
206 self.dut.log.info("Removing network suggestions")
207 asserts.assert_true(
208 self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions),
209 "Failed to remove suggestions")
210 wutils.wait_for_disconnect(self.dut)
211 self.dut.ed.clear_all_events()
212
213 # Now ensure that we didn't connect back.
214 asserts.assert_false(
215 wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False),
216 "Device should not connect back")
217
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700218 def _test_connect_to_wifi_network_reboot_config_store(self,
219 network_suggestions,
220 wifi_network):
221 """ Test network suggestion with reboot config store
222
223 Args:
224 1. network_suggestions: network suggestions in list to add to the device.
225 2. wifi_network: expected wifi network to connect to
226 """
227
228 self.add_suggestions_and_ensure_connection(
229 network_suggestions, wifi_network[WifiEnums.SSID_KEY], None)
230
231 # Reboot and wait for connection back to the same suggestion.
232 self.dut.reboot()
233 time.sleep(DEFAULT_TIMEOUT)
234
235 wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY])
236
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700237 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
238 network_suggestions, wifi_network[WifiEnums.SSID_KEY])
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700239
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800240 # Reboot with empty suggestion, verify user approval is kept.
241 self.dut.reboot()
242 time.sleep(DEFAULT_TIMEOUT)
243 asserts.assert_true(self.is_approved(), "User approval should be kept")
244
Roshan Piusf028bd32018-12-06 15:18:21 -0800245 @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108")
Roshan Piusd1204442018-11-12 12:20:39 -0800246 def test_connect_to_wpa_psk_2g(self):
247 """ Adds a network suggestion and ensure that the device connected.
248
249 Steps:
250 1. Send a network suggestion to the device.
251 2. Wait for the device to connect to it.
252 3. Ensure that we did not receive the post connection broadcast
253 (isAppInteractionRequired = False).
Roshan Piusffc29912019-01-18 13:39:49 -0800254 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800255 """
256 self.add_suggestions_and_ensure_connection(
257 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY],
258 False)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700259
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700260 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
261 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800262
Roshan Piusc6fceca2019-03-22 13:23:58 -0700263 @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43")
264 def test_connect_to_highest_priority(self):
265 """
266 Adds network suggestions and ensures that device connects to
267 the suggestion with the highest priority.
268
269 Steps:
270 1. Send 2 network suggestions to the device (with different priorities).
271 2. Wait for the device to connect to the network with the highest
272 priority.
Nate Jiang172c6902019-09-09 17:54:33 -0700273 3. In-place modify network suggestions with priorities reversed
274 4. Restart wifi, wait for the device to connect to the network with the highest
275 priority.
276 5. Re-add the suggestions with the priorities reversed again.
277 6. Again wait for the device to connect to the network with the highest
Roshan Piusc6fceca2019-03-22 13:23:58 -0700278 priority.
279 """
280 network_suggestion_2g = self.wpa_psk_2g
281 network_suggestion_5g = self.wpa_psk_5g
282
283 # Add suggestions & wait for the connection event.
284 network_suggestion_2g[WifiEnums.PRIORITY] = 5
285 network_suggestion_5g[WifiEnums.PRIORITY] = 2
286 self.add_suggestions_and_ensure_connection(
287 [network_suggestion_2g, network_suggestion_5g],
288 self.wpa_psk_2g[WifiEnums.SSID_KEY],
289 None)
290
Nate Jiang172c6902019-09-09 17:54:33 -0700291 # In-place modify Reverse the priority, should be no disconnect
292 network_suggestion_2g[WifiEnums.PRIORITY] = 2
293 network_suggestion_5g[WifiEnums.PRIORITY] = 5
294 self.dut.log.info("Modifying network suggestions");
295 asserts.assert_true(
296 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g,
297 network_suggestion_5g]),
298 "Failed to add suggestions")
299 wutils.ensure_no_disconnect(self.dut)
300
301 # Disable and re-enable wifi, should connect to higher priority
302 wutils.wifi_toggle_state(self.dut, False)
303 time.sleep(DEFAULT_TIMEOUT)
304 wutils.wifi_toggle_state(self.dut, True)
305 wutils.start_wifi_connection_scan_and_return_status(self.dut)
306 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
307
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700308 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
Nate Jiang0878aef2019-09-16 13:33:26 -0700309 [], self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Piusc6fceca2019-03-22 13:23:58 -0700310
311 # Reverse the priority.
312 # Add suggestions & wait for the connection event.
Nate Jiang172c6902019-09-09 17:54:33 -0700313 network_suggestion_2g[WifiEnums.PRIORITY] = 5
314 network_suggestion_5g[WifiEnums.PRIORITY] = 2
Roshan Piusc6fceca2019-03-22 13:23:58 -0700315 self.add_suggestions_and_ensure_connection(
316 [network_suggestion_2g, network_suggestion_5g],
Nate Jiang0878aef2019-09-16 13:33:26 -0700317 self.wpa_psk_2g[WifiEnums.SSID_KEY],
Roshan Piusc6fceca2019-03-22 13:23:58 -0700318 None)
319
Roshan Piusf028bd32018-12-06 15:18:21 -0800320 @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f")
Roshan Piusd1204442018-11-12 12:20:39 -0800321 def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self):
322 """ Adds a network suggestion and ensure that the device connected.
323
324 Steps:
325 1. Send a network suggestion to the device with
326 isAppInteractionRequired set.
327 2. Wait for the device to connect to it.
328 3. Ensure that we did receive the post connection broadcast
329 (isAppInteractionRequired = True).
Roshan Piusffc29912019-01-18 13:39:49 -0800330 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800331 """
332 network_suggestion = self.wpa_psk_2g
333 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
334 self.add_suggestions_and_ensure_connection(
335 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
336 True)
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700337 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
338 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800339
Roshan Piusf028bd32018-12-06 15:18:21 -0800340 @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710")
Roshan Piusd1204442018-11-12 12:20:39 -0800341 def test_connect_to_wpa_psk_5g_reboot_config_store(self):
342 """
343 Adds a network suggestion and ensure that the device connects to it
344 after reboot.
345
346 Steps:
347 1. Send a network suggestion to the device.
348 2. Wait for the device to connect to it.
349 3. Ensure that we did not receive the post connection broadcast
350 (isAppInteractionRequired = False).
351 4. Reboot the device.
352 5. Wait for the device to connect to back to it.
Roshan Piusffc29912019-01-18 13:39:49 -0800353 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800354 7. Reboot the device again, ensure user approval is kept
Roshan Piusd1204442018-11-12 12:20:39 -0800355 """
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700356 self._test_connect_to_wifi_network_reboot_config_store(
357 [self.wpa_psk_5g], self.wpa_psk_5g)
Roshan Piusd1204442018-11-12 12:20:39 -0800358
Girish Moturuc2033ae2019-07-31 09:04:36 -0700359 @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700360 def test_connect_to_wpa_ent_config_aka_reboot_config_store(self):
361 """
362 Adds a network suggestion and ensure that the device connects to it
363 after reboot.
Roshan Piusd1204442018-11-12 12:20:39 -0800364
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700365 Steps:
366 1. Send a Enterprise AKA network suggestion to the device.
367 2. Wait for the device to connect to it.
368 3. Ensure that we did not receive the post connection broadcast.
369 4. Reboot the device.
370 5. Wait for the device to connect to the wifi network.
371 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800372 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700373 """
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800374 if "carrierId" in self.config_aka:
375 self.set_carrier_approved(self.config_aka["carrierId"], True)
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700376 self._test_connect_to_wifi_network_reboot_config_store(
377 [self.config_aka], self.ent_network_2g)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800378 if "carrierId" in self.config_aka:
379 self.clear_carrier_approved(self.config_aka["carrierId"])
Roshan Piusd1204442018-11-12 12:20:39 -0800380
Girish Moturuc2033ae2019-07-31 09:04:36 -0700381 @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700382 def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self):
383 """
384 Adds a network suggestion and ensure that the device connects to it
385 after reboot.
Roshan Piusffc29912019-01-18 13:39:49 -0800386
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700387 Steps:
388 1. Send a Enterprise TTLS PAP network suggestion to the device.
389 2. Wait for the device to connect to it.
390 3. Ensure that we did not receive the post connection broadcast.
391 4. Reboot the device.
392 5. Wait for the device to connect to the wifi network.
393 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800394 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700395 """
396 config = dict(self.config_ttls)
397 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
398
399 self._test_connect_to_wifi_network_reboot_config_store(
400 [config], self.ent_network_2g)
Roshan Piusffc29912019-01-18 13:39:49 -0800401
Roshan Pius3e3bd342019-01-09 13:55:17 -0800402 @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb")
403 def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
404 """
405 Adds a network suggestion and ensure that the device does not
406 connect to it until we approve the app.
407
408 Steps:
409 1. Send a network suggestion to the device with the app not approved.
410 2. Ensure the network is present in scan results, but we don't connect
411 to it.
412 3. Now approve the app.
413 4. Wait for the device to connect to it.
414 """
415 self.dut.log.info("Adding network suggestions");
416 asserts.assert_true(
417 self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
418 "Failed to add suggestions")
419
420 # Disable suggestions by the app.
421 self.set_approved(False)
422
423 # Ensure the app is not approved.
424 asserts.assert_false(
425 self.is_approved(),
426 "Suggestions should be disabled")
427
428 # Start a new scan to trigger auto-join.
429 wutils.start_wifi_connection_scan_and_ensure_network_found(
430 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
431
432 # Ensure we don't connect to the network.
433 asserts.assert_false(
434 wutils.wait_for_connect(
435 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
436 "Should not connect to network suggestions from unapproved app")
437
438 self.dut.log.info("Enabling suggestions from test");
439 # Now Enable suggestions by the app & ensure we connect to the network.
440 self.set_approved(True)
441
442 # Ensure the app is approved.
443 asserts.assert_true(
444 self.is_approved(),
445 "Suggestions should be enabled")
446
447 # Start a new scan to trigger auto-join.
448 wutils.start_wifi_connection_scan_and_ensure_network_found(
449 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
450
451 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Pius89b22bd2019-01-24 14:12:49 -0800452
Roshan Pius3d57f132019-01-28 10:25:18 -0800453 @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800454 def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self):
455 """
456 Adds a network suggestion and ensures that the device does not
457 connect to it after the user forgot the network previously.
458
459 Steps:
460 1. Send a network suggestion to the device with
461 isAppInteractionRequired set.
462 2. Wait for the device to connect to it.
463 3. Ensure that we did receive the post connection broadcast
464 (isAppInteractionRequired = True).
465 4. Simulate user forgetting the network and the device does not
466 connecting back even though the suggestion is active from the app.
467 """
468 network_suggestion = self.wpa_psk_2g
469 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
470 self.add_suggestions_and_ensure_connection(
471 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
472 True)
473
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700474 # Simulate user forgetting the ephemeral network.
Roshan Pius89b22bd2019-01-24 14:12:49 -0800475 self.dut.droid.wifiDisableEphemeralNetwork(
476 self.wpa_psk_2g[WifiEnums.SSID_KEY])
477 wutils.wait_for_disconnect(self.dut)
478 self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
479 self.dut.ed.clear_all_events()
480
481 # Now ensure that we don't connect back even though the suggestion
482 # is still active.
483 asserts.assert_false(
484 wutils.wait_for_connect(self.dut,
485 self.wpa_psk_2g[WifiEnums.SSID_KEY],
486 assert_on_fail=False),
487 "Device should not connect back")
Nate Jiang20af5e82019-08-08 12:45:24 -0700488
489 @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1")
490 def test_connect_to_hidden_network(self):
491 """
492 Adds a network suggestion with hidden SSID config, ensure device can scan
493 and connect to this network.
494
495 Steps:
496 1. Send a hidden network suggestion to the device.
497 2. Wait for the device to connect to it.
498 3. Ensure that we did not receive the post connection broadcast
499 (isAppInteractionRequired = False).
500 4. Remove the suggestions and ensure the device does not connect back.
501 """
502 asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test")
503
504 network_suggestion = self.hidden_network
505 self.add_suggestions_and_ensure_connection(
506 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False)
507 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
508 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700509
Girish Moturua5d28482019-10-23 10:15:37 -0700510 @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700511 def test_connect_to_passpoint_network_with_post_connection_broadcast(self):
512 """ Adds a passpoint network suggestion and ensure that the device connected.
513
514 Steps:
515 1. Send a network suggestion to the device.
516 2. Wait for the device to connect to it.
517 3. Ensure that we did receive the post connection broadcast
518 (isAppInteractionRequired = true).
519 4. Remove the suggestions and ensure the device does not connect back.
520 """
521 asserts.skip_if(not hasattr(self, "passpoint_networks"),
522 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700523 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700524 passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800525 if "carrierId" in passpoint_config:
526 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700527 self.add_suggestions_and_ensure_connection([passpoint_config],
528 passpoint_config[WifiEnums.SSID_KEY], True)
529 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
530 [passpoint_config], passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800531 if "carrierId" in passpoint_config:
532 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700533
Girish Moturua5d28482019-10-23 10:15:37 -0700534 @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700535 def test_connect_to_passpoint_network_reboot_config_store(self):
536 """
537 Adds a passpoint network suggestion and ensure that the device connects to it
538 after reboot.
539
540 Steps:
541 1. Send a network suggestion to the device.
542 2. Wait for the device to connect to it.
543 3. Ensure that we did not receive the post connection broadcast
544 (isAppInteractionRequired = False).
545 4. Reboot the device.
546 5. Wait for the device to connect to back to it.
547 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800548 7. Reboot the device again, ensure user approval is kept
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700549 """
550 asserts.skip_if(not hasattr(self, "passpoint_networks"),
551 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700552 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800553 if "carrierId" in passpoint_config:
554 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700555 self._test_connect_to_wifi_network_reboot_config_store([passpoint_config],
556 passpoint_config)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800557 if "carrierId" in passpoint_config:
558 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700559
Girish Moturua5d28482019-10-23 10:15:37 -0700560 @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700561 def test_fail_to_connect_to_passpoint_network_when_not_approved(self):
562 """
563 Adds a passpoint network suggestion and ensure that the device does not
564 connect to it until we approve the app.
565
566 Steps:
567 1. Send a network suggestion to the device with the app not approved.
568 2. Ensure the network is present in scan results, but we don't connect
569 to it.
570 3. Now approve the app.
571 4. Wait for the device to connect to it.
572 """
573 asserts.skip_if(not hasattr(self, "passpoint_networks"),
574 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700575 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700576 self.dut.log.info("Adding network suggestions")
577 asserts.assert_true(
578 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
579 "Failed to add suggestions")
580
581 # Disable suggestions by the app.
582 self.set_approved(False)
583
584 # Ensure the app is not approved.
585 asserts.assert_false(
586 self.is_approved(),
587 "Suggestions should be disabled")
588
589 # Start a new scan to trigger auto-join.
590 wutils.start_wifi_connection_scan_and_ensure_network_found(
591 self.dut, passpoint_config[WifiEnums.SSID_KEY])
592
593 # Ensure we don't connect to the network.
594 asserts.assert_false(
595 wutils.wait_for_connect(
596 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
597 "Should not connect to network suggestions from unapproved app")
598
599 self.dut.log.info("Enabling suggestions from test");
600 # Now Enable suggestions by the app & ensure we connect to the network.
601 self.set_approved(True)
602
603 # Ensure the app is approved.
604 asserts.assert_true(
605 self.is_approved(),
606 "Suggestions should be enabled")
607
608 # Start a new scan to trigger auto-join.
609 wutils.start_wifi_connection_scan_and_ensure_network_found(
610 self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700611 time.sleep(PASSPOINT_TIMEOUT)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700612 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800613
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800614 @test_tracker_info(uuid="")
615 def test_fail_to_connect_to_passpoint_network_when_imsi_protection_exemption_not_approved(self):
616 """
617 Adds a passpoint network suggestion using SIM credential without IMSI privacy protection.
618 Before user approves the exemption, ensure that the device does noconnect to it until we
619 approve the carrier exemption.
620
621 Steps:
622 1. Send a network suggestion to the device with IMSI protection exemption not approved.
623 2. Ensure the network is present in scan results, but we don't connect
624 to it.
625 3. Now approve the carrier.
626 4. Wait for the device to connect to it.
627 """
628 asserts.skip_if(not hasattr(self, "passpoint_networks"),
629 "No passpoint networks, skip this test")
630 passpoint_config = self.passpoint_networks[ATT]
631 asserts.skip_if("carrierId" not in passpoint_config,
632 "Not a SIM based passpoint network, skip this test")
633
634 self.dut.log.info("Adding network suggestions")
635 asserts.assert_true(
636 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
637 "Failed to add suggestions")
638
639 # Ensure the carrier imsi protection exemption is not approved.
640 asserts.assert_false(
641 self.is_carrier_approved(passpoint_config["carrierId"]),
642 "Carrier should not be approved")
643
644 # Start a new scan to trigger auto-join.
645 wutils.start_wifi_connection_scan_and_ensure_network_found(
646 self.dut, passpoint_config[WifiEnums.SSID_KEY])
647
648 # Ensure we don't connect to the network.
649 asserts.assert_false(
650 wutils.wait_for_connect(
651 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
652 "Should not connect to network suggestions from unapproved app")
653
654 self.dut.log.info("Enabling suggestions from test")
655 # Now approve IMSI protection exemption by carrier & ensure we connect to the network.
656 self.set_carrier_approved(passpoint_config["carrierId"], True)
657
658 # Ensure the carrier is approved.
659 asserts.assert_true(
660 self.is_carrier_approved(passpoint_config["carrierId"]),
661 "Carrier should be approved")
662
663 # Start a new scan to trigger auto-join.
664 wutils.start_wifi_connection_scan_and_ensure_network_found(
665 self.dut, passpoint_config[WifiEnums.SSID_KEY])
666 time.sleep(PASSPOINT_TIMEOUT)
667 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
668 self.clear_carrier_approved(passpoint_config["carrierId"])
669
Girish Moturu31f58f22020-01-30 18:54:40 -0800670 @test_tracker_info(uuid="e35f99c8-78a4-4b96-9258-f9834b6ddd33")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800671 def test_initial_auto_join_on_network_suggestion(self):
672 """
673 Add a network suggestion with enableAutojoin bit set to false, ensure the device doesn't
674 auto connect to this network
675
676 Steps:
677 1. Create a network suggestion.
678 2. Set EnableAutojoin to false.
679 3. Add this suggestion
680 4. Ensure device doesn't connect to his network
681 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800682 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800683 # Set suggestion auto join initial to false.
684 network_suggestion["enableAutojoin"] = False
685 self.dut.log.info("Adding network suggestions")
686 asserts.assert_true(
687 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]),
688 "Failed to add suggestions")
689 # Enable suggestions by the app.
690 self.dut.log.debug("Enabling suggestions from test")
691 self.set_approved(True)
692 wutils.start_wifi_connection_scan_and_return_status(self.dut)
693 asserts.assert_false(
694 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
695 assert_on_fail=False), "Device should not connect.")
696
Girish Moturu31f58f22020-01-30 18:54:40 -0800697 @test_tracker_info(uuid="ff4e451f-a380-4ff5-a5c2-dd9b1633d5e5")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800698 def test_user_override_auto_join_on_network_suggestion(self):
699 """
700 Add a network suggestion, user change the auto join to false, ensure the device doesn't
701 auto connect to this network
702
703 Steps:
704 1. Create a network suggestion.
705 2. Add this suggestion, and ensure we connect to this network
706 3. Simulate user change the auto join to false.
707 4. Toggle the Wifi off and on
708 4. Ensure device doesn't connect to his network
709 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800710 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800711 self.add_suggestions_and_ensure_connection([network_suggestion],
712 network_suggestion[WifiEnums.SSID_KEY], False)
713 wifi_info = self.dut.droid.wifiGetConnectionInfo()
714 self.dut.log.info(wifi_info)
715 network_id = wifi_info[WifiEnums.NETID_KEY]
716 # Simulate user disable auto join through Settings.
717 self.dut.log.info("Disable auto join on suggestion")
718 self.dut.droid.wifiEnableAutojoin(network_id, False)
719 wutils.wifi_toggle_state(self.dut, False)
720 wutils.wifi_toggle_state(self.dut, True)
721 asserts.assert_false(
722 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
723 assert_on_fail=False), "Device should not connect.")