Пример #1
0
    def connect(self, timeout=10, check_boot_completed=True):  # pylint: disable=arguments-differ
        start = time.time()
        device = self.connection_settings.get('device')
        if device and ':' in device:
            # ADB does not automatically remove a network device from it's
            # devices list when the connection is broken by the remote, so the
            # adb connection may have gone "stale", resulting in adb blocking
            # indefinitely when making calls to the device. To avoid this,
            # always disconnect first.
            adb_disconnect(device)
        super(AndroidTarget, self).connect(timeout=timeout)
        if self.working_directory is None:
            self.working_directory = '/data/local/tmp/devlib-target'
        self._file_transfer_cache = self.path.join(self.working_directory,
                                                   '.file-cache')
        if self.executables_directory is None:
            self.executables_directory = self.path.join(
                self.working_directory, 'bin')

        if check_boot_completed:
            boot_completed = boolean(self.getprop('sys.boot_completed'))
            while not boot_completed and timeout >= time.time() - start:
                time.sleep(5)
                boot_completed = boolean(self.getprop('sys.boot_completed'))
            if not boot_completed:
                raise TargetError('Connected but Android did not fully boot.')
Пример #2
0
 def _probe_file(self, filepath):
     """
     Internal method to check if the target has a certain file
     """
     command = 'if [ -e \'{}\' ]; then echo 1; else echo 0; fi'
     output = self.execute(command.format(filepath), as_root=self.is_rooted)
     return boolean(output.strip())
Пример #3
0
 def is_screen_on(self):
     output = self.execute('dumpsys power')
     match = ANDROID_SCREEN_STATE_REGEX.search(output)
     if match:
         return boolean(match.group(1))
     else:
         raise TargetError('Could not establish screen state.')
Пример #4
0
 def _probe_file(self, filepath):
     """
     Internal method to check if the target has a certain file
     """
     command = 'if [ -e \'{}\' ]; then echo 1; else echo 0; fi'
     output = self.execute(command.format(filepath), as_root=self.is_rooted)
     return boolean(output.strip())
Пример #5
0
    def set_feature(self, feature, enable, verify=True):
        """
        Set the status of a specified scheduler feature

        :param feature: the feature name to set
        :param enable: true to enable the feature, false otherwise

        :raise ValueError: if the specified enable value is not bool
        :raise RuntimeError: if the specified feature cannot be set
        """
        if not self.has_debug:
            raise RuntimeError("sched_features not available")
        feature = feature.upper()
        feat_value = feature
        if not boolean(enable):
            feat_value = 'NO_' + feat_value
        self.target.write_value('/sys/kernel/debug/sched_features',
                                feat_value,
                                verify=False)
        if not verify:
            return
        msg = 'Failed to set {}, feature not supported?'.format(feat_value)
        features = self.get_features()
        feat_value = features.get(feature, not enable)
        if feat_value != enable:
            raise RuntimeError(msg)
Пример #6
0
    def connect(self, timeout=10, check_boot_completed=True):  # pylint: disable=arguments-differ
        start = time.time()
        device = self.connection_settings.get('device')
        if device and ':' in device:
            # ADB does not automatically remove a network device from it's
            # devices list when the connection is broken by the remote, so the
            # adb connection may have gone "stale", resulting in adb blocking
            # indefinitely when making calls to the device. To avoid this,
            # always disconnect first.
            adb_disconnect(device)
        super(AndroidTarget, self).connect(timeout=timeout)

        if check_boot_completed:
            boot_completed = boolean(self.getprop('sys.boot_completed'))
            while not boot_completed and timeout >= time.time() - start:
                time.sleep(5)
                boot_completed = boolean(self.getprop('sys.boot_completed'))
            if not boot_completed:
                raise TargetError('Connected but Android did not fully boot.')
Пример #7
0
 def list_subsystems(self):
     subsystems = []
     for line in self.target.execute('{} cat /proc/cgroups'\
             .format(self.target.busybox), as_root=self.target.is_rooted).splitlines()[1:]:
         line = line.strip()
         if not line or line.startswith('#'):
             continue
         name, hierarchy, num_cgroups, enabled = line.split()
         subsystems.append(
             CgroupSubsystemEntry(name, int(hierarchy), int(num_cgroups),
                                  boolean(enabled)))
     return subsystems
Пример #8
0
 def list_subsystems(self):
     subsystems = []
     for line in self.target.execute('cat /proc/cgroups').split('\n')[1:]:
         line = line.strip()
         if not line or line.startswith('#'):
             continue
         name, hierarchy, num_cgroups, enabled = line.split()
         subsystems.append(CgroupSubsystemEntry(name,
                                                int(hierarchy),
                                                int(num_cgroups),
                                                boolean(enabled)))
     return subsystems
Пример #9
0
 def __init__(self, config_dict):
     if isinstance(config_dict, UefiConfig):
         self.__dict__ = copy(config_dict.__dict__)
     else:
         try:
             self.image_name = config_dict['image_name']
             self.image_args = config_dict['image_args']
             self.fdt_support = boolean(config_dict['fdt_support'])
         except KeyError as e:
             raise ValueError('Missing mandatory parameter for UEFI entry config: "{}"'.format(e))
         self.initrd = config_dict.get('initrd')
         self.fdt_path = config_dict.get('fdt_path')
         if self.fdt_path and not self.fdt_support:
             raise ValueError('FDT path has been specfied for UEFI entry, when FDT support is "False"')
Пример #10
0
 def __init__(self, config_dict):
     if isinstance(config_dict, UefiConfig):
         self.__dict__ = copy(config_dict.__dict__)
     else:
         try:
             self.image_name = config_dict['image_name']
             self.image_args = config_dict['image_args']
             self.fdt_support = boolean(config_dict['fdt_support'])
         except KeyError as e:
             raise ValueError(
                 'Missing mandatory parameter for UEFI entry config: "{}"'.
                 format(e))
         self.initrd = config_dict.get('initrd')
         self.fdt_path = config_dict.get('fdt_path')
         if self.fdt_path and not self.fdt_support:
             raise ValueError(
                 'FDT path has been specfied for UEFI entry, when FDT support is "False"'
             )
Пример #11
0
 def _decode(string):
     value_type = string[:1]
     value_dimension = string[1:2]
     value = unquote(string[2:])
     if value_dimension == 's':
         if value_type == 's':
             return str(value)
         elif value_type == 'b':
             return boolean(value)
         elif value_type == 'd':
             return int(value)
         elif value_type == 'f':
             return float(value)
         elif value_type == 'i':
             return int(value)
         elif value_type == 'n':
             return None
     elif value_dimension == 'l':
         return [ParameterDict._decode(value_type + 's' + x)
                 for x in value.split('0newelement0')]
     else:
         raise ValueError('Unknown {} {}'.format(type(string), string))
Пример #12
0
 def is_enabled(self):
     return not boolean(self.get("disable"))
Пример #13
0
 def directory_exists(self, filepath):
     output = self.execute('if [ -d \'{}\' ]; then echo 1; else echo 0; fi'.format(filepath))
     # output from ssh my contain part of the expression in the buffer,
     # split out everything except the last word.
     return boolean(output.split()[-1])  # pylint: disable=maybe-no-member
Пример #14
0
 def file_exists(self, filepath):
     command = 'if [ -e \'{}\' ]; then echo 1; else echo 0; fi'
     return boolean(self.execute(command.format(filepath)).strip())
Пример #15
0
 def is_enabled(self):
     return not boolean(self.get('disable'))
Пример #16
0
 def file_exists(self, filepath):
     command = 'if [ -e \'{}\' ]; then echo 1; else echo 0; fi'
     output = self.execute(command.format(filepath), as_root=self.is_rooted)
     return boolean(output.strip())
Пример #17
0
 def is_enabled(self):
     return not boolean(self.get('disable'))