diff options
2 files changed, 16 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt index d5965ec8fbfc..c20730e1b4a4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt @@ -25,6 +25,7 @@ import android.content.Intent import android.util.Log import android.view.View import android.widget.Chronometer +import androidx.annotation.VisibleForTesting import com.android.internal.jank.InteractionJankMonitor import com.android.systemui.R import com.android.systemui.animation.ActivityLaunchAnimator @@ -122,6 +123,7 @@ class OngoingCallController @Inject constructor( * Should only be called from [CollapsedStatusBarFragment]. */ fun setChipView(chipView: View) { + tearDownChipView() this.chipView = chipView if (hasOngoingCall()) { updateChip() @@ -165,8 +167,7 @@ class OngoingCallController @Inject constructor( val currentCallNotificationInfo = callNotificationInfo ?: return val currentChipView = chipView - val timeView = - currentChipView?.findViewById<Chronometer>(R.id.ongoing_call_chip_time) + val timeView = currentChipView?.getTimeView() val backgroundView = currentChipView?.findViewById<View>(R.id.ongoing_call_chip_background) @@ -248,12 +249,19 @@ class OngoingCallController @Inject constructor( private fun removeChip() { callNotificationInfo = null + tearDownChipView() mListeners.forEach { l -> l.onOngoingCallStateChanged(animate = true) } if (uidObserver != null) { iActivityManager.unregisterUidObserver(uidObserver) } } + /** Tear down anything related to the chip view to prevent leaks. */ + @VisibleForTesting + fun tearDownChipView() = chipView?.getTimeView()?.stop() + + private fun View.getTimeView(): Chronometer? = this.findViewById(R.id.ongoing_call_chip_time) + private data class CallNotificationInfo( val key: String, val callStartTime: Long, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt index 94c9de0d2035..c81d46898ff9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt @@ -43,6 +43,7 @@ import com.android.systemui.util.concurrency.FakeExecutor import com.android.systemui.util.mockito.any import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat +import org.junit.After import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -117,6 +118,11 @@ class OngoingCallControllerTest : SysuiTestCase() { .thenReturn(PROC_STATE_INVISIBLE) } + @After + fun tearDown() { + controller.tearDownChipView() + } + @Test fun onEntryUpdated_isOngoingCallNotif_listenerNotified() { notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry()) |