parameters: (self,
              read_only=True,
              snapshot_save=False,
              window=False,
              writable_system=False,
              gpu_mode=_DEFAULT_GPU_MODE,
              wipe_data=False,
              debug_tags=None)
docstring: Starts the emulator running an instance of the given AVD.
docstring_summary: Starts the emulator running an instance of the given AVD.
docstring_tokens: Starts the emulator running an instance of the given AVD .
function: def Start(self,
              read_only=True,
              snapshot_save=False,
              window=False,
              writable_system=False,
              gpu_mode=_DEFAULT_GPU_MODE,
              wipe_data=False,
              debug_tags=None):
      """Starts the emulator running an instance of the given AVD."""
  
      with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing(
          socket.socket(socket.AF_UNIX))) as sock:
        sock.bind(socket_path)
        emulator_cmd = [
            self._emulator_path,
            '-avd',
            self._avd_name,
            '-report-console',
            'unix:%s' % socket_path,
            '-no-boot-anim',
        ]
  
        if wipe_data:
          emulator_cmd.append('-wipe-data')
        if read_only:
          emulator_cmd.append('-read-only')
        if not snapshot_save:
          emulator_cmd.append('-no-snapshot-save')
        if writable_system:
          emulator_cmd.append('-writable-system')
        # Note when "--gpu-mode" is set to "host":
        #  * It needs a valid DISPLAY env, even if "--emulator-window" is false.
        #    Otherwise it may throw errors like "Failed to initialize backend
        #    EGL display". See the code in https://bit.ly/3ruiMlB as an example
        #    to setup the DISPLAY env with xvfb.
        #  * It will not work under remote sessions like chrome remote desktop.
        if gpu_mode:
          emulator_cmd.extend(['-gpu', gpu_mode])
        if debug_tags:
          emulator_cmd.extend(['-debug', debug_tags])
  
        emulator_env = {}
        if self._emulator_home:
          emulator_env['ANDROID_EMULATOR_HOME'] = self._emulator_home
        if 'DISPLAY' in os.environ:
          emulator_env['DISPLAY'] = os.environ.get('DISPLAY')
        if window:
          if 'DISPLAY' not in emulator_env:
            raise AvdException('Emulator failed to start: DISPLAY not defined')
        else:
          emulator_cmd.append('-no-window')
  
        sock.listen(1)
  
        logging.info('Starting emulator with commands: %s',
                     ' '.join(emulator_cmd))
  
        # TODO(jbudorick): Add support for logging emulator stdout & stderr at
        # higher logging levels.
        # Enable the emulator log when debug_tags is set.
        if not debug_tags:
          self._sink = open('/dev/null', 'w')
        self._emulator_proc = cmd_helper.Popen(
            emulator_cmd, stdout=self._sink, stderr=self._sink, env=emulator_env)
  
        # Waits for the emulator to report its serial as requested via
        # -report-console. See http://bit.ly/2lK3L18 for more.
        def listen_for_serial(s):
          logging.info('Waiting for connection from emulator.')
          with contextlib.closing(s.accept()[0]) as conn:
            val = conn.recv(1024)
            return 'emulator-%d' % int(val)
  
        try:
          self._emulator_serial = timeout_retry.Run(
              listen_for_serial, timeout=30, retries=0, args=[sock])
          logging.info('%s started', self._emulator_serial)
        except Exception as e:
          self.Stop()
          # avd.py is executed with python2.
          # pylint: disable=W0707
          raise AvdException('Emulator failed to start: %s' % str(e))
function_tokens: def Start ( self , read_only = True , snapshot_save = False , window = False , writable_system = False , gpu_mode = _DEFAULT_GPU_MODE , wipe_data = False , debug_tags = None ) : with tempfile_ext . TemporaryFileName ( ) as socket_path , ( contextlib . closing ( socket . socket ( socket . AF_UNIX ) ) ) as sock : sock . bind ( socket_path ) emulator_cmd = [ self . _emulator_path , '-avd' , self . _avd_name , '-report-console' , 'unix:%s' % socket_path , '-no-boot-anim' , ] if wipe_data : emulator_cmd . append ( '-wipe-data' ) if read_only : emulator_cmd . append ( '-read-only' ) if not snapshot_save : emulator_cmd . append ( '-no-snapshot-save' ) if writable_system : emulator_cmd . append ( '-writable-system' ) # Note when "--gpu-mode" is set to "host": #  * It needs a valid DISPLAY env, even if "--emulator-window" is false. #    Otherwise it may throw errors like "Failed to initialize backend #    EGL display". See the code in https://bit.ly/3ruiMlB as an example #    to setup the DISPLAY env with xvfb. #  * It will not work under remote sessions like chrome remote desktop. if gpu_mode : emulator_cmd . extend ( [ '-gpu' , gpu_mode ] ) if debug_tags : emulator_cmd . extend ( [ '-debug' , debug_tags ] ) emulator_env = { } if self . _emulator_home : emulator_env [ 'ANDROID_EMULATOR_HOME' ] = self . _emulator_home if 'DISPLAY' in os . environ : emulator_env [ 'DISPLAY' ] = os . environ . get ( 'DISPLAY' ) if window : if 'DISPLAY' not in emulator_env : raise AvdException ( 'Emulator failed to start: DISPLAY not defined' ) else : emulator_cmd . append ( '-no-window' ) sock . listen ( 1 ) logging . info ( 'Starting emulator with commands: %s' , ' ' . join ( emulator_cmd ) ) # TODO(jbudorick): Add support for logging emulator stdout & stderr at # higher logging levels. # Enable the emulator log when debug_tags is set. if not debug_tags : self . _sink = open ( '/dev/null' , 'w' ) self . _emulator_proc = cmd_helper . Popen ( emulator_cmd , stdout = self . _sink , stderr = self . _sink , env = emulator_env ) # Waits for the emulator to report its serial as requested via # -report-console. See http://bit.ly/2lK3L18 for more. def listen_for_serial ( s ) : logging . info ( 'Waiting for connection from emulator.' ) with contextlib . closing ( s . accept ( ) [ 0 ] ) as conn : val = conn . recv ( 1024 ) return 'emulator-%d' % int ( val ) try : self . _emulator_serial = timeout_retry . Run ( listen_for_serial , timeout = 30 , retries = 0 , args = [ sock ] ) logging . info ( '%s started' , self . _emulator_serial ) except Exception as e : self . Stop ( ) # avd.py is executed with python2. # pylint: disable=W0707 raise AvdException ( 'Emulator failed to start: %s' % str ( e ) )