autool/DroidBot/core/abstract_app.py
2026-06-17 19:44:18 +08:00

93 lines
2.4 KiB
Python

"""
Abstract App Base Class
Platform-agnostic application interface that all platform implementations must inherit.
"""
from abc import ABC, abstractmethod
from typing import Optional, List, Any
import logging
class AbstractApp(ABC):
"""
所有平台应用的抽象基类
定义了应用操作的标准接口,包括:
- 应用标识
- 入口点管理
- 启动/停止命令
"""
def __init__(self, output_dir: Optional[str] = None):
"""
初始化应用基类
:param output_dir: 输出目录路径
"""
self.logger = logging.getLogger(self.__class__.__name__)
self.output_dir = output_dir
# ==================== 应用标识 ====================
@property
@abstractmethod
def identifier(self) -> str:
"""
获取应用唯一标识符
Android: package_name
iOS: bundle_id
Windows: exe_path 或 window_class
:return: 应用标识符
"""
pass
def get_package_name(self) -> str:
"""
获取应用包名(兼容旧接口)
:return: 应用标识符
"""
return self.identifier
# ==================== 入口点管理 ====================
@property
def main_activity(self) -> Optional[str]:
"""
获取应用主入口点(可选)
Android: main_activity
iOS: main_scene
Windows: main_window_class
:return: 主入口点,如果不适用则返回 None
"""
return None
@property
def activities(self) -> List[str]:
"""
获取应用入口点列表(可选)
Android: activities 列表
iOS: scenes 列表
:return: 入口点列表
"""
return []
# ==================== 可选接口 ====================
def get_start_with_profiling_intent(self, trace_file: str, sampling: Optional[int] = None) -> Any:
"""
获取带性能分析的启动命令(可选)
:param trace_file: 跟踪文件路径
:param sampling: 采样间隔
:return: 带性能分析的启动命令
:raises NotImplementedError: 如果平台不支持
"""
raise NotImplementedError("This platform does not support profiling intent")