Skip to content

Conversation

@FinchOrigin
Copy link

No description provided.

Comment on lines 36 to 44
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()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

192.168.240.112 是固定的吗,我感觉只是你本机的局域网ip

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我有搜索过其他人也是该ip。不过确实官方从来没有保证过ip一定是这一个,官方文档只保证了端口一定是5555。
现在将该函数修改为直接返回serial,异常情况返回空字符串

Comment on lines 95 to 123
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尝试直接读取配置文件,而不是通过命令行

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解对照windows的话,总是会优先从系统环境来获取已安装的模拟器信息,所以我是通过查找环境变量来实现的。

从配置文件读取也挺好,不过 EmulatorManagerBase 当中并没有config成员变量,我是否可以新增父类成员变量来实现让子类可以读取配置信息?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

或者是我理解错了?你指的是模拟器的配置文件或者Linux系统的配置文件?不过Linux系统种类挺多的,规范上没法做到统一,确实不如直接判断waydroid安装后在环境变量中的可执行文件是否存在来的方便

Comment on lines 79 to 91
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,
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waydroid只能有一个实例,不能多开吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前版本不能多开。官方文档中没有相关说明,其参数也没有对应实现

Comment on lines 20 to 32
@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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

设置 start_new_session=True

start_new_session to avoid emulator getting tree-killed when Alas gets killed

设置 shell="/usr/bin/bash" 不妥,不同 linux系统的路径可能不一样,也没必要通过shell执行,直接执行就好了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Comment on lines 161 to 162
def emulator_start(self):
logger.hr("Emulator start", level=1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复用windows下的函数

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Comment on lines 105 to 123
result = []
exe = subprocess.check_output(['type', '-p', 'waydroid'], text=True)
if os.path.exists(exe):
result.add(exe)

return result
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尝试使用shutil.which
result = [] 没有add方法

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Comment on lines 36 to 46
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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果waydroid不存在,可能抛出FileNotFoundError,调用waydroid相关命令也可能遇到权限问题等等。尝试通过waydroid执行文件的路径查找它的配置文件,直接从文件中读取

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. waydroid的adb ip地址是不可配置的,所以不存在相关的配置文件可以查询,只能在运行时通过指令获取
  2. waydroid的二进制文件就是该模拟器的入口,也不该存在权限问题。因为那意味着模拟器的启动和停止会遇见相同的问题(文件找不到或者权限问题)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要处理异常,系统不一定有 waydroid 命令,或者alas有权限执行它

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Comment on lines 80 to 91
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,
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_waydroid_serial() 可能返回空字符串,缺少处理

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

Comment on lines 180 to 189
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在停止模拟器的时候,重试不应该再次启动它

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改。这块原本是保持和 platform_windows.py 下逻辑一致的,以防Windows下有特殊场景适用,我就不修改 platform_windows.py 的内容了

Comment on lines 85 to 93
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10061 状态码是windows上的,在linux上可能有不同的消息,需要测试

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在else分支加了日志打印,若后续有特殊场景,依据日志更新代码

@FinchOrigin FinchOrigin force-pushed the self branch 2 times, most recently from 721ddc5 to 29e77a9 Compare October 9, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants