From c4b3181dfa001808ee24d13d8f2cfa42b64c532a Mon Sep 17 00:00:00 2001 From: Till Skrodzki Date: Fri, 20 Sep 2024 14:10:59 +0200 Subject: [PATCH] Add check whether injection has taken place whilst handle_screen is running --- .../mitm_receiver/endpoints/ReceiveProtosEndpoint.py | 8 ++++---- mapadroid/route/routecalc/calculate_route_all.py | 3 +++ mapadroid/worker/strategy/AbstractMitmBaseStrategy.py | 8 ++++++-- mapadroid/worker/strategy/AbstractWorkerStrategy.py | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mapadroid/mitm_receiver/endpoints/ReceiveProtosEndpoint.py b/mapadroid/mitm_receiver/endpoints/ReceiveProtosEndpoint.py index 4f860ba41..e0363620c 100644 --- a/mapadroid/mitm_receiver/endpoints/ReceiveProtosEndpoint.py +++ b/mapadroid/mitm_receiver/endpoints/ReceiveProtosEndpoint.py @@ -2,10 +2,11 @@ import time from typing import List, Optional +import orjson from aiohttp import web from loguru import logger -import orjson +import mapadroid.mitm_receiver.protos.Rpc_pb2 as pogoprotos from mapadroid.db.helper.SettingsDeviceHelper import SettingsDeviceHelper from mapadroid.db.helper.TrsVisitedHelper import TrsVisitedHelper from mapadroid.db.model import SettingsDevice @@ -15,7 +16,6 @@ from mapadroid.utils.collections import Location from mapadroid.utils.DatetimeWrapper import DatetimeWrapper from mapadroid.utils.ProtoIdentifier import ProtoIdentifier -import mapadroid.mitm_receiver.protos.Rpc_pb2 as pogoprotos class ReceiveProtosEndpoint(AbstractMitmReceiverRootEndpoint): @@ -96,8 +96,8 @@ async def __handle_proto_data_dict(self, origin: str, data: dict) -> None: if proto_type == ProtoIdentifier.GMO.value: # TODO: Offload transformation gmo: pogoprotos.GetMapObjectsOutProto = ProtoHelper.parse(ProtoIdentifier.GMO, decoded_raw_proto) - if not gmo.map_cell: - logger.debug("Ignoring apparently empty GMO") + if gmo.status != 1 or not gmo.map_cell: + logger.debug("Ignoring apparently empty GMO or unsuccessful status {}", gmo.status) return elif proto_type == ProtoIdentifier.FORT_SEARCH.value: logger.debug("Checking fort search proto type 101") diff --git a/mapadroid/route/routecalc/calculate_route_all.py b/mapadroid/route/routecalc/calculate_route_all.py index 7b38d4a39..a0982110f 100644 --- a/mapadroid/route/routecalc/calculate_route_all.py +++ b/mapadroid/route/routecalc/calculate_route_all.py @@ -74,6 +74,9 @@ def format_solution(manager, routing, solution): def _run_in_process_executor(method, less_coordinates, route_name): # Utility method to init logging in process executor... + + if not MadGlobals.application_args: + MadGlobals.load_args() init_logging(MadGlobals.application_args, print_info=False) try: return method(less_coordinates, route_name) diff --git a/mapadroid/worker/strategy/AbstractMitmBaseStrategy.py b/mapadroid/worker/strategy/AbstractMitmBaseStrategy.py index 08b3303a0..db2669f5c 100644 --- a/mapadroid/worker/strategy/AbstractMitmBaseStrategy.py +++ b/mapadroid/worker/strategy/AbstractMitmBaseStrategy.py @@ -428,12 +428,15 @@ async def start_pogo(self) -> bool: else: return started_pogo + async def _is_injected(self) -> bool: + return await self._mitm_mapper.get_injection_status(self._worker_state.origin) + async def _wait_for_injection(self): not_injected_count = 0 injection_thresh_reboot = int( await self.get_devicesettings_value(MappingManagerDevicemappingKey.INJECTION_THRESH_REBOOT, 20)) window_check_frequency = 3 - while not await self._mitm_mapper.get_injection_status(self._worker_state.origin): + while not await self._is_injected(): await self._check_for_mad_job() if not_injected_count >= injection_thresh_reboot: logger.warning("Not injected in time - reboot") @@ -445,7 +448,8 @@ async def _wait_for_injection(self): and not self._worker_state.stop_worker_event.is_set(): logger.info("Retry check_windows while waiting for injection at count {}", not_injected_count) - await self._handle_screen() + + await self._handle_screen(additional_eval=self._is_injected) not_injected_count += 1 wait_time = 0 while wait_time < 20: diff --git a/mapadroid/worker/strategy/AbstractWorkerStrategy.py b/mapadroid/worker/strategy/AbstractWorkerStrategy.py index bee73f10d..445487443 100644 --- a/mapadroid/worker/strategy/AbstractWorkerStrategy.py +++ b/mapadroid/worker/strategy/AbstractWorkerStrategy.py @@ -2,7 +2,8 @@ import os import time from abc import ABC, abstractmethod -from typing import Any, List, Optional +from asyncio import Task +from typing import Any, Awaitable, Callable, Coroutine, List, Optional from loguru import logger @@ -319,9 +320,9 @@ async def _ensure_pogo_topmost(self): else: return False - async def _handle_screen(self) -> ScreenType: + async def _handle_screen(self, additional_eval: Optional[Callable[[], Awaitable[bool]]] = None) -> ScreenType: screen_type: ScreenType = ScreenType.UNDEFINED - while not self._worker_state.stop_worker_event.is_set(): + while not self._worker_state.stop_worker_event.is_set() and (additional_eval is None or not await additional_eval()): if self._worker_state.login_error_count > 2: logger.warning('Could not login again - clearing game data and restarting device') await self.stop_pogo()