예제 #1
0
PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev, blocking=True)()
try:

    # ########### Preconditions ###############
    # #########################################

    bluetooth_steps.LogInfo("######## SETUP ########")()
    # DUT: turn on BT
    bluetooth_steps.StopPackage(serial=serial, blocking=True)()
    bluetooth_steps.PressHome(serial=serial, blocking=True)()
    bluetooth_steps.OpenBluetoothSettings(serial=serial,
                                          use_intent=True,
                                          version=DUT_VERSION,
                                          blocking=True)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                         state="ON",
                                         version=DUT_VERSION,
                                         blocking=True)()
    # DEV: turn on BT
    bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)()
    bluetooth_steps.PressHome(serial=serial_dev, blocking=True)()
    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev,
                                          use_intent=True,
                                          version=DEV_VERSION,
                                          blocking=True)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev,
                                         state="ON",
                                         version=DEV_VERSION,
                                         blocking=True)()

    # DUT: wait scan, rename device and remove all paired devices
    bluetooth_steps.WaitBtScanning(serial=serial,
예제 #2
0
def opp_send_file(serial, serial_dev, condition, event,
                  file_path="/storage/emulated/0/acs_files",
                  file_name="10MB.txt", iteration=1, q=None):
    result = []
    try:
        file_full_path = file_path + '/' + file_name
        # Initialize versions and names (we only need dev name)
        DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial,
                                                        blocking=True)()
        DEV_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial_dev,
                                                        blocking=True)()
        PAIRING_DUT_NAME = bluetooth_steps.GetBtMac(serial=serial,
                                                    blocking=True)()
        PAIRING_DEV_NAME = bluetooth_steps.GetBtMac(serial=serial_dev,
                                                    blocking=True)()
        # taking only the name and removing the extensions
        FILE_NAME = file_name.split(".")[0]

        bluetooth_steps.LogInfo("######## SETUP ########")()

        for _ in range(0, iteration):
            if initiator == "dev" and _ == 0:
                serial, serial_dev = serial_dev, serial
                DUT_VERSION, DEV_VERSION = DEV_VERSION, DUT_VERSION
                PAIRING_DUT_NAME, PAIRING_DEV_NAME = PAIRING_DEV_NAME, \
                                                     PAIRING_DUT_NAME

            if iteration > 1:
                log.info("Opp transfer: Iteration #{}".format(_ + 1))
            if priority == 'bt' and _ == 0:
                # print e.is_set()
                # print 'bt 1st event wait'
                event.wait(CONDITION_EVENT_TIMEOUT)
                event.clear()
            elif not priority == "toggle":
                # print 'bt 1st event set'
                event.set()

            with condition:
                # print 'Before wifi'
                if priority == 'wifi' and _ == 0:
                    condition.wait(CONDITION_EVENT_TIMEOUT)
                # print 'Started after notified from wifi'
                # DUT: clear all notifications etc
                bluetooth_steps.StopPackage(serial=serial, blocking=True)()
                bluetooth_steps.PressHome(serial=serial, blocking=True)()
                bluetooth_steps.ClearAllNotifications(serial=serial,
                                                      version=DUT_VERSION,
                                                      blocking=True)()
                bluetooth_steps.BtOppDismissEventualIncoming(serial=serial,
                                                             version=DUT_VERSION,
                                                             blocking=True)()
                bluetooth_steps.ClearRecentApps(serial=serial,
                                                    version=DUT_VERSION,
                                                    blocking=True)()

                # DEV: clear all notifications/opp files etc
                bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)()
                bluetooth_steps.PressHome(serial=serial_dev, blocking=True)()
                bluetooth_steps.ClearAllNotifications(serial=serial_dev,
                                                      version=DEV_VERSION,
                                                      blocking=True)()
                bluetooth_steps.BtOppDismissEventualIncoming(serial=serial_dev,
                                                             version=DEV_VERSION,
                                                             blocking=True)()
                bluetooth_steps.ClearPath(serial=serial_dev, blocking=True)()

                if _ == 0:
                    # DUT: turn on bt
                    # already turned on during TC setup phase
                    bluetooth_steps.OpenBluetoothSettings(serial=serial,
                                                          use_intent=True,
                                                          version=DUT_VERSION,
                                                          blocking=True)()
                    bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON",
                                                         version=DUT_VERSION,
                                                         blocking=True)()

                    # DEV: turn on bt
                    # already turned on during TC setup phase
                    bluetooth_steps.OpenBluetoothSettings(serial=serial_dev,
                                                          use_intent=True,
                                                          version=DEV_VERSION,
                                                          blocking=True)()
                    bluetooth_steps.ClickBluetoothSwitch(serial=serial_dev,
                                                         state="ON",
                                                         version=DEV_VERSION,
                                                         blocking=True)()

                    # DUT: wait scan and remove paired devices
                    bluetooth_steps.WaitBtScanning(serial=serial,
                                                   version=DUT_VERSION,
                                                   blocking=True)()
                    bluetooth_steps.BtChangeDeviceName(serial=serial,
                                                       name=PAIRING_DUT_NAME,
                                                       version=DUT_VERSION,
                                                       blocking=True)()
                    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial,
                                                             version=DUT_VERSION,
                                                             blocking=True)()
                    bluetooth_steps.CheckBtVisibility(serial=serial,
                                                      version=DUT_VERSION,
                                                      blocking=True)()

                    # DEV:  wait scan (should be already finished), rename and
                    # remove paired devices
                    bluetooth_steps.WaitBtScanning(serial=serial_dev,
                                                   timeout_appear=0,
                                                   version=DEV_VERSION,
                                                   blocking=True)()
                    bluetooth_steps.BtChangeDeviceName(serial=serial_dev,
                                                       name=PAIRING_DEV_NAME,
                                                       version=DEV_VERSION,
                                                       blocking=True)()
                    bluetooth_steps.BtRemoveAllPairedDevices(serial=serial_dev,
                                                             version=DEV_VERSION,
                                                             blocking=True)()
                    bluetooth_steps.CheckBtVisibility(serial=serial_dev,
                                                      version=DEV_VERSION,
                                                      blocking=True)()
                    if priority == 'bt' and _ == 0:
                        condition.notify()

            if _ == 0 and bt_pair_device:
                if not pair_device(serial, serial_dev, PAIRING_DUT_NAME,
                        PAIRING_DEV_NAME, DUT_VERSION, DEV_VERSION):
                    raise

            if priority == 'bt' and _ == 0:
                # print e.is_set()
                # print 'bt 2nd event wait'
                event.wait(CONDITION_EVENT_TIMEOUT)
                event.clear()
            elif not priority == 'toggle':
                # print 'bt 2nd event set'
                event.set()

            with condition:
                if priority == 'wifi' and _ == 0:
                    condition.wait(CONDITION_EVENT_TIMEOUT)

                bt_opp_receive_obj = None
                bluetooth_steps.BrowseFileInSettingsStorage(serial=serial,
                                                            file_full_path=file_full_path)()
                bluetooth_steps.BtOppShareFile(serial=serial,
                                               server_dut=str(PAIRING_DEV_NAME),
                                               bt_already_opened=True,
                                               version=DUT_VERSION,
                                               blocking=True)()
                bt_opp_receive_obj = bluetooth_steps.BtOppReceiveFile(
                    serial=serial_dev,
                    action='Accept',
                    filename_starting_string=FILE_NAME,
                    version=DEV_VERSION,
                    check_file_received=False)
                bt_opp_receive_obj()
                if priority == 'bt' and _ == 0:
                    condition.notify()

                # this condition will notify the 'toggle_wifi' to proceed to
                # toggle state
                if priority == 'toggle':
                    event.set()

            # This waits for Wifi to start downloas as both collides when
            # start together
            if initiator == "dev" and priority == "bt" and _ == 0:
                event.wait(CONDITION_EVENT_TIMEOUT)
                event.clear()

            # Below verification of OPP received file is separated from
            # above BtOppReceiveFile because parallelly when file is receiving
            # toggling WIFI should happen
            try:
                # open notification menu and click on incoming file notification
                if not bluetooth_steps.OpenNotificationsMenu(serial=serial_dev,
                                                             version=DEV_VERSION,
                                                             critical=False,
                                                             no_log=True)():
                    raise Exception("Notifications menu not opened")
                if not bluetooth_steps.BtCheckNotificationAppear(serial=serial_dev,
                                                                 text_contains="Bluetooth share: Receiving",
                                                                 click_on_notification=True,
                                                                 time_to_appear=VIEW_TIMEOUT,
                                                                 version=DEV_VERSION,
                                                                 critical=False,
                                                                 no_log=True)():
                    if not bluetooth_steps.BtCheckNotificationAppear(serial=serial_dev,
                                                                 text_contains="Bluetooth share: Received",
                                                                 click_on_notification=True,
                                                                 time_to_appear=VIEW_TIMEOUT,
                                                                 version=DEV_VERSION,
                                                                 critical=False,
                                                                 no_log=True)():
                        raise Exception("Receiving file notification click failed")
                    else:
                        if not bt_opp_receive_obj.uidevice(
                                textContains=FILE_NAME).wait.exists(timeout=VIEW_TIMEOUT):
                            raise Exception("Receiving file not found in "
                                            "Inbound transfers window")
                        if not bt_opp_receive_obj.uidevice(
                                    textContains="Received complete"):
                            raise Exception("File not received completely")
                        bt_opp_receive_obj.uidevice.press.back()
                else:
                    if not bt_opp_receive_obj.uidevice(
                            resourceId="android:id/alertTitle",
                            text="File transfer").wait.exists(timeout=VIEW_TIMEOUT):
                        raise Exception("File transfer progress window not "
                                        "shown after click on receiving file notification")
                    # check the filename in the window (if not empty)
                    if FILE_NAME != "":
                        filename_obj = bt_opp_receive_obj.uidevice(
                            textContains="File:")
                        if not filename_obj.wait.exists(timeout=VIEW_TIMEOUT):
                            raise Exception(
                                "Receiving File Name not found in the file "
                                "transfer window")
                        filename_text = str(filename_obj.text)
                        if FILE_NAME not in filename_text:
                            raise Exception("Not expected string contained in the "
                                            "file transfer window, exp " + str(
                                FILE_NAME) + " but found " + filename_text)
                    # wait till the file is received
                    if not bt_opp_receive_obj.uidevice(
                            text="File received").wait.exists(
                            timeout=TRANSFER_TIMEOUT):
                        if bt_opp_receive_obj.uidevice(textContains="OK",
                                        className="android.widget.Button").exists:
                            bt_opp_receive_obj.uidevice.press.back()
                            #bt_opp_receive_obj.uidevice(textContains="OK",
                            #
                            # className="android.widget.Button").click.wait()
                        raise Exception("Timeout reached, file transfer not finished")
                    # return to the previous window
                    bt_opp_receive_obj.uidevice.press.back()
                    if not bt_opp_receive_obj.uidevice(
                            resourceId="android:id/alertTitle",
                            text="File transfer").wait.gone(timeout=VIEW_TIMEOUT):
                        #if bt_opp_receive_obj.uidevice(textContains="OK",
                        #            className="android.widget.Button").exists:
                        #    bt_opp_receive_obj.uidevice.press.back()
                            #bt_opp_receive_obj.uidevice(textContains="OK",
                            #           className="android.widget.Button").click()

                        # this will help avoid the "File transfer" window
                        # appear in next opp transfer
                        bt_opp_receive_obj.uidevice.press.back()
                        raise Exception("File transfer progress window not closed")
                log.info("File received successfully")
                result.append(True)
            except Exception, e:
                log.error(e.message)
                log.error(traceback.format_exc())
                log.error("Exception raised, File not received successfully")
                result.append(False)
    except:
        log.error('OppTransferFile: Unexpected Error')
        log.error(traceback.format_exc())
        result.append(False)
    finally:
        bluetooth_steps.LogInfo("####### CLEANUP #######")()

        # DUT: close inbounds transfers, turn off bt, clear all opp notifications/files
        bluetooth_steps.DismissTransferList(serial=serial, version=DUT_VERSION,
                                            critical=False)()
        bluetooth_steps.StopPackage(serial=serial, critical=False)()
        bluetooth_steps.ClearAllNotifications(serial=serial,
                                              version=DUT_VERSION,
                                              critical=False)()
        bluetooth_steps.PressHome(serial=serial, critical=False)()

        # DEV: turn off bt, clear all opp notifications/files
        bluetooth_steps.ClearAllNotifications(serial=serial_dev,
                                              version=DEV_VERSION,
                                              critical=False)()
        bluetooth_steps.StopPackage(serial=serial_dev, critical=False)()
        bluetooth_steps.PressHome(serial=serial_dev, critical=False)()

    if False in result:
        q.put(['OppTransferFile', 'Fail', result])
    else:
        q.put(['OppTransferFile', 'Pass'])
        # Teardown
    log.info("BT Opp transfer completed")
                         package_name="com.android.settings",
                         blocking=True)()
ui_steps.am_stop_package(serial=serial2,
                         package_name="com.android.settings",
                         blocking=True)()

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.BtChangeDeviceName(serial=serial, name=DUT_NAME,
                                   blocking=True)()
bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON",
                                     blocking=True)()

# add step to connect device
bluetooth_steps.BtRemoveAllPairedDevices(serial=serial, blocking=True)()
bluetooth_steps.CheckBtVisibility(serial=serial, blocking=True)()
bluetooth_steps.CheckBtVisibility(serial=serial2, blocking=True)()

# Set Up

bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()

bt_utils.bt_pair_devices(serial=serial,
                         dev=serial2,
                         dut_name=DUT_NAME,
                         dev_name=DEV_MAC_ADDRESS,
                         version_dut=DUT_VERSION,
예제 #4
0
def pair_a2dp_device(serial, a2dp_device_name, event, timeout=10000,
                     scan_max_attempts=2, scan_timeout=60000, q=None,
                     **kwargs):
    result = []
    # Initialize versions and names
    DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial,
                                                    blocking=True)()
    try:

        # ########### Preconditions ###############
        # #########################################

        bluetooth_steps.LogInfo("######## SETUP ########")()

        # DUT: turn on BT
        bluetooth_steps.StopPackage(serial=serial, blocking=True)()
        bluetooth_steps.PressHome(serial=serial, blocking=True)()
        bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True,
                                              version=DUT_VERSION,
                                              blocking=True)()
        bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON",
                                             version=DUT_VERSION,
                                             blocking=True)()

        # DUT: wait scanning, rename device and remove all paired devices
        bluetooth_steps.WaitBtScanning(serial=serial,
                                       scan_timeout=scan_timeout,
                                       version=DUT_VERSION, blocking=True)()
        bluetooth_steps.BtRemoveAllPairedDevices(serial=serial,
                                                 version=DUT_VERSION,
                                                 blocking=True)()
        bluetooth_steps.CheckBtVisibility(serial=serial, version=DUT_VERSION,
                                          blocking=True)()

        # ############ Actual Test ################
        # #########################################

        bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()

        bluetooth_steps.PairDevice(serial=serial, dev_to_pair_name=a2dp_device_name,
                                   scan_timeout=scan_timeout, timeout=timeout,
                                   scan_max_attempts=scan_max_attempts)()
        event.set()
        result.append(True)
    except:
        event.set()
        log.error('ConnectA2dpDevice: Unexpected Error')
        log.error(traceback.format_exc())
        result.append(False)
    finally:
        if total_actions > 1:
            event.wait(CONDITION_EVENT_TIMEOUT)
            event.clear()
        # ########### Postconditions ##############
        # #########################################

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

        # DUT: stop settings and turn on BT (if not already)
        bluetooth_steps.StopPackage(serial=serial, critical=False)()
        bluetooth_steps.PressHome(serial=serial, critical=False)()
        bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True,
                                              version=DUT_VERSION,
                                              critical=False)()
        bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON",
                                             version=DUT_VERSION,
                                             critical=False)()

        # DUT: remove all paired devices and turn off BT
        bluetooth_steps.WaitBtScanning(serial=serial,
                                       scan_timeout=scan_timeout,
                                       version=DUT_VERSION, critical=False)()
        bluetooth_steps.BtRemoveAllPairedDevices(serial=serial,
                                                 version=DUT_VERSION,
                                                 critical=False)()
        bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="OFF",
                                             version=DUT_VERSION,
                                             critical=False)()
        bluetooth_steps.StopPackage(serial=serial, critical=False)()
        bluetooth_steps.PressHome(serial=serial, critical=False)()

    if False in result:
        action_result = ["A2dpBtConnect", 'Fail']
    else:
        action_result = ["A2dpBtDevice", 'Pass']
    return action_result if q is None else q.put(action_result)
globals().update(vars(get_args(sys.argv)))
if not script_args:
    raise Exception("--script-args is mandatory")
args = {}
for entry in script_args:
    key, val = entry.split("=")
    args[key] = val
DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial, blocking=True)()
bluetooth_steps.StopPackage(serial=serial, blocking=True)()
bluetooth_steps.PressHome(serial=serial, blocking=True)()
bluetooth_steps.OpenBluetoothSettings(serial=serial,
                                      use_intent=True,
                                      version=DUT_VERSION,
                                      blocking=True)()
bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                     state="ON",
                                     version=DUT_VERSION,
                                     blocking=True)()
###############################################################
# Bluetooth state after device into sleep and wakeup
#sleep and wakeup device through keyevent26
###############################################################
adb_steps.put_device_into_sleep_mode(serial=serial)()
time.sleep(30)
adb_steps.wake_up_device(serial=serial)()
ui_steps.unlock_device_swipe(serial=serial)()
bluetooth_steps.OpenBluetoothSettings(serial=serial,
                                      use_intent=True,
                                      version=DUT_VERSION,
                                      blocking=True)()
###checking_BT_Status
bt_current_state = bluetooth_utils.check_bluetooth_state_on(serial)
예제 #6
0
    bluetooth_steps.OpenBluetoothSettings(serial=serial2, use_intent=True)()

    bluetooth_steps.BtChangeDeviceName(serial=serial2, name=serial2)()

    bluetooth_steps.WaitBtScanning(serial=serial)()

    bluetooth_steps.InitiatePairRequest(serial=serial,
                                        dev_to_pair_name=serial2,
                                        scan_max_attempts=5)()

    bluetooth_steps.PerformActionPairRequest(serial=serial)()
    bluetooth_steps.PerformActionPairRequest(serial=serial2)()

    bluetooth_steps.ConnectPairedDevices(serial=serial,
                                         dev_to_connect_name=serial2)()

    ui_steps.add_trusted_device(serial=serial, pin="1234",
                                device_name=serial2)()
    check_smart_lock(serial=serial)()

    bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True)()
    bluetooth_steps.WaitBtScanning(serial=serial)()
    bluetooth_steps.UnpairDevice(serial=serial, device_name=serial2)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="OFF")()

    bluetooth_steps.OpenBluetoothSettings(serial=serial2, use_intent=True)()
    bluetooth_steps.WaitBtScanning(serial=serial2)()
    bluetooth_steps.UnpairDevice(serial=serial2, device_name=serial)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial2, state="OFF")()
예제 #7
0
    bluetooth_steps.LogInfo("######## SETUP ########")()

    bluetooth_steps.StopPackage(serial=serial, blocking=True)()
    bluetooth_steps.PressHome(serial=serial, blocking=True)()

    # ############ Actual Test ################
    # #########################################

    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()

    bluetooth_steps.OpenBluetoothSettings(serial=serial,
                                          use_intent=True,
                                          version=DUT_VERSION)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial,
                                         state="ON",
                                         version=DUT_VERSION)()
    bluetooth_steps.WaitBtScanning(serial=serial, version=DUT_VERSION)()

    bluetooth_steps.BtChangeDeviceName(serial=serial,
                                       name="",
                                       version=DUT_VERSION)()

finally:

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

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

    bluetooth_steps.StopPackage(serial=serial, critical=False)()
# Initialize version
DUT_VERSION = bluetooth_steps.GetAndroidVersion(serial=serial, blocking=True)()

try:

    # ########### Preconditions ###############
    # #########################################

    bluetooth_steps.LogInfo("######## SETUP ########")()

    bluetooth_steps.StopPackage(serial=serial, blocking=True)()
    bluetooth_steps.PressHome(serial=serial, blocking=True)()
    bluetooth_steps.BtSetTethering(serial=serial, state="OFF", version=DUT_VERSION, blocking=True)()
    bluetooth_steps.PressHome(serial=serial, blocking=True)()
    bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True, version=DUT_VERSION, blocking=True)()
    bluetooth_steps.ClickBluetoothSwitch(serial=serial, state="ON", version=DUT_VERSION, blocking=True)()
    bluetooth_steps.PressHome(serial=serial, blocking=True)()

    # ############ Actual Test ################
    # #########################################

    bluetooth_steps.LogInfo("##### ACTUAL TEST #####")()

    # ##### Tethering should not turn off when leaving Tethering menu #####
    bluetooth_steps.BtSetTethering(serial=serial, state="ON", check_if_already=True, version=DUT_VERSION)()
    bluetooth_steps.PressHome(serial=serial)()
    bluetooth_steps.BtCheckTetheringState(serial=serial, state="ON", tethering_settings_opened=False,
                                          version=DUT_VERSION)()
    bluetooth_steps.PressHome(serial=serial)()
    # ##### Tethering should be turned off and remain off when BT is ON #####
    bluetooth_steps.OpenBluetoothSettings(serial=serial, use_intent=True, version=DUT_VERSION)()