# Path: android_env/components/log_stream.py
# class LogStream(metaclass=abc.ABCMeta):
#   def __init__(self, verbose: bool = False):
#   def get_stream_output(self):
#   def _get_stream_output(self):
#   def stop_stream(self):
#   def set_log_filters(self, log_filters: List[str]):
# 
# Path: android_env/components/thread_function.py
# class ThreadFunction(metaclass=abc.ABCMeta):
#   class Signal(enum.IntEnum):
#     KILL = 1
#   def __init__(self, block_input: bool, block_output: bool, name: str):
#   def read(self, block: bool = True, timeout: Optional[float] = None):
#   def write(self, value, block: bool = True, timeout: Optional[float] = None):
#   def main(self):
#   def kill(self):
#   def _run(self):
#   def _read_value(self):
#   def _write_value(self, value):


import re
import threading
from typing import Callable, Match, NamedTuple, Optional, Pattern
from absl import logging
from android_env.components import log_stream as log_stream_lib
from android_env.components import thread_function
from android_env.proto import task_pb2
    self._log_stream.stop_stream()

    super().kill()

  def main(self) -> None:
    # pylint: disable=g-line-too-long
    # Format is: "TIME_SEC PID TID PRIORITY TAG: MESSAGE"
    #
    # Example:
    #  '         1553110400.424  5583  5658 D NostalgicRacer: com.google.example.games.nostalgicracer.views.renderers.OpenGLRenderDriver@912fb8.onSurfaceChanged 480x320'    #
    #
    # If a log_prefix is given, then the format becomes:
    # "TIME_SEC PID TID PRIORITY TAG: LOG_PREFIX MESSAGE"
    # pylint: enable=g-line-too-long

    regexp = r"""
      ^                                   # Beginning of the line.
      [ ]+(?P<timestamp>[0-9]+\.[0-9]+)   # Spaces and a float.
      [ ]+(?P<pid>[0-9]+)                 # Spaces and an int.
      [ ]+(?P<tid>[0-9]+)                 # Spaces and an int.
      [ ]+(?P<priority>.)                 # Spaces and any single character.
      [ ]+(?P<tag>[^:]*):                 # Spaces and any char that's not ':'.
    """

    regexp += r"""[ ](?P<message>.*)$"""
    logline_re = re.compile(regexp, re.VERBOSE)

    for line in self._stdout:
      # We never hand back control to ThreadFunction._run() so we need to
      # explicitly check for self._should_run here.

# Path: android_env/components/log_stream.py
# class LogStream(metaclass=abc.ABCMeta):
#   def __init__(self, verbose: bool = False):
#   def get_stream_output(self):
#   def _get_stream_output(self):
#   def stop_stream(self):
#   def set_log_filters(self, log_filters: List[str]):
# 
# Path: android_env/components/thread_function.py
# class ThreadFunction(metaclass=abc.ABCMeta):
#   class Signal(enum.IntEnum):
#     KILL = 1
#   def __init__(self, block_input: bool, block_output: bool, name: str):
#   def read(self, block: bool = True, timeout: Optional[float] = None):
#   def write(self, value, block: bool = True, timeout: Optional[float] = None):
#   def main(self):
#   def kill(self):
#   def _run(self):
#   def _read_value(self):
#   def _write_value(self, value):


# Path: android_env/components/logcat_thread.py
import re
import threading
from typing import Callable, Match, NamedTuple, Optional, Pattern
from absl import logging
from android_env.components import log_stream as log_stream_lib
from android_env.components import thread_function
from android_env.proto import task_pb2

    self._log_stream.stop_stream()

    super().kill()

  def main(self) -> None:
    # pylint: disable=g-line-too-long
    # Format is: "TIME_SEC PID TID PRIORITY TAG: MESSAGE"
    #
    # Example:
    #  '         1553110400.424  5583  5658 D NostalgicRacer: com.google.example.games.nostalgicracer.views.renderers.OpenGLRenderDriver@912fb8.onSurfaceChanged 480x320'    #
    #
    # If a log_prefix is given, then the format becomes:
    # "TIME_SEC PID TID PRIORITY TAG: LOG_PREFIX MESSAGE"
    # pylint: enable=g-line-too-long

    regexp = r"""
      ^                                   # Beginning of the line.
      [ ]+(?P<timestamp>[0-9]+\.[0-9]+)   # Spaces and a float.
      [ ]+(?P<pid>[0-9]+)                 # Spaces and an int.
      [ ]+(?P<tid>[0-9]+)                 # Spaces and an int.
      [ ]+(?P<priority>.)                 # Spaces and any single character.
      [ ]+(?P<tag>[^:]*):                 # Spaces and any char that's not ':'.
    """

    regexp += r"""[ ](?P<message>.*)$"""
    logline_re = re.compile(regexp, re.VERBOSE)

    for line in self._stdout:
      # We never hand back control to ThreadFunction._run() so we need to
      # explicitly check for self._should_run here.

      if not self._should_run: