• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#   Copyright 2019 - The Android Open Source Project
3#
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15
16import time
17
18from acts import asserts
19from acts.controllers.openwrt_ap import MOBLY_CONTROLLER_CONFIG_NAME as OPENWRT
20from acts.test_decorators import test_tracker_info
21from acts_contrib.test_utils.net import connectivity_const as cconst
22from acts_contrib.test_utils.net import connectivity_test_utils as cutils
23from acts_contrib.test_utils.net import ui_utils as uutils
24from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
25from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
26
27WifiEnums = wutils.WifiEnums
28IFACE = "InterfaceName"
29TIME_OUT = 20
30WLAN = "wlan0"
31ACCEPT_CONTINUE = "Accept and Continue"
32CONNECTED = "Connected"
33SIGN_IN_NOTIFICATION = "Sign in to network"
34FAS_FDQN = "netsplashpage.net"
35NETWORK_AND_INTERNET = ["Network & internet", "Network and Internet"]
36
37
38class CaptivePortalTest(WifiBaseTest):
39    """Check device can access the network after pass captive portal check."""
40
41    def setup_class(self):
42        """Setup devices for tests and unpack params.
43
44        Required params:
45          1. rk_captive_portal: SSID of ruckus captive portal network in dict
46          2. gg_captive_portal: SSID of guestgate network in dict
47          3. uicd_workflows: uicd workflow that specify click actions to accept
48             a captive portal connection. Ex: Click on SignIn, Accept & Continue
49             //wireless/android/platform/testing/wifi/configs/uicd/
50          4. uic_zip: Zip file location of UICD application
51        """
52        self.dut = self.android_devices[0]
53        opt_params = ["rk_captive_portal", "gg_captive_portal",
54                      "configure_OpenWrt", "wifi_network"]
55        self.unpack_userparams(opt_param_names=opt_params,)
56        wutils.wifi_test_device_init(self.dut)
57
58        if OPENWRT in self.user_params:
59            self.openwrt = self.access_points[0]
60            if hasattr(self, "configure_OpenWrt") and self.configure_OpenWrt == "skip":
61                self.dut.log.info("Skip configure Wifi interface due to config setup.")
62            else:
63                self.configure_openwrt_ap_and_start(wpa_network=True)
64                self.wifi_network = self.openwrt.get_wifi_network()
65            self.openwrt.network_setting.setup_captive_portal(FAS_FDQN)
66
67    def teardown_class(self):
68        """Reset devices."""
69        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
70        wutils.reset_wifi(self.dut)
71        self.dut.droid.telephonyToggleDataConnection(True)
72
73    def setup_test(self):
74        """Setup device."""
75        wutils.reset_wifi(self.dut)
76        self.dut.unlock_screen()
77        self._go_to_wifi_settings()
78
79    def on_fail(self, test_name, begin_time):
80        self.dut.take_bug_report(test_name, begin_time)
81
82    ### Helper methods ###
83
84    def _go_to_wifi_settings(self):
85        """Go to wifi settings to perform UI actions for Captive portal."""
86        self.dut.adb.shell("am start -a android.settings.SETTINGS")
87
88        access_internet_setting = False
89        for text in NETWORK_AND_INTERNET:
90            if uutils.has_element(self.dut, text=text):
91                uutils.wait_and_click(self.dut, text=text)
92                access_internet_setting = True
93                break
94        asserts.assert_true(access_internet_setting,
95                            "Fail to find button NETWORK_AND_INTERNET from UI.")
96        android_version = self.dut.adb.getprop("ro.build.version.release")
97        if int(android_version) < 12:
98            uutils.wait_and_click(self.dut, text="Wi‑Fi")
99        else:
100            uutils.wait_and_click(self.dut, text="Internet")
101
102    def _verify_sign_in_notification(self):
103        """Verify sign in notification shows for captive portal."""
104        curr_time = time.time()
105        while time.time() < curr_time + TIME_OUT:
106            time.sleep(3) # wait for sometime before checking the notification
107            screen_dump = uutils.get_screen_dump_xml(self.dut)
108            nodes = screen_dump.getElementsByTagName('node')
109            for node in nodes:
110                if SIGN_IN_NOTIFICATION in node.getAttribute(
111                    'text') or CONNECTED in node.getAttribute('text'):
112                  return
113        asserts.fail("Failed to get sign in notification")
114
115    def _verify_captive_portal(self, network, user="username",
116                               mail="user@example.net",
117                               click_accept=ACCEPT_CONTINUE):
118        """Connect to captive portal network using uicd workflow.
119
120        Steps:
121            1. Connect to captive portal network
122            2. Run uicd workflow to accept connection
123            3. Verify internet connectivity
124
125        Args:
126            network: captive portal network to connect to
127            user: Option for captive portal login in
128            mail: Option for captive portal login in
129            click_accept: Notification to select to accept captive portal
130        """
131        # connect to captive portal wifi network
132        wutils.connect_to_wifi_network(
133            self.dut, network, check_connectivity=False)
134        # Wait for captive portal detection.
135        time.sleep(10)
136        # run ui automator
137        self._verify_sign_in_notification()
138        uutils.wait_and_click(self.dut, text="%s" % network["SSID"])
139        if uutils.has_element(self.dut, class_name="android.widget.EditText"):
140            uutils.wait_and_click(self.dut, class_name="android.widget.EditText")
141            self.dut.adb.shell("input text %s" % user)
142            self.dut.adb.shell("input keyevent 20")
143            self.dut.adb.shell("input text %s" % mail)
144            uutils.wait_and_click(self.dut, text="Accept Terms of Service")
145        if uutils.has_element(self.dut, text="%s" % click_accept):
146            uutils.wait_and_click(self.dut, text="%s" % click_accept)
147
148        # wait for sometime for captive portal connection to go through
149        curr_time = time.time()
150        while time.time() < curr_time + TIME_OUT:
151            time.sleep(3) # wait for sometime for AP to send DHCP info
152            link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
153            self.log.debug("Link properties %s" % link_prop)
154            if link_prop and link_prop[IFACE] == WLAN:
155                break
156
157        # verify connectivity
158        asserts.assert_true(
159            wutils.validate_connection(self.dut, ping_gateway=False),
160            "Failed to connect to internet. Captive portal test failed")
161
162    ### Test Cases ###
163
164    @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040")
165    @WifiBaseTest.wifi_test_wrap
166    def test_ruckus_captive_portal_default(self):
167        """Verify captive portal network.
168
169        Steps:
170            1. Set default private dns mode
171            2. Connect to ruckus captive portal network
172            3. Verify connectivity
173        """
174        # set private dns to opportunistic
175        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
176
177        # verify connection to captive portal network
178        self._verify_captive_portal(self.rk_captive_portal)
179
180    @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab")
181    @WifiBaseTest.wifi_test_wrap
182    def test_ruckus_captive_portal_private_dns_off(self):
183        """Verify captive portal network.
184
185        Steps:
186            1. Turn off private dns mode
187            2. Connect to ruckus captive portal network
188            3. Verify connectivity
189        """
190        # turn off private dns
191        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
192
193        # verify connection to captive portal network
194        self._verify_captive_portal(self.rk_captive_portal)
195
196    @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4")
197    @WifiBaseTest.wifi_test_wrap
198    def test_ruckus_captive_portal_private_dns_strict(self):
199        """Verify captive portal network.
200
201        Steps:
202            1. Set strict private dns mode
203            2. Connect to ruckus captive portal network
204            3. Verify connectivity
205        """
206        # set private dns to strict mode
207        cutils.set_private_dns(self.dut,
208                               cconst.PRIVATE_DNS_MODE_STRICT,
209                               cconst.DNS_GOOGLE_HOSTNAME)
210
211        # verify connection to captive portal network
212        self._verify_captive_portal(self.rk_captive_portal)
213
214    @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a")
215    def test_guestgate_captive_portal_default(self):
216        """Verify captive portal network.
217
218        Steps:
219            1. Set default private dns mode
220            2. Connect to guestgate captive portal network
221            3. Verify connectivity
222        """
223        # set private dns to opportunistic
224        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
225
226        # verify connection to captive portal network
227        self._verify_captive_portal(self.gg_captive_portal)
228
229    @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc")
230    def test_guestgate_captive_portal_private_dns_off(self):
231        """Verify captive portal network.
232
233        Steps:
234            1. Turn off private dns mode
235            2. Connect to guestgate captive portal network
236            3. Verify connectivity
237        """
238        # turn off private dns
239        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
240
241        # verify connection to captive portal network
242        self._verify_captive_portal(self.gg_captive_portal)
243
244    @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a")
245    def test_guestgate_captive_portal_private_dns_strict(self):
246        """Verify captive portal network.
247
248        Steps:
249            1. Set strict private dns mode
250            2. Connect to guestgate captive portal network
251            3. Verify connectivity
252        """
253        # set private dns to strict mode
254        cutils.set_private_dns(self.dut,
255                               cconst.PRIVATE_DNS_MODE_STRICT,
256                               cconst.DNS_GOOGLE_HOSTNAME)
257
258        # verify connection to captive portal network
259        self._verify_captive_portal(self.gg_captive_portal)
260
261    @test_tracker_info(uuid="c25a1be7-f202-41c4-ac95-bed1720833ab")
262    def test_openwrt_captive_portal_default(self):
263        """Verify captive portal network.
264
265        Steps:
266            1. Set default private dns mode
267            2. Connect to openwrt captive portal network
268            3. Verify connectivity
269        """
270        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
271        self.openwrt.network_setting.service_manager.restart("opennds")
272        self._verify_captive_portal(self.wifi_network, click_accept="Continue")
273
274    @test_tracker_info(uuid="1419e36d-0303-44ba-bc60-4d707b45ef48")
275    def test_openwrt_captive_portal_private_dns_off(self):
276        """Verify captive portal network.
277
278        Steps:
279            1. Turn off private dns mode
280            2. Connect to openwrt captive portal network
281            3. Verify connectivity
282        """
283        cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
284        self.openwrt.network_setting.service_manager.restart("opennds")
285        self._verify_captive_portal(self.wifi_network, click_accept="Continue")
286
287    @test_tracker_info(uuid="5aae44ee-fa62-47b9-9b3d-8121f9f92da1")
288    def test_openwrt_captive_portal_private_dns_strict(self):
289        """Verify captive portal network.
290
291        Steps:
292            1. Set strict private dns mode
293            2. Connect to openwrt captive portal network
294            3. Verify connectivity
295        """
296        cutils.set_private_dns(self.dut,
297                               cconst.PRIVATE_DNS_MODE_STRICT,
298                               cconst.DNS_GOOGLE_HOSTNAME)
299        self.openwrt.network_setting.service_manager.restart("opennds")
300        self._verify_captive_portal(self.wifi_network, click_accept="Continue")
301
302
303