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

Commit e8ebac7e authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Cancel coroutine job before replacing BiometricContextListener

Only allow one IBiometricContextListener to be registered at a time in
AuthController, and cancel previous coroutine jobs before replacing
the listener. Otherwise, the coroutines of old listener will continue to
run forever.

Bug: 317205264
Bug: 316125692
Flag: NONE
Test: AuthControllerTest
Change-Id: I0617aefbece18a261aed43ce5c90fc5ef1094338
parent fb6dda64
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ import javax.inject.Inject;
import javax.inject.Provider;

import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Job;

/**
 * Receives messages sent from {@link com.android.server.biometrics.BiometricService} and shows the
@@ -136,6 +137,7 @@ public class AuthController implements
    private final Provider<UdfpsController> mUdfpsControllerFactory;
    private final Provider<SideFpsController> mSidefpsControllerFactory;
    private final CoroutineScope mApplicationCoroutineScope;
    private Job mBiometricContextListenerJob = null;

    // TODO: these should be migrated out once ready
    @NonNull private final Provider<PromptCredentialInteractor> mPromptCredentialInteractor;
@@ -914,6 +916,10 @@ public class AuthController implements

    @Override
    public void setBiometricContextListener(IBiometricContextListener listener) {
        if (mBiometricContextListenerJob != null) {
            mBiometricContextListenerJob.cancel(null);
        }
        mBiometricContextListenerJob =
                mLogContextInteractor.get().addBiometricContextListener(listener);
    }