Example #1
0
 def fake_emergency_call_test(self, by_emergency_dialer=True, attemps=3):
     self.dut.log.info("ServiceState is in %s",
                       get_service_state_by_adb(self.log, self.dut))
     if by_emergency_dialer:
         dialing_func = initiate_emergency_dialer_call_by_adb
         callee = self.fake_emergency_number
     else:
         dialing_func = initiate_call
         # Initiate_call method has to have "+" in front
         # otherwise the number will be in dialer without dial out
         # with sl4a fascade. Need further investigation
         callee = "+%s" % self.fake_emergency_number
     for i in range(attemps):
         begin_time = get_current_epoch_time()
         result = True
         if not self.change_emergency_number_list():
             self.dut.log.error("Unable to add number to ril.ecclist")
             return False
         time.sleep(1)
         last_call_number = dumpsys_last_call_number(self.dut)
         call_result = dialing_func(self.log, self.dut, callee)
         time.sleep(3)
         hangup_call_by_adb(self.dut)
         if not call_result:
             last_call_drop_reason(self.dut, begin_time)
         self.dut.send_keycode("BACK")
         self.dut.send_keycode("BACK")
         if not dumpsys_new_call_info(self.dut, last_call_number):
             result = False
         if call_result == self.expected_call_result:
             self.dut.log.info("Call to %s returns %s as expected", callee,
                               self.expected_call_result)
         else:
             self.dut.log.info("Call to %s returns %s", callee,
                               not self.expected_call_result)
             result = False
         if result:
             return True
         ecclist = self.dut.adb.getprop("ril.ecclist")
         self.dut.log.info("ril.ecclist = %s", ecclist)
         if self.fake_emergency_number in ecclist:
             if i == attemps - 1:
                 self.dut.log.error("%s is in ril-ecclist, but call failed",
                                    self.fake_emergency_number)
             else:
                 self.dut.log.warning(
                     "%s is in ril-ecclist, but call failed, try again",
                     self.fake_emergency_number)
         else:
             if i == attemps - 1:
                 self.dut.log.error("Fail to write %s to ril-ecclist",
                                    self.fake_emergency_number)
             else:
                 self.dut.log.info("%s is not in ril-ecclist",
                                   self.fake_emergency_number)
     self.dut.log.info("fake_emergency_call_test result is %s", result)
     return result
Example #2
0
    def check_emergency_call_back_mode(self,
                                       by_emergency_dialer=True,
                                       non_emergency_call_allowed=True,
                                       attemps=3):
        state = "true" if non_emergency_call_allowed else "false"
        self.set_allow_non_emergency_call(state)
        result = True
        for _ in range(attemps):
            if not self.change_emergency_number_list():
                self.dut.log.error("Unable to add number to ril.ecclist")
                return False
            last_call_number = dumpsys_last_call_number(self.dut)
            self.dut.log.info("Hung up fake emergency call in ringing")
            if by_emergency_dialer:
                initiate_emergency_dialer_call_by_adb(
                    self.log, self.dut, self.fake_emergency_number, timeout=0)
            else:
                callee = "+%s" % self.fake_emergency_number
                self.dut.droid.telecomCallNumber(callee)
            time.sleep(3)
            hangup_call_by_adb(self.dut)
            ecclist = self.dut.adb.getprop("ril.ecclist")
            self.dut.log.info("ril.ecclist = %s", ecclist)
            if self.fake_emergency_number in ecclist:
                break
        call_info = dumpsys_new_call_info(self.dut, last_call_number)
        if not call_info:
            return False
        call_tech = call_info.get("callTechnologies", "")
        if "CDMA" in call_tech:
            expected_ecbm = True
            expected_data = False
            expected_call = non_emergency_call_allowed
        elif "GSM" in call_tech:
            expected_ecbm = True
            expected_data = True
            expected_call = True
        else:
            expected_ecbm = False
            expected_data = True
            expected_call = True
        last_call_number = dumpsys_last_call_number(self.dut)
        begin_time = get_current_epoch_time()
        self.dut.ensure_screen_on()
        self.dut.exit_setup_wizard()
        reset_device_password(self.dut, None)
        call_check = call_setup_teardown(self.log,
                                         self.dut,
                                         self.android_devices[1],
                                         ad_hangup=self.dut)
        if call_check != expected_call:
            self.dut.log.error("Regular phone call is %s, expecting %s",
                               call_check, expected_call)
            result = False
        call_info = dumpsys_new_call_info(self.dut, last_call_number)
        if not call_info:
            self.dut.log.error("New call is not in dumpsys telecom")
            return False
        if expected_ecbm:
            if "ecbm" in call_info["callProperties"]:
                self.dut.log.info("New call is in ecbm.")
            else:
                self.dut.log.error(
                    "New call is not in emergency call back mode.")
                result = False
        else:
            if "ecbm" in call_info["callProperties"]:
                self.dut.log.error("New call is in emergency call back mode")
                result = False
        if not expected_data:
            if self.dut.droid.telephonyGetDataConnectionState():
                self.dut.log.info(
                    "Data connection is off as expected in ECB mode")
                self.dut.log.info("Wait for getting out of ecbm")
                if not wait_for_cell_data_connection(self.log, self.dut, True,
                                                     400):
                    self.dut.log.error(
                        "Data connection didn't come back after 5 minutes")
                    result = False
                #if not self.dut.droid.telephonyGetDataConnectionState():
                #    self.dut.log.error(
                #        "Data connection is not coming back")
                #    result = False
                elif not verify_internet_connection(self.log, self.dut):
                    self.dut.log.error(
                        "Internet connection check failed after getting out of ECB"
                    )
                    result = False

            else:
                self.dut.log.error("Data connection is not off in ECB mode")
                if not verify_internet_connection(self.log, self.dut, False):
                    self.dut.log.error("Internet connection is not off")
                    result = False
        else:
            if self.dut.droid.telephonyGetDataConnectionState():
                self.dut.log.info("Data connection is on as expected")
                if not verify_internet_connection(self.log, self.dut):
                    self.dut.log.error("Internet connection check failed")
                    result = False
            else:
                self.dut.log.error("Data connection is off, expecting on")
                result = False
        if expected_call:
            return result
        elapsed_time = (get_current_epoch_time() - begin_time) / 1000
        if elapsed_time < BLOCK_DURATION:
            time.sleep(BLOCK_DURATION - elapsed_time + 10)
        if not call_setup_teardown(
                self.log, self.dut, self.android_devices[1],
                ad_hangup=self.dut):
            self.dut.log.error("Regular phone call failed after out of ecbm")
            result = False
        return result
    def _cbrs_call_sequence(
            self, ads, mo_mt, cbrs_phone_setup_func,
            verify_cbrs_initial_idle_func, verify_data_initial_func,
            verify_cbrs_in_call_state_func, verify_data_in_call_func,
            incall_cbrs_setting_check_func, verify_data_final_func,
            verify_cbrs_final_func, expected_result):
        """_cbrs_call_sequence

        Args:
            ads: list of android devices. This list should have 2 ad.
            mo_mt: indicating this call sequence is MO or MT.
                Valid input: DIRECTION_MOBILE_ORIGINATED and
                DIRECTION_MOBILE_TERMINATED.

        Returns:
            if expected_result is True,
                Return True if call sequence finish without exception.
            if expected_result is string,
                Return True if expected exception happened. Otherwise False.

        """
        class _CBRSCallSequenceException(Exception):
            pass

        if (len(ads) != 2) or (mo_mt not in [
                DIRECTION_MOBILE_ORIGINATED, DIRECTION_MOBILE_TERMINATED
        ]):
            self.log.error("Invalid parameters.")
            return False

        self.cbrs_subid, self.default_subid = get_cbrs_and_default_sub_id(
            ads[0])

        if mo_mt == DIRECTION_MOBILE_ORIGINATED:
            ad_caller = ads[0]
            ad_callee = ads[1]
            caller_number = get_phone_number(self.log, ad_caller)
            callee_number = get_phone_number(self.log, ad_callee)
            mo_operator = get_operator_name(ads[0].log, ads[0])
            mt_operator = get_operator_name(ads[1].log, ads[1])
        else:
            ad_caller = ads[1]
            ad_callee = ads[0]
            caller_number = get_phone_number(self.log, ad_caller)
            callee_number = get_phone_number(self.log, ad_callee)
            mt_operator = get_operator_name(ads[0].log, ads[0])
            mo_operator = get_operator_name(ads[1].log, ads[1])

        self.log.info("-->Begin cbrs_call_sequence: %s to %s<--",
                      caller_number, callee_number)
        self.log.info("--> %s to %s <--", mo_operator, mt_operator)

        try:
            # Setup
            if cbrs_phone_setup_func and not cbrs_phone_setup_func():
                raise _CBRSCallSequenceException("cbrs_phone_setup_func fail.")
            if not phone_setup_voice_general(self.log, ads[1]):
                raise _CBRSCallSequenceException(
                    "phone_setup_voice_general fail.")
            time.sleep(WAIT_TIME_BETWEEN_REG_AND_CALL)

            # Ensure idle status correct
            if verify_cbrs_initial_idle_func and not \
                verify_cbrs_initial_idle_func():
                raise _CBRSCallSequenceException(
                    "verify_cbrs_initial_idle_func fail.")

            # Ensure data checks are performed
            if verify_data_initial_func and not \
                verify_data_initial_func():
                raise _CBRSCallSequenceException(
                    "verify_data_initial_func fail.")

            # Make MO/MT call.
            if not initiate_call(self.log, ad_caller, callee_number):
                raise _CBRSCallSequenceException("initiate_call fail.")
            if not wait_and_answer_call(self.log, ad_callee, caller_number):
                raise _CBRSCallSequenceException("wait_and_answer_call fail.")
            time.sleep(WAIT_TIME_FOR_CBRS_DATA_SWITCH)

            # Check state, wait 30 seconds, check again.
            if (verify_cbrs_in_call_state_func
                    and not verify_cbrs_in_call_state_func()):
                raise _CBRSCallSequenceException(
                    "verify_cbrs_in_call_state_func fail.")

            if is_phone_not_in_call(self.log, ads[1]):
                raise _CBRSCallSequenceException("PhoneB not in call.")

            # Ensure data checks are performed
            if verify_data_in_call_func and not \
                verify_data_in_call_func():
                raise _CBRSCallSequenceException(
                    "verify_data_in_call_func fail.")

            time.sleep(WAIT_TIME_IN_CALL)

            if (verify_cbrs_in_call_state_func
                    and not verify_cbrs_in_call_state_func()):
                raise _CBRSCallSequenceException(
                    "verify_cbrs_in_call_state_func fail after 30 seconds.")
            if is_phone_not_in_call(self.log, ads[1]):
                raise _CBRSCallSequenceException(
                    "PhoneB not in call after 30 seconds.")

            # in call change setting and check
            if (incall_cbrs_setting_check_func
                    and not incall_cbrs_setting_check_func()):
                raise _CBRSCallSequenceException(
                    "incall_cbrs_setting_check_func fail.")

            # Hangup call
            if is_phone_in_call(self.log, ads[0]):
                if not hangup_call(self.log, ads[0]):
                    raise _CBRSCallSequenceException("hangup_call fail.")
            else:
                if incall_cbrs_setting_check_func is None:
                    raise _CBRSCallSequenceException("Unexpected call drop.")

            time.sleep(WAIT_TIME_FOR_CBRS_DATA_SWITCH)

            # Ensure data checks are performed
            if verify_data_final_func and not \
                verify_data_final_func():
                raise _CBRSCallSequenceException(
                    "verify_data_final_func fail.")

            # Ensure data checks are performed
            if verify_cbrs_final_func and not \
                verify_cbrs_final_func():
                raise _CBRSCallSequenceException(
                    "verify_cbrs_final_func fail.")

        except _CBRSCallSequenceException as e:
            if str(e) == expected_result:
                self.log.info("Expected exception: <%s>, return True.", e)
                return True
            else:
                self.log.info("Unexpected exception: <%s>, return False.", e)
                return False
        finally:
            for ad in ads:
                if ad.droid.telecomIsInCall():
                    hangup_call_by_adb(ad)
        self.log.info("cbrs_call_sequence finished, return %s",
                      expected_result is True)
        return (expected_result is True)
    def _test_CBRS_switch(self, ads, verify_data_is_on_cbrs,
                          verify_data_initial_func, simulate_signal,
                          verify_data_in_call_func,
                          incall_cbrs_setting_check_func, stop_simulation,
                          verify_data_final_func, verify_cbrs_final_func,
                          expected_result):
        """ Test CBRS Signal in Reduced Signal Strength
        By Default Data will be on CBRS.
        Fake Signal strength of CBRS to weak.
        Verify the data is switched to LTE.
        Increase the signal strength on CBRS
        Verify data is back on CBRS.
        """
        class _CBRSCallSequenceException1(Exception):
            pass

        self.cbrs_subid, self.default_subid = get_cbrs_and_default_sub_id(
            ads[0])

        # Check if Data is on CBRS
        try:
            if verify_data_is_on_cbrs and not \
                verify_data_is_on_cbrs():
                raise _CBRSCallSequenceException1(
                    "verify_cbrs_initial_idle_func fail.")

            # Check if Data works well on CBRS
            if verify_data_initial_func and not \
                verify_data_initial_func():
                raise _CBRSCallSequenceException1(
                    "verify_data_initial_func fail.")

            # Reduce the Signal strength on CBRS
            self.log.info("Simulating the Signal using Scone CAT")
            load_scone_cat_simulate_data(ads[0], simulate_signal[0], 1)
            time.sleep(15)

            # Ensure data checks are performed and it works on Default Sub Id
            if verify_data_in_call_func and not \
                verify_data_in_call_func():
                raise _CBRSCallSequenceException1(
                    "verify_data_on_default SubId fail.")

            # in call change setting and check
            if (incall_cbrs_setting_check_func and not \
                incall_cbrs_setting_check_func()):
                raise _CBRSCallSequenceException1(
                    "incall_cbrs_setting_check_func fail.")

            # Stop Stimulation and wait for CBRS signal to recover
            load_scone_cat_simulate_data(ads[0], stop_simulation[0], 1)
            time.sleep(15)

            # Verify Data is Back on CBRS
            # Ensure data checks are performed
            if verify_data_final_func and not \
                verify_data_final_func():
                raise _CBRSCallSequenceException1(
                    "verify_data_final_func fail.")

            # Ensure data checks are performed
            if verify_cbrs_final_func and not \
                verify_cbrs_final_func():
                raise _CBRSCallSequenceException1(
                    "verify_cbrs_final_func fail.")

        except _CBRSCallSequenceException1 as e:
            if str(e) == expected_result:
                self.log.info("Expected exception: <%s>, return True.", e)
                return True
            else:
                self.log.info("Unexpected exception: <%s>, return False.", e)
                return False
        finally:
            for ad in ads:
                if ad.droid.telecomIsInCall():
                    hangup_call_by_adb(ad)
        self.log.info("cbrs_data_switch finished, return %s",
                      expected_result is True)
        return (expected_result is True)
Example #5
0
 def _make_phone_call(self, call_verification_func=None):
     ads = self.android_devices[:]
     if not self.single_phone_test:
         random.shuffle(ads)
     the_number = self.result_info["Call Total"] + 1
     duration = random.randrange(self.min_phone_call_duration,
                                 self.max_phone_call_duration)
     result = True
     test_name = "%s_No_%s_phone_call" % (self.test_name, the_number)
     log_msg = "[Test Case] %s" % test_name
     self.log.info("%s for %s seconds begin", log_msg, duration)
     begin_time = get_device_epoch_time(ads[0])
     for ad in self.android_devices:
         if self.user_params.get("turn_on_tcpdump", True):
             start_adb_tcpdump(ad, interface="any", mask="all")
         if not getattr(ad, "droid", None):
             ad.droid, ad.ed = ad.get_droid()
             ad.ed.start()
         else:
             try:
                 if not ad.droid.is_live:
                     ad.droid, ad.ed = ad.get_droid()
                     ad.ed.start()
                 else:
                     ad.ed.clear_all_events()
             except Exception:
                 ad.log.info("Create new sl4a session for phone call")
                 ad.droid, ad.ed = ad.get_droid()
                 ad.ed.start()
         ad.droid.logI("%s begin" % log_msg)
     start_qxdm_loggers(self.log, self.android_devices, begin_time)
     failure_reasons = set()
     self.dut_incall = True
     if self.single_phone_test:
         call_setup_result = initiate_call(
             self.log,
             self.dut,
             self.call_server_number,
             incall_ui_display=INCALL_UI_DISPLAY_BACKGROUND
         ) and wait_for_in_call_active(self.dut, 60, 3)
     else:
         call_setup_result = call_setup_teardown(
             self.log,
             ads[0],
             ads[1],
             ad_hangup=None,
             verify_caller_func=call_verification_func,
             verify_callee_func=call_verification_func,
             wait_time_in_call=0,
             incall_ui_display=INCALL_UI_DISPLAY_BACKGROUND)
     if not call_setup_result:
         call_logs = ads[0].search_logcat(
             "ActivityManager: START u0 {act=android.intent.action.CALL",
             begin_time)
         messaging_logs = ads[0].search_logcat(
             "com.google.android.apps.messaging/.ui.conversation.ConversationActivity",
             begin_time)
         if call_logs and messaging_logs:
             if messaging_logs[-1]["datetime_obj"] - call_logs[-1]["datetime_obj"] < 5:
                 ads[0].log.info(
                     "Call setup failure due to simultaneous activities")
                 self.result_info[
                     "Call Setup Failure With Simultaneous Activity"] += 1
                 return True
         self.log.error("%s: Setup Call failed.", log_msg)
         failure_reasons.add("Setup")
         result = False
     else:
         elapsed_time = 0
         check_interval = 5
         while (elapsed_time < duration):
             check_interval = min(check_interval, duration - elapsed_time)
             time.sleep(check_interval)
             elapsed_time += check_interval
             time_message = "at <%s>/<%s> second." % (elapsed_time,
                                                      duration)
             for ad in ads:
                 if not call_verification_func(self.log, ad):
                     ad.log.warning("Call is NOT in correct %s state at %s",
                                    call_verification_func.__name__,
                                    time_message)
                     if call_verification_func.__name__ == "is_phone_in_call_iwlan":
                         if is_phone_in_call(self.log, ad):
                             if getattr(ad, "data_rat_state_error_count",
                                        0) < 1:
                                 setattr(ad, "data_rat_state_error_count",
                                         1)
                                 continue
                     failure_reasons.add("Maintenance")
                     last_call_drop_reason(ad, begin_time)
                     hangup_call(self.log, ads[0])
                     result = False
                 else:
                     ad.log.info("Call is in correct %s state at %s",
                                 call_verification_func.__name__,
                                 time_message)
             if not result:
                 break
     if not hangup_call(self.log, ads[0]):
         failure_reasons.add("Teardown")
         result = False
     for ad in ads:
         if not wait_for_call_id_clearing(ad,
                                          []) or ad.droid.telecomIsInCall():
             ad.log.error("Fail to hang up call")
             failure_reasons.add("Teardown")
             result = False
     self.result_info["Call Total"] += 1
     for ad in self.android_devices:
         try:
             ad.droid.logI("%s end" % log_msg)
         except:
             pass
     self.log.info("%s end", log_msg)
     self.dut_incall = False
     if not result:
         self.log.info("%s failed", log_msg)
         if self.gps_log_file:
             gps_info = job.run(
                 "tail %s" % self.gps_log_file, ignore_status=True)
             if gps_info.stdout:
                 gps_log_path = os.path.join(self.log_path, test_name,
                                             "gps_logs.txt")
                 utils.create_dir(gps_log_path)
                 job.run(
                     "tail %s > %s" % (self.gps_log_file, gps_log_path),
                     ignore_status=True)
                 self.log.info("gps log:\n%s", gps_info.stdout)
             else:
                 self.log.warning("Fail to get gps log %s",
                                  self.user_params["gps_log_file"])
         for reason in failure_reasons:
             self.result_info["Call %s Failure" % reason] += 1
         for ad in ads:
             log_path = os.path.join(self.log_path, test_name,
                                     "%s_binder_logs" % ad.serial)
             utils.create_dir(log_path)
             ad.pull_files(BINDER_LOGS, log_path)
         try:
             self._take_bug_report(test_name, begin_time)
         except Exception as e:
             self.log.exception(e)
         for ad in ads:
             if ad.droid.telecomIsInCall():
                 hangup_call_by_adb(ad)
     else:
         self.log.info("%s test succeed", log_msg)
         self.result_info["Call Success"] += 1
         if self.result_info["Call Total"] % 50 == 0:
             for ad in ads:
                 synchronize_device_time(ad)
                 if not check_is_wifi_connected(self.log, ad,
                                                self.wifi_network_ssid):
                     ensure_wifi_connected(self.log, ad,
                                           self.wifi_network_ssid,
                                           self.wifi_network_pass)
                     force_connectivity_metrics_upload(ad)
                     time.sleep(300)
                     wifi_toggle_state(self.log, ad, False)
                 if self.get_binder_logs:
                     log_path = os.path.join(self.log_path,
                                             "%s_binder_logs" % test_name,
                                             "%s_binder_logs" % ad.serial)
                     utils.create_dir(log_path)
                     ad.pull_files(BINDER_LOGS, log_path)
     return result