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

Commit 75e025a2 authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Delay handler messages until class is fully initialized" into main

parents e2606313 24c38549
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -2507,8 +2507,18 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            String message = "";
            switch (msg.what) {
                case SHOW:
                    // There is a potential race condition when SysUI starts up. CentralSurfaces
                    // must invoke #registerCentralSurfaces on this class before any messages can be
                    // processed. If this happens, repost the message with a small delay and try
                    // again.
                    if (mCentralSurfaces == null) {
                        message = "DELAYING SHOW";
                        Message newMsg = mHandler.obtainMessage(SHOW, (Bundle) msg.obj);
                        mHandler.sendMessageDelayed(newMsg, 100);
                    } else {
                        message = "SHOW";
                        handleShow((Bundle) msg.obj);
                    }
                    break;
                case HIDE:
                    message = "HIDE";
@@ -2595,8 +2605,18 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                    Trace.endSection();
                    break;
                case SYSTEM_READY:
                    // There is a potential race condition when SysUI starts up. CentralSurfaces
                    // must invoke #registerCentralSurfaces on this class before any messages can be
                    // processed. If this happens, repost the message with a small delay and try
                    // again.
                    if (mCentralSurfaces == null) {
                        message = "DELAYING SYSTEM_READY";
                        Message newMsg = mHandler.obtainMessage(SYSTEM_READY);
                        mHandler.sendMessageDelayed(newMsg, 100);
                    } else {
                        message = "SYSTEM_READY";
                        handleSystemReady();
                    }
                    break;
            }
            Log.d(TAG, "KeyguardViewMediator queue processing message: " + message);
+29 −0
Original line number Diff line number Diff line
@@ -307,6 +307,28 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        }
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testRaceCondition_doNotRegisterCentralSurfacesImmediately() {
        create(false);

        // GIVEN central surfaces is not registered with KeyguardViewMediator, but a call to enable
        // keyguard comes in
        mViewMediator.onSystemReady();
        mViewMediator.setKeyguardEnabled(true);
        TestableLooper.get(this).processAllMessages();

        // If this step has been reached, then system ui has not crashed. Now register
        // CentralSurfaces
        assertFalse(mViewMediator.isShowingAndNotOccluded());
        register();
        TestableLooper.get(this).moveTimeForward(100);
        TestableLooper.get(this).processAllMessages();

        // THEN keyguard is shown
        assertTrue(mViewMediator.isShowingAndNotOccluded());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void onLockdown_showKeyguard_evenIfKeyguardIsNotEnabledExternally() {
@@ -1139,6 +1161,11 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    }

    private void createAndStartViewMediator(boolean orderUnlockAndWake) {
        create(orderUnlockAndWake);
        register();
    }

    private void create(boolean orderUnlockAndWake) {
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.bool.config_orderUnlockAndWake, orderUnlockAndWake);

@@ -1189,7 +1216,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
                mSelectedUserInteractor,
                mKeyguardInteractor);
        mViewMediator.start();
    }

    private void register() {
        mViewMediator.registerCentralSurfaces(mCentralSurfaces, null, null, null, null, null);
    }