• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2022 - 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
17
18import time
19
20from acts import asserts
21from acts import signals
22from acts.test_decorators import test_tracker_info
23from acts.libs.utils.multithread import multithread_func
24
25from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
26from acts_contrib.test_utils.tel.GFTInOutBaseTest import GFTInOutBaseTest
27from acts_contrib.test_utils.tel.gft_inout_defines import VOICE_CALL
28from acts_contrib.test_utils.tel.gft_inout_utils import check_no_service_time
29from acts_contrib.test_utils.tel.gft_inout_utils import check_back_to_service_time
30from acts_contrib.test_utils.tel.gft_inout_utils import mo_voice_call
31from acts_contrib.test_utils.tel.tel_defines import RAT_3G
32from acts_contrib.test_utils.tel.tel_defines import RAT_4G
33from acts_contrib.test_utils.tel.tel_defines import RAT_5G
34from acts_contrib.test_utils.tel.tel_defines import GEN_3G
35from acts_contrib.test_utils.tel.tel_defines import GEN_4G
36from acts_contrib.test_utils.tel.tel_defines import GEN_5G
37from acts_contrib.test_utils.tel.tel_defines import YOUTUBE_PACKAGE_NAME
38from acts_contrib.test_utils.tel.tel_data_utils import start_youtube_video
39from acts_contrib.test_utils.tel.tel_data_utils import wait_for_cell_data_connection
40from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_network_generation
41from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phone_default_state
42from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_idle
43from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
44from acts_contrib.test_utils.tel.tel_test_utils import set_preferred_network_mode_pref
45
46AIRPLANE_MODE_ON_TIME = 60
47AIRPLANE_MODE_OFF_TIME = 60
48MOBILE_DATA_ON_OFF_CASE = 1
49DATA_TRANSFER_CASE = 2
50WIFI_HOTSPOT_CASE = 3
51IN_CALL_CASE = 4
52
53class TelLabGFTAirplaneModeTest(GFTInOutBaseTest):
54    def __init__(self, controllers):
55        GFTInOutBaseTest.__init__(self, controllers)
56
57
58    def setup_test(self):
59        for ad in self.android_devices:
60            ensure_phone_default_state(self.log, ad)
61        GFTInOutBaseTest.setup_test(self)
62        self.my_error_msg = ""
63
64    def teardown_test(self):
65        for ad in self.android_devices:
66            ad.force_stop_apk(YOUTUBE_PACKAGE_NAME)
67        ensure_phones_idle(self.log, self.android_devices)
68
69    @test_tracker_info(uuid="c5d2e9b3-478c-4f86-86e5-c8341944d222")
70    @TelephonyBaseTest.tel_test_wrap
71    def test_airplane_mode_mobile_data_off_3g(self):
72        '''
73            1.9.5 - 3G Airplane mode on/off - Mobile data off
74
75            Returns:
76                True if pass; False if fail
77        '''
78        tasks = [(self._airplane_mode_helper, (ad, MOBILE_DATA_ON_OFF_CASE, RAT_3G))
79            for ad in self.android_devices]
80        if not multithread_func(self.log, tasks):
81            raise signals.TestFailure("_airplane_mode_data_on_off failure: %s"
82                %(self.my_error_msg))
83        return True
84
85    @test_tracker_info(uuid="22956c54-ab2a-4031-8dfc-95fdb69fb3a6")
86    @TelephonyBaseTest.tel_test_wrap
87    def test_airplane_mode_mobile_data_off_4g(self):
88        '''
89            1.13.5 - 4G Airplane mode on/off - Mobile data off
90
91            Returns:
92                True if pass; False if fail
93        '''
94        tasks = [(self._airplane_mode_helper, (ad, MOBILE_DATA_ON_OFF_CASE, RAT_4G))
95            for ad in self.android_devices]
96        if not multithread_func(self.log, tasks):
97            raise signals.TestFailure("_airplane_mode_data_on_off failure: %s"
98                %(self.my_error_msg))
99        return True
100
101
102    @test_tracker_info(uuid="9ab8e183-6864-4543-855e-4d9a6cb74e42")
103    @TelephonyBaseTest.tel_test_wrap
104    def test_airplane_mode_mobile_data_off_5g(self):
105        '''
106            1.14.5 - 5G [NSA/SA] Airplane mode on/off - Mobile data off
107
108            Returns:
109                True if pass; False if fail
110        '''
111        tasks = [(self._airplane_mode_helper, (ad, MOBILE_DATA_ON_OFF_CASE, RAT_5G))
112            for ad in self.android_devices]
113        if not multithread_func(self.log, tasks):
114            raise signals.TestFailure("_airplane_mode_data_on_off failure: %s"
115                %(self.my_error_msg))
116        return True
117
118
119    @test_tracker_info(uuid="114afeb6-4c60-4da3-957f-b4b0005223be")
120    @TelephonyBaseTest.tel_test_wrap
121    def test_airplane_mode_voice_call_3g(self):
122        '''
123            3G 1.9.2 - Airplane mode on/off - Active call
124
125            Returns:
126                True if pass; False if fail
127        '''
128        tasks = [(self._airplane_mode_helper, (ad, IN_CALL_CASE, GEN_3G))
129            for ad in self.android_devices]
130        if not multithread_func(self.log, tasks):
131            raise signals.TestFailure("_airplane_mode_voice_call failure: %s"
132                %(self.my_error_msg))
133        return True
134
135
136    @test_tracker_info(uuid="0e00ca1a-f896-4a18-a3c8-05514975ecd6")
137    @TelephonyBaseTest.tel_test_wrap
138    def test_airplane_mode_voice_call_4g(self):
139        '''
140            4G 1.13.2 - Airplane mode on/off - Active call
141
142            Returns:
143                True if pass; False if fail
144        '''
145        tasks = [(self._airplane_mode_helper, (ad, IN_CALL_CASE, GEN_4G))
146            for ad in self.android_devices]
147        if not multithread_func(self.log, tasks):
148            raise signals.TestFailure("_airplane_mode_voice_call failure: %s"
149                %(self.my_error_msg))
150        return True
151
152    @test_tracker_info(uuid="cb228d48-78b4-48b4-9996-26ac252a9486")
153    @TelephonyBaseTest.tel_test_wrap
154    def test_airplane_mode_voice_call_5g(self):
155        '''
156            5G 1.14.2 - [NSA/SA] Airplane mode on/off - Active call
157            For NSA, call goes through IMS over LTE (VoLTE).
158            For SA, call goes through IMS over LTE/NR (EPSFB or VoNR)
159            depends on carrier's implementation.
160
161            Returns:
162                True if pass; False if fail
163        '''
164        tasks = [(self._airplane_mode_helper, (ad, IN_CALL_CASE, GEN_5G))
165            for ad in self.android_devices]
166        if not multithread_func(self.log, tasks):
167            raise signals.TestFailure("_airplane_mode_voice_call failure: %s"
168                %(self.my_error_msg))
169        return True
170
171    def _airplane_mode_mobile_data_off(self, ad):
172        """ Mobile data on/off and airplane mode on/off.
173
174        Args:
175            ad: android_device object.
176
177        Returns:
178            result: True if operation succeed. False if error happens.
179        """
180        # Repeat for 3 cycles.
181        for x in range (3):
182            ad.log.info("Turn off mobile data")
183            ad.droid.telephonyToggleDataConnection(False)
184            if not wait_for_cell_data_connection(self.log, ad, False):
185                self.my_error_msg += "fail to turn off mobile data"
186                return False
187            if not self._airplane_mode_on_off(ad):
188                return False
189            ad.log.info("Turn on mobile data")
190            ad.droid.telephonyToggleDataConnection(True)
191            #If True, it will wait for status to be DATA_STATE_CONNECTED
192            if not wait_for_cell_data_connection(self.log, ad, True):
193                self.my_error_msg += "fail to turn on mobile data"
194                return False
195            # UE turn airplane mode on then off.
196            if not self._airplane_mode_on_off(ad):
197                return False
198        return True
199
200
201    def _airplane_mode_on_off(self, ad):
202        """ Toggle airplane mode on/off.
203
204        Args:
205            ad: android_device object.
206
207        Returns:
208            result: True if operation succeed. False if error happens.
209        """
210        ad.log.info("Turn on airplane mode")
211        if not toggle_airplane_mode(self.log, ad, True):
212            self.my_error_msg += "Fail to enable airplane mode on. "
213            return False
214        time.sleep(AIRPLANE_MODE_ON_TIME)
215        ad.log.info("Turn off airplane mode")
216        if not toggle_airplane_mode(self.log, ad, False):
217            self.my_error_msg += "Fail to enable airplane mode off. "
218            return False
219        time.sleep(AIRPLANE_MODE_OFF_TIME)
220        return True
221
222
223    def _airplane_mode_voice_call(self, ad):
224        """ Airplane mode on/off while in-call.
225
226        Args:
227            ad: android_device object.
228
229        Returns:
230            result: True if operation succeed. False if error happens.
231        """
232        # Repeat for 3 cycles.
233        for x in range (3):
234            ad.log.info("Make a MO call.")
235            if not mo_voice_call(self.log, ad, VOICE_CALL, False):
236                return False
237            self.log.info("turn airplane mode on then off during in call")
238            if not self._airplane_mode_on_off(ad):
239                return False
240        return True
241
242    def _airplane_mode_data_transfer(self, ad):
243        """ Airplane mode on/off while data transfer.
244
245        Args:
246            ad: android_device object.
247
248        Returns:
249            result: True if operation succeed. False if error happens.
250        """
251        # Repeat for 3 cycles.
252        for x in range (3):
253            ad.log.info("Perform a data transferring. Start streaming")
254            if not start_youtube_video(ad):
255                ad.log.warning("Fail to bring up youtube video")
256                self.my_error_msg += "Fail to bring up youtube video. "
257                return False
258            self.log.info("turn airplane mode on then off during data transferring")
259            if not self._airplane_mode_on_off(ad):
260                return False
261        return True
262
263
264    def _airplane_mode_wifi_hotspot(self, ad):
265        """ Airplane mode on/off Wi-Fi hotspot enabled
266
267        Args:
268            ad: android_device object.
269
270        Returns:
271            result: True if operation succeed. False if error happens.
272        """
273        # Repeat for 3 cycles.
274        for x in range (3):
275            ad.log.info("Enable Wi-Fi Hotspot on UE")
276            #if not start_youtube_video(ad):
277            #    return False
278            self.log.info("turn airplane mode on then off")
279            if not self._airplane_mode_on_off(ad):
280                return False
281        return True
282
283    def _airplane_mode_helper(self, ad, case= MOBILE_DATA_ON_OFF_CASE, rat=GEN_4G, loop=1):
284        self.log.info("Lock network mode to %s." , rat)
285        if not ensure_network_generation(self.log, ad, rat):
286            raise signals.TestFailure("device fail to register at %s"
287                %(rat))
288
289        for x in range(self.user_params.get("apm_cycle", 1)):
290            self.log.info("%s loop: %s/%s" %(self.current_test_name,x+1, loop))
291            if case == MOBILE_DATA_ON_OFF_CASE:
292                if not self._airplane_mode_mobile_data_off(ad):
293                    return False
294            elif case == DATA_TRANSFER_CASE:
295                if not self._airplane_mode_data_transfer(ad):
296                    return False
297            elif case == WIFI_HOTSPOT_CASE:
298                if not self._airplane_mode_wifi_hotspot(ad):
299                    return False
300            elif case == IN_CALL_CASE:
301                if not self._airplane_mode_voice_call(ad):
302                    return False
303            #check radio function
304            tasks = [(self.verify_device_status, (ad, VOICE_CALL))
305                for ad in self.android_devices]
306            if not multithread_func(self.log, tasks):
307                raise signals.TestFailure("verify_device_status failure: %s"
308                    %(self.my_error_msg))
309        return True
310
311    @test_tracker_info(uuid="0205ec77-36c1-478f-9d05-c8a72fffdd03")
312    @TelephonyBaseTest.tel_test_wrap
313    def test_airplane_mode_data_transfer_5g(self):
314        '''
315            5G - [NSA/SA] Airplane mode on/off - transfer
316            For NSA, call goes through IMS over LTE (VoLTE).
317            For SA, call goes through IMS over LTE/NR (EPSFB or VoNR)
318            depends on carrier's implementation.
319            Raises:
320                TestFailure if not success.
321            Returns:
322                True if pass; False if fail
323        '''
324        tasks = [(self._airplane_mode_helper, (ad, DATA_TRANSFER_CASE, GEN_5G))
325            for ad in self.android_devices]
326        if not multithread_func(self.log, tasks):
327            raise signals.TestFailure("_airplane_mode_data_transfer failure: %s"
328                %(self.my_error_msg))
329        return True
330
331    @test_tracker_info(uuid="c76a1154-29c0-4259-bd4c-05279d80537b")
332    @TelephonyBaseTest.tel_test_wrap
333    def test_airplane_mode_data_transfer_4g(self):
334        '''
335            4G - Airplane mode on/off - Data transferring
336
337            Raises:
338                TestFailure if not success.
339            Returns:
340                True if pass; False if fail
341        '''
342        tasks = [(self._airplane_mode_helper, (ad, DATA_TRANSFER_CASE, GEN_4G))
343            for ad in self.android_devices]
344        if not multithread_func(self.log, tasks):
345            raise signals.TestFailure("_airplane_mode_data_transfer failure: %s"
346                %(self.my_error_msg))
347        return True
348
349    @test_tracker_info(uuid="c16ea0bb-0155-4f5f-97a8-22c7e0e6e2f5")
350    @TelephonyBaseTest.tel_test_wrap
351    def test_airplane_mode_data_transfer_3g(self):
352        '''
353            3G - Airplane mode on/off - Data transferring
354
355            Raises:
356                TestFailure if not success.
357
358            Returns:
359                True if pass; False if fail
360        '''
361        tasks = [(self._airplane_mode_helper, (ad, DATA_TRANSFER_CASE, GEN_3G))
362            for ad in self.android_devices]
363        if not multithread_func(self.log, tasks):
364            raise signals.TestFailure("_airplane_mode_data_transfer failure: %s"
365                %(self.my_error_msg))
366        return True
367
368    @test_tracker_info(uuid="b1db4e3b-ea0b-4b61-9f2c-4b8fc251c71a")
369    @TelephonyBaseTest.tel_test_wrap
370    def test_airplane_mode_wifi_hotspot_5g(self):
371        '''
372            5G -[NSA/SA] Airplane mode off/on - Wi-Fi Hotspot enabled
373            For NSA, call goes through IMS over LTE (VoLTE).
374            For SA, call goes through IMS over LTE/NR (EPSFB or VoNR)
375            depends on carrier's implementation.
376            Raises:
377                TestFailure if not success.
378            Returns:
379                True if pass; False if fail
380        '''
381        tasks = [(self._airplane_mode_helper, (ad, WIFI_HOTSPOT_CASE, GEN_5G))
382            for ad in self.android_devices]
383        if not multithread_func(self.log, tasks):
384            raise signals.TestFailure("_airplane_mode_wifi_hotspot failure: %s"
385                %(self.my_error_msg))
386        return True
387
388    @test_tracker_info(uuid="f21f4554-7755-4019-b8a2-6f86d1ebd57a")
389    @TelephonyBaseTest.tel_test_wrap
390    def test_airplane_mode_wifi_hotspot_4g(self):
391        '''
392            4G - Airplane mode off/on - Wi-Fi Hotspot enabled
393
394            Raises:
395                TestFailure if not success.
396            Returns:
397                True if pass; False if fail
398        '''
399        tasks = [(self._airplane_mode_helper, (ad, WIFI_HOTSPOT_CASE, GEN_4G))
400            for ad in self.android_devices]
401        if not multithread_func(self.log, tasks):
402            raise signals.TestFailure("_airplane_mode_wifi_hotspot failure: %s"
403                %(self.my_error_msg))
404        return True
405
406    @test_tracker_info(uuid="8cf3c617-4534-4b08-b31f-f702c5f8bb8b")
407    @TelephonyBaseTest.tel_test_wrap
408    def test_airplane_mode_wifi_hotspot_3g(self):
409        '''
410            3G - Airplane mode off/on - Wi-Fi Hotspot enabled
411
412            Raises:
413                TestFailure if not success.
414            Returns:
415                True if pass; False if fail
416        '''
417        tasks = [(self._airplane_mode_helper, (ad, WIFI_HOTSPOT_CASE, GEN_3G))
418            for ad in self.android_devices]
419        if not multithread_func(self.log, tasks):
420            raise signals.TestFailure("_airplane_mode_wifi_hotspot failure: %s"
421                %(self.my_error_msg))
422        return True