"""App friendly-name resolution from the package manifest (P5-1). Parses `pm dump ` output for the ``application-label`` line — the default-locale variant; localized suffixed variants (``application-label-:``) are skipped, and multi-label blocks across locales are tolerated (first default-locale label wins), mirroring the tolerant pattern of the androidtv-adb core helper. """ import re _APPLICATION_LABEL_RE = re.compile(r"application-label(?:-[A-Za-z_-]+)?:\s*'([^']*)'") def parse_application_label(dump: str) -> str | None: """The package's default-locale application label, or None. Returns None on empty/failed dumps too — callers fall through to the next name tier. """ if not dump: return None for match in _APPLICATION_LABEL_RE.finditer(dump): label = (match.group(1) or "").strip() if label and label not in ("null", ""): return label return None