Exemplo n.º 1
0
 def initialize_with_host_apk(self, context, installed_version):
     host_version = ApkInfo(self.apk_file).version_name
     if installed_version != host_version:
         if installed_version:
             message = '{} host version: {}, device version: {}; re-installing...'
             self.logger.debug(
                 message.format(os.path.basename(self.apk_file),
                                host_version, installed_version))
         else:
             message = '{} host version: {}, not found on device; installing...'
             self.logger.debug(
                 message.format(os.path.basename(self.apk_file),
                                host_version))
         self.force_install = True  # pylint: disable=attribute-defined-outside-init
     else:
         message = '{} version {} found on both device and host.'
         self.logger.debug(
             message.format(os.path.basename(self.apk_file), host_version))
     if self.force_install:
         if installed_version:
             self.device.uninstall(self.package)
         self.install_apk(context)
     else:
         self.reset(context)
     self.apk_version = host_version
Exemplo n.º 2
0
def get_from_list_by_extension(resource,
                               filelist,
                               extension,
                               version=None,
                               variant=None):
    filelist = [
        ff for ff in filelist
        if os.path.splitext(ff)[1].lower().endswith(extension)
    ]
    if variant:
        filelist = [
            ff for ff in filelist
            if variant.lower() in os.path.basename(ff).lower()
        ]
    if version:
        if extension == 'apk':
            filelist = [
                ff for ff in filelist
                if version.lower() in ApkInfo(ff).version_name.lower()
            ]
        else:
            filelist = [
                ff for ff in filelist
                if version.lower() in os.path.basename(ff).lower()
            ]
    if len(filelist) == 1:
        return filelist[0]
    elif not filelist:
        return None
    else:
        raise ResourceError('More than one .{} found in {} for {}.'.format(
            extension, filelist, resource.owner.name))
Exemplo n.º 3
0
 def initialize_with_host_apk(self, context, installed_version):
     host_version = ApkInfo(self.apk_file).version_name
     if installed_version != host_version:
         if installed_version:
             message = '{} host version: {}, device version: {}; re-installing...'
             self.logger.debug(
                 message.format(os.path.basename(self.apk_file),
                                host_version, installed_version))
         else:
             message = '{} host version: {}, not found on device; installing...'
             self.logger.debug(
                 message.format(os.path.basename(self.apk_file),
                                host_version))
         self.force_install = True  # pylint: disable=attribute-defined-outside-init
     else:
         message = '{} version {} found on both device and host.'
         self.logger.debug(
             message.format(os.path.basename(self.apk_file), host_version))
     if self.force_install:
         if installed_version:
             self.device.uninstall(self.package)
         # It's possible that that the uninstall above fails, which will result in
         # install failing and a warning, hower execution would the proceed, so need
         # to make sure that the right apk_vesion is reported in the end.
         if self.install_apk(context):
             self.apk_version = host_version
         else:
             self.apk_version = installed_version
     else:
         self.apk_version = installed_version
         self.reset(context)
 def init_resources(self, context):
     # TODO: find a better APK to use for this.
     peacekeeper = ExtensionLoader().get_workload('peacekeeper',
                                                  self.device)
     self.apk_file = context.resolver.get(
         wlauto.common.android.resources.ApkFile(peacekeeper),
         variant_name='chrome')
     self.package = ApkInfo(self.apk_file).package
Exemplo n.º 5
0
 def check_host_version(self):
     host_version = None
     if self.apk_file is not None:
         host_version = ApkInfo(self.apk_file).version_name
         if host_version:
             host_version = LooseVersion(host_version)
         self.logger.debug("Found version '{}' on host".format(host_version))
     return host_version
Exemplo n.º 6
0
def get_from_list_by_extension(resource,
                               filelist,
                               extension,
                               version=None,
                               variant=None):
    filelist = [
        ff for ff in filelist
        if os.path.splitext(ff)[1].lower().endswith('.' + extension)
    ]
    if variant:
        filelist = [
            ff for ff in filelist
            if variant.lower() in os.path.basename(ff).lower()
        ]
    if version:
        if extension == 'apk':
            filelist = [
                ff for ff in filelist
                if version.lower() in ApkInfo(ff).version_name.lower()
            ]
        else:
            filelist = [
                ff for ff in filelist
                if version.lower() in os.path.basename(ff).lower()
            ]
    if extension == 'apk':
        filelist = [
            ff for ff in filelist if not ApkInfo(ff).native_code
            or resource.platform in ApkInfo(ff).native_code
        ]
        filelist = [
            ff for ff in filelist
            if not resource.package or resource.package == ApkInfo(ff).package
        ]
        filelist = [
            ff for ff in filelist if resource.uiauto == (
                'com.arm.wlauto.uiauto' in ApkInfo(ff).package)
        ]
    if len(filelist) == 1:
        return filelist[0]
    elif not filelist:
        return None
    else:
        raise ResourceError('More than one .{} found in {} for {}.'.format(
            extension, filelist, resource.owner.name))
Exemplo n.º 7
0
 def setup(self, context):
     if self.version == "6.0.1":
         antutu_3d = context.resolver.get(File(self, "com.antutu.benchmark.full-1.apk"))
         info = ApkInfo(antutu_3d)
         if not context.device.is_installed(info.package):
             self.device.install_apk(antutu_3d, timeout=120)
         # Antutu doesnt seem to list this as one of its permissions, but it asks for it.
         self.device.execute("pm grant com.antutu.ABenchMark android.permission.ACCESS_FINE_LOCATION")
     super(Antutu, self).setup(context)
Exemplo n.º 8
0
    def setup(self, context):
        Workload.setup(self, context)

        # Get target version
        target_version = self.device.get_installed_package_version(
            self.package)
        if target_version:
            target_version = LooseVersion(target_version)
            self.logger.debug(
                "Found version '{}' on target device".format(target_version))

        # Get host version
        self.apk_file = context.resolver.get(
            ApkFile(self, self.device.abi),
            version=getattr(self, 'version', None),
            check_abi=getattr(self, 'check_abi', False),
            variant_name=getattr(self, 'variant_name', None),
            strict=False)
        host_version = None
        if self.apk_file is not None:
            host_version = ApkInfo(self.apk_file).version_name
            if host_version:
                host_version = LooseVersion(host_version)
            self.logger.debug(
                "Found version '{}' on host".format(host_version))

        # Error if apk was not found anywhere
        if target_version is None and host_version is None:
            msg = "Could not find APK for '{}' on the host or target device"
            raise ResourceError(msg.format(self.name))

        if self.exact_apk_version is not None:
            if self.exact_apk_version != target_version and self.exact_apk_version != host_version:
                msg = "APK version '{}' not found on the host '{}' or target '{}'"
                raise ResourceError(
                    msg.format(self.exact_apk_version, host_version,
                               target_version))

        # Ensure the apk is setup on the device
        if self.force_install:
            self.force_install_apk(context, host_version)
        elif self.check_apk:
            self.prefer_host_apk(context, host_version, target_version)
        else:
            self.prefer_target_apk(context, host_version, target_version)

        self.reset(context)
        self.apk_version = self.device.get_installed_package_version(
            self.package)
        context.add_classifiers(apk_version=self.apk_version)

        if self.launch_main:
            self.launch_package(
            )  # launch default activity without intent data
        self.device.execute('am kill-all')  # kill all *background* activities
        self.device.clear_logcat()
Exemplo n.º 9
0
 def setup(self, context):
     if self.version == "6.0.1":
         antutu_3d = context.resolver.get(
             File(self, "com.antutu.benchmark.full-1.apk"))
         info = ApkInfo(antutu_3d)
         if not context.device.is_installed(info.package):
             self.device.install_apk(antutu_3d, timeout=120)
         if self.device.get_sdk_version() >= 23:
             # Antutu doesnt seem to list this as one of its permissions, but on some devices it asks for it.
             try:
                 self.device.execute(
                     "pm grant com.antutu.ABenchMark android.permission.ACCESS_FINE_LOCATION"
                 )
             except DeviceError:
                 self.logger.debug(
                     "failed to grant ACCESS_FINE_LOCATION, continuing")
     super(Antutu, self).setup(context)
Exemplo n.º 10
0
    def __init__(self, target, apk, service='.TrafficMetricsService'):
        """
        Additional paramerter:

        :apk: Path to the APK file that contains ``com.arm.devlab.netstats``
              package. If not specified, it will be assumed that an APK with
              name "netstats.apk" is located in the same directory as the
              Python module for the instrument.
        :service: Name of the service to be launched. This service must be
                  present in the APK.

        """
        self.target = target
        self.apk = apk
        self.logger = logging.getLogger('netstat')
        self.package = ApkInfo(self.apk).package
        self.service = service
        self.tag = None
        self.command = None
        self.stop_command = 'am kill {}'.format(self.package)
Exemplo n.º 11
0
 def initialize_package(self, context):
     installed_version = self.device.get_installed_package_version(self.package)
     host_version = ApkInfo(self.apk_file).version_name
     if installed_version != host_version:
         if installed_version:
             message = '{} host version: {}, device version: {}; re-installing...'
             self.logger.debug(message.format(os.path.basename(self.apk_file), host_version, installed_version))
         else:
             message = '{} host version: {}, not found on device; installing...'
             self.logger.debug(message.format(os.path.basename(self.apk_file), host_version))
         self.force_reinstall = True
     else:
         message = '{} version {} found on both device and host.'
         self.logger.debug(message.format(os.path.basename(self.apk_file), host_version))
     if self.force_reinstall:
         if installed_version:
             self.device.uninstall(self.package)
         self.install_apk(context)
     else:
         self.reset(context)
     self.apk_version = host_version
Exemplo n.º 12
0
 def setup(self, context):
     if hasattr(context.workload, 'apk_file'):
         self.apk_info = ApkInfo(context.workload.apk_file)
     else:
         self.apk_info = None
Exemplo n.º 13
0
    def setup(self, context):
        apk_file = context.resolver.get(File(self, self.apk_file))
        self.package = ApkInfo(apk_file).package  # pylint: disable=attribute-defined-outside-init

        self.logger.info('Installing {}'.format(apk_file))
        return self.device.install(apk_file)