From 28f08eb2b2d6d548bbd9021f75ff2dea31c69d69 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 22 Jun 2026 22:01:48 +0000 Subject: [PATCH] Fix call chip lifecycle tracking --- .../layout/StockLayoutCanvasController.java | 36 ++++++++++++++++--- .../render/UnlockedStockSourceCollector.java | 3 +- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/se/ajpanton/statusbartweak/runtime/layout/StockLayoutCanvasController.java b/app/src/main/java/se/ajpanton/statusbartweak/runtime/layout/StockLayoutCanvasController.java index f0170c9..7440584 100644 --- a/app/src/main/java/se/ajpanton/statusbartweak/runtime/layout/StockLayoutCanvasController.java +++ b/app/src/main/java/se/ajpanton/statusbartweak/runtime/layout/StockLayoutCanvasController.java @@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable; import android.os.Looper; import android.os.PowerManager; import android.service.notification.StatusBarNotification; +import android.telecom.TelecomManager; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -2454,8 +2455,7 @@ final class StockLayoutCanvasController { } if (!isTrackableStatusChipSurface(view) && !isTrackedHiddenStatusChipSource(root, view)) { - hiddenViewStates.remove(view); - trackedUnlockedStockSurfaces.remove(view); + forgetTrackedStatusChipState(view); staleViews.add(view); continue; } @@ -3457,6 +3457,9 @@ final class StockLayoutCanvasController { if (view == null || ownedIconHostManager.isOwnedHost(view)) { return false; } + if (view.getVisibility() != View.VISIBLE) { + return false; + } String idName = ViewIdNames.idName(view); if (!"ongoing_activity_capsule".equals(idName)) { return false; @@ -3485,9 +3488,26 @@ final class StockLayoutCanvasController { || !isStatusChipCandidate(view)) { return false; } + if (isCallStatusChip(view) + && view.getVisibility() != View.VISIBLE + && !isPhoneCallActive(view)) { + return false; + } return hasVisibleStatusChipContent(view); } + private boolean isPhoneCallActive(View view) { + if (view == null || view.getContext() == null) { + return false; + } + try { + TelecomManager telecomManager = view.getContext().getSystemService(TelecomManager.class); + return telecomManager != null && telecomManager.isInCall(); + } catch (RuntimeException ignored) { + return false; + } + } + private boolean hasVisibleStatusChipContent(View source) { if (!(source instanceof ViewGroup group)) { return false; @@ -4303,11 +4323,19 @@ final class StockLayoutCanvasController { || isStatusChipShell(view)) { return false; } - hiddenViewStates.remove(view); + forgetTrackedStatusChip(view); + return true; + } + + private void forgetTrackedStatusChip(View view) { + forgetTrackedStatusChipState(view); trackedStatusChipSources.remove(view); + } + + private void forgetTrackedStatusChipState(View view) { + hiddenViewStates.remove(view); trackedUnlockedStockSurfaces.remove(view); statusChipLifecycleLayoutSignatureByView.remove(view); - return true; } private void cleanupLayoutOffRoot(View root, SceneKey activeScene) { diff --git a/app/src/main/java/se/ajpanton/statusbartweak/runtime/render/UnlockedStockSourceCollector.java b/app/src/main/java/se/ajpanton/statusbartweak/runtime/render/UnlockedStockSourceCollector.java index cccf2f5..da913ac 100644 --- a/app/src/main/java/se/ajpanton/statusbartweak/runtime/render/UnlockedStockSourceCollector.java +++ b/app/src/main/java/se/ajpanton/statusbartweak/runtime/render/UnlockedStockSourceCollector.java @@ -1188,6 +1188,7 @@ final class UnlockedStockSourceCollector { View view = source.view(); if (view == null || view == root + || view.getVisibility() != View.VISIBLE || !view.isAttachedToWindow() || !ViewGeometry.isDescendantOf(view, root) || ReflectionSupport.getBooleanField(view, "sbtStatusChipForcedHidden", false) @@ -1301,7 +1302,7 @@ final class UnlockedStockSourceCollector { } private boolean isStatusChipMetricCandidate(View root, View view, boolean allowHidden) { - if (view == null || view == root || root == null) { + if (view == null || view == root || root == null || view.getVisibility() != View.VISIBLE) { return false; } if (!allowHidden && view.getAlpha() <= 0f && !hasRenderableStatusChipContent(view)) {