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

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

    # DUT: clear all notifications/opp files 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.ClearPath(serial=serial, blocking=True)()

    # DEV: clear all notifications etc
    bluetooth_steps.StopPackage(serial=serial_dev, blocking=True)()
    bluetooth_steps.ClearDataPackage(
        serial=serial_dev,
        package_name="com.google.android.apps.photos",
        blocking=True)()
    bluetooth_steps.StopPackage(serial=serial_dev,
                                package_name="com.google.android.apps.photos",
                                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,
Пример #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")