blob: 1cd3911099e7cf9a48afd05ee097d2e312aec864 [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],
Girish Moturu7e30c782020-02-05 12:37:06 -080088 "carrierId": str(self.dut.droid.telephonyGetSimCarrierId()),
Nate Jiang68f3ffa2019-08-07 15:23:49 -070089 }
90 self.config_ttls = {
91 Ent.EAP: int(EAP.TTLS),
92 Ent.CA_CERT: self.ca_cert,
93 Ent.IDENTITY: self.eap_identity,
94 Ent.PASSWORD: self.eap_password,
95 Ent.PHASE2: int(EapPhase2.MSCHAPV2),
96 WifiEnums.SSID_KEY: self.ent_network_2g[WifiEnums.SSID_KEY],
97 }
Girish Moturua069a4a2019-10-23 13:21:42 -070098 if hasattr(self, "hidden_networks") and \
99 isinstance(self.hidden_networks, list):
100 self.hidden_network = self.hidden_networks[0]
Roshan Piusd1204442018-11-12 12:20:39 -0800101 self.dut.droid.wifiRemoveNetworkSuggestions([])
102
103 def setup_test(self):
104 self.dut.droid.wakeLockAcquireBright()
105 self.dut.droid.wakeUpNow()
Roshan Pius89b22bd2019-01-24 14:12:49 -0800106 self.clear_deleted_ephemeral_networks()
Roshan Piusd1204442018-11-12 12:20:39 -0800107 wutils.wifi_toggle_state(self.dut, True)
Roshan Pius159222c2019-02-07 10:33:32 -0800108 self.dut.ed.clear_all_events()
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800109 self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId()))
Roshan Piusd1204442018-11-12 12:20:39 -0800110
111 def teardown_test(self):
112 self.dut.droid.wakeLockRelease()
113 self.dut.droid.goToSleepNow()
114 self.dut.droid.wifiRemoveNetworkSuggestions([])
Roshan Piusffc29912019-01-18 13:39:49 -0800115 self.dut.droid.wifiDisconnect()
Roshan Piusd1204442018-11-12 12:20:39 -0800116 wutils.reset_wifi(self.dut)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700117 wutils.wifi_toggle_state(self.dut, False)
Roshan Piusd1204442018-11-12 12:20:39 -0800118 self.dut.ed.clear_all_events()
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800119 self.clear_carrier_approved(str(self.dut.droid.telephonyGetSimCarrierId()))
Roshan Piusd1204442018-11-12 12:20:39 -0800120
121 def on_fail(self, test_name, begin_time):
122 self.dut.take_bug_report(test_name, begin_time)
123 self.dut.cat_adb_log(test_name, begin_time)
124
125 def teardown_class(self):
126 if "AccessPoint" in self.user_params:
127 del self.user_params["reference_networks"]
128 del self.user_params["open_network"]
129
130 """Helper Functions"""
Roshan Pius3e3bd342019-01-09 13:55:17 -0800131 def set_approved(self, approved):
132 self.dut.log.debug("Setting suggestions from sl4a app "
133 + "approved" if approved else "not approved")
134 self.dut.adb.shell("cmd wifi network-suggestions-set-user-approved"
135 + " " + SL4A_APK_NAME
136 + " " + ("yes" if approved else "no"))
137
138 def is_approved(self):
139 is_approved_str = self.dut.adb.shell(
140 "cmd wifi network-suggestions-has-user-approved"
141 + " " + SL4A_APK_NAME)
142 return True if (is_approved_str == "yes") else False
143
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800144 def set_carrier_approved(self, carrier_id, approved):
145 self.dut.log.debug(("Setting IMSI protection exemption for carrier: " + carrier_id
146 + "approved" if approved else "not approved"))
147 self.dut.adb.shell("cmd wifi imsi-protection-exemption-set-user-approved-for-carrier"
148 + " " + carrier_id
149 + " " + ("yes" if approved else "no"))
150
151 def is_carrier_approved(self, carrier_id):
152 is_approved_str = self.dut.adb.shell(
153 "cmd wifi imsi-protection-exemption-has-user-approved-for-carrier"
154 + " " + carrier_id)
155 return True if (is_approved_str == "yes") else False
156
157 def clear_carrier_approved(self, carrier_id):
158 self.dut.adb.shell(
159 "cmd wifi imsi-protection-exemption-clear-user-approved-for-carrier"
160 + " " + carrier_id)
161
Roshan Pius89b22bd2019-01-24 14:12:49 -0800162 def clear_deleted_ephemeral_networks(self):
163 self.dut.log.debug("Clearing deleted ephemeral networks")
164 self.dut.adb.shell(
165 "cmd wifi clear-deleted-ephemeral-networks")
166
Roshan Piusd1204442018-11-12 12:20:39 -0800167 def add_suggestions_and_ensure_connection(self, network_suggestions,
168 expected_ssid,
169 expect_post_connection_broadcast):
Roshan Pius3702f242019-02-28 09:14:40 -0800170 if expect_post_connection_broadcast is not None:
171 self.dut.droid.wifiStartTrackingNetworkSuggestionStateChange()
172
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800173 self.dut.log.info("Adding network suggestions")
Roshan Piusd1204442018-11-12 12:20:39 -0800174 asserts.assert_true(
175 self.dut.droid.wifiAddNetworkSuggestions(network_suggestions),
176 "Failed to add suggestions")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800177 # Enable suggestions by the app.
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700178 self.dut.log.debug("Enabling suggestions from test")
Roshan Pius3e3bd342019-01-09 13:55:17 -0800179 self.set_approved(True)
lutina49d3e512019-07-05 14:42:33 +0800180 wutils.start_wifi_connection_scan_and_return_status(self.dut)
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700181 # if suggestion is passpoint wait longer for connection.
182 if "profile" in network_suggestions:
183 time.sleep(PASSPOINT_TIMEOUT)
Roshan Piusd1204442018-11-12 12:20:39 -0800184 wutils.wait_for_connect(self.dut, expected_ssid)
185
186 if expect_post_connection_broadcast is None:
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700187 return
Roshan Piusd1204442018-11-12 12:20:39 -0800188
189 # Check if we expected to get the broadcast.
190 try:
Roshan Piusd1204442018-11-12 12:20:39 -0800191 event = self.dut.ed.pop_event(
192 wifi_constants.WIFI_NETWORK_SUGGESTION_POST_CONNECTION, 60)
Roshan Piusd1204442018-11-12 12:20:39 -0800193 except queue.Empty:
194 if expect_post_connection_broadcast:
195 raise signals.TestFailure(
196 "Did not receive post connection broadcast")
197 else:
198 if not expect_post_connection_broadcast:
199 raise signals.TestFailure(
200 "Received post connection broadcast")
Roshan Pius3702f242019-02-28 09:14:40 -0800201 finally:
202 self.dut.droid.wifiStopTrackingNetworkSuggestionStateChange()
Roshan Piusff6ca4c2019-03-26 13:53:31 -0700203 self.dut.ed.clear_all_events()
Roshan Piusd1204442018-11-12 12:20:39 -0800204
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700205 def remove_suggestions_disconnect_and_ensure_no_connection_back(self,
206 network_suggestions,
207 expected_ssid):
208 # Remove suggestion trigger disconnect and wait for the disconnect.
209 self.dut.log.info("Removing network suggestions")
210 asserts.assert_true(
211 self.dut.droid.wifiRemoveNetworkSuggestions(network_suggestions),
212 "Failed to remove suggestions")
213 wutils.wait_for_disconnect(self.dut)
214 self.dut.ed.clear_all_events()
215
216 # Now ensure that we didn't connect back.
217 asserts.assert_false(
218 wutils.wait_for_connect(self.dut, expected_ssid, assert_on_fail=False),
219 "Device should not connect back")
220
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700221 def _test_connect_to_wifi_network_reboot_config_store(self,
222 network_suggestions,
223 wifi_network):
224 """ Test network suggestion with reboot config store
225
226 Args:
227 1. network_suggestions: network suggestions in list to add to the device.
228 2. wifi_network: expected wifi network to connect to
229 """
230
231 self.add_suggestions_and_ensure_connection(
232 network_suggestions, wifi_network[WifiEnums.SSID_KEY], None)
233
234 # Reboot and wait for connection back to the same suggestion.
235 self.dut.reboot()
236 time.sleep(DEFAULT_TIMEOUT)
237
238 wutils.wait_for_connect(self.dut, wifi_network[WifiEnums.SSID_KEY])
239
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700240 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
241 network_suggestions, wifi_network[WifiEnums.SSID_KEY])
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700242
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800243 # Reboot with empty suggestion, verify user approval is kept.
244 self.dut.reboot()
245 time.sleep(DEFAULT_TIMEOUT)
246 asserts.assert_true(self.is_approved(), "User approval should be kept")
247
Roshan Piusf028bd32018-12-06 15:18:21 -0800248 @test_tracker_info(uuid="bda8ed20-4382-4380-831a-64cf77eca108")
Roshan Piusd1204442018-11-12 12:20:39 -0800249 def test_connect_to_wpa_psk_2g(self):
250 """ Adds a network suggestion and ensure that the device connected.
251
252 Steps:
253 1. Send a network suggestion to the device.
254 2. Wait for the device to connect to it.
255 3. Ensure that we did not receive the post connection broadcast
256 (isAppInteractionRequired = False).
Roshan Piusffc29912019-01-18 13:39:49 -0800257 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800258 """
259 self.add_suggestions_and_ensure_connection(
260 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY],
261 False)
Nate Jiang1ef58c32019-07-15 19:13:26 -0700262
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700263 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
264 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800265
Roshan Piusc6fceca2019-03-22 13:23:58 -0700266 @test_tracker_info(uuid="f54bc250-d9e9-4f00-8b5b-b866e8550b43")
267 def test_connect_to_highest_priority(self):
268 """
269 Adds network suggestions and ensures that device connects to
270 the suggestion with the highest priority.
271
272 Steps:
273 1. Send 2 network suggestions to the device (with different priorities).
274 2. Wait for the device to connect to the network with the highest
275 priority.
Nate Jiang172c6902019-09-09 17:54:33 -0700276 3. In-place modify network suggestions with priorities reversed
277 4. Restart wifi, wait for the device to connect to the network with the highest
278 priority.
279 5. Re-add the suggestions with the priorities reversed again.
280 6. Again wait for the device to connect to the network with the highest
Roshan Piusc6fceca2019-03-22 13:23:58 -0700281 priority.
282 """
283 network_suggestion_2g = self.wpa_psk_2g
284 network_suggestion_5g = self.wpa_psk_5g
285
286 # Add suggestions & wait for the connection event.
287 network_suggestion_2g[WifiEnums.PRIORITY] = 5
288 network_suggestion_5g[WifiEnums.PRIORITY] = 2
289 self.add_suggestions_and_ensure_connection(
290 [network_suggestion_2g, network_suggestion_5g],
291 self.wpa_psk_2g[WifiEnums.SSID_KEY],
292 None)
293
Nate Jiang172c6902019-09-09 17:54:33 -0700294 # In-place modify Reverse the priority, should be no disconnect
295 network_suggestion_2g[WifiEnums.PRIORITY] = 2
296 network_suggestion_5g[WifiEnums.PRIORITY] = 5
297 self.dut.log.info("Modifying network suggestions");
298 asserts.assert_true(
299 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion_2g,
300 network_suggestion_5g]),
301 "Failed to add suggestions")
302 wutils.ensure_no_disconnect(self.dut)
303
304 # Disable and re-enable wifi, should connect to higher priority
305 wutils.wifi_toggle_state(self.dut, False)
306 time.sleep(DEFAULT_TIMEOUT)
307 wutils.wifi_toggle_state(self.dut, True)
308 wutils.start_wifi_connection_scan_and_return_status(self.dut)
309 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
310
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700311 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
Nate Jiang0878aef2019-09-16 13:33:26 -0700312 [], self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Piusc6fceca2019-03-22 13:23:58 -0700313
314 # Reverse the priority.
315 # Add suggestions & wait for the connection event.
Nate Jiang172c6902019-09-09 17:54:33 -0700316 network_suggestion_2g[WifiEnums.PRIORITY] = 5
317 network_suggestion_5g[WifiEnums.PRIORITY] = 2
Roshan Piusc6fceca2019-03-22 13:23:58 -0700318 self.add_suggestions_and_ensure_connection(
319 [network_suggestion_2g, network_suggestion_5g],
Nate Jiang0878aef2019-09-16 13:33:26 -0700320 self.wpa_psk_2g[WifiEnums.SSID_KEY],
Roshan Piusc6fceca2019-03-22 13:23:58 -0700321 None)
322
Roshan Piusf028bd32018-12-06 15:18:21 -0800323 @test_tracker_info(uuid="b1d27eea-23c8-4c4f-b944-ef118e4cc35f")
Roshan Piusd1204442018-11-12 12:20:39 -0800324 def test_connect_to_wpa_psk_2g_with_post_connection_broadcast(self):
325 """ Adds a network suggestion and ensure that the device connected.
326
327 Steps:
328 1. Send a network suggestion to the device with
329 isAppInteractionRequired set.
330 2. Wait for the device to connect to it.
331 3. Ensure that we did receive the post connection broadcast
332 (isAppInteractionRequired = True).
Roshan Piusffc29912019-01-18 13:39:49 -0800333 4. Remove the suggestions and ensure the device does not connect back.
Roshan Piusd1204442018-11-12 12:20:39 -0800334 """
335 network_suggestion = self.wpa_psk_2g
336 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
337 self.add_suggestions_and_ensure_connection(
338 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
339 True)
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700340 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
341 [self.wpa_psk_2g], self.wpa_psk_2g[WifiEnums.SSID_KEY])
Roshan Piusd1204442018-11-12 12:20:39 -0800342
Roshan Piusf028bd32018-12-06 15:18:21 -0800343 @test_tracker_info(uuid="a036a24d-29c0-456d-ae6a-afdde34da710")
Roshan Piusd1204442018-11-12 12:20:39 -0800344 def test_connect_to_wpa_psk_5g_reboot_config_store(self):
345 """
346 Adds a network suggestion and ensure that the device connects to it
347 after reboot.
348
349 Steps:
350 1. Send a network suggestion to the device.
351 2. Wait for the device to connect to it.
352 3. Ensure that we did not receive the post connection broadcast
353 (isAppInteractionRequired = False).
354 4. Reboot the device.
355 5. Wait for the device to connect to back to it.
Roshan Piusffc29912019-01-18 13:39:49 -0800356 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800357 7. Reboot the device again, ensure user approval is kept
Roshan Piusd1204442018-11-12 12:20:39 -0800358 """
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700359 self._test_connect_to_wifi_network_reboot_config_store(
360 [self.wpa_psk_5g], self.wpa_psk_5g)
Roshan Piusd1204442018-11-12 12:20:39 -0800361
Girish Moturuc2033ae2019-07-31 09:04:36 -0700362 @test_tracker_info(uuid="61649a2b-0f00-4272-9b9b-40ad5944da31")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700363 def test_connect_to_wpa_ent_config_aka_reboot_config_store(self):
364 """
365 Adds a network suggestion and ensure that the device connects to it
366 after reboot.
Roshan Piusd1204442018-11-12 12:20:39 -0800367
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700368 Steps:
369 1. Send a Enterprise AKA network suggestion to the device.
370 2. Wait for the device to connect to it.
371 3. Ensure that we did not receive the post connection broadcast.
372 4. Reboot the device.
373 5. Wait for the device to connect to the wifi network.
374 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800375 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700376 """
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800377 if "carrierId" in self.config_aka:
378 self.set_carrier_approved(self.config_aka["carrierId"], True)
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700379 self._test_connect_to_wifi_network_reboot_config_store(
380 [self.config_aka], self.ent_network_2g)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800381 if "carrierId" in self.config_aka:
382 self.clear_carrier_approved(self.config_aka["carrierId"])
Roshan Piusd1204442018-11-12 12:20:39 -0800383
Girish Moturuc2033ae2019-07-31 09:04:36 -0700384 @test_tracker_info(uuid="98b2d40a-acb4-4a2f-aba1-b069e2a1d09d")
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700385 def test_connect_to_wpa_ent_config_ttls_pap_reboot_config_store(self):
386 """
387 Adds a network suggestion and ensure that the device connects to it
388 after reboot.
Roshan Piusffc29912019-01-18 13:39:49 -0800389
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700390 Steps:
391 1. Send a Enterprise TTLS PAP network suggestion to the device.
392 2. Wait for the device to connect to it.
393 3. Ensure that we did not receive the post connection broadcast.
394 4. Reboot the device.
395 5. Wait for the device to connect to the wifi network.
396 6. Remove suggestions and ensure device doesn't connect back to it.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800397 7. Reboot the device again, ensure user approval is kept
Girish Moturub1e7a5c2019-07-29 13:48:11 -0700398 """
399 config = dict(self.config_ttls)
400 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
401
402 self._test_connect_to_wifi_network_reboot_config_store(
403 [config], self.ent_network_2g)
Roshan Piusffc29912019-01-18 13:39:49 -0800404
Roshan Pius3e3bd342019-01-09 13:55:17 -0800405 @test_tracker_info(uuid="554b5861-22d0-4922-a5f4-712b4cf564eb")
406 def test_fail_to_connect_to_wpa_psk_5g_when_not_approved(self):
407 """
408 Adds a network suggestion and ensure that the device does not
409 connect to it until we approve the app.
410
411 Steps:
412 1. Send a network suggestion to the device with the app not approved.
413 2. Ensure the network is present in scan results, but we don't connect
414 to it.
415 3. Now approve the app.
416 4. Wait for the device to connect to it.
417 """
418 self.dut.log.info("Adding network suggestions");
419 asserts.assert_true(
420 self.dut.droid.wifiAddNetworkSuggestions([self.wpa_psk_5g]),
421 "Failed to add suggestions")
422
423 # Disable suggestions by the app.
424 self.set_approved(False)
425
426 # Ensure the app is not approved.
427 asserts.assert_false(
428 self.is_approved(),
429 "Suggestions should be disabled")
430
431 # Start a new scan to trigger auto-join.
432 wutils.start_wifi_connection_scan_and_ensure_network_found(
433 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
434
435 # Ensure we don't connect to the network.
436 asserts.assert_false(
437 wutils.wait_for_connect(
438 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY], assert_on_fail=False),
439 "Should not connect to network suggestions from unapproved app")
440
441 self.dut.log.info("Enabling suggestions from test");
442 # Now Enable suggestions by the app & ensure we connect to the network.
443 self.set_approved(True)
444
445 # Ensure the app is approved.
446 asserts.assert_true(
447 self.is_approved(),
448 "Suggestions should be enabled")
449
450 # Start a new scan to trigger auto-join.
451 wutils.start_wifi_connection_scan_and_ensure_network_found(
452 self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
453
454 wutils.wait_for_connect(self.dut, self.wpa_psk_5g[WifiEnums.SSID_KEY])
Roshan Pius89b22bd2019-01-24 14:12:49 -0800455
Roshan Pius3d57f132019-01-28 10:25:18 -0800456 @test_tracker_info(uuid="98400dea-776e-4a0a-9024-18845b27331c")
Roshan Pius89b22bd2019-01-24 14:12:49 -0800457 def test_fail_to_connect_to_wpa_psk_2g_after_user_forgot_network(self):
458 """
459 Adds a network suggestion and ensures that the device does not
460 connect to it after the user forgot the network previously.
461
462 Steps:
463 1. Send a network suggestion to the device with
464 isAppInteractionRequired set.
465 2. Wait for the device to connect to it.
466 3. Ensure that we did receive the post connection broadcast
467 (isAppInteractionRequired = True).
468 4. Simulate user forgetting the network and the device does not
469 connecting back even though the suggestion is active from the app.
470 """
471 network_suggestion = self.wpa_psk_2g
472 network_suggestion[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
473 self.add_suggestions_and_ensure_connection(
474 [network_suggestion], self.wpa_psk_2g[WifiEnums.SSID_KEY],
475 True)
476
Nate Jiang68f3ffa2019-08-07 15:23:49 -0700477 # Simulate user forgetting the ephemeral network.
Roshan Pius89b22bd2019-01-24 14:12:49 -0800478 self.dut.droid.wifiDisableEphemeralNetwork(
479 self.wpa_psk_2g[WifiEnums.SSID_KEY])
480 wutils.wait_for_disconnect(self.dut)
481 self.dut.log.info("Disconnected from network %s", self.wpa_psk_2g)
482 self.dut.ed.clear_all_events()
483
484 # Now ensure that we don't connect back even though the suggestion
485 # is still active.
486 asserts.assert_false(
487 wutils.wait_for_connect(self.dut,
488 self.wpa_psk_2g[WifiEnums.SSID_KEY],
489 assert_on_fail=False),
490 "Device should not connect back")
Nate Jiang20af5e82019-08-08 12:45:24 -0700491
492 @test_tracker_info(uuid="93c86b05-fa56-4d79-ad27-009a16f691b1")
493 def test_connect_to_hidden_network(self):
494 """
495 Adds a network suggestion with hidden SSID config, ensure device can scan
496 and connect to this network.
497
498 Steps:
499 1. Send a hidden network suggestion to the device.
500 2. Wait for the device to connect to it.
501 3. Ensure that we did not receive the post connection broadcast
502 (isAppInteractionRequired = False).
503 4. Remove the suggestions and ensure the device does not connect back.
504 """
505 asserts.skip_if(not hasattr(self, "hidden_networks"), "No hidden networks, skip this test")
506
507 network_suggestion = self.hidden_network
508 self.add_suggestions_and_ensure_connection(
509 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY], False)
510 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
511 [network_suggestion], network_suggestion[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700512
Girish Moturua5d28482019-10-23 10:15:37 -0700513 @test_tracker_info(uuid="806dff14-7543-482b-bd0a-598de59374b3")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700514 def test_connect_to_passpoint_network_with_post_connection_broadcast(self):
515 """ Adds a passpoint network suggestion and ensure that the device connected.
516
517 Steps:
518 1. Send a network suggestion to the device.
519 2. Wait for the device to connect to it.
520 3. Ensure that we did receive the post connection broadcast
521 (isAppInteractionRequired = true).
522 4. Remove the suggestions and ensure the device does not connect back.
523 """
524 asserts.skip_if(not hasattr(self, "passpoint_networks"),
525 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700526 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700527 passpoint_config[WifiEnums.IS_APP_INTERACTION_REQUIRED] = True
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800528 if "carrierId" in passpoint_config:
529 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700530 self.add_suggestions_and_ensure_connection([passpoint_config],
531 passpoint_config[WifiEnums.SSID_KEY], True)
532 self.remove_suggestions_disconnect_and_ensure_no_connection_back(
533 [passpoint_config], passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800534 if "carrierId" in passpoint_config:
535 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700536
Girish Moturua5d28482019-10-23 10:15:37 -0700537 @test_tracker_info(uuid="159b8b8c-fb00-4d4e-a29f-606881dcbf44")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700538 def test_connect_to_passpoint_network_reboot_config_store(self):
539 """
540 Adds a passpoint network suggestion and ensure that the device connects to it
541 after reboot.
542
543 Steps:
544 1. Send a network suggestion to the device.
545 2. Wait for the device to connect to it.
546 3. Ensure that we did not receive the post connection broadcast
547 (isAppInteractionRequired = False).
548 4. Reboot the device.
549 5. Wait for the device to connect to back to it.
550 6. Remove the suggestions and ensure the device does not connect back.
Nate(Qiang) Jiang8a62e372019-12-19 11:04:05 -0800551 7. Reboot the device again, ensure user approval is kept
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700552 """
553 asserts.skip_if(not hasattr(self, "passpoint_networks"),
554 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700555 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800556 if "carrierId" in passpoint_config:
557 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700558 self._test_connect_to_wifi_network_reboot_config_store([passpoint_config],
559 passpoint_config)
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800560 if "carrierId" in passpoint_config:
561 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700562
Girish Moturua5d28482019-10-23 10:15:37 -0700563 @test_tracker_info(uuid="34f3d28a-bedf-43fe-a12d-2cfadf6bc6eb")
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700564 def test_fail_to_connect_to_passpoint_network_when_not_approved(self):
565 """
566 Adds a passpoint network suggestion and ensure that the device does not
567 connect to it until we approve the app.
568
569 Steps:
570 1. Send a network suggestion to the device with the app not approved.
571 2. Ensure the network is present in scan results, but we don't connect
572 to it.
573 3. Now approve the app.
574 4. Wait for the device to connect to it.
575 """
576 asserts.skip_if(not hasattr(self, "passpoint_networks"),
577 "No passpoint networks, skip this test")
Girish Moturua069a4a2019-10-23 13:21:42 -0700578 passpoint_config = self.passpoint_networks[ATT]
Nate(Qiang) Jiang647afb92020-02-06 13:44:14 -0800579 if "carrierId" in passpoint_config:
580 self.set_carrier_approved(passpoint_config["carrierId"], True)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700581 self.dut.log.info("Adding network suggestions")
582 asserts.assert_true(
583 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
584 "Failed to add suggestions")
585
586 # Disable suggestions by the app.
587 self.set_approved(False)
588
589 # Ensure the app is not approved.
590 asserts.assert_false(
591 self.is_approved(),
592 "Suggestions should be disabled")
593
594 # Start a new scan to trigger auto-join.
595 wutils.start_wifi_connection_scan_and_ensure_network_found(
596 self.dut, passpoint_config[WifiEnums.SSID_KEY])
597
598 # Ensure we don't connect to the network.
599 asserts.assert_false(
600 wutils.wait_for_connect(
601 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
602 "Should not connect to network suggestions from unapproved app")
603
604 self.dut.log.info("Enabling suggestions from test");
605 # Now Enable suggestions by the app & ensure we connect to the network.
606 self.set_approved(True)
607
608 # Ensure the app is approved.
609 asserts.assert_true(
610 self.is_approved(),
611 "Suggestions should be enabled")
612
613 # Start a new scan to trigger auto-join.
614 wutils.start_wifi_connection_scan_and_ensure_network_found(
615 self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang051b8142019-11-01 17:23:33 -0700616 time.sleep(PASSPOINT_TIMEOUT)
Nate(Qiang) Jiang55582152019-10-07 12:13:47 -0700617 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
Nate(Qiang) Jiang647afb92020-02-06 13:44:14 -0800618 if "carrierId" in passpoint_config:
619 self.clear_carrier_approved(passpoint_config["carrierId"])
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800620
Girish Moturu7e30c782020-02-05 12:37:06 -0800621 @test_tracker_info(uuid="cf624cda-4d25-42f1-80eb-6c717fb08338")
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800622 def test_fail_to_connect_to_passpoint_network_when_imsi_protection_exemption_not_approved(self):
623 """
624 Adds a passpoint network suggestion using SIM credential without IMSI privacy protection.
625 Before user approves the exemption, ensure that the device does noconnect to it until we
626 approve the carrier exemption.
627
628 Steps:
629 1. Send a network suggestion to the device with IMSI protection exemption not approved.
630 2. Ensure the network is present in scan results, but we don't connect
631 to it.
632 3. Now approve the carrier.
633 4. Wait for the device to connect to it.
634 """
635 asserts.skip_if(not hasattr(self, "passpoint_networks"),
636 "No passpoint networks, skip this test")
637 passpoint_config = self.passpoint_networks[ATT]
638 asserts.skip_if("carrierId" not in passpoint_config,
639 "Not a SIM based passpoint network, skip this test")
640
Nate(Qiang) Jiang92251a62020-02-28 10:13:30 -0800641 # Ensure the carrier is not approved.
642 asserts.assert_false(
643 self.is_carrier_approved(passpoint_config["carrierId"]),
644 "Carrier shouldn't be approved")
645
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800646 self.dut.log.info("Adding network suggestions")
647 asserts.assert_true(
648 self.dut.droid.wifiAddNetworkSuggestions([passpoint_config]),
649 "Failed to add suggestions")
650
Nate(Qiang) Jiangacaf8892020-01-29 14:04:12 -0800651 # Start a new scan to trigger auto-join.
652 wutils.start_wifi_connection_scan_and_ensure_network_found(
653 self.dut, passpoint_config[WifiEnums.SSID_KEY])
654
655 # Ensure we don't connect to the network.
656 asserts.assert_false(
657 wutils.wait_for_connect(
658 self.dut, passpoint_config[WifiEnums.SSID_KEY], assert_on_fail=False),
659 "Should not connect to network suggestions from unapproved app")
660
661 self.dut.log.info("Enabling suggestions from test")
662 # Now approve IMSI protection exemption by carrier & ensure we connect to the network.
663 self.set_carrier_approved(passpoint_config["carrierId"], True)
664
665 # Ensure the carrier is approved.
666 asserts.assert_true(
667 self.is_carrier_approved(passpoint_config["carrierId"]),
668 "Carrier should be approved")
669
670 # Start a new scan to trigger auto-join.
671 wutils.start_wifi_connection_scan_and_ensure_network_found(
672 self.dut, passpoint_config[WifiEnums.SSID_KEY])
673 time.sleep(PASSPOINT_TIMEOUT)
674 wutils.wait_for_connect(self.dut, passpoint_config[WifiEnums.SSID_KEY])
675 self.clear_carrier_approved(passpoint_config["carrierId"])
676
Girish Moturu31f58f22020-01-30 18:54:40 -0800677 @test_tracker_info(uuid="e35f99c8-78a4-4b96-9258-f9834b6ddd33")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800678 def test_initial_auto_join_on_network_suggestion(self):
679 """
680 Add a network suggestion with enableAutojoin bit set to false, ensure the device doesn't
681 auto connect to this network
682
683 Steps:
684 1. Create a network suggestion.
685 2. Set EnableAutojoin to false.
686 3. Add this suggestion
687 4. Ensure device doesn't connect to his network
688 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800689 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800690 # Set suggestion auto join initial to false.
691 network_suggestion["enableAutojoin"] = False
692 self.dut.log.info("Adding network suggestions")
693 asserts.assert_true(
694 self.dut.droid.wifiAddNetworkSuggestions([network_suggestion]),
695 "Failed to add suggestions")
696 # Enable suggestions by the app.
697 self.dut.log.debug("Enabling suggestions from test")
698 self.set_approved(True)
699 wutils.start_wifi_connection_scan_and_return_status(self.dut)
700 asserts.assert_false(
701 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
702 assert_on_fail=False), "Device should not connect.")
703
Girish Moturu31f58f22020-01-30 18:54:40 -0800704 @test_tracker_info(uuid="ff4e451f-a380-4ff5-a5c2-dd9b1633d5e5")
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800705 def test_user_override_auto_join_on_network_suggestion(self):
706 """
707 Add a network suggestion, user change the auto join to false, ensure the device doesn't
708 auto connect to this network
709
710 Steps:
711 1. Create a network suggestion.
712 2. Add this suggestion, and ensure we connect to this network
713 3. Simulate user change the auto join to false.
714 4. Toggle the Wifi off and on
715 4. Ensure device doesn't connect to his network
716 """
Girish Moturu2155dc12020-01-21 15:16:17 -0800717 network_suggestion = self.wpa_psk_5g
Nate(Qiang) Jiange7a400e2020-01-16 17:27:23 -0800718 self.add_suggestions_and_ensure_connection([network_suggestion],
719 network_suggestion[WifiEnums.SSID_KEY], False)
720 wifi_info = self.dut.droid.wifiGetConnectionInfo()
721 self.dut.log.info(wifi_info)
722 network_id = wifi_info[WifiEnums.NETID_KEY]
723 # Simulate user disable auto join through Settings.
724 self.dut.log.info("Disable auto join on suggestion")
725 self.dut.droid.wifiEnableAutojoin(network_id, False)
726 wutils.wifi_toggle_state(self.dut, False)
727 wutils.wifi_toggle_state(self.dut, True)
728 asserts.assert_false(
729 wutils.wait_for_connect(self.dut, network_suggestion[WifiEnums.SSID_KEY],
730 assert_on_fail=False), "Device should not connect.")