Esempio n. 1
0
def pair_device(initiator_serial, receiver_serial, initiator_name,
                receiver_name, version_initiator, version_receiver,
                scan_max_attempts=2, timeout=10000, scan_timeout=60000,
                **kwargs):
    try:
        bluetooth_steps.BtSearchDevices(serial=receiver_serial,
            dev_to_find=initiator_name, scan_timeout=scan_timeout, timeout=timeout,
            max_attempts=scan_max_attempts, version=version_receiver, **kwargs)()
        bluetooth_steps.InitiatePairRequest(serial=initiator_serial,
            dev_to_pair_name=receiver_name, scan_timeout=scan_timeout, timeout=timeout,
            scan_max_attempts=scan_max_attempts, version=version_initiator, **kwargs)()
        bluetooth_steps.ReceivePairRequest(serial=receiver_serial,
            dev_receiving_from_name=initiator_name, version=version_receiver,
                                           timeout=timeout, **kwargs)()

        # now we have both devices into pair request window, so we can check the passkey
        passkey_string_initiator = bluetooth_steps.GetPasskey(
            serial=initiator_serial, version=version_initiator, **kwargs)()
        passkey_string_receiver = bluetooth_steps.GetPasskey(
            serial=receiver_serial, version=version_receiver, **kwargs)()
        bluetooth_steps.PasskeyCheck(serial=serial,
            passkey_initiator=passkey_string_initiator,
            passkey_receiver=passkey_string_receiver, **kwargs)()

        # if actions are performed first on pair request initiator, we have the following scenarios that must
        # be treated
        bluetooth_steps.PerformActionPairRequest(serial=initiator_serial,
            action="Pair", version=version_initiator, **kwargs)()
        bluetooth_steps.PerformActionPairRequest( serial=receiver_serial,
            action="Pair", version=version_receiver, **kwargs)()

        bluetooth_steps.CheckIfPaired(serial=initiator_serial,
                                      dev_paired_with=receiver_name,
                                      paired=True, timeout=timeout,
                                      version=version_initiator, **kwargs)()
        bluetooth_steps.CheckIfPaired(serial=receiver_serial,
                                      dev_paired_with=initiator_name,
                                      paired=True, timeout=timeout,
                                      version=version_receiver, **kwargs)()
    except:
        log.error("Failed to pair dut and reference device")
        return False
    return True
Esempio n. 2
0
                version_dev=DEV_VERSION)
            bluetooth_steps.BtRemoveAllPairedDevices(serial=serial,
                                                     version=DUT_VERSION,
                                                     critical=False)()
            bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev,
                                                     version=DEV_VERSION,
                                                     critical=False)()
            bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                                 state="OFF",
                                                 version=DUT_VERSION)()
        if action_initiator == "Scan":
            bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                                 state="ON",
                                                 version=DUT_VERSION)()
            bluetooth_steps.BtSearchDevices(serial=serial_dev,
                                            dev_to_find=DUT_NAME,
                                            scan_timeout=60000,
                                            version=DEV_VERSION)()
            bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                                 state="OFF",
                                                 version=DUT_VERSION)()
        counter = counter + 1
finally:

    # ########### Postconditions ##############
    # #########################################

    bluetooth_steps.LogInfo("####### CLEANUP #######")()

    # DUT: turn on BT if not already
    bluetooth_steps.StopPackage(serial=serial, critical=False)()
    bluetooth_steps.PressHome(serial=serial, critical=False)()
Esempio n. 3
0
def bt_pair_devices(serial, dev, dut_name, dev_name, action_dut="Pair", action_dev="Pair",
                    perform_action_first_on_initiator=True,
                    pair_request_initiator="dut", scan_timeout=60000, timeout=10000, scan_max_attempts=1,
                    time_to_wait_timeout_action=60000, version_dut="", version_dev="", **kwargs):
    """Description:
            Given two devices by the serial and the name, they will pair,
            cancel or timeout depending on the action requested. The pair
            request can be initiated by default by DUT either by the other
            device if pair_request_initiator is different by DUT. Make sure
            that you call this with BT settings opened on both devices(with
            BT opened and not any process in progress). Note that, if the
            first action performed is Timeout(either on initiator, or receiver),
            the other one action does not matter, because we must only validate
            that the pair request window is gone also on the another one device
            after timeout has expired
        Usage:
            bt_utils.bt_pair_devices(serial=dut_serial, dev=dev_serial,
                        dut_name="DUT_Name", dev_name="DEV_Name", action_dut="Pair",
                        action_dev="Pair", perform_action_first_on_initiator=True,
                        pair_request_initiator="DUT", scan_timeout=60000,
                        timeout=10000, scan_max_attempts=1, time_to_wait_timeout_action=60000,
                        version_dut="", version_dev="",critical=True, no_log=False)()
    :param serial: serial of DUT
    :param dev: serial of the DEV
    :param dut_name: name of DUT
    :param dev_name: name of DEV
    :param action_dut: "Pair"/"Cancel"/"Timeout" action to be performed on DUT
    :param action_dev: "Pair"/"Cancel"/"Timeout" action to be performed on DEV
    :param perform_action_first_on_initiator: True, to perform first on initiator the action, False otherwise
    :param pair_request_initiator: "dut"/"dev" - what device should initiate the pairing request
    :param scan_timeout: maximum timeout for scanning progress
    :param timeout: default timeout for each wait for exists
    :param scan_max_attempts: maximum no. of scan tries till the device is found
    :param time_to_wait_timeout_action: maximum time to wait for "Timeout" action
    :param version_dut: os version of the DUT
    :param version_dev: os version of the DEV
    :param kwargs: no_log and standard kwargs for base_step
    """

    #  ### initiate all required vars, according to params ###

    #  expected time for the pair request window to disappear on a device after disappears on other one device
    #  theoretically, when pair request is gone on a device, it is expected to be gone also on other one device; we will
    #  consider 1s timeout for slow ui platforms
    __request_disappear_timeout = 1000

    pair_request_initiator = pair_request_initiator.lower()
    if pair_request_initiator == "dut":
        receiver_name = dev_name
        initiator_name = dut_name
        initiator_serial = serial
        receiver_serial = dev
        action_initiator = action_dut
        action_receiver = action_dev
        version_initiator = version_dut
        version_receiver = version_dev
    elif pair_request_initiator == "dev":
        receiver_name = dut_name
        initiator_name = dev_name
        initiator_serial = dev
        receiver_serial = serial
        action_initiator = action_dev
        action_receiver = action_dut
        version_initiator = version_dev
        version_receiver = version_dut
    else:
        raise Exception("Config error: not any expected value for pair_request_initiator")
    if action_dut not in ["Cancel", "Pair", "Timeout"]:
        raise Exception("Config error: not any expected value for action_dut")
    if action_dev not in ["Cancel", "Pair", "Timeout"]:
        raise Exception("Config error: not any expected value for action_dev")

    #  ### call here all the required steps ###

    bluetooth_steps.BtSearchDevices(serial=receiver_serial, dev_to_find=initiator_name, scan_timeout=scan_timeout,
                                    timeout=timeout, max_attempts=scan_max_attempts, version=version_receiver,
                                    **kwargs)()

    bluetooth_steps.InitiatePairRequest(serial=initiator_serial, dev_to_pair_name=receiver_name,
                                        scan_timeout=scan_timeout, timeout=timeout,
                                        scan_max_attempts=scan_max_attempts, version=version_initiator, **kwargs)()
    bluetooth_steps.ReceivePairRequest(serial=receiver_serial, dev_receiving_from_name=initiator_name,
                                       version=version_receiver, timeout=timeout, **kwargs)()

    #  now we have both devices into pair request window, so we can check the passkey
    passkey_string_initiator = bluetooth_steps.GetPasskey(serial=initiator_serial, version=version_initiator,
                                                          **kwargs)()
    passkey_string_receiver = bluetooth_steps.GetPasskey(serial=receiver_serial, version=version_receiver, **kwargs)()
    bluetooth_steps.PasskeyCheck(serial=serial, passkey_initiator=passkey_string_initiator,
                                 passkey_receiver=passkey_string_receiver, **kwargs)()

    #  if actions are performed first on pair request initiator, we have the following scenarios that must
    #  be treated
    if perform_action_first_on_initiator:
        if action_initiator == "Pair":
            bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                     version=version_initiator, **kwargs)()
            if action_receiver == "Pair":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
            elif action_receiver == "Cancel":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
            elif action_receiver == "Timeout":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
        elif action_initiator == "Cancel":
            bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                     version=version_initiator, **kwargs)()
            bluetooth_steps.WaitPairRequest(serial=receiver_serial, appear=False,
                                            time_to_wait=__request_disappear_timeout, **kwargs)()
            if version_initiator.startswith("5.") or version_initiator.startswith("7"):
                #  LLP,N version
                #  no window to treat
                pass
            else:
                #  M versions
                bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
        elif action_initiator == "Timeout":
            #  does not matter what action is on receiver, only check if after timeout on initiator, pair
            #  request is gone on receiver
            bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                     timeout=time_to_wait_timeout_action, version=version_initiator,
                                                     **kwargs)()
            bluetooth_steps.WaitPairRequest(serial=receiver_serial, appear=False,
                                            time_to_wait=__request_disappear_timeout, version=version_receiver,
                                            **kwargs)()
    #  if actions are performed first on pair request receiver, we have the following scenarios that must
    #  be treated
    else:
        if action_initiator == "Pair":
            if action_receiver == "Pair":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         version=version_initiator, **kwargs)()
            elif action_receiver == "Cancel":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         version=version_initiator, **kwargs)()
                bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
            elif action_receiver == "Timeout":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.WaitPairRequest(serial=initiator_serial, appear=False,
                                                time_to_wait=__request_disappear_timeout, version=version_initiator,
                                                **kwargs)()
        elif action_initiator == "Cancel":
            if action_receiver == "Pair":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         version=version_initiator, **kwargs)()
                bluetooth_steps.CouldNotPairDialogCheck(serial=receiver_serial, **kwargs)()
                if version_initiator.startswith("5.") or version_initiator.startswith("7"):
                    #  LLP,N version
                    #  no window to treat
                    pass
                else:
                    #  M versions
                    bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
            elif action_receiver == "Cancel":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         version=version_initiator, **kwargs)()
                if version_initiator.startswith("5.") or version_initiator.startswith("7"):
                    #  LLP,N version
                    #  no window to treat
                    pass
                else:
                    #  M versions
                    bluetooth_steps.CouldNotPairDialogCheck(serial=initiator_serial, **kwargs)()
            elif action_receiver == "Timeout":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.WaitPairRequest(serial=initiator_serial, appear=False,
                                                time_to_wait=__request_disappear_timeout, version=version_initiator,
                                                **kwargs)()
        elif action_initiator == "Timeout":
            if action_receiver == "Pair":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_initiator, **kwargs)()
                bluetooth_steps.CouldNotPairDialogCheck(serial=receiver_serial, **kwargs)()
            elif action_receiver == "Cancel":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.PerformActionPairRequest(serial=initiator_serial, action=action_initiator,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_initiator, **kwargs)()
            elif action_receiver == "Timeout":
                bluetooth_steps.PerformActionPairRequest(serial=receiver_serial, action=action_receiver,
                                                         timeout=time_to_wait_timeout_action,
                                                         version=version_receiver, **kwargs)()
                bluetooth_steps.WaitPairRequest(serial=initiator_serial, appear=False,
                                                time_to_wait=__request_disappear_timeout, version=version_initiator,
                                                **kwargs)()

    #  now we must check if devices are paired, or not, according to parameters
    if action_dut == "Pair" and action_dev == "Pair":
        bluetooth_steps.CheckIfPaired(serial=serial, dev_paired_with=dev_name, paired=True, timeout=timeout,
                                      version=version_dut, **kwargs)()
        bluetooth_steps.CheckIfPaired(serial=dev, dev_paired_with=dut_name, paired=True, timeout=timeout,
                                      version=version_dev, **kwargs)()
    else:
        bluetooth_steps.CheckIfPaired(serial=serial, dev_paired_with=dev_name, paired=False, timeout=timeout,
                                      version=version_dut, **kwargs)()
        bluetooth_steps.CheckIfPaired(serial=dev, dev_paired_with=dut_name, paired=False, timeout=timeout,
                                      version=version_dev, **kwargs)()
Esempio n. 4
0
# Setup
ui_steps.press_home(serial=serial)()
ui_steps.press_home(serial=serial2)()
ui_steps.am_stop_package(serial=serial,
                         package_name="com.android.settings",
                         blocking=True)()
ui_steps.am_stop_package(serial=serial2,
                         package_name="com.android.settings",
                         blocking=True)()

# Run
bluetooth_steps.OpenBluetoothSettings(serial=serial2,
                                      use_intent=True,
                                      blocking=True)()
bluetooth_steps.BtChangeDeviceName(serial=serial2,
                                   name=DEV_MAC_ADDRESS,
                                   blocking=True)()
bluetooth_steps.OpenBluetoothSettings(serial=serial, blocking=True)()
bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON",
                                     blocking=True)()
# porting needs to be done for the below api to work on Andorid O, currently
#  not done because of the Bt available device refresh
bluetooth_steps.BtSearchDevices(serial=serial, dev_to_find=DEV_MAC_ADDRESS)()

# Teardown
ui_steps.am_stop_package(serial=serial,
                         package_name="com.android.settings",
                         blocking=False)()
ui_steps.am_stop_package(serial=serial2,
                         package_name="com.android.settings",
                         blocking=False)()
Esempio n. 5
0
     bluetooth_steps.BtSetService(serial=serial,paired_device_name=PAIRING_DEV_NAME, state=True,
                                  service="Contact sharing", check_if_already=False,
                                  disable_profile_confirm=True,version=DUT_VERSION)()
     bluetooth_steps.BtSetService(serial=serial_dev,
                                  paired_device_name=DUT_NAME, state=True,
                                  service="Contact sharing", check_if_already=False,
                                  disable_profile_confirm=True,version=DEV_VERSION)()
     bluetooth_steps.BtSetService(serial=serial,
                                  paired_device_name=PAIRING_DEV_NAME, state=False,
                                  service="Contact sharing", check_if_already=True,
                                  disable_profile_confirm=True,version=DUT_VERSION)()
     bluetooth_steps.BtSetService(serial=serial,
                                  paired_device_name=PAIRING_DEV_NAME, state=True,
                                  service="Contact sharing", check_if_already=False,
                                  disable_profile_confirm=True,version=DUT_VERSION)()
     if not bluetooth_steps.BtSearchDevices(serial=serial_dev, dev_to_find=DUT_NAME, scan_timeout=scan_timeout,
                                     max_attempts=scan_max_attempts)():
         raise Exception("scanning list not found")
     ui_steps.press_car(serial=serial)()
     if not ui_steps.wait_for_view_common(serial=serial, view_to_find={"textContains": "Contacts"})():
         ui_steps.press_car(serial=serial)()
     if not ui_steps.click_button_common(serial=serial, view_to_find={"textContains": "Contacts"},
                                         view_to_check={"className": "android.widget.TextView"})():
         raise Exception("Contacts list not found")
 if action_initiator == "Chistory":
     bt_utils.bt_pair_devices(serial=serial, dev=serial_dev,
                              dut_name=DUT_NAME,
                              dev_name=PAIRING_DEV_NAME,
                              action_dut=action_dut,
                              action_dev=action_dev,
                              perform_action_first_on_initiator=action_initiator_first,
                              pair_request_initiator=initiator,
                                       name=PAIRING_DEV_NAME,
                                       blocking=True)()
    #  ############ Actual Test ################
    #  #########################################

    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()
    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"],
                                          use_intent=True,
                                          version=DUT_VERSION)()
    bluetooth_steps.ClickBluetoothSwitch(serial=args["serial"],
                                         state="ON",
                                         version=DUT_VERSION)()
    counter = 1
    while counter < 3:
        bluetooth_steps.BtSearchDevices(serial=args["serial"],
                                        dev_to_find=PAIRING_DEV_NAME,
                                        scan_timeout=60000,
                                        version=DEV_VERSION)()
        counter = counter + 1
finally:

    #  ########### Postconditions ##############
    #  #########################################

    bluetooth_steps.LogInfo("####### CLEANUP #######")()

    bluetooth_steps.StopPackage(serial=args["serial"], critical=False)()
    bluetooth_steps.PressHome(serial=args["serial"], critical=False)()
    bluetooth_steps.OpenBluetoothSettings(serial=args["serial"],
                                          use_intent=True,
                                          version=DUT_VERSION,
                                          critical=False)()