def _KillAllEmulators(): """Kill all running emulators that look like ones we started. There are odd 'sticky' cases where there can be no emulator process running but a device slot is taken. A little bot trouble and and we're out of room forever. """ emulators = android_commands.GetEmulators() if not emulators: return for emu_name in emulators: cmd_helper.GetCmdOutput(['adb', '-s', emu_name, 'emu', 'kill']) logging.info('Emulator killing is async; give a few seconds for all to die.') for i in range(5): if not android_commands.GetEmulators(): return time.sleep(1)
def _GetAvailablePort(): """Returns an available TCP port for the console.""" used_ports = [] emulators = android_commands.GetEmulators() for emulator in emulators: used_ports.append(emulator.split('-')[1]) for port in PortPool.port_range(): if str(port) not in used_ports: return port