예제 #1
0
 def scan_config_devices_update_list_view(self):
     """
     Scans for saved devices
     :return:
     """
     self.devices_view.clear()
     paired_devices = self.config['device']
     for i in paired_devices:
         if paired_devices[i].get('wifi'):
             icon = ':/icons/icons/portrait_mobile_disconnect.svg'
             devices_view_list_item = QListWidgetItem(
                 QIcon(icon), "{device}\n{mode}\n{status}".format(
                     device=paired_devices[i].get('model'),
                     mode=i,
                     status='Disconnected'))
             __sha_shift = self.config.get('sha_shift', 5)
             __sha = hashlib.sha256(
                 str(i).encode()).hexdigest()[__sha_shift:__sha_shift + 6]
             devices_view_list_item.setToolTip(
                 "<span style='color: #{color}'>Device</snap>: <b>{d}</b>\n"
                 "Status: {s}".format(
                     d=i,
                     s="Disconnected. Right click 'ping' to attempt "
                     "reconnect",
                     color=__sha))
             devices_view_list_item.setFont(QFont('Noto Sans', 8))
             self.devices_view.addItem(devices_view_list_item)
     return paired_devices
예제 #2
0
    def scan_devices_update_list_view(self):
        """
        Scan for new devices; and update the list view
        :return:
        """
        # self.devices_view.clear()
        device_exists_in_view = False
        paired_devices = []
        for index in range(self.devices_view.count()):
            paired_devices.append(self.devices_view.item(index))

        __devices = self.adb.devices_detailed()
        log(__devices)
        for i in __devices:
            device_is_wifi = \
                i['identifier'].count('.') >= 3 and (':' in i['identifier'])

            if i['identifier'] not in self.config['device'].keys():
                device_paired_and_exists = False
                self.config['device'][i['identifier']] = {'rotation': 0}
            else:
                device_paired_and_exists = True

            if device_is_wifi:
                _icon_suffix = '_wifi'
            else:
                _icon_suffix = '_usb'

            icon = ':/icons/icons/portrait_mobile_white{}.svg'.format(
                _icon_suffix)

            if i['status'] == 'offline':
                icon = ':/icons/icons/portrait_mobile_error.svg'
            elif i['status'] == 'unauthorized':
                icon = ':/icons/icons/portrait_mobile_warning.svg'

            if i['status'] == 'no_permission':
                log("pairfilter: 5")
                # https://stackoverflow.com/questions/
                # 53887322/adb-devices-no-permissions-user-in-
                # plugdev-group-are-your-udev-rules-wrong
                udev_error = "Error connecting to device. Your udev rules are"\
                    " incorrect. See https://stackoverflow.com/questions"\
                    "/53887322/adb-devices-no-permissions-user-in-plugdev-"\
                    "group-are-your-udev-rules-wrong"
                self.display_public_message(udev_error)
                print(udev_error)
                return []
            # Check if device is unauthorized
            elif i['status'] == "unauthorized":
                log("unauthorized device detected: Click Allow on your device")
                log("pairfilter: 4")
                # The device is connected; and might/might't paired in the past
                # And is connected to the same IP address
                # It is possibly a bug with the connection;
                # Temporarily create a new QListItem to display the
                # device with the error
                paired = False
                device_paired_and_exists = False
                self.display_public_message(
                    f"{i['identifier']} is unauthorized. Please click allow "
                    f"on your device.")
                # Remove other devices with the same id and offline and
                # unauthorized
                self.remove_device_device_view(
                    i['identifier'], statuses=['offline', 'unauthorized'])
                # Unauthorized device cannot be considered as a paired device
                devices_view_list_item = QListWidgetItem()
            else:
                # check if device is paired
                # if yes, just update the list item
                if not device_paired_and_exists:
                    paired = False
                    devices_view_list_item = QListWidgetItem()
                else:
                    for paired_device in paired_devices:
                        if paired_device.text().split()[0] == i['model']:
                            log("pairfilter: 1")
                            paired = True
                            devices_view_list_item = paired_device
                            # as we have found a paired device
                            # we know by assumption; there cannot be two
                            # devices with the same local IP address;
                            # lets scan the devices_view once more in a loop
                            # to check for any device with the same
                            # identifier and remove them; based on this same
                            # assumption
                            self.remove_device_device_view(
                                i['identifier'],
                                statuses=['offline', 'unauthorized'])
                            break
                        elif paired_device.text().split()[1] ==\
                                i['identifier']:
                            log("pairfilter: 2")
                            self.remove_device_device_view(
                                i['identifier'],
                                statuses=['offline', 'unauthorized'])
                            devices_view_list_item = QListWidgetItem()
                            paired = False
                            break
                    else:
                        log("pairfilter: 3")
                        paired = False
                        devices_view_list_item = QListWidgetItem()

            devices_view_list_item.setIcon(QIcon(icon))

            devices_view_list_item.setText("{device}\n{mode}\n{status}".format(
                device=i['model'], mode=i['identifier'], status=i['status']))
            __sha_shift = self.config.get('sha_shift', 5)
            __sha = hashlib.sha256(str(i['identifier']).encode()).hexdigest(
            )[__sha_shift:__sha_shift + 6]
            devices_view_list_item.setToolTip(
                "Device: "
                "<span style='color: #{inv_color};background-color: #{color}'>"
                "<b>{d}</b></span>\n"
                "<br>"
                "Model: {m}\n<br>"
                "Alias: {a}\n<br>"
                "Status: {s}\n<br>"
                "Transport ID: {t}\n<br>"
                "Paired: {p}".format(d=i['identifier'],
                                     m=i['model'],
                                     a=i['product'],
                                     s=i['status'],
                                     t=i['transport_id'],
                                     p=paired,
                                     color=__sha,
                                     inv_color=str(
                                         hex(0xFFFFFF - int(__sha, 16))[2:])))

            devices_view_list_item.setFont(QFont('Noto Sans', 8))
            log(f"Pairing status: {device_paired_and_exists}")
            if device_paired_and_exists and device_is_wifi:
                # we need to only neglect wifi devices
                # paired usb device need to still show in the display
                continue
            elif device_exists_in_view:
                # devices exists in the list with the same status and
                # we should not add the new detected list item
                continue
            # If and only if the device doesn't exist; add it
            self.devices_view.addItem(devices_view_list_item)
        return __devices