31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
"""App friendly-name resolution from the package manifest (P5-1).
|
|
|
|
Parses `pm dump <package>` output for the ``application-label`` line — the
|
|
default-locale variant; localized suffixed variants
|
|
(``application-label-<lang>:``) 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*'([^']*)'"
|
|
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 match.group(2) or "").strip()
|
|
if label and label not in ("null", ""):
|
|
return label
|
|
return None
|