• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2016 - 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"""
17Fi Switching Methods
18"""
19import time
20from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
21from acts.controllers.anritsu_lib.md8475a import CBCHSetup
22from acts.controllers.anritsu_lib.md8475a import CTCHSetup
23from acts.controllers.anritsu_lib.md8475a import MD8475A
24from acts_contrib.test_utils.tel.anritsu_utils import cb_serial_number
25from acts_contrib.test_utils.tel.anritsu_utils import set_system_model_lte
26from acts_contrib.test_utils.tel.anritsu_utils import set_usim_parameters
27from acts_contrib.test_utils.tel.anritsu_utils import set_post_sim_params
28from acts_contrib.test_utils.tel.tel_test_utils import \
29    ensure_preferred_network_type_for_subscription
30from acts_contrib.test_utils.tel.tel_test_utils import ensure_phones_idle
31from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
32from acts_contrib.test_utils.tel.tel_test_utils import start_qxdm_loggers
33from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
34from acts_contrib.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
35from acts_contrib.test_utils.tel.tel_defines import RAT_FAMILY_LTE
36from acts.test_decorators import test_tracker_info
37from acts_contrib.test_utils.tel.tel_defines import RAT_LTE
38from acts_contrib.test_utils.tel.tel_defines import CARRIER_SPT
39from acts_contrib.test_utils.tel.tel_defines import CARRIER_TMO
40from acts_contrib.test_utils.tel.tel_defines import CARRIER_USCC
41from acts_contrib.test_utils.tel.tel_lookup_tables import operator_name_from_plmn_id
42from acts_contrib.test_utils.tel.tel_test_utils import abort_all_tests
43from acts_contrib.test_utils.tel.tel_test_utils import ensure_phone_subscription
44from acts_contrib.test_utils.tel.tel_test_utils import ensure_wifi_connected
45from acts_contrib.test_utils.tel.tel_test_utils import is_sim_ready
46from acts_contrib.test_utils.tel.tel_test_utils import log_screen_shot
47from acts_contrib.test_utils.tel.tel_test_utils import multithread_func
48from acts_contrib.test_utils.tel.tel_test_utils import reboot_device
49from acts_contrib.test_utils.tel.tel_test_utils import refresh_droid_config
50from acts_contrib.test_utils.tel.tel_test_utils import send_dialer_secret_code
51from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
52from acts_contrib.test_utils.tel.tel_test_utils import wait_for_state
53from acts_contrib.test_utils.tel.tel_test_utils import add_google_account
54from acts_contrib.test_utils.tel.tel_test_utils import remove_google_account
55
56WAIT_TIME_BETWEEN_REG_AND_MSG = 15  # default 15 sec
57CARRIER = None
58CARRIER_AUTO = "auto"
59
60_CARRIER_DIALER_CODE_LOOKUP = {
61    CARRIER_AUTO: '342886',
62    CARRIER_SPT: '34777',
63    CARRIER_TMO: '34866',
64    CARRIER_USCC: '34872'
65}
66
67_SWITCHING_PREF_FILE = (
68    '/data/data/com.google.android.apps.tycho/shared_prefs/switching.xml')
69
70_INTENT_FLAGS = int(0x00008000 | 0x10000000 | 0x00080000 | 0x00020000)
71_TYCHO_PKG = 'com.google.android.apps.tycho'
72_MAX_WAIT_TIME = 120
73_TYCHO_VERBOSE_LOGGING_CMDS = [
74    "setprop log.tag.Tycho VERBOSE",
75    "CLASSPATH=/system/framework/am.jar su root app_process "
76    "/system/bin com.android.commands.am.Am broadcast -a "
77    "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
78    "-e tycho.enable_request_logging true",
79    "CLASSPATH=/system/framework/am.jar su root app_process "
80    "/system/bin com.android.commands.am.Am broadcast -a "
81    "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
82    "-e tycho.enable_sensitive_logging true",
83    "CLASSPATH=/system/framework/am.jar su root app_process "
84    "/system/bin com.android.commands.am.Am broadcast -a "
85    "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
86    "-e tycho.enable_ample_logging true"
87]
88
89_TYCHO_SERVER_LAB_OVERRIDE_CMD = (
90    "am broadcast -a com.google.gservices.intent.action.GSERVICES_OVERRIDE -e "
91    "url:tycho_server_endpoint https://android.googleapis.com/nova/nfe/ rewrite"
92    " https://android.googleapis.com/lab/nova/nfe/")
93
94
95class TychoClassId(object):
96    """Tycho Activity/Service Classnames."""
97    # Activities
98    CARRIER_SETUP = 'CarrierSetupEntryPointTrampoline'
99    INIT_ACTIVITY = 'InitActivity'
100    # Services
101    SYNC_SERVICE = 'services.SyncService'
102    ACTIVATE_SUPER_NETWORK_SERVICE = 'services.SuperNetworkConfigurationService'
103
104
105class ActionTypeId(object):
106    """Andorid Action Type to trigger events."""
107    MAIN = 'android.intent.action.MAIN'
108    MASTER_CLEAR_NOTIFICATION = 'android.intent.action.MASTER_CLEAR_NOTIFICATION'
109    TYCHO_ACTIVATE_SUPER_NETWORK = (
110        'com.google.android.apps.tycho.ActionType.ACTIVATE_SUPER_NETWORK')
111
112
113class TelLabProjectFiTest(TelephonyBaseTest):
114    SERIAL_NO = cb_serial_number()
115
116    def setup_class(self):
117        super().setup_class()
118        self.ad = self.android_devices[0]
119        self.ad.sim_card = getattr(self.ad, "sim_card", None)
120        self.md8475a_ip_address = self.user_params[
121            "anritsu_md8475a_ip_address"]
122        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
123        self.md8475_version = self.user_params.get("md8475", "A")
124        self.ad.adb.shell("settings put secure cmas_additional_broadcast_pkg "
125                          "com.googlecode.android_scripting")
126        self.wait_time_between_reg_and_msg = self.user_params.get(
127            "wait_time_between_reg_and_msg", WAIT_TIME_BETWEEN_REG_AND_MSG)
128
129        try:
130            self.anritsu = MD8475A(self.md8475a_ip_address, self.wlan_option,
131                                   self.md8475_version)
132        except AnritsuError:
133            self.log.error("Error in connecting to Anritsu Simulator")
134            return False
135        self.activation_attemps = self.user_params.get("activation_attemps", 3)
136        return True
137
138    def setup_test(self):
139        if getattr(self, "qxdm_log", True):
140            start_qxdm_loggers(self.log, self.android_devices)
141        ensure_phones_idle(self.log, self.android_devices)
142        toggle_airplane_mode(self.log, self.ad, True)
143        return True
144
145    def teardown_test(self):
146        self.log.info("Stopping Simulation")
147        self.anritsu.stop_simulation()
148        toggle_airplane_mode(self.log, self.ad, True)
149
150    def teardown_class(self):
151        self.anritsu.disconnect()
152        return True
153
154    def _bring_up_callbox(
155            self,
156            set_simulation_func,
157            rat):
158        try:
159            [self.bts1] = set_simulation_func(self.anritsu, self.user_params,
160                                              self.ad.sim_card)
161            set_usim_parameters(self.anritsu, self.ad.sim_card)
162            if rat == RAT_LTE:
163                set_post_sim_params(self.anritsu, self.user_params,
164                                    self.ad.sim_card)
165            self.anritsu.start_simulation()
166
167            if rat == RAT_LTE:
168                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
169                rat_family = RAT_FAMILY_LTE
170            else:
171                self.log.error("No valid RAT provided to bring up callbox.")
172                return False
173
174            if not ensure_preferred_network_type_for_subscription(
175                    self.ad,
176                    preferred_network_setting):
177                self.log.error(
178                    "Failed to set rat family {}, preferred network:{}".format(
179                        rat_family, preferred_network_setting))
180                return False
181
182            if self.ad.droid.connectivityCheckAirplaneMode():
183                toggle_airplane_mode(self.log, self.ad, False)
184        except AnritsuError as e:
185            self.log.error("Error in connection with Anritsu Simulator: " +
186                           str(e))
187            return False
188        return True
189
190    def pre_switching_callbox_setup(self):
191        """ Setup environment to enable carrier switching
192        Returns:
193            True if pass; False if fail
194        """
195        return self._bring_up_callbox(set_system_model_lte, RAT_LTE)
196
197    def _install_account_util(self, ad):
198        account_util = self.user_params["account_util"]
199        if isinstance(account_util, list):
200            account_util = account_util[0]
201        ad.log.info("Install account_util %s", account_util)
202        ad.ensure_screen_on()
203        ad.adb.install("-r %s" % account_util, timeout=300, ignore_status=True)
204        time.sleep(3)
205        if not ad.is_apk_installed("com.google.android.tradefed.account"):
206            ad.log.info("com.google.android.tradefed.account is not installed")
207            return False
208        return True
209
210    def _account_registration(self, ad):
211        toggle_airplane_mode_by_adb(self.log, ad, new_state=False)
212        for cmd in _TYCHO_VERBOSE_LOGGING_CMDS:
213            ad.adb.shell(cmd)
214        if hasattr(ad, "user_account"):
215            ad.exit_setup_wizard()
216            if not ad.is_apk_installed("com.google.android.tradefed.account"
217                                       ) and \
218                    self.user_params.get("account_util"):
219                for _ in range(2):
220                    if self._install_account_util(ad):
221                        break
222                else:
223                    ad.log.error(
224                        "Fail to install com.google.android.tradefed.account")
225                    return False
226            ad.force_stop_apk(_TYCHO_PKG)
227            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
228                                         self.wifi_network_pass):
229                ad.log.error("Failed to connect to wifi")
230                return False
231            ad.log.info("Add google account")
232            if not add_google_account(ad):
233                ad.log.error("Failed to add google account")
234                return False
235            ad.adb.shell(
236                'am instrument -w -e account "%s@gmail.com" -e password '
237                '"%s" -e sync true -e wait-for-checkin false '
238                'com.google.android.tradefed.account/.AddAccount' %
239                (ad.user_account, ad.user_password))
240            ad.log.info("Enable and activate tycho apk")
241            if not ad.is_apk_installed(_TYCHO_PKG):
242                ad.log.info("%s is not installed", _TYCHO_PKG)
243                return False
244            ad.adb.shell('pm enable %s' % _TYCHO_PKG)
245            # ad.adb.shell(_TYCHO_SERVER_LAB_OVERRIDE_CMD)
246            for i in range(1, self.activation_attemps + 1):
247                if i == self.activation_attemps:
248                    ad.log.info("Reboot and try Fi activation again")
249                    reboot_device(ad)
250                self.activate_fi_account(ad)
251                if not self.check_project_fi_activated(ad):
252                    ad.log.error("Fail to activate Fi account on attempt-%s",
253                                 i)
254                    if i == self.activation_attemps:
255                        return False
256                else:
257                    ad.log.info("Fi account is activated successfully")
258                    break
259        elif "Fi Network" in ad.adb.getprop("gsm.sim.operator.alpha"):
260            ad.log.error("Google account is not provided for Fi Network")
261            return False
262        if not ensure_phone_subscription(self.log, ad):
263            ad.log.error("Unable to find a valid subscription!")
264            return False
265        refresh_droid_config(self.log, ad)
266        return True
267
268    def start_service(self, ad, package, service_id, extras, action_type):
269        """Starts the specified service.
270
271        Args:
272          ad: (android_device.AndroidDevice) device to start activity on
273          package: (str) the package to start the service from
274          service_id: (str) service to start
275          extras: (dict) extras needed to specify with the activity id
276          action_type: The action type id to create the intent
277        """
278        ad.log.info('Starting service %s/.%s.', package, service_id)
279        intent = ad.droid.makeIntent(action_type, None, None, extras,
280                                     ['android.intent.category.DEFAULT'],
281                                     package, package + '.' + service_id,
282                                     _INTENT_FLAGS)
283        ad.droid.startServiceIntent(intent)
284
285    def start_activity(self, ad, package, activity_id, extras=None):
286        """Starts the specified activity.
287
288        Args:
289          ad: (android_device.AndroidDevice) device to start activity on
290          package: (str) the package to start
291          activity_id: (str) activity to start
292          extras: (dict) extras needed to specify with the activity id
293        """
294        ad.log.info('Starting activity %s/.%s.', package, activity_id)
295        intent = ad.droid.makeIntent(ActionTypeId.MAIN, None, None, extras,
296                                     ['android.intent.category.LAUNCHER'],
297                                     package, package + '.' + activity_id,
298                                     _INTENT_FLAGS)
299        ad.droid.startActivityIntent(intent, False)
300
301    def activate_fi_account(self, ad):
302        """Start Tycho InitActivity.
303
304        For in-app Tycho activition (post-SUW tests), Tycho does not
305        automatically trigger OMADM process. This method is used to start
306        Tycho InitActivity before launching super network activation.
307
308        The device will finally stay on Sprint network if everything goes well.
309
310        Args:
311          ad: Android device need to start Tycho InitActivity.
312        """
313        ad.force_stop_apk(_TYCHO_PKG)
314        ad.send_keycode("HOME")
315        extra = {'in_setup_wizard': False, 'force_show_account_chooser': False}
316        self.start_activity(ad, _TYCHO_PKG, TychoClassId.INIT_ACTIVITY, extra)
317        for _ in range(30):
318            ad.send_keycode("WAKEUP")
319            time.sleep(1)
320            current_window = ad.get_my_current_focus_window()
321            log_screen_shot(ad, self.test_name)
322            if ad.adb.shell(
323                    "settings get global device_provisioning_mobile_data"
324            ) != "1":
325                ad.adb.shell(
326                    "settings put global device_provisioning_mobile_data 1")
327            if 'SwitchConfirmDialogActivity' in current_window:
328                ad.log.info("In Switch Confirmation Dialog")
329                if ad.adb.getprop("ro.build.version.release")[0] not in ("8",
330                                                                         "O"):
331                    ad.send_keycode("TAB")
332                ad.send_keycode("TAB")
333                ad.send_keycode("ENTER")
334                time.sleep(10)
335            elif 'tycho.InitActivity' in current_window:
336                ad.log.info("In Tycho InitActivity")
337                ad.send_keycode("TAB")
338                ad.send_keycode("TAB")
339                ad.send_keycode("ENTER")
340                time.sleep(10)
341
342            elif 'tycho.AccountChooserActivity' in current_window:
343                ad.send_keycode("ENTER")
344            else:
345                ad.log.info("Finished activation process")
346                return
347
348    def check_project_fi_activated(self, ad, retries=20):
349        for _ in range(retries):
350            if is_sim_ready(self.log, ad) and (
351                    ad.droid.telephonyGetSimOperatorName() == "Fi Network"):
352                ad.log.info("SIM state is READY, SIM operator is Fi")
353                return True
354            time.sleep(5)
355
356    def start_tycho_activation(self, ad):
357        """Start the Tycho client and register to cellular network.
358
359        Starts Tycho within SUW:
360         - Tycho is expected to follow the in-SUW work flow:
361          - Tycho will perform TychoInit, handshake to server,
362            account configuration, etc
363          - If successful, Tycho will trigger a switch to Sprint Network
364          - If successful, Tycho will start OMA-DM activation sessions
365
366        The device will finally stay on Sprint network if everything goes well.
367
368        Args:
369          ad: Android device need to start Tycho activation.
370        """
371        extra = {'device_setup': True, 'has_account': True}
372        self.start_activity(ad, _TYCHO_PKG, TychoClassId.CARRIER_SETUP, extra)
373
374    def start_super_network_activation(self, ad):
375        """Start the Super-Network activation.
376
377        For in-app Tycho activition (post-SUW tests), this method starts
378        super-network activation after Tycho is initialized.
379
380        The device will finally stay on Sprint network if everything goes well.
381
382        Args:
383          ad: Android device need to start Tycho super network activation.
384        """
385        extra = {'in_setup_wizard': False, 'is_interactive': True}
386        self.start_service(ad, _TYCHO_PKG,
387                           TychoClassId.ACTIVATE_SUPER_NETWORK_SERVICE, extra,
388                           ActionTypeId.TYCHO_ACTIVATE_SUPER_NETWORK)
389
390    def get_active_carrier(self, ad):
391        """Gets the active carrier profile value from the device.
392
393        Args:
394            ad: An AndroidDevice Object.
395
396        Returns:
397            (string) A key from the CARRIER_TO_MCC_MNC map representing the
398            active carrier.
399
400        Raises:
401            KeyError: when an mcc_mnc code reported by the device is not a
402            recognized Fi partner carrier.
403        """
404        mcc_mnc = ad.droid.telephonyGetSimOperator()
405        if not mcc_mnc:
406            return "UNKNOWN"
407        try:
408            return operator_name_from_plmn_id(mcc_mnc)
409        except KeyError:
410            ad.log.error('Unknown Mobile Country Code/Mobile Network Code %s',
411                         mcc_mnc)
412            raise
413
414    def switch_sim(self, ad):
415        """Requests switch between physical sim and esim.
416
417        Args:
418            ad: An AndroidDevice Object.
419            timeout: (optional -- integer) the number of seconds in which a
420                     switch should be completed.
421
422        Raises:
423            Error: whenever a device is not set to the desired carrier within
424                   the timeout window.
425        """
426        old_sim_operator = ad.droid.telephonyGetSimOperatorName()
427        ad.log.info("Before SIM switch, SIM operator = %s", old_sim_operator)
428        send_dialer_secret_code(ad, "794824746")
429        time.sleep(10)
430        new_sim_operator = ad.droid.telephonyGetSimOperatorName()
431        ad.log.info("After SIM switch, SIM operator = %s", new_sim_operator)
432        refresh_droid_config(self.log, ad)
433        return old_sim_operator != new_sim_operator
434
435    def set_active_carrier(self,
436                           ad,
437                           carrier,
438                           timeout=_MAX_WAIT_TIME,
439                           check_interval=10):
440        """Requests an active carrier to be set on the device sim.
441
442        If switching to a different carrier, after the switch is completed
443        auto-switching will be disabled. To re-enable, call
444        enable_auto_switching.
445
446        Args:
447            ad: An AndroidDevice Object.
448            carrier: (carrier_constants.Carrier) Which carrier to switch to.
449            timeout: (optional -- integer) the number of seconds in which a
450                     switch should be completed.
451
452        Raises:
453            Error: whenever a device is not set to the desired carrier within
454                   the timeout window.
455        """
456        # If there's no need to switch, then don't.
457
458        if self.pre_switching_callbox_setup():
459            self.log.info("Turned ON Anritsu for Switching")
460            pass
461        else:
462            self.log.error("Failed to Camp to Anritsu")
463            return False
464
465        max_time = timeout
466        while max_time >= 0:
467            if self.is_ready_to_make_carrier_switch(ad):
468                break
469            time.sleep(check_interval)
470            max_time -= check_interval
471        else:
472            ad.log.error("Device stays in carrier switch lock state")
473            return False
474        if carrier == CARRIER_AUTO:
475            send_dialer_secret_code(ad, _CARRIER_DIALER_CODE_LOOKUP[carrier])
476            return True
477        old_carrier = self.get_active_carrier(ad)
478        if carrier == old_carrier:
479            ad.log.info('Already on %s, so no need to switch', carrier)
480            return True
481
482        # Start switch on device, using events to verify that the switch starts.
483        ad.log.info('Initiating unsolicited switch from %s to %s.',
484                    old_carrier, carrier)
485        send_dialer_secret_code(ad, _CARRIER_DIALER_CODE_LOOKUP[carrier])
486        return self.wait_for_carrier_switch_completed(
487            ad, carrier, timeout=timeout, check_interval=check_interval)
488
489    def is_switching_silent(self, ad):
490        """Checks if Tycho switching controller is in silent mode.
491
492        Note that silent mode is a sign of airplane mode, not of a switching \
493        lock.
494
495        Args: ad: An AndroidDevice Object.
496
497        Returns:
498            A Boolean True if the preferences file reports True, False
499            otherwise.
500        """
501        return "isInSilentMode\" value=\"true" in ad.adb.shell(
502            "cat %s | grep isInSilentMode" % _SWITCHING_PREF_FILE,
503            ignore_status=True)
504
505    def is_switching_locked(self, ad):
506        """Checks if Tycho switching controller is locked.
507
508        Args: ad: An AndroidDevice Object.
509
510        Returns:
511            A Boolean True if the switching controller is locked for any reason,
512            False otherwise.
513        """
514        return "switchingInProgress\" value=\"true" in ad.adb.shell(
515            "cat %s | grep switchingInProgress" % _SWITCHING_PREF_FILE)
516
517    def is_ready_to_make_carrier_switch(self, ad):
518        """Checks if device is ready to make carrier switch.
519
520        Args:
521            ad: An AndroidDevice Object.
522
523        Returns:
524             A Boolean True if it is ready to make switch, False otherwise.
525        """
526        # Check Tycho switching controller states.
527        if self.is_switching_silent(ad):
528            ad.log.info(
529                "Cannot make carrier switch: SwitchingController is in silent "
530                "mode!")
531            return False
532        if self.is_switching_locked(ad):
533            ad.log.info(
534                "Cannot make carrier switch: SwitchingController is locked!")
535            return False
536        if self.is_carrier_switch_in_progress(ad):
537            ad.log.info("Cannot make carrier switch: Switch in progress!")
538            return False
539        return True
540
541    def is_carrier_switch_in_progress(self, ad):
542        """Checks if Tycho says that a switch is currently in progress.
543
544        Args:
545            ad: An AndroidDevice Object.
546
547        Returns:
548             A Boolean True if the preferences file reports True, False
549             otherwise.
550        """
551        switching_preferences = ad.adb.shell("cat %s" % _SWITCHING_PREF_FILE)
552        return 'InProgress\" value=\"true' in switching_preferences
553
554    def check_network_carrier(self, ad, carrier):
555        current_carrier = self.get_active_carrier(ad)
556        ad.log.info("Current network carrier is %s", current_carrier)
557        is_in_switch = self.is_carrier_switch_in_progress(ad)
558        ad.log.info("Device in carrier switch progress mode")
559        return current_carrier == carrier and is_in_switch
560
561    def wait_for_carrier_switch_completed(self,
562                                          ad,
563                                          carrier,
564                                          timeout=_MAX_WAIT_TIME,
565                                          check_interval=10):
566        """Wait for carrier switch to complete.
567
568        This function waits for a carrier switch to complete by monitoring the
569        Tycho switching controller preference file.
570
571        Args:
572            ad: An Android device object.
573            carrier: The target carrier network to switch to.
574            timeout: (integer) Time wait for switch to complete.
575
576        Return:
577            True or False for successful/unsuccessful switch.
578        """
579        check_args = [ad, carrier]
580        if wait_for_state(self.check_network_carrier, True, check_interval,
581                          timeout, *check_args):
582            ad.log.info("Switched to %s successfully", carrier)
583            ad.send_keycode("ENTER")
584            return True
585        else:
586            active_carrier = self.get_active_carrier(ad)
587            if active_carrier == carrier:
588                ad.log.info("Switched to %s successfully", carrier)
589                return True
590            ad.log.error("Carrier is %s. Fail to switch to %s", active_carrier,
591                         carrier)
592            return False
593
594    def operator_network_switch(self, ad, carrier):
595        if ad.droid.telephonyGetSimOperatorName() == "Google Fi":
596            for i in range(3):
597                if self.set_active_carrier(ad, carrier):
598                    break
599                elif i == 2:
600                    ad.log.error("Failed to switch to %s", carrier)
601                    return False
602        if not ensure_phone_subscription(self.log, ad):
603            ad.log.error("Unable to find a valid subscription!")
604            return False
605        refresh_droid_config(self.log, ad)
606        return True
607
608    def network_switch_test(self, carrier):
609        tasks = [(self.operator_network_switch, [ad, carrier])
610                 for ad in self.android_devices]
611        if not multithread_func(self.log, tasks):
612            abort_all_tests(self.log,
613                            "Unable to switch to network %s" % carrier)
614        return True
615
616    """ Tests Begin """
617
618    @test_tracker_info(uuid="4d92318e-4980-471a-882b-3136c5dda384")
619    @TelephonyBaseTest.tel_test_wrap
620    def test_project_fi_account_activation(self):
621        """Test activate Fi account.
622
623        Returns:
624            True if success.
625            False if failed.
626        """
627        tasks = [(self._account_registration, [ad])
628                 for ad in self.android_devices]
629        try:
630            if not multithread_func(self.log, tasks):
631                abort_all_tests(self.log, "Unable to activate Fi account!")
632        except Exception as e:
633            self.log.error(e)
634            abort_all_tests(self.log, "Unable to activate Fi account!")
635        return True
636
637    @test_tracker_info(uuid="6bfbcc1d-e318-4964-bf36-5b82f086860d")
638    @TelephonyBaseTest.tel_test_wrap
639    def test_switch_to_tmobile_network(self):
640        """Test switch to tmobile network.
641
642        Returns:
643            True if success.
644            False if failed.
645        """
646        setattr(self.ad, "sim_card", "FiTMO")
647        return self.network_switch_test(CARRIER_TMO)
648
649    @test_tracker_info(uuid="4f27944d-f3c5-423d-b0c5-5c66dbb98376")
650    @TelephonyBaseTest.tel_test_wrap
651    def test_switch_to_sprint_network(self):
652        """Test switch to sprint network.
653
654        Returns:
655            True if success.
656            False if failed.
657        """
658        setattr(self.ad, "sim_card", "FiSPR")
659        return self.network_switch_test(CARRIER_SPT)
660
661    @test_tracker_info(uuid="5f30c9bd-b79e-4805-aa46-7855ed9023f0")
662    @TelephonyBaseTest.tel_test_wrap
663    def test_switch_to_uscc_network(self):
664        """Test switch to uscc network.
665
666        Returns:
667            True if success.
668            False if failed.
669        """
670        setattr(self.ad, "sim_card", "FiUSCC")
671        return self.network_switch_test(CARRIER_USCC)
672
673    @test_tracker_info(uuid="0b062751-d59d-420e-941e-3ffa02aea0d5")
674    @TelephonyBaseTest.tel_test_wrap
675    def test_switch_to_auto_network(self):
676        """Test switch to auto network selection.
677
678        Returns:
679            True if success.
680            False if failed.
681        """
682        return self.network_switch_test(CARRIER_AUTO)
683
684    @test_tracker_info(uuid="13c5f080-69bf-42fd-86ed-c67b1984c347")
685    @TelephonyBaseTest.tel_test_wrap
686    def test_switch_between_sim(self):
687        """Test switch between physical sim and esim.
688
689        Returns:
690            True if success.
691            False if failed.
692        """
693        for ad in self.android_devices:
694            self.switch_sim(ad)
695
696    @test_tracker_info(uuid="")
697    @TelephonyBaseTest.tel_test_wrap
698    def test_remove_google_account(self):
699        for ad in self.android_devices:
700            remove_google_account(ad)
701
702
703""" Tests End """
704