# Path: android_env/components/simulators/emulator/emulator_launcher.py
# _GRPC_KEEPALIVE_MS = 100000
# class EmulatorLauncher():
#   def __init__(
#       self,
#       local_tmp_dir: str = '/tmp',
#       adb_port: Optional[int] = None,
#       adb_server_port: Optional[int] = None,
#       emulator_console_port: Optional[int] = None,
#       grpc_port: int = -1,
#       emulator_path: str = '',
#       android_sdk_root: str = '',
#       avd_name: str = '',
#       run_headless: bool = False,
#       kvm_device: str = '/dev/kvm',
#       gpu_mode: str = 'swiftshader_indirect',
#       android_avd_home: str = '',
#       startup_wait_time_sec: int = 300,
#   ):
#   def launch(self) -> None:
#   def restart(self) -> None:
#   def create_emulator_stub(
#       cls,
#       grpc_port: int,
#       use_async: bool = False,
#   ) -> emulator_controller_pb2_grpc.EmulatorControllerStub:
#   def get_emulator_stub(
#       self) -> emulator_controller_pb2_grpc.EmulatorControllerStub:
#   def _kill_emulator_process(self) -> None:
#   def close(self):
#   def __del__(self):


import builtins
import os
import subprocess
import grpc
import mock
from absl.testing import absltest
from android_env.components.simulators.emulator import emulator_launcher

  @mock.patch.object(os, 'environ', autospec=True, return_value=dict())
  def test_launch(self, os_environ):
    del os_environ

    launcher = emulator_launcher.EmulatorLauncher(
        adb_port=self._adb_port,
        adb_server_port=self._adb_server_port,
        emulator_console_port=self._emulator_console_port,
        emulator_path=self._emulator_path,
        avd_name=self._avd_name,
        grpc_port=-1)

    with mock.patch.object(
        subprocess, 'Popen', autospec=True) as emulator_init, \
        mock.patch.object(
            builtins, 'open', autospec=True,
            return_value=self._emulator_output):

      launcher.launch()
      emulator_init.assert_called_once_with(
          args=self._expected_command + self._ports,
          env=self._expected_env_vars,
          stdout=self._emulator_output,
          stderr=self._emulator_output)

  @mock.patch.object(os, 'environ', autospec=True, return_value=dict())
  def test_grpc_port(self, os_environ):
    del os_environ


# Path: android_env/components/simulators/emulator/emulator_launcher.py
# _GRPC_KEEPALIVE_MS = 100000
# class EmulatorLauncher():
#   def __init__(
#       self,
#       local_tmp_dir: str = '/tmp',
#       adb_port: Optional[int] = None,
#       adb_server_port: Optional[int] = None,
#       emulator_console_port: Optional[int] = None,
#       grpc_port: int = -1,
#       emulator_path: str = '',
#       android_sdk_root: str = '',
#       avd_name: str = '',
#       run_headless: bool = False,
#       kvm_device: str = '/dev/kvm',
#       gpu_mode: str = 'swiftshader_indirect',
#       android_avd_home: str = '',
#       startup_wait_time_sec: int = 300,
#   ):
#   def launch(self) -> None:
#   def restart(self) -> None:
#   def create_emulator_stub(
#       cls,
#       grpc_port: int,
#       use_async: bool = False,
#   ) -> emulator_controller_pb2_grpc.EmulatorControllerStub:
#   def get_emulator_stub(
#       self) -> emulator_controller_pb2_grpc.EmulatorControllerStub:
#   def _kill_emulator_process(self) -> None:
#   def close(self):
#   def __del__(self):


# Path: android_env/components/simulators/emulator/emulator_launcher_test.py
import builtins
import os
import subprocess
import grpc
import mock
from absl.testing import absltest
from android_env.components.simulators.emulator import emulator_launcher


  @mock.patch.object(os, 'environ', autospec=True, return_value=dict())
  def test_launch(self, os_environ):
    del os_environ

    launcher = emulator_launcher.EmulatorLauncher(
        adb_port=self._adb_port,
        adb_server_port=self._adb_server_port,
        emulator_console_port=self._emulator_console_port,
        emulator_path=self._emulator_path,
        avd_name=self._avd_name,
        grpc_port=-1)

    with mock.patch.object(
        subprocess, 'Popen', autospec=True) as emulator_init, \
        mock.patch.object(
            builtins, 'open', autospec=True,
            return_value=self._emulator_output):

      launcher.launch()
      emulator_init.assert_called_once_with(
          args=self._expected_command + self._ports,
          env=self._expected_env_vars,
          stdout=self._emulator_output,
          stderr=self._emulator_output)

  @mock.patch.object(os, 'environ', autospec=True, return_value=dict())
  def test_grpc_port(self, os_environ):
    del os_environ


    launcher = emulator_launcher.EmulatorLauncher(