Esempio n. 1
0
 def apk_update_status(self):
     update_info = {}
     sql = "SELECT `usage`, `arch`, `version`, `download_status`, `last_checked`\n" \
           "FROM `mad_apk_autosearch`"
     autosearch_data = self._db.autofetch_all(sql)
     apk_info: MAD_APKS = get_apk_status(self.storage_obj)
     package: APK_Type = None
     arch: APK_Arch = None
     for row in autosearch_data:
         arch = lookup_arch_enum(row['arch'])
         package = lookup_apk_enum(row['usage'])
         composite_key = '%s_%s' % (row['usage'], row['arch'])
         update_info[composite_key] = {}
         if row['download_status'] != 0:
             update_info[composite_key]['download_status'] = row[
                 'download_status']
         try:
             curr_info = apk_info[package][arch]
         except KeyError:
             curr_info = None
         if package == APK_Type.pogo:
             if not curr_info or is_newer_version(row['version'],
                                                  curr_info.version):
                 update_info[composite_key]['update'] = 1
         else:
             if curr_info is None or curr_info.size is None or row[
                     'version'] is None:
                 update_info[composite_key]['update'] = 1
             elif int(curr_info.size) != int(row['version']):
                 update_info[composite_key]['update'] = 1
         if not update_info[composite_key]:
             del update_info[composite_key]
     return Response(json.dumps(update_info), mimetype='application/json')
Esempio n. 2
0
    def start_job_type(self, item, jobtype, ws_conn):
        try:
            jobtype = JobType[jobtype.split('.')[1]]
            if jobtype == JobType.INSTALLATION:
                file_ = self._log[str(item)]['file']
                if str(file_).lower().endswith(".apk"):
                    returning = ws_conn.install_apk(300,
                                                    filepath=os.path.join(
                                                        self._args.upload_path,
                                                        file_))
                elif str(file_).lower().endswith(".zip"):
                    returning = ws_conn.install_bundle(
                        600,
                        filepath=os.path.join(self._args.upload_path, file_))
                else:
                    # unknown filetype
                    returning = False
                return returning if not 'RemoteGpsController'.lower() in str(
                    file_).lower() else True
            elif jobtype == jobtype.SMART_UPDATE:
                package_ver: str = None
                package_raw = self._log[str(item)]['file']
                version_job = "dumpsys package %s | grep versionName" % (
                    package_raw, )
                architecture_job = ws_conn.passthrough(
                    'getprop ro.product.cpu.abi')
                package_ver_job = ws_conn.passthrough(version_job)
                try:
                    architecture_raw = re.search(r'\[(\S+)\]',
                                                 architecture_job).group(1)
                except AttributeError:
                    logger.warning(
                        'Unable to determine the architecture of the device')
                    return False
                try:
                    package_ver = re.search(r'versionName=([0-9\.]+)',
                                            package_ver_job).group(1)
                except AttributeError:
                    if package_ver_job and package_ver_job.split(
                            '\n')[0].strip() == 'OK':
                        logger.info(
                            'No information returned.  Assuming package is not installed'
                        )
                    else:
                        logger.warning(
                            'Unable to determine version for {}: {}',
                            self._log[str(item)]['file'], package_ver_job)
                        return False
                package = getattr(APKType, APKPackage(package_raw).name)
                architecture = lookup_arch_enum(architecture_raw)
                package_all: MADPackages = self._storage_obj.get_current_package_info(
                    package)
                if package_all is None:
                    logger.warning('No MAD APK for {} [{}]', package,
                                   architecture.name)
                    return False
                try:
                    mad_apk = package_all[architecture]
                except KeyError:
                    architecture = APKArch.noarch
                    mad_apk = package_all[architecture.noarch]

                if mad_apk.filename is None:
                    logger.warning('No MAD APK for {} [{}]', package,
                                   architecture.name)
                    return False
                # Validate it is supported
                if package == APKType.pogo:
                    if not supported_pogo_version(architecture,
                                                  mad_apk.version):
                        self.write_status_log(str(item),
                                              field='status',
                                              value='not supported')
                        return True
                if not is_newer_version(mad_apk.version, package_ver):
                    logger.info(
                        'Both versions are the same.  No update required')
                    self.write_status_log(str(item),
                                          field='status',
                                          value='not required')
                    return True
                else:
                    logger.info('Smart Update APK Installation for {} to {}',
                                package.name, self._log[str(item)]['origin'])
                    apk_file = bytes()
                    for chunk in file_generator(self._db, self._storage_obj,
                                                package, architecture):
                        apk_file += chunk
                    if mad_apk.mimetype == 'application/zip':
                        returning = ws_conn.install_bundle(300, data=apk_file)
                    else:
                        returning = ws_conn.install_apk(300, data=apk_file)
                    return returning if not 'RemoteGpsController'.lower(
                    ) in str(self._log[str(item)]['file']).lower() else True
            elif jobtype == JobType.REBOOT:
                return ws_conn.reboot()
            elif jobtype == JobType.RESTART:
                return ws_conn.restart_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.STOP:
                return ws_conn.stop_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.START:
                return ws_conn.start_app("com.nianticlabs.pokemongo")
            elif jobtype == JobType.PASSTHROUGH:
                command = self._log[str(item)]['file']
                returning = ws_conn.passthrough(command).replace(
                    '\r', '').replace('\n', '').replace('  ', '')
                self.write_status_log(str(item),
                                      field='returning',
                                      value=returning)
                self.set_returning(
                    origin=self._log[str(item)]['origin'],
                    fieldname=self._log[str(item)].get('fieldname'),
                    value=returning)
                return returning if 'KO' not in returning else False
            return False
        except Exception as e:
            logger.error(
                'Error while getting response from device - Reason: {}', e)
        return False