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

Commit a281760e authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix race condition

Variable could have been nullified before it arrived in the handler.
Let's cache it.

Test: BiometricsUnlockControllerTest
Fixes: 150563967
Change-Id: I35e994d838501865b7c76df761efdb49123548a3
parent 13fa0257
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -394,10 +394,11 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
    public void onFinishedGoingToSleep(int why) {
        Trace.beginSection("BiometricUnlockController#onFinishedGoingToSleep");
        if (mPendingAuthenticated != null) {
            PendingAuthenticated pendingAuthenticated = mPendingAuthenticated;
            // Post this to make sure it's executed after the device is fully locked.
            mHandler.post(() -> onBiometricAuthenticated(mPendingAuthenticated.userId,
                    mPendingAuthenticated.biometricSourceType,
                    mPendingAuthenticated.isStrongBiometric));
            mHandler.post(() -> onBiometricAuthenticated(pendingAuthenticated.userId,
                    pendingAuthenticated.biometricSourceType,
                    pendingAuthenticated.isStrongBiometric));
            mPendingAuthenticated = null;
        }
        Trace.endSection();
+4 −1
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
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;

@@ -325,11 +326,13 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase {
        mBiometricUnlockController.onFinishedGoingToSleep(-1);
        verify(mHandler, never()).post(any());

        ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
        // the value of isStrongBiometric doesn't matter here since we only care about the returned
        // value of isUnlockingWithBiometricAllowed()
        mBiometricUnlockController.onBiometricAuthenticated(1 /* userId */,
                BiometricSourceType.FACE, true /* isStrongBiometric */);
        mBiometricUnlockController.onFinishedGoingToSleep(-1);
        verify(mHandler).post(any());
        verify(mHandler).post(captor.capture());
        captor.getValue().run();
    }
}