예제 #1
0
 def resolve_resource(self, resource):
     # pylint: disable=too-many-branches
     assets = self.index.get(resource.owner.name, {})
     if not assets:
         return {}
     if resource.name in ["apk", "jar"]:
         paths = [a["path"] for a in assets]
         version = getattr(resource, "version", None)
         found = get_from_list_by_extension(resource, paths, resource.name, version)
         if found:
             for a in assets:
                 if a["path"] == found:
                     return a
     elif resource.name == "revent":
         device_model = resource.owner.device.get_device_model()
         wa_device_name = resource.owner.device.name
         for name in [device_model, wa_device_name]:
             if not name:
                 continue
             filename = ".".join([name, resource.stage, "revent"]).lower()
             for asset in assets:
                 pathname = os.path.basename(asset["path"]).lower()
                 if pathname == filename:
                     try:
                         ReventParser.check_revent_file(asset["path"])
                         return asset
                     except ValueError as e:
                         self.logger.warning(e.message)
     else:  # file
         for asset in assets:
             if asset["path"].lower() == resource.path.lower():
                 return asset
 def initialize(self, context):
     self.revent_setup_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'setup'))
     self.revent_run_file = context.resolver.get(wlauto.common.android.resources.ReventFile(self, 'run'))
     devpath = self.device.path
     self.on_device_setup_revent = devpath.join(self.device.working_directory,
                                                os.path.split(self.revent_setup_file)[-1])
     self.on_device_run_revent = devpath.join(self.device.working_directory,
                                              os.path.split(self.revent_run_file)[-1])
     self._check_revent_files(context)
     default_setup_timeout = ceil(ReventParser.get_revent_duration(self.revent_setup_file)) + 30
     default_run_timeout = ceil(ReventParser.get_revent_duration(self.revent_run_file)) + 30
     self.setup_timeout = self.setup_timeout or default_setup_timeout
     self.run_timeout = self.run_timeout or default_run_timeout
예제 #3
0
 def get(self, resource, **kwargs):
     device_model = resource.owner.device.get_device_model()
     wa_device_name = resource.owner.device.name
     for name in [device_model, wa_device_name]:
         if not name:
             continue
         filename = ".".join([name, resource.stage, "revent"]).lower()
         location = _d(os.path.join(self.get_base_location(resource), "revent_files"))
         for candidate in os.listdir(location):
             if candidate.lower() == filename.lower():
                 path = os.path.join(location, candidate)
                 try:
                     ReventParser.check_revent_file(path)
                     return path
                 except ValueError as e:
                     self.logger.warning(e.message)
예제 #4
0
    def setup(self, context):
        self.revent_setup_file = context.resolver.get(ReventFile(self, 'setup'))
        self.revent_run_file = context.resolver.get(ReventFile(self, 'run'))
        devpath = self.device.path
        self.on_device_setup_revent = devpath.join(self.device.working_directory,
                                                   os.path.split(self.revent_setup_file)[-1])
        self.on_device_run_revent = devpath.join(self.device.working_directory,
                                                 os.path.split(self.revent_run_file)[-1])
        self._check_revent_files(context)
        default_setup_timeout = ceil(ReventParser.get_revent_duration(self.revent_setup_file)) + 30
        default_run_timeout = ceil(ReventParser.get_revent_duration(self.revent_run_file)) + 30
        self.setup_timeout = self.setup_timeout or default_setup_timeout
        self.run_timeout = self.run_timeout or default_run_timeout

        Workload.setup(self, context)
        self.device.killall('revent')
        command = '{} replay {}'.format(self.on_device_revent_binary, self.on_device_setup_revent)
        self.device.execute(command, timeout=self.setup_timeout)
예제 #5
0
    def get_from(self, resource, version, location):  # pylint: disable=no-self-use
        # pylint: disable=too-many-branches
        if resource.name in ["apk", "jar"]:
            return get_from_location_by_extension(resource, location, resource.name, version)
        elif resource.name == "file":
            filepath = os.path.join(location, resource.path)
            if os.path.exists(filepath):
                return filepath
        elif resource.name == "revent":
            device_model = resource.owner.device.get_device_model()
            wa_device_name = resource.owner.device.name
            for name in [device_model, wa_device_name]:
                if not name:
                    continue
                filename = ".".join([name, resource.stage, "revent"]).lower()
                alternate_location = os.path.join(location, "revent_files")
                # There tends to be some confusion as to where revent files should
                # be placed. This looks both in the extension's directory, and in
                # 'revent_files' subdirectory under it, if it exists.
                path = None
                if os.path.isdir(alternate_location):
                    for candidate in os.listdir(alternate_location):
                        if candidate.lower() == filename.lower():
                            path = os.path.join(alternate_location, candidate)
                if os.path.isdir(location):
                    for candidate in os.listdir(location):
                        if candidate.lower() == filename.lower():
                            path = os.path.join(location, candidate)
                if path:
                    try:
                        ReventParser.check_revent_file(path)
                        return path
                    except ValueError as e:
                        self.logger.warning(e.message)

        else:
            raise ValueError("Unexpected resource type: {}".format(resource.name))
예제 #6
0
    def run(self, args):
        self.logger.info("Pushing file to device")
        self.device.push_file(args.revent, self.device.working_directory)
        revent_file = self.device.path.join(self.device.working_directory, os.path.split(args.revent)[1])

        if args.clear:
            self.device.execute("pm clear {}".format(args.package))

        if args.package:
            self.logger.info("Starting {}".format(args.package))
            self.device.execute('monkey -p {} -c android.intent.category.LAUNCHER 1'.format(args.package))

        self.logger.info("Replaying recording")
        command = "{} replay {}".format(self.target_binary, revent_file)
        timeout = ceil(ReventParser.get_revent_duration(args.revent)) + 30
        self.device.execute(command, timeout=timeout)
        self.logger.info("Finished replay")