Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion module/config/argument/args.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
"MuMuPlayer",
"MuMuPlayerX",
"MuMuPlayer12",
"MEmuPlayer"
"MEmuPlayer",
"Waydroid"
]
},
"name": {
Expand Down
1 change: 1 addition & 0 deletions module/config/argument/argument.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ EmulatorInfo:
MuMuPlayerX,
MuMuPlayer12,
MEmuPlayer,
Waydroid,
]
name:
value: null
Expand Down
2 changes: 1 addition & 1 deletion module/config/config_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GeneratedConfig:
Emulator_AdbRestart = False

# Group `EmulatorInfo`
EmulatorInfo_Emulator = 'auto' # auto, NoxPlayer, NoxPlayer64, BlueStacks4, BlueStacks5, BlueStacks4HyperV, BlueStacks5HyperV, LDPlayer3, LDPlayer4, LDPlayer9, MuMuPlayer, MuMuPlayerX, MuMuPlayer12, MEmuPlayer
EmulatorInfo_Emulator = 'auto' # auto, NoxPlayer, NoxPlayer64, BlueStacks4, BlueStacks5, BlueStacks4HyperV, BlueStacks5HyperV, LDPlayer3, LDPlayer4, LDPlayer9, MuMuPlayer, MuMuPlayerX, MuMuPlayer12, MEmuPlayer, Waydroid
EmulatorInfo_name = None
EmulatorInfo_path = None

Expand Down
3 changes: 2 additions & 1 deletion module/config/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@
"MuMuPlayer": "MuMu Player",
"MuMuPlayerX": "MuMu Player X",
"MuMuPlayer12": "MuMu Player 12",
"MEmuPlayer": "MEmu Player"
"MEmuPlayer": "MEmu Player",
"Waydroid": "Waydroid"
},
"name": {
"name": "Emulator Instance Name",
Expand Down
3 changes: 2 additions & 1 deletion module/config/i18n/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@
"MuMuPlayer": "MuMuPlayer",
"MuMuPlayerX": "MuMuPlayerX",
"MuMuPlayer12": "MuMuPlayer12",
"MEmuPlayer": "MEmuPlayer"
"MEmuPlayer": "MEmuPlayer",
"Waydroid": "Waydroid"
},
"name": {
"name": "EmulatorInfo.name.name",
Expand Down
5 changes: 3 additions & 2 deletions module/config/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@
"MuMuPlayer": "MuMu模拟器",
"MuMuPlayerX": "MuMu模拟器X",
"MuMuPlayer12": "MuMu模拟器12",
"MEmuPlayer": "逍遥模拟器"
"MEmuPlayer": "逍遥模拟器",
"Waydroid": "Waydroid模拟器"
},
"name": {
"name": "模拟器实例名称",
Expand Down Expand Up @@ -2738,4 +2739,4 @@
"ChooseFile": "选择文件"
}
}
}
}
5 changes: 3 additions & 2 deletions module/config/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@
"MuMuPlayer": "MuMu模擬器",
"MuMuPlayerX": "MuMu模擬器X",
"MuMuPlayer12": "MuMu模擬器12",
"MEmuPlayer": "逍遙模擬器"
"MEmuPlayer": "逍遙模擬器",
"Waydroid": "Waydroid模擬器"
},
"name": {
"name": "模擬器實例名稱",
Expand Down Expand Up @@ -2738,4 +2739,4 @@
"ChooseFile": "選擇檔案"
}
}
}
}
4 changes: 2 additions & 2 deletions module/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from lxml import etree

from module.device.env import IS_WINDOWS
from module.device.env import IS_LINUX, IS_WINDOWS
# Patch pkg_resources before importing adbutils and uiautomator2
from module.device.pkg_resources import get_distribution

Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(self, *args, **kwargs):
raise RequestHumanTakeover

# Auto-fill emulator info
if IS_WINDOWS and self.config.EmulatorInfo_Emulator == 'auto':
if (IS_WINDOWS or IS_LINUX) and self.config.EmulatorInfo_Emulator == 'auto':
_ = self.emulator_instance

self.screenshot_interval_set()
Expand Down
4 changes: 3 additions & 1 deletion module/device/platform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from module.device.env import IS_WINDOWS
from module.device.env import IS_LINUX, IS_WINDOWS

if IS_WINDOWS:
from module.device.platform.platform_windows import PlatformWindows as Platform
elif IS_LINUX:
from module.device.platform.platform_linux import PlatformLinux as Platform
else:
from module.device.platform.platform_base import PlatformBase as Platform
1 change: 1 addition & 0 deletions module/device/platform/emulator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class EmulatorBase:
MuMuPlayer12 = 'MuMuPlayer12'
MuMuPlayerFamily = [MuMuPlayer, MuMuPlayerX, MuMuPlayer12]
MEmuPlayer = 'MEmuPlayer'
Waydroid = 'Waydroid'

@classmethod
def path_to_type(cls, path: str) -> str:
Expand Down
192 changes: 192 additions & 0 deletions module/device/platform/emulator_linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import os
import shutil
import subprocess
import typing as t

# module/device/platform/emulator_base.py
# module/device/platform/emulator_windows.py
# Will be used in Alas Easy Install, they shouldn't import any Alas modules.
from module.device.platform.emulator_base import (
EmulatorBase,
EmulatorInstanceBase,
EmulatorManagerBase,
remove_duplicated_path,
)
from module.device.platform.utils import cached_property


def get_waydroid_serial() -> str:
"""
Need to make sure waydroid is running

Returns:
waydroid IP address
"""

"""
$ waydroid --version
1.4.3
$ waydroid status
Session: RUNNING
Container: RUNNING
Vendor type: MAINLINE
IP address: 192.168.240.112
Session user: docker(1000)
Wayland display: wayland-0
"""

waydroid_cmd = shutil.which('waydroid')
if waydroid_cmd is None:
return ''

try:
waydroid_status = subprocess.check_output([waydroid_cmd, 'status'], text=True)
except (PermissionError, OSError):
return ''

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'


class EmulatorInstance(EmulatorInstanceBase):
@cached_property
def emulator(self):
"""
Returns:
Emulator:
"""
return Emulator(self.path)


class Emulator(EmulatorBase):
@classmethod
def path_to_type(cls, path: str) -> str:
"""
Args:
path: Path to .exe file, case insensitive

Returns:
str: Emulator type, such as Emulator.NoxPlayer
"""
folder, exe = os.path.split(path)
folder, dir1 = os.path.split(folder)
folder, dir2 = os.path.split(folder)
exe = exe.lower()
dir1 = dir1.lower()
dir2 = dir2.lower()

if exe == 'waydroid':
return cls.Waydroid

return ''

def iter_instances(self):
"""
Yields:
EmulatorInstance: Emulator instances found in this emulator
"""
if self == Emulator.Waydroid:
# Waydroid has no multi instances, on 5555 only
serial=get_waydroid_serial()
if serial:
yield EmulatorInstance(
serial=serial,
name='',
path=self.path,
)


class EmulatorManager(EmulatorManagerBase):
@staticmethod
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 = shutil.which('waydroid')
if exe is not None:
result.append(exe)

return result

@staticmethod
def iter_running_emulator():
"""
Yields:
str: Path to emulator executables, may contains duplicate values
"""
try:
import psutil
except ModuleNotFoundError:
return
# Since this is a one-time-usage, we access psutil._psplatform.Process directly
# to bypass the call of psutil.Process.is_running().
# This only costs about 0.017s.
for pid in psutil.pids():
proc = psutil._psplatform.Process(pid)
try:
exe = proc.cmdline()
except (psutil.AccessDenied, psutil.NoSuchProcess):
# psutil.AccessDenied
# NoSuchProcess: process no longer exists (pid=xxx)
continue

if len(exe) == 0:
continue
if len(exe) >= 1 and Emulator.is_emulator(exe[0]):
yield exe[0]
# /usr/bin/python3 /usr/bin/waydroid show-full-ui
if len(exe) >= 2 and Emulator.is_emulator(exe[1]):
yield exe[1]

@cached_property
def all_emulators(self) -> t.List[Emulator]:
"""
Get all emulators installed on current computer.
"""
exe = set([])

for file in EmulatorManager.get_install_emulator():
if Emulator.is_emulator(file) and os.path.exists(file):
exe.add(file)

# Running
for file in EmulatorManager.iter_running_emulator():
if os.path.exists(file):
exe.add(file)

# De-redundancy
exe = [Emulator(path).path for path in exe if Emulator.is_emulator(path)]
exe = [Emulator(path) for path in remove_duplicated_path(exe)]
return exe

@cached_property
def all_emulator_instances(self) -> t.List[EmulatorInstance]:
"""
Get all emulator instances installed on current computer.
"""
instances = []
for emulator in self.all_emulators:
instances += list(emulator.iter_instances())

instances: t.List[EmulatorInstance] = sorted(instances, key=lambda x: str(x))
return instances


if __name__ == '__main__':
self = EmulatorManager()
for emu in self.all_emulator_instances:
print(emu)
Loading