Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def directory_exists(self, filepath):
output = self.execute('if [ -d {} ]; then echo 1; else echo 0; fi'.format(quote(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
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))
def set_auto_rotation(self, autorotate):
cmd = 'settings put system accelerometer_rotation {}'
self.execute(cmd.format(int(boolean(autorotate))))
def is_screen_on(self):
output = self.execute('dumpsys power')
match = ANDROID_SCREEN_STATE_REGEX.search(output)
if match:
if 'DOZE' in match.group(1).upper():
return True
return boolean(match.group(1))
else:
raise TargetStableError('Could not establish screen state.')
def set_airplane_mode(self, mode):
root_required = self.get_sdk_version() > 23
if root_required and not self.is_rooted:
raise TargetStableError('Root is required to toggle airplane mode on Android 7+')
mode = int(boolean(mode))
cmd = 'settings put global airplane_mode_on {}'
self.execute(cmd.format(mode))
self.execute('am broadcast -a android.intent.action.AIRPLANE_MODE '
'--ez state {}'.format(mode), as_root=root_required)
def file_exists(self, filepath):
command = 'if [ -e {} ]; then echo 1; else echo 0; fi'
output = self.execute(command.format(quote(filepath)), as_root=self.is_rooted)
return boolean(output.strip())
def set_auto_brightness(self, auto_brightness):
cmd = 'settings put system screen_brightness_mode {}'
self.execute(cmd.format(int(boolean(auto_brightness))))
def get_airplane_mode(self):
cmd = 'settings get global airplane_mode_on'
return boolean(self.execute(cmd).strip())