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

Commit e7fe2e75 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch 'lineage-20.0' of gitlab.e.foundation:e/os/android_frameworks_base into v1-t

parents ee0fb4e6 37d9448f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -267,8 +267,8 @@ public class IntentForwarderActivityTest {
                Intent.ACTION_VIEW, Intent.CATEGORY_BROWSABLE);
        IntentForwarderWrapperActivity activity = mActivityRule.launchActivity(intent);

        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mIPm, times(2)).canForwardTo(
                intentCaptor.capture(), nullable(String.class), anyInt(), anyInt());
        List<Intent> capturedIntents = intentCaptor.getAllValues();
+42 −3
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
    private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
    private static final int SYSTEM_READY = 18;
    private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19;
    private static final int USER_SWITCH_COMPLETE = 23;

    private final List<LockNowCallback> mLockNowCallbacks = new ArrayList<>();

@@ -393,6 +394,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
    private boolean mDeviceInteractive;
    private boolean mGoingToSleep;

    private final Object mDismissToken = new Object();

    // last known state of the cellular connection
    private String mPhoneState = TelephonyManager.EXTRA_STATE_IDLE;

@@ -556,6 +559,35 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                }
            };

    @VisibleForTesting
    protected UserTracker.Callback mUserChangedCallback = new UserTracker.Callback() {

        @Override
        public void onUserChanged(int newUser, Context userContext) {
            mHandler.sendMessage(mHandler.obtainMessage(USER_SWITCH_COMPLETE,
                    newUser, 0));
        }
    };

    /**
     * Handle {@link #USER_SWITCH_COMPLETE}
     */
    @VisibleForTesting
    void handleUserSwitchComplete(int userId) {
        Log.d(TAG, String.format("onUserSwitchComplete %d", userId));
        if (userId != KeyguardUpdateMonitor.getCurrentUser()) {
            Log.i(TAG, "Ignoring user switch complete, new user change");
            return;
        }
        // Calling dismiss on a secure user will show the bouncer
        // We are calling dismiss with a delay as there are race conditions in some scenarios
        // caused by async layout listeners
        if (!mLockPatternUtils.isSecure(userId)) {
            mHandler.postDelayed(() -> dismiss(null /* callback */, null /* message */),
                    mDismissToken, 500);
        }
    }

    KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() {

        @Override
@@ -1361,6 +1393,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                com.android.internal.R.anim.lock_screen_behind_enter);

        mWorkLockController = new WorkLockActivityController(mContext, mUserTracker);
        mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
    }

    @Override
@@ -1439,6 +1472,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        // explicitly DO NOT want to call
        // mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(false)
        // here, since that will mess with the device lock state.
        mKeyguardStateController.notifyKeyguardGoingAway(false);
        mUpdateMonitor.dispatchKeyguardGoingAway(false);

        notifyStartedGoingToSleep();
@@ -2126,7 +2160,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
     * Send message to keyguard telling it to hide itself
     * @see #handleHide()
     */
    private void hideLocked() {
    @VisibleForTesting
    void hideLocked() {
        Trace.beginSection("KeyguardViewMediator#hideLocked");
        if (DEBUG) Log.d(TAG, "hideLocked");
        Message msg = mHandler.obtainMessage(HIDE);
@@ -2197,6 +2232,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            if (newUserId != KeyguardUpdateMonitor.getCurrentUser()) {
                Log.d(TAG, String.format("setCurrentUser %d", newUserId));
                KeyguardUpdateMonitor.setCurrentUser(newUserId);
                mHandler.removeCallbacksAndMessages(mDismissToken);
                mHandler.removeMessages(DISMISS);
                mHandler.removeMessages(HIDE);
                mHandler.removeMessages(START_KEYGUARD_EXIT_ANIM);
@@ -2365,6 +2401,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                case SYSTEM_READY:
                    handleSystemReady();
                    break;
                case USER_SWITCH_COMPLETE:
                    handleUserSwitchComplete(msg.arg1);
                    break;
            }
        }
    };
@@ -3683,8 +3722,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            if (mUserId != currentUserId) {
                Log.e(TAG, "Not executing OnHideAnimationFinished.run() due to userId mismatch. "
                        + "Requested: " + mUserId + ", current: " + currentUserId);
                resetStateLocked();
                mShadeController.get().instantCollapseShade();
                resetStateLocked();
                return;
            }

+13 −20
Original line number Diff line number Diff line
@@ -228,34 +228,27 @@ class KeyguardTransitionRepositoryImpl @Inject constructor() : KeyguardTransitio
    }

    private fun emitTransition(nextStep: TransitionStep, isManual: Boolean = false) {
        trace(nextStep, isManual)
        val emitted = _transitions.tryEmit(nextStep)
        if (!emitted) {
            Log.w(TAG, "Failed to emit next value without suspending")
        }
        logAndTrace(nextStep, isManual)
        _transitions.tryEmit(nextStep)
        lastStep = nextStep
    }

    private fun trace(step: TransitionStep, isManual: Boolean) {
    private fun logAndTrace(step: TransitionStep, isManual: Boolean) {
        if (step.transitionState == TransitionState.RUNNING) {
            return
        }
        val traceName =
            "Transition: ${step.from} -> ${step.to} " +
                if (isManual) {
                    "(manual)"
                } else {
                    ""
                }
        val manualStr = if (isManual) " (manual)" else ""
        val traceName = "Transition: ${step.from} -> ${step.to}$manualStr"

        val traceCookie = traceName.hashCode()
        if (step.transitionState == TransitionState.STARTED) {
            Trace.beginAsyncSection(traceName, traceCookie)
        } else if (
            step.transitionState == TransitionState.FINISHED ||
                step.transitionState == TransitionState.CANCELED
        ) {
            Trace.endAsyncSection(traceName, traceCookie)
        when (step.transitionState) {
            TransitionState.STARTED -> Trace.beginAsyncSection(traceName, traceCookie)
            TransitionState.FINISHED -> Trace.endAsyncSection(traceName, traceCookie)
            TransitionState.CANCELED -> Trace.endAsyncSection(traceName, traceCookie)
            else -> {}
        }

        Log.i(TAG, "${step.transitionState.name} transition: $step$manualStr")
    }

    companion object {
+24 −12
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
@@ -57,6 +58,7 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardDisplayManager;
import com.android.keyguard.KeyguardSecurityView;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.keyguard.mediator.ScreenOnCoordinator;
import com.android.systemui.DejankUtils;
import com.android.systemui.SysuiTestCase;
@@ -189,8 +191,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {

        // Setup keyguard
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
        processAllMessagesAndBgExecutorMessages();
        mViewMediator.setShowingLocked(true);

        // Request keyguard going away
@@ -207,8 +208,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class);
        mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers,
                null, callback);
        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
        processAllMessagesAndBgExecutorMessages();

        // Followed by a request to dismiss the keyguard completely
        mViewMediator.mViewMediatorCallback.keyguardDonePending(true, insecureUserId);
@@ -218,8 +218,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        int nextUserId = 500;
        setCurrentUser(nextUserId, /* isSecure= */true);

        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
        processAllMessagesAndBgExecutorMessages();

        // This simulates the race condition in DejankUtils.postAfterTraversal()
        mPostAfterTraversalRunnable.run();
@@ -426,6 +425,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void testCancelKeyguardExitAnimation_noPendingLock_keyguardWillNotBeShowing() {
        when(mPowerManager.isInteractive()).thenReturn(true);

        setCurrentUser(0, false);
        startMockKeyguardExitAnimation();
        cancelMockKeyguardExitAnimation();

@@ -477,12 +479,21 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        assertTrue(mViewMediator.isAnimatingBetweenKeyguardAndSurfaceBehind());
    }

    /**
     * Interactions with the ActivityTaskManagerService and others are posted to an executor that
     * doesn't use the testable looper. Use this method to ensure those are run as well.
     */
    private void processAllMessagesAndBgExecutorMessages() {
        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
    }

    /**
     * Configures mocks appropriately, then starts the keyguard exit animation.
     */
    private void startMockKeyguardExitAnimation() {
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();

        mViewMediator.setShowingLocked(true);

@@ -495,9 +506,11 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        IRemoteAnimationFinishedCallback callback = mock(IRemoteAnimationFinishedCallback.class);

        when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(true);
        mViewMediator.hideLocked();
        processAllMessagesAndBgExecutorMessages();
        mViewMediator.startKeyguardExitAnimation(TRANSIT_OLD_KEYGUARD_GOING_AWAY, apps, wallpapers,
                null, callback);
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();
    }

    /**
@@ -506,7 +519,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    private void cancelMockKeyguardExitAnimation() {
        when(mKeyguardStateController.isKeyguardGoingAway()).thenReturn(false);
        mViewMediator.cancelKeyguardExitAnimation();
        TestableLooper.get(this).processAllMessages();
        processAllMessagesAndBgExecutorMessages();
    }

    @Test
@@ -635,7 +648,6 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {

        onHideAnimationFinished.getValue().run();


        // This is executed when the user is incorrect
        verify(mShadeController).instantCollapseShade();
    }
@@ -686,9 +698,9 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
    }

    private void setCurrentUser(int userId, boolean isSecure) {
        when(mUserTracker.getUserId()).thenReturn(userId);
        when(mLockPatternUtils.isSecure(userId)).thenReturn(isSecure);
        mViewMediator.setCurrentUser(userId);
        TestableLooper.get(this).processAllMessages();
        mUiBgExecutor.runAllReady();
        processAllMessagesAndBgExecutorMessages();
    }
}
+12 −12
Original line number Diff line number Diff line
@@ -450,25 +450,25 @@ public class UserControllerTest {

        setUpUser(TEST_USER_ID1, 0);
        setUpUser(TEST_USER_ID2, 0);
        int numerOfUserSwitches = 1;
        int numberOfUserSwitches = 1;
        addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM,
                numerOfUserSwitches, false);
                numberOfUserSwitches, false);
        // running: user 0, USER_ID
        assertTrue(mUserController.canStartMoreUsers());
        assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}),
                mUserController.getRunningUsersLU());

        numerOfUserSwitches++;
        numberOfUserSwitches++;
        addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID,
                numerOfUserSwitches, false);
                numberOfUserSwitches, false);
        // running: user 0, USER_ID, USER_ID1
        assertFalse(mUserController.canStartMoreUsers());
        assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID, TEST_USER_ID1}),
                mUserController.getRunningUsersLU());

        numerOfUserSwitches++;
        numberOfUserSwitches++;
        addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1,
                numerOfUserSwitches, false);
                numberOfUserSwitches, false);
        UserState ussUser2 = mUserStates.get(TEST_USER_ID2);
        // skip middle step and call this directly.
        mUserController.finishUserSwitch(ussUser2);
@@ -493,20 +493,20 @@ public class UserControllerTest {

        setUpUser(TEST_USER_ID1, 0);
        setUpUser(TEST_USER_ID2, 0);
        int numerOfUserSwitches = 1;
        int numberOfUserSwitches = 1;
        addForegroundUserAndContinueUserSwitch(TEST_USER_ID, UserHandle.USER_SYSTEM,
                numerOfUserSwitches, false);
                numberOfUserSwitches, false);
        // running: user 0, USER_ID
        assertTrue(mUserController.canStartMoreUsers());
        assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID}),
                mUserController.getRunningUsersLU());
        numerOfUserSwitches++;
        numberOfUserSwitches++;

        addForegroundUserAndContinueUserSwitch(TEST_USER_ID1, TEST_USER_ID,
                numerOfUserSwitches, true);
                numberOfUserSwitches, true);
        // running: user 0, USER_ID1
        // stopped + unlocked: USER_ID
        numerOfUserSwitches++;
        numberOfUserSwitches++;
        assertTrue(mUserController.canStartMoreUsers());
        assertEquals(Arrays.asList(new Integer[] {0, TEST_USER_ID1}),
                mUserController.getRunningUsersLU());
@@ -521,7 +521,7 @@ public class UserControllerTest {
                .lockUserKey(anyInt());

        addForegroundUserAndContinueUserSwitch(TEST_USER_ID2, TEST_USER_ID1,
                numerOfUserSwitches, true);
                numberOfUserSwitches, true);
        // running: user 0, USER_ID2
        // stopped + unlocked: USER_ID1
        // stopped + locked: USER_ID