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

Commit 344e05cf authored by wilsonshih's avatar wilsonshih Committed by Android Build Coastguard Worker
Browse files

Fix unit test crash on eng builds due to Log.wtf

A unit test was crashing on engineering builds because a call to
flushAll() was executing a pending UncertainTracker message. This
intentionally triggers a Log.wtf() crash, which occurs after SWC posts
the tracker to the mainExecute queue.
The fix is to remove the pending UncertainTracker message from the
queue before flushAll() runs. The test is also updated to verify that
removeCallbacks() is correctly called to verify the transactionCommit()
will remove the tracker.
Also shorter the UNCERTAIN_TRANSITION_TIMEOUT_MS since the
startTransaction should normally applied right after the transition
is handled.

Bug: 431189806
Flag: EXEMPT bugfix
Test: atest StartingWindowControllerTests
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:368b0e5e17ca014c887eff1451830d4e581df4dd
Merged-In: I3295257bee5f9f50f3456ef6db08f714468f5bf8
Change-Id: I3295257bee5f9f50f3456ef6db08f714468f5bf8
parent a8ee8ff4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class StartingWindowController implements RemoteCallable<StartingWindowCo
    public static final String TAG = "ShellStartingWindow";

    private static final long TASK_BG_COLOR_RETAIN_TIME_MS = 5000;
    private static final long UNCERTAIN_TRANSITION_TIMEOUT_MS = 5000;
    static final long UNCERTAIN_TRANSITION_TIMEOUT_MS = 2000;

    private final StartingSurfaceDrawer mStartingSurfaceDrawer;
    private final StartingWindowTypeAlgorithm mStartingWindowTypeAlgorithm;
+19 −1
Original line number Diff line number Diff line
@@ -19,12 +19,16 @@ package com.android.wm.shell.startingsurface;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.window.TransitionInfo.FLAG_IS_BEHIND_STARTING_WINDOW;

import static com.android.wm.shell.startingsurface.StartingWindowController.RemoveStartingObserver.UncertainTracker;
import static com.android.wm.shell.startingsurface.StartingWindowController.UNCERTAIN_TRANSITION_TIMEOUT_MS;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -62,6 +66,7 @@ import com.android.wm.shell.transition.Transitions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@@ -100,7 +105,7 @@ public class StartingWindowControllerTests extends ShellTestCase {
        mShellInit = spy(new ShellInit(mSplashScreenExecutor));
        mShellController = spy(new ShellController(mContext, mShellInit, mShellCommandHandler,
                mDisplayInsetsController, mUserManager, mSplashScreenExecutor));
        mMainExecutor = new TestShellExecutor();
        mMainExecutor = spy(new TestShellExecutor());
        mController = new StartingWindowController(mContext, mShellInit, mShellController,
                mTaskOrganizer, mSplashScreenExecutor, mTypeAlgorithm, mIconProvider,
                mTransactionPool, mMainExecutor, mTransitions);
@@ -170,19 +175,32 @@ public class StartingWindowControllerTests extends ShellTestCase {
        observer.onTransitionReady(token, info, st, st);
        notifyTransactionCommitted(st);
        observer.onTransitionReady(secondToken, secondInfo, st, st);
        final ArgumentCaptor<UncertainTracker> trackerCaptor =
                ArgumentCaptor.forClass(UncertainTracker.class);
        verify(mMainExecutor).executeDelayed(trackerCaptor.capture(),
                eq(UNCERTAIN_TRANSITION_TIMEOUT_MS));
        UncertainTracker tracker = trackerCaptor.getValue();
        mMainExecutor.removeCallbacks(tracker);
        notifyTransactionCommitted(st);
        verify(mMainExecutor, times(2)).removeCallbacks(eq(tracker));
        assertTrue(observer.hasPendingRemoval());
        observer.requestRemoval(taskId, removalInfo);
        assertFalse(observer.hasPendingRemoval());

        st.clear();
        clearInvocations(mMainExecutor);
        observer.onAddingWindow(taskId, token, appToken);
        observer.onTransitionReady(token, info, st, st);
        notifyTransactionCommitted(st);
        observer.onTransitionReady(secondToken, secondInfo, st, st);
        verify(mMainExecutor).executeDelayed(trackerCaptor.capture(),
                eq(UNCERTAIN_TRANSITION_TIMEOUT_MS));
        observer.requestRemoval(taskId, removalInfo);
        assertTrue(observer.hasPendingRemoval());
        tracker = trackerCaptor.getValue();
        mMainExecutor.removeCallbacks(tracker);
        notifyTransactionCommitted(st);
        verify(mMainExecutor, times(2)).removeCallbacks(eq(tracker));
        assertFalse(observer.hasPendingRemoval());
    }