Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p = self.adb.start_shell('CLASSPATH=%s exec app_process /system/bin %s.Recorder --stop-record' % (pkg_path, YOSEMITE_PACKAGE))
p.wait()
self.recording_proc = None
if is_interrupted:
return
for line in p.stdout.readlines():
if line is None:
break
if six.PY3:
line = line.decode("utf-8")
m = re.match("stop result: Stop ok! File path:(.*\.mp4)", line.strip())
if m:
self.recording_file = m.group(1)
self.adb.pull(self.recording_file, output)
return True
raise AirtestError("start_recording first")
package: package name
Raises:
AdbShellError: if any adb error occurs
AirtestError: if package is not found on the device
Returns:
path to the package
"""
try:
output = self.shell(['pm', 'path', package])
except AdbShellError:
output = ""
if 'package:' not in output:
raise AirtestError('package not found, output:[%s]' % output)
return output.split("package:")[1].strip()
cmds = [self.proxy_process, str(local_port), str(remote_port)]
proc = subprocess.Popen(
cmds,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# something like port binding fail
time.sleep(0.5)
if proc.poll() is not None:
stdout, stderr = proc.communicate()
stdout = stdout.decode(get_std_encoding(sys.stdout))
stderr = stderr.decode(get_std_encoding(sys.stderr))
raise AirtestError((stdout, stderr))
self.subprocessHandle.append(proc)
Args:
package: package name
Raises:
AirtestError: if package is not found
Returns:
True if package has been found
"""
output = self.shell(['dumpsys', 'package', package])
pattern = r'Package\s+\[' + str(package) + '\]'
match = re.search(pattern, output)
if match is None:
raise AirtestError('package "{}" not found'.format(package))
return True
"""
This is InvalidMatchingMethodError BaseError
When an invalid matching method is used in settings.
"""
pass
class TargetNotFoundError(AirtestError):
"""
This is TargetNotFoundError BaseError
When something is not found
"""
pass
class ScriptParamError(AirtestError):
"""
This is ScriptParamError BaseError
When something goes wrong
"""
pass
class AdbError(Exception):
"""
This is AdbError BaseError
When ADB have something wrong
"""
def __init__(self, stdout, stderr):
self.stdout = stdout
self.stderr = stderr
def _install_and_setup(self):
"""
Install and setup the RotationWatcher package
Raises:
RuntimeError: if any error occurs while installing the package
Returns:
None
"""
try:
apk_path = self.adb.path_app(ROTATIONWATCHER_PACKAGE)
except AirtestError:
self.adb.install_app(ROTATIONWATCHER_APK, ROTATIONWATCHER_PACKAGE)
apk_path = self.adb.path_app(ROTATIONWATCHER_PACKAGE)
p = self.adb.start_shell('export CLASSPATH=%s;exec app_process /system/bin jp.co.cyberagent.stf.rotationwatcher.RotationWatcher' % apk_path)
if p.poll() is not None:
raise RuntimeError("orientationWatcher setup error")
self.ow_proc = p
# reg_cleanup(self.ow_proc.kill)
class AirtestError(BaseError):
"""
This is Airtest BaseError
"""
pass
class InvalidMatchingMethodError(BaseError):
"""
This is InvalidMatchingMethodError BaseError
When an invalid matching method is used in settings.
"""
pass
class TargetNotFoundError(AirtestError):
"""
This is TargetNotFoundError BaseError
When something is not found
"""
pass
class ScriptParamError(AirtestError):
"""
This is ScriptParamError BaseError
When something goes wrong
"""
pass
class AdbError(Exception):
def test_path_app(self):
self._install_test_app()
app_path = self.android.path_app(PKG)
self.assertIn(PKG, app_path)
self.assertTrue(app_path.startswith("/"))
with self.assertRaises(AirtestError):
self.android.path_app('com.netease.this.is.error')
def is_locked(self):
"""
Perform `adb shell dumpsys window policy` command and search for information if screen is locked or not
Raises:
AirtestError: if lock screen can't be detected
Returns:
True or False whether the screen is locked or not
"""
lockScreenRE = re.compile('(?:mShowingLockscreen|isStatusBarKeyguard)=(true|false)')
m = lockScreenRE.search(self.shell('dumpsys window policy'))
if not m:
raise AirtestError("Couldn't determine screen lock state")
return (m.group(1) == 'true')
def is_screenon(self):
"""
Perform `adb shell dumpsys window policy` command and search for information if screen is turned on or off
Raises:
AirtestError: if screen state can't be detected
Returns:
True or False whether the screen is turned on or off
"""
screenOnRE = re.compile('mScreenOnFully=(true|false)')
m = screenOnRE.search(self.shell('dumpsys window policy'))
if m:
return (m.group(1) == 'true')
raise AirtestError("Couldn't determine screen ON state")