mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-11 23:18:22 +08:00
Modified the way to realize the WSA solution
Fix:A rare situation caused the game to shut down during restart in WSA solution
This commit is contained in:
@@ -67,7 +67,7 @@ def retry(func):
|
||||
except AssertionError as e:
|
||||
logger.exception(e)
|
||||
possible_reasons(
|
||||
'If you are using BlueStacks or LD player, '
|
||||
'If you are using BlueStacks or LD player or WSA, '
|
||||
'please enable ADB in the settings of your emulator'
|
||||
)
|
||||
break
|
||||
|
||||
@@ -76,7 +76,7 @@ def handle_adb_error(e):
|
||||
# AdbError()
|
||||
logger.exception(e)
|
||||
possible_reasons(
|
||||
'If you are using BlueStacks or LD player, please enable ADB in the settings of your emulator',
|
||||
'If you are using BlueStacks or LD player or WSA, please enable ADB in the settings of your emulator',
|
||||
'Emulator died, please restart emulator',
|
||||
'Serial incorrect, no such device exists or emulator is not running'
|
||||
)
|
||||
|
||||
@@ -55,19 +55,22 @@ def retry(func):
|
||||
class WSA(Connection):
|
||||
|
||||
@retry
|
||||
def app_start_wsa_display_0(self, package_name, allow_failure=False):
|
||||
def app_start_wsa(self, package_name, display, allow_failure=False):
|
||||
"""
|
||||
Args:
|
||||
package_name (str):
|
||||
display (int):
|
||||
allow_failure (bool):
|
||||
|
||||
Returns:
|
||||
bool: If success to start
|
||||
"""
|
||||
|
||||
self.adb_shell(['svc', 'power', 'stayon', 'true'])
|
||||
activity_name = self.get_main_activity_name(package_name=package_name)
|
||||
result = self.adb_shell(
|
||||
['am', 'start', '--display', '0', self.config.Emulator_PackageName +
|
||||
'/com.manjuu.azurlane.MainActivity'])
|
||||
['am', 'start', '--display', display, package_name +
|
||||
'/' + activity_name])
|
||||
if 'No activities found' in result:
|
||||
# ** No activities found to run, monkey aborted.
|
||||
if allow_failure:
|
||||
@@ -81,22 +84,34 @@ class WSA(Connection):
|
||||
# ## Network stats: elapsed time=4ms (0ms mobile, 0ms wifi, 4ms not connected)
|
||||
return True
|
||||
|
||||
@retry
|
||||
def get_main_activity_name(self, package_name):
|
||||
output = self.adb_shell(['dumpsys', 'package', package_name])
|
||||
_activityRE = re.compile(
|
||||
r'\w+ ' + package_name + r'/(?P<activity>[^/\s]+) filter'
|
||||
)
|
||||
ms = _activityRE.finditer(output)
|
||||
ret = next(ms).group('activity')
|
||||
if ret: # get first result
|
||||
return ret
|
||||
raise OSError("Couldn't get activity name, please check setting Emulator.PackageName")
|
||||
|
||||
@retry
|
||||
def get_display_id(self):
|
||||
"""
|
||||
Returns:
|
||||
0: Could not find
|
||||
int: Display id of the game
|
||||
"""
|
||||
try:
|
||||
get_dump_sys_display = str(self.adb_shell(['dumpsys', 'display']))
|
||||
display_id_list = re.findall(r'systemapp:' + self.config.Emulator_PackageName + ':' + '(.+?)', get_dump_sys_display, re.S)
|
||||
display_id = list(set(display_id_list))[0]
|
||||
display_id = int(display_id_list[0])
|
||||
return display_id
|
||||
except IndexError:
|
||||
return '0'
|
||||
return 0 # When game running on display 0, its display id could not be found
|
||||
|
||||
@retry
|
||||
def wrong_screen_handling(self):
|
||||
logger.warning('Game not running on display 0')
|
||||
self.adb_shell(['am', 'force-stop', self.config.Emulator_PackageName])
|
||||
|
||||
@retry
|
||||
def resize_wsa_display_0(self):
|
||||
logger.warning('display 0 should be resized')
|
||||
self.adb_shell(['wm', 'size', '1280x720', '-d', '0'])
|
||||
def display_resize_wsa(self, display):
|
||||
logger.warning('display ' + display + ' should be resized')
|
||||
self.adb_shell(['wm', 'size', '1280x720', '-d', display])
|
||||
|
||||
Reference in New Issue
Block a user