Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c23ccbb2 authored by Caitlin Cassidy's avatar Caitlin Cassidy Committed by Automerger Merge Worker
Browse files

Merge "[Ongoing Call] Always unregister the UidObserver." into sc-dev am:...

Merge "[Ongoing Call] Always unregister the UidObserver." into sc-dev am: 3d1c1803 am: dcf8838a am: 14dfa6ce

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15503430

Change-Id: I43f4b0c4c3b502bcd170231e70e7cf188d713cf6
parents 705530d6 14dfa6ce
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -216,6 +216,10 @@ class OngoingCallController @Inject constructor(
        isCallAppVisible = isProcessVisibleToUser(
                iActivityManager.getUidProcessState(currentCallNotificationInfo.uid, null))

        if (uidObserver != null) {
            iActivityManager.unregisterUidObserver(uidObserver)
        }

        uidObserver = object : IUidObserver.Stub() {
            override fun onUidStateChanged(
                uid: Int,
+15 −0
Original line number Diff line number Diff line
@@ -184,6 +184,21 @@ class OngoingCallControllerTest : SysuiTestCase() {
                .isGreaterThan(0)
    }

    /** Regression test for b/194731244. */
    @Test
    fun onEntryUpdated_calledManyTimes_uidObserverUnregisteredManyTimes() {
        val numCalls = 4

        for (i in 0 until numCalls) {
            // Re-create the notification each time so that it's considered a different object and
            // observers will get re-registered (and hopefully unregistered).
            notifCollectionListener.onEntryUpdated(createOngoingCallNotifEntry())
        }

        // There should be 1 observer still registered, so we should unregister n-1 times.
        verify(mockIActivityManager, times(numCalls - 1)).unregisterUidObserver(any())
    }

    /**
     * If a call notification is never added before #onEntryRemoved is called, then the listener
     * should never be notified.