def setup_class(self):
     super(BluetoothCarHfpBaseTest, self).setup_class()
     if not "sim_conf_file" in self.user_params.keys():
         self.log.error("Missing mandatory user config \"sim_conf_file\"!")
         return False
     sim_conf_file = self.user_params["sim_conf_file"][0]
     if not os.path.isfile(sim_conf_file):
         sim_conf_file = os.path.join(
             self.user_params[Config.key_config_path.value], sim_conf_file)
         if not os.path.isfile(sim_conf_file):
             self.log.error("Unable to load user config " + sim_conf_file +
                            " from test config file.")
             return False
     setup_droid_properties(self.log, self.ag, sim_conf_file)
     self.ag_phone_number = get_phone_number(self.log, self.ag)
     self.ag.log.info("ag tel: {}".format(self.ag_phone_number))
     if self.re:
         setup_droid_properties(self.log, self.re, sim_conf_file)
         self.re_phone_number = get_phone_number(self.log, self.re)
         self.re.log.info("re tel: {}".format(self.re_phone_number))
     if self.re2:
         setup_droid_properties(self.log, self.re2, sim_conf_file)
         self.re2_phone_number = get_phone_number(self.log, self.re2)
         self.re2.log.info("re2 tel: {}".format(self.re2_phone_number))
     # Pair and connect the devices.
     # Grace time inbetween stack state changes
     time.sleep(5)
     if not pair_pri_to_sec(
             self.hf, self.ag, attempts=4, auto_confirm=False):
         self.log.error("Failed to pair")
         return False
     return True
Exemplo n.º 2
0
    def send_message(self, remotes):
        self.REMOTE.droid.smsStartTrackingIncomingSmsMessage()
        destinations = []
        for phone in remotes:
            destinations.append("tel:{}".format(
                get_phone_number(self.log, phone)))
        self.log.info(destinations)
        self.MCE.droid.mapSendMessage(
            self.MSE.droid.bluetoothGetLocalAddress(), destinations,
            MESSAGE_TO_SEND)
        try:
            self.MCE.ed.pop_event(EventSmsSentSuccess, 15)
        except queue.Empty:
            self.MCE.log.error("Message failed to send.")
            return False

        try:
            receivedMessage = self.REMOTE.ed.pop_event(EventSmsReceived, 15)
            self.REMOTE.log.info("Received a message: {}".format(
                receivedMessage['data']['Text']))
        except queue.Empty:
            self.REMOTE.log.error("Remote did not receive message.")
            return False

        if MESSAGE_TO_SEND != receivedMessage['data']['Text']:
            self.log.error("Messages don't match.")
            self.log.error("Sent     {}".format(MESSAGE_TO_SEND))
            self.log.error("Received {}".format(
                receivedMessage['data']['Text']))
            return False
        return True
 def outgoing_call_hsp_disabled_then_enabled_during_call(
         self, pri_dut, sec_dut):
     self.log.info(
         "Test outgoing call hsp disabled then enable during call.")
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, sec_dut)
     if not pri_dut.droid.bluetoothHspDisconnect(self.target_mac_address):
         self.log.error("Failed to disconnect HSP service...")
         return False
     time.sleep(self.short_timeout)
     if len(pri_dut.droid.bluetoothHspGetConnectedDevices()) != 0:
         self.log.error("Failed to disconnect from HSP service")
         return False
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     time.sleep(default_timeout)
     pri_dut.droid.bluetoothConnectBonded(self.target_mac_address)
     time.sleep(self.short_timeout)
     test_result = True
     if len(pri_dut.droid.bluetoothHspGetConnectedDevices()) != 1:
         self.log.error("Failed to reconnect to HSP service...")
         return
     if not hangup_call(self.log, pri_dut):
         self.log.error("Failed to hangup call")
         return False
     return test_result
Exemplo n.º 4
0
def setup_tel_config(pri_ad, sec_ad, sim_conf_file):
    """Sets tel properties for primary device and secondary devices

    Args:
        pri_ad: An android device object.
        sec_ad: An android device object.
        sim_conf_file: Sim card map.

    Returns:
        pri_ad_num: Phone number of primary device.
        sec_ad_num: Phone number of secondary device.
    """
    setup_droid_properties(logging, pri_ad, sim_conf_file)
    pri_ad_num = get_phone_number(logging, pri_ad)
    setup_droid_properties(logging, sec_ad, sim_conf_file)
    sec_ad_num = get_phone_number(logging, sec_ad)
    return pri_ad_num, sec_ad_num
Exemplo n.º 5
0
 def test_receive_message(self):
     self.MSE.log.info("Start Tracking SMS.")
     self.MSE.droid.smsStartTrackingIncomingSmsMessage()
     self.REMOTE.log.info("Ready to send")
     self.REMOTE.droid.smsSendTextMessage(
         get_phone_number(self.log, self.MSE), "test_receive_message",
         False)
     self.MCE.log.info("Check inbound Messages.")
     receivedMessage = self.MCE.ed.pop_event(EVENT_MAP_MESSAGE_RECEIVED, 15)
     self.MCE.log.info(receivedMessage['data'])
     return True
Exemplo n.º 6
0
 def test_receive_message(self):
     bt_test_utils.connect_pri_to_sec(
         self.MCE, self.MSE, set([BtEnum.BluetoothProfile.MAP_MCE.value]))
     self.MSE.log.info("Start Tracking SMS.")
     self.MSE.droid.smsStartTrackingIncomingSmsMessage()
     self.REMOTE.log.info("Ready to send")
     self.REMOTE.droid.smsSendTextMessage(
         get_phone_number(self.log, self.MSE), "test_receive_message",
         False)
     self.MCE.log.info("Check inbound Messages.")
     receivedMessage = self.MCE.ed.pop_event(EVENT_MAP_MESSAGE_RECEIVED, 15)
     self.MCE.log.info(receivedMessage['data'])
     return True
 def outgoing_multi_call_join_conference_call(self, pri_dut, sec_dut,
                                              ter_dut):
     self.log.info(
         "Test 2 outgoing calls scenario from phone then join the calls.")
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, sec_dut)
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, sec_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     outgoing_num = get_phone_number(self.log, ter_dut)
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, ter_dut):
         self.log.error("Failed to answer call.")
         return False
     input("Press enter to join active calls...")
     calls = pri_dut.droid.telecomCallGetCallIds()
     pri_dut.droid.telecomCallJoinCallsInConf(calls[0], calls[1])
     time.sleep(WAIT_TIME_IN_CALL)
     if num_active_calls(self.log, pri_dut) != 4:
         self.log.error("Total number of call ids in {} is not 4.".format(
             pri_dut.serial))
         return False
     input("Press enter to hangup call 1...")
     if not hangup_call(self.log, sec_dut):
         self.log.error("Failed to hangup call")
         return False
     input("Press enter to hangup call 2...")
     if not hangup_call(self.log, ter_dut):
         self.log.error("Failed to hangup call")
         return False
     return True
 def setup_multi_call(self, caller0, caller1, callee):
     outgoing_num = get_phone_number(self.log, callee)
     if not initiate_call(self.log, caller0, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, callee):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     if not initiate_call(self.log, caller1, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, callee):
         self.log.error("Failed to answer call.")
         return False
     return True
 def incomming_call_unknown_contact(self, pri_dut, ter_dut):
     self.log.info(
         "Test incomming call scenario to phone from unknown contact")
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, pri_dut)
     if not initiate_call(self.log, ter_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, pri_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     input("Press enter to hangup call...")
     if not hangup_call(self.log, ter_dut):
         self.log.error("Failed to hangup call")
         return False
     return True
 def outgoing_call_private_number(self, pri_dut, ter_dut):
     self.log.info(
         "Test outgoing call scenario from phone to private number")
     input("Press enter to execute this testcase...")
     outgoing_num = "*67" + get_phone_number(self.log, ter_dut)
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, ter_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     input("Press enter to hangup call...")
     if not hangup_call(self.log, pri_dut):
         self.log.error("Failed to hangup call")
         return False
     return True
 def call_audio_routes(self, pri_dut, sec_dut):
     self.log.info("Test various audio routes scenario from phone.")
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, sec_dut)
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, sec_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     call_id = pri_dut.droid.telecomCallGetCallIds()[0]
     pri_dut.droid.telecomCallPlayDtmfTone(call_id, "9")
     input("Press enter to switch to speaker...")
     self.log.info("Switching to speaker.")
     set_audio_route(self.log, pri_dut, AUDIO_ROUTE_SPEAKER)
     time.sleep(self.short_timeout)
     if get_audio_route(self.log, pri_dut) != AUDIO_ROUTE_SPEAKER:
         self.log.error(
             "Audio Route not set to {}".format(AUDIO_ROUTE_SPEAKER))
         return False
     input("Press enter to switch to earpiece...")
     self.log.info("Switching to earpiece.")
     set_audio_route(self.log, pri_dut, AUDIO_ROUTE_EARPIECE)
     time.sleep(self.short_timeout)
     if get_audio_route(self.log, pri_dut) != AUDIO_ROUTE_EARPIECE:
         self.log.error(
             "Audio Route not set to {}".format(AUDIO_ROUTE_EARPIECE))
         return False
     input("Press enter to switch to Bluetooth...")
     self.log.info("Switching to Bluetooth...")
     set_audio_route(self.log, pri_dut, AUDIO_ROUTE_BLUETOOTH)
     time.sleep(self.short_timeout)
     if get_audio_route(self.log, pri_dut) != AUDIO_ROUTE_BLUETOOTH:
         self.log.error(
             "Audio Route not set to {}".format(AUDIO_ROUTE_BLUETOOTH))
         return False
     input("Press enter to hangup call...")
     self.log.info("Hanging up call...")
     pri_dut.droid.telecomCallStopDtmfTone(call_id)
     if not hangup_call(self.log, pri_dut):
         self.log.error("Failed to hangup call")
         return False
     return True
 def outgoing_call_multiple_iterations(self, pri_dut, sec_dut):
     iteration_count = 3
     self.log.info(
         "Test outgoing call scenario from phone {} times from known contact"
         .format(iteration_count))
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, sec_dut)
     for _ in range(iteration_count):
         if not initiate_call(self.log, pri_dut, outgoing_num):
             self.log.error("Failed to initiate call")
             return False
         if not wait_and_answer_call(self.log, sec_dut):
             self.log.error("Failed to answer call.")
             return False
         time.sleep(self.short_timeout)
         if not hangup_call(self.log, pri_dut):
             self.log.error("Failed to hangup call")
             return False
     return True
 def sms_during_incomming_call(self, pri_dut, sec_dut):
     self.log.info(
         "Test incomming call scenario to phone from unknown contact")
     input("Press enter to execute this testcase...")
     outgoing_num = get_phone_number(self.log, pri_dut)
     if not initiate_call(self.log, sec_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, pri_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     msg = [rand_ascii_str(10)]
     if not sms_send_receive_verify(self.log, sec_dut, pri_dut, msg):
         return False
     else:
         self.log.info("Successfully sent sms. Please verify on carkit.")
     input("Press enter to hangup call...")
     if not hangup_call(self.log, sec_dut):
         self.log.error("Failed to hangup call")
         return False
     return True
 def outgoing_call_a2dp_play_before_and_after(self, pri_dut, sec_dut):
     self.log.info(
         "Test outgoing call scenario while playing music. Music should resume after call."
     )
     pri_dut.adb.shell(KEYCODE_EVENT_PREVIOUS)
     input(
         "Press enter to execute this testcase when music is in a play state..."
     )
     outgoing_num = get_phone_number(self.log, sec_dut)
     if not initiate_call(self.log, pri_dut, outgoing_num):
         self.log.error("Failed to initiate call")
         return False
     if not wait_and_answer_call(self.log, sec_dut):
         self.log.error("Failed to answer call.")
         return False
     time.sleep(self.short_timeout)
     input("Press enter to hangup call...")
     if not hangup_call(self.log, pri_dut):
         self.log.error("Failed to hangup call")
         return False
     input("Press enter when music continues to play.")
     self.log.info("Pausing Music...")
     pri_dut.adb.shell(KEYCODE_EVENT_PLAY_PAUSE)
     return True
    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)