Fix: [ALAS] Raise error if app_keep_alive is enabled in MuMu 12

This commit is contained in:
LmeSzinc 2023-08-21 00:40:40 +08:00
parent af37f4c252
commit adefd5a956
2 changed files with 41 additions and 5 deletions

View File

@ -111,6 +111,8 @@ class Connection(ConnectionAttr):
logger.attr('PackageName', self.package) logger.attr('PackageName', self.package)
logger.attr('Server', self.config.SERVER) logger.attr('Server', self.config.SERVER)
self.check_mumu_app_keep_alive()
@Config.when(DEVICE_OVER_HTTP=False) @Config.when(DEVICE_OVER_HTTP=False)
def adb_command(self, cmd, timeout=10): def adb_command(self, cmd, timeout=10):
""" """
@ -216,13 +218,25 @@ class Connection(ConnectionAttr):
# str # str
return result return result
def adb_getprop(self, name):
"""
Get system property in Android, same as `getprop <name>`
Args:
name (str): Property name
Returns:
str:
"""
return self.adb_shell(['getprop', name]).strip()
@cached_property @cached_property
def cpu_abi(self) -> str: def cpu_abi(self) -> str:
""" """
Returns: Returns:
str: arm64-v8a, armeabi-v7a, x86, x86_64 str: arm64-v8a, armeabi-v7a, x86, x86_64
""" """
abi = self.adb_shell(['getprop', 'ro.product.cpu.abi']).strip() abi = self.adb_getprop('ro.product.cpu.abi')
if not len(abi): if not len(abi):
logger.error(f'CPU ABI invalid: "{abi}"') logger.error(f'CPU ABI invalid: "{abi}"')
return abi return abi
@ -232,7 +246,7 @@ class Connection(ConnectionAttr):
""" """
Android SDK/API levels, see https://apilevels.com/ Android SDK/API levels, see https://apilevels.com/
""" """
sdk = self.adb_shell(['getprop', 'ro.build.version.sdk']).strip() sdk = self.adb_getprop('ro.build.version.sdk')
try: try:
return int(sdk) return int(sdk)
except ValueError: except ValueError:
@ -244,12 +258,32 @@ class Connection(ConnectionAttr):
def is_avd(self): def is_avd(self):
if get_serial_pair(self.serial)[0] is None: if get_serial_pair(self.serial)[0] is None:
return False return False
if 'ranchu' in self.adb_shell(['getprop', 'ro.hardware']): if 'ranchu' in self.adb_getprop('ro.hardware'):
return True return True
if 'goldfish' in self.adb_shell(['getprop', 'ro.hardware.audio.primary']): if 'goldfish' in self.adb_getprop('ro.hardware.audio.primary'):
return True return True
return False return False
def check_mumu_app_keep_alive(self):
if not self.is_mumu_family:
return False
res = self.adb_getprop('nemud.app_keep_alive')
logger.attr('nemud.app_keep_alive', res)
if res == '':
# Empry property, might not be a mumu emulator or might be an old mumu
return True
elif res == 'false':
# Disabled
return True
elif res == 'true':
# https://mumu.163.com/help/20230802/35047_1102450.html
logger.critical('请在MuMu模拟器设置内关闭 "后台挂机时保活运行"')
raise RequestHumanTakeover
else:
logger.warning(f'Invalid nemud.app_keep_alive value: {res}')
return False
@cached_property @cached_property
def _nc_server_host_port(self): def _nc_server_host_port(self):
""" """

View File

@ -101,7 +101,9 @@ class ConnectionAttr:
@cached_property @cached_property
def is_mumu_family(self): def is_mumu_family(self):
return self.serial == '127.0.0.1:7555' # 127.0.0.1:7555
# 127.0.0.1:16384 + 32*n
return self.serial == '127.0.0.1:7555' or self.serial.startswith('127.0.0.1:16')
@cached_property @cached_property
def is_emulator(self): def is_emulator(self):