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

Commit 86af3487 authored by Beverly's avatar Beverly
Browse files

Add removeAltInterceptor method

In case a ViewController is detached after a new ViewController was
already attached, we have to check whether the altAuthInterceptor is the
correct one to remove, else we could unintentionally set
altAuthInterceptor=null when it shouldn't be null.

Test: manual
Fixes: 189328154
Change-Id: If04ca36b1259083e552db8fd33706f8d176ce949
parent a0ecdaaf
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
        mStatusBarStateController.addCallback(mStateListener);

        mUdfpsRequested = false;

        mStatusBarState = mStatusBarStateController.getState();
        mQsExpanded = mKeyguardViewManager.isQsExpanded();
        mInputBouncerHiddenAmount = KeyguardBouncer.EXPANSION_HIDDEN;
@@ -125,7 +126,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
        mFaceDetectRunning = false;

        mStatusBarStateController.removeCallback(mStateListener);
        mKeyguardViewManager.setAlternateAuthInterceptor(null);
        mKeyguardViewManager.removeAlternateAuthInterceptor(mAlternateAuthInterceptor);
        mTransitioningFromHome = false;
        mKeyguardUpdateMonitor.requestFaceAuthOnOccludingApp(false);

+18 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.WindowManagerGlobal;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

@@ -63,6 +64,7 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Optional;

import javax.inject.Inject;
@@ -268,10 +270,23 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
        registerListeners();
    }

    public void setAlternateAuthInterceptor(@Nullable AlternateAuthInterceptor authInterceptor) {
        final boolean newlyNull = authInterceptor == null && mAlternateAuthInterceptor != null;
    /**
     * Sets the given alt auth interceptor to null if it's the current auth interceptor. Else,
     * does nothing.
     */
    public void removeAlternateAuthInterceptor(@NonNull AlternateAuthInterceptor authInterceptor) {
        if (Objects.equals(mAlternateAuthInterceptor, authInterceptor)) {
            mAlternateAuthInterceptor = null;
            resetAlternateAuth(true);
        }
    }

    /**
     * Sets a new alt auth interceptor.
     */
    public void setAlternateAuthInterceptor(@NonNull AlternateAuthInterceptor authInterceptor) {
        mAlternateAuthInterceptor = authInterceptor;
        resetAlternateAuth(newlyNull);
        resetAlternateAuth(false);
    }

    private void registerListeners() {
+4 −4
Original line number Diff line number Diff line
@@ -254,15 +254,15 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {

    @Test
    public void testOnDetachedStateReset() {
        // GIVEN view is attached, alt auth is force being shown
        // GIVEN view is attached
        mController.onViewAttached();
        captureStatusBarStateListeners();
        captureAltAuthInterceptor();

        // WHEN view is detached
        mController.onViewDetached();

        // THEN set alternate auth interceptor to null
        verify(mStatusBarKeyguardViewManager).setAlternateAuthInterceptor(null);
        // THEN remove alternate auth interceptor
        verify(mStatusBarKeyguardViewManager).removeAlternateAuthInterceptor(mAltAuthInterceptor);
    }

    private void sendStatusBarStateChanged(int statusBarState) {