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

Commit 115934b9 authored by Aaron Liu's avatar Aaron Liu
Browse files

Move register callback on view attach and detach

callback being added and removed in onResume and onPause is not reliable and is causing memory leaks, which is causing ANRs.

Fixes: 318362552
Test: open simpin view and see that it works properly.
Test: atest KeyguardSimPinViewControllerTest
Flag: NONE
Change-Id: I44f3fc61d2a43bfd175f46a581e67da2f5c7be4f
parent fd5d1ad6
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -100,9 +100,12 @@ class KeyguardSimPinViewControllerTest : SysuiTestCase() {
                mSelectedUserInteractor
            )
        underTest.init()
        underTest.onViewAttached()
        underTest.onResume(0)
        verify(keyguardUpdateMonitor)
            .registerCallback(updateMonitorCallbackArgumentCaptor.capture())
        reset(keyguardMessageAreaController)
        reset(keyguardUpdateMonitor)
    }

    @Test
@@ -110,25 +113,24 @@ class KeyguardSimPinViewControllerTest : SysuiTestCase() {
        underTest.onViewAttached()
        verify(keyguardMessageAreaController)
            .setMessage(context.resources.getString(R.string.keyguard_enter_your_pin), false)
        verify(keyguardUpdateMonitor)
            .registerCallback(any(KeyguardUpdateMonitorCallback::class.java))
    }

    @Test
    fun onViewDetached() {
        underTest.onViewDetached()
        verify(keyguardUpdateMonitor).removeCallback(any(KeyguardUpdateMonitorCallback::class.java))
    }

    @Test
    fun onResume() {
        reset(keyguardUpdateMonitor)
        underTest.onResume(KeyguardSecurityView.VIEW_REVEALED)
        verify(keyguardUpdateMonitor)
            .registerCallback(any(KeyguardUpdateMonitorCallback::class.java))
    }

    @Test
    fun onPause() {
        underTest.onPause()
        verify(keyguardUpdateMonitor).removeCallback(any(KeyguardUpdateMonitorCallback::class.java))
    }

    @Test
+7 −2
Original line number Diff line number Diff line
@@ -105,6 +105,13 @@ public class KeyguardSimPinViewController
    @Override
    protected void onViewAttached() {
        super.onViewAttached();
        mKeyguardUpdateMonitor.registerCallback(mUpdateMonitorCallback);
    }

    @Override
    protected void onViewDetached() {
        super.onViewDetached();
        mKeyguardUpdateMonitor.removeCallback(mUpdateMonitorCallback);
    }

    @Override
@@ -128,14 +135,12 @@ public class KeyguardSimPinViewController
    @Override
    public void onResume(int reason) {
        super.onResume(reason);
        mKeyguardUpdateMonitor.registerCallback(mUpdateMonitorCallback);
        mView.resetState();
    }

    @Override
    public void onPause() {
        super.onPause();
        mKeyguardUpdateMonitor.removeCallback(mUpdateMonitorCallback);

        // dismiss the dialog.
        if (mSimUnlockProgressDialog != null) {