Exemplo n.º 1
0
 def __init__(self, adb):
     self.adb = adb
     self.ow_proc = None
     self.ow_callback = []
     self._t = None
     self.current_orientation = None
     reg_cleanup(self.teardown)
Exemplo n.º 2
0
    def _setup_stream_server(self):
        """
        Setup stream server

        Returns:
            adb shell process, non-blocking stream reader and local port

        """
        localport, deviceport = self.adb.setup_forward("localabstract:javacap_{}".format)
        deviceport = deviceport[len("localabstract:"):]
        # setup agent proc
        apkpath = self.adb.path_app(self.APP_PKG)
        cmds = ["CLASSPATH=" + apkpath, 'exec', 'app_process', '/system/bin', self.SCREENCAP_SERVICE,
                "--scale", "100", "--socket", "%s" % deviceport, "-lazy", "2>&1"]
        proc = self.adb.start_shell(cmds)
        # check proc output
        nbsp = NonBlockingStreamReader(proc.stdout, print_output=True, name="javacap_sever")
        while True:
            gevent.sleep(0.01)
            line = nbsp.readline(timeout=5.0)
            if line is None:
                raise RuntimeError("javacap server setup timeout")
            if b"Capture server listening on" in line:
                break
            if b"Address already in use" in line:
                raise RuntimeError("javacap server setup error: %s" % line)
        reg_cleanup(proc.kill)
        return proc, nbsp, localport
Exemplo n.º 3
0
 def __init__(self, iosHandle):
     self.iosHandle = iosHandle
     self.session = iosHandle.session
     self.ow_callback = []
     self.roundProcess = None
     self._stopEvent = threading.Event()
     self.last_result = None
     reg_cleanup(self.teardown)
Exemplo n.º 4
0
 def __init__(self, adb, backend=False, ori_function=None):
     self.adb = adb
     self.backend = backend
     self.server_proc = None
     self.client = None
     self.size_info = None
     self.ori_function = ori_function if callable(
         ori_function) else self.adb.getPhysicalDisplayInfo
     self.max_x, self.max_y = None, None
     reg_cleanup(self.teardown)
Exemplo n.º 5
0
    def _setup_stream_server(self, lazy=False):
        """
        Setup minicap process on device

        Args:
            lazy: parameter `-l` is used when True

        Returns:
            adb shell process, non-blocking stream reader and local port

        """
        localport, deviceport = self.adb.setup_forward(
            "localabstract:minicap_{}".format)
        deviceport = deviceport[len("localabstract:"):]
        other_opt = "-l" if lazy else ""
        params, display_info = self._get_params()
        proc = self.adb.start_shell(
            "%s -n '%s' -P %dx%d@%dx%d/%d %s 2>&1" %
            tuple([self.CMD, deviceport] + list(params) + [other_opt]), )
        nbsp = NonBlockingStreamReader(proc.stdout,
                                       print_output=True,
                                       name="minicap_server")
        while True:
            line = nbsp.readline(timeout=5.0)
            if line is None:
                raise RuntimeError("minicap server setup timeout")
            if b"Server start" in line:
                break

        if proc.poll() is not None:
            # minicap server setup error, may be already setup by others
            # subprocess exit immediately
            raise RuntimeError("minicap server quit immediately")

        reg_cleanup(proc.kill)
        self._stream_rotation = int(display_info["rotation"])
        return proc, nbsp, localport
Exemplo n.º 6
0
                        offsetx, offsety, x, y = offsety, offsetx, y, x
                    x, y = x - offsetx, y - offsety
        return {
            "offset_x": offsetx,
            "offset_y": offsety,
            "offset_width": x,
            "offset_height": y
        }

    def _search_for_current_package(self, ret):
        """
        Search for current app package name from the output of command "adb shell dumpsys window windows"

        Returns:
            package name if exists else ""
        """
        packageRE = re.compile(
            '\s*mCurrentFocus=Window{.* ([A-Za-z0-9_.]+)/[A-Za-z0-9_.]+}')
        m = packageRE.findall(ret)
        if m:
            return m[-1]
        return ""


def cleanup_adb_forward():
    for adb in ADB._instances:
        adb._cleanup_forwards()


reg_cleanup(cleanup_adb_forward)