Conversation
| waydroid_status = subprocess.check_output(["waydroid", "status"], text=True) | ||
| ip_address_line = None | ||
| for line in waydroid_status.splitlines(): | ||
| if line.startswith("IP address:"): | ||
| ip_address_line = line | ||
| break | ||
| if ip_address_line is None or ip_address_line.endswith("UNKNOWN"): | ||
| return "192.168.240.112" | ||
| return ip_address_line.removeprefix("IP address:").strip() |
There was a problem hiding this comment.
192.168.240.112 是固定的吗,我感觉只是你本机的局域网ip
There was a problem hiding this comment.
我有搜索过其他人也是该ip。不过确实官方从来没有保证过ip一定是这一个,官方文档只保证了端口一定是5555。
现在将该函数修改为直接返回serial,异常情况返回空字符串
| def get_install_emulator() -> list[str]: | ||
| """ | ||
| Args: | ||
| path (str): f'SOFTWARE\\leidian\\ldplayer' | ||
| key (str): 'InstallDir' | ||
|
|
||
| Returns: | ||
| list[str]: Installation dir or None | ||
| """ | ||
| result = [] | ||
| exe = subprocess.check_output( | ||
| ["type", "-p", "waydroid"], shell="/usr/bin/bash", text=True | ||
| ) | ||
| if os.path.exists(exe): | ||
| result.add(exe) | ||
|
|
||
| return result |
There was a problem hiding this comment.
我理解对照windows的话,总是会优先从系统环境来获取已安装的模拟器信息,所以我是通过查找环境变量来实现的。
从配置文件读取也挺好,不过 EmulatorManagerBase 当中并没有config成员变量,我是否可以新增父类成员变量来实现让子类可以读取配置信息?
There was a problem hiding this comment.
或者是我理解错了?你指的是模拟器的配置文件或者Linux系统的配置文件?不过Linux系统种类挺多的,规范上没法做到统一,确实不如直接判断waydroid安装后在环境变量中的可执行文件是否存在来的方便
| def iter_instances(self): | ||
| """ | ||
| Yields: | ||
| EmulatorInstance: Emulator instances found in this emulator | ||
| """ | ||
| if self == Emulator.Waydroid: | ||
| # MuMu has no multi instances, on 7555 only | ||
| yield EmulatorInstance( | ||
| serial=f"{get_waydroid_ip()}:5555", | ||
| name="", | ||
| path=self.path, | ||
| ) |
There was a problem hiding this comment.
目前版本不能多开。官方文档中没有相关说明,其参数也没有对应实现
| @classmethod | ||
| def execute(cls, command): | ||
| """ | ||
| Args: | ||
| command (str): | ||
|
|
||
| Returns: | ||
| subprocess.Popen: | ||
| """ | ||
| logger.info(f"Execute: {command}") | ||
| return subprocess.Popen( | ||
| command, close_fds=True, shell="/usr/bin/bash", text=True | ||
| ) # only work on Linux |
There was a problem hiding this comment.
设置 start_new_session=True
start_new_sessionto avoid emulator getting tree-killed when Alas gets killed
设置 shell="/usr/bin/bash" 不妥,不同 linux系统的路径可能不一样,也没必要通过shell执行,直接执行就好了
| def emulator_start(self): | ||
| logger.hr("Emulator start", level=1) |
| result = [] | ||
| exe = subprocess.check_output(['type', '-p', 'waydroid'], text=True) | ||
| if os.path.exists(exe): | ||
| result.add(exe) | ||
|
|
||
| return result |
There was a problem hiding this comment.
尝试使用shutil.which
result = [] 没有add方法
| waydroid_status = subprocess.check_output(['waydroid', 'status'], text=True) | ||
| ip_address_line = None | ||
| for line in waydroid_status.splitlines(): | ||
| if line.startswith('IP address:'): | ||
| ip_address_line = line | ||
| break | ||
| if ip_address_line is None or ip_address_line.endswith('UNKNOWN'): | ||
| return '' | ||
| ip_address = ip_address_line.removeprefix('IP address:').strip() | ||
| return f'{ip_address}:5555' |
There was a problem hiding this comment.
如果waydroid不存在,可能抛出FileNotFoundError,调用waydroid相关命令也可能遇到权限问题等等。尝试通过waydroid执行文件的路径查找它的配置文件,直接从文件中读取
There was a problem hiding this comment.
- waydroid的adb ip地址是不可配置的,所以不存在相关的配置文件可以查询,只能在运行时通过指令获取
- waydroid的二进制文件就是该模拟器的入口,也不该存在权限问题。因为那意味着模拟器的启动和停止会遇见相同的问题(文件找不到或者权限问题)
There was a problem hiding this comment.
需要处理异常,系统不一定有 waydroid 命令,或者alas有权限执行它
| def iter_instances(self): | ||
| """ | ||
| Yields: | ||
| EmulatorInstance: Emulator instances found in this emulator | ||
| """ | ||
| if self == Emulator.Waydroid: | ||
| # Waydroid has no multi instances, on 5555 only | ||
| yield EmulatorInstance( | ||
| serial=get_waydroid_serial(), | ||
| name='', | ||
| path=self.path, | ||
| ) |
There was a problem hiding this comment.
get_waydroid_serial() 可能返回空字符串,缺少处理
| def emulator_stop(self): | ||
| logger.hr('Emulator stop', level=1) | ||
| for _ in range(3): | ||
| # Stop | ||
| if self._emulator_function_wrapper(self._emulator_stop): | ||
| # Success | ||
| return True | ||
| else: | ||
| # Failed to stop, start and stop again | ||
| if self._emulator_function_wrapper(self._emulator_start): | ||
| continue | ||
| else: | ||
| return False | ||
|
|
||
| logger.error('Failed to stop emulator 3 times, stopped') | ||
| return False |
There was a problem hiding this comment.
已修改。这块原本是保持和 platform_windows.py 下逻辑一致的,以防Windows下有特殊场景适用,我就不修改 platform_windows.py 的内容了
| def adb_connect(): | ||
| m = self.adb_client.connect(self.serial) | ||
| if 'connected' in m: | ||
| # Connected to 127.0.0.1:59865 | ||
| # Already connected to 127.0.0.1:59865 | ||
| return False | ||
| elif '(10061)' in m: | ||
| # cannot connect to 127.0.0.1:55555: | ||
| # No connection could be made because the target machine actively refused it. (10061) | ||
| return False | ||
| else: | ||
| return True |
There was a problem hiding this comment.
10061 状态码是windows上的,在linux上可能有不同的消息,需要测试
There was a problem hiding this comment.
在else分支加了日志打印,若后续有特殊场景,依据日志更新代码
721ddc5 to
29e77a9
Compare
No description provided.