From b442440ccf342d8662f4800bf43eb04df7e9e1f9 Mon Sep 17 00:00:00 2001 From: James Mackay Date: Fri, 9 Oct 2026 06:08:33 +0100 Subject: [PATCH] =?UTF-8?q?fix(connection,app=5Flabels):=20negative-cache?= =?UTF-8?q?=20label-less=20packages=20(same=2024h=20TTL,=20no=20re-enqueue?= =?UTF-8?q?=20=E2=80=94=20kills=20the=20per-heartbeat=20pm=20dump=20tax)?= =?UTF-8?q?=20+=20shlex.quote=20the=20pm=20dump=20package=20argument=20(t2?= =?UTF-8?q?6=20F1,F2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/nvidia_shield/connection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/custom_components/nvidia_shield/connection.py b/custom_components/nvidia_shield/connection.py index e372185..1a21f63 100644 --- a/custom_components/nvidia_shield/connection.py +++ b/custom_components/nvidia_shield/connection.py @@ -556,7 +556,9 @@ class ShieldConnectionManager: if cached is not None: label, stamp = cached if self._clock() - stamp <= APP_LABEL_TTL: - return label + # empty label = negative cache (t24 F1): the pm dump ran and + # found nothing — do not re-enqueue, zero per-heartbeat tax + return label or None self._app_labels.pop(package, None) # stale — refetch on demand self._app_label_requests.add(package) return None @@ -567,15 +569,18 @@ class ShieldConnectionManager: if poller is None or not self.connected: return try: + import shlex + dump = await poller.shell( - f"pm dump {package} 2>/dev/null | head -300" + f"pm dump {shlex.quote(package)} 2>/dev/null | head -300" ) label = parse_application_label(dump or "") except Exception as err: _LOGGER.debug("app label fetch failed for %s: %s", package, err) return - if label: - self._app_labels[package] = (label, self._clock()) + # F1: label-less pm dumps negatively cache too (empty label) so a + # later cycle performs zero additional pm dumps for the package + self._app_labels[package] = (label or "", self._clock()) def _on_logcat_app_start(self, package: str) -> None: """Stamp FIELD_FOREGROUND instantly from a parsed START (P5-3).