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

Commit 03083be9 authored by Diya Bera's avatar Diya Bera
Browse files

Make listener non-nullable

Test: atest BaseClientMonitorTest
Bug: 300103815

Change-Id: Idcecef148f1dbda85881cb77f31589603847bf7a
parent 3b29a4d1
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -112,10 +112,8 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
            getLogger().logOnError(getContext(), getOperationContext(),
                    errorCode, vendorCode, getTargetUserId());
            try {
                if (getListener() != null) {
                mShouldSendErrorToClient = false;
                getListener().onError(getSensorId(), getCookie(), errorCode, vendorCode);
                }
            } catch (RemoteException e) {
                Slog.w(TAG, "Failed to invoke sendError", e);
            }
@@ -147,9 +145,7 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement

        final int errorCode = BiometricConstants.BIOMETRIC_ERROR_CANCELED;
        try {
            if (getListener() != null) {
            getListener().onError(getSensorId(), getCookie(), errorCode, 0 /* vendorCode */);
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed to invoke sendError", e);
        }
@@ -181,7 +177,7 @@ public abstract class AcquisitionClient<T> extends HalClientMonitor<T> implement
        }

        try {
            if (getListener() != null && shouldSend) {
            if (shouldSend) {
                getListener().onAcquired(getSensorId(), acquiredInfo, vendorCode);
            }
        } catch (RemoteException e) {
+7 −15
Original line number Diff line number Diff line
@@ -265,7 +265,6 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
                Slog.d(TAG, "Skipping addAuthToken");
            }
            try {
                if (listener != null) {
                if (!mIsRestricted) {
                    listener.onAuthenticationSucceeded(getSensorId(), identifier, byteToken,
                            getTargetUserId(), mIsStrongBiometric);
@@ -274,9 +273,6 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
                            byteToken,
                            getTargetUserId(), mIsStrongBiometric);
                }
                } else {
                    Slog.e(TAG, "Received successful auth, but client was not listening");
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Unable to notify listener", e);
                mCallback.onClientFinished(this, false);
@@ -301,11 +297,7 @@ public abstract class AuthenticationClient<T, O extends AuthenticateOptions>
                }

                try {
                    if (listener != null) {
                    listener.onAuthenticationFailed(getSensorId());
                    } else {
                        Slog.e(TAG, "Received failed auth, but client was not listening");
                    }
                } catch (RemoteException e) {
                    Slog.e(TAG, "Unable to notify listener", e);
                    mCallback.onClientFinished(this, false);
+8 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.IBiometricSensorReceiver;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
@@ -55,7 +56,7 @@ public abstract class BaseClientMonitor implements IBinder.DeathRecipient {

    @Nullable private IBinder mToken;
    private long mRequestId;
    @Nullable private ClientMonitorCallbackConverter mListener;
    @NonNull private ClientMonitorCallbackConverter mListener;
    // Currently only used for authentication client. The cookie generated by BiometricService
    // is never 0.
    private final int mCookie;
@@ -95,7 +96,8 @@ public abstract class BaseClientMonitor implements IBinder.DeathRecipient {
        mContext = context;
        mToken = token;
        mRequestId = -1;
        mListener = listener;
        mListener = listener == null ? new ClientMonitorCallbackConverter(
                new IBiometricSensorReceiver.Default()) : listener;
        mTargetUserId = userId;
        mOwner = owner;
        mCookie = cookie;
@@ -199,7 +201,7 @@ public abstract class BaseClientMonitor implements IBinder.DeathRecipient {
        }
        mToken = null;
        if (clearListener) {
            mListener = null;
            mListener = new ClientMonitorCallbackConverter(new IBiometricSensorReceiver.Default());
        }
    }

@@ -233,8 +235,8 @@ public abstract class BaseClientMonitor implements IBinder.DeathRecipient {
        return mOwner;
    }

    @Nullable
    public final ClientMonitorCallbackConverter getListener() {
    @NonNull
    protected ClientMonitorCallbackConverter getListener() {
        return mListener;
    }

@@ -312,9 +314,7 @@ public abstract class BaseClientMonitor implements IBinder.DeathRecipient {
        final int errorCode = BiometricConstants.BIOMETRIC_ERROR_CANCELED;
        try {
            ClientMonitorCallbackConverter listener = getListener();
            if (listener != null) {
            listener.onError(getSensorId(), getCookie(), errorCode, 0 /* vendorCode */);
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed to invoke sendError", e);
        }
+1 −3
Original line number Diff line number Diff line
@@ -82,9 +82,7 @@ public abstract class EnrollClient<T> extends AcquisitionClient<T> implements En

        final ClientMonitorCallbackConverter listener = getListener();
        try {
            if (listener != null) {
            listener.onEnrollResult(identifier, remaining);
            }
        } catch (RemoteException e) {
            Slog.e(TAG, "Remote exception", e);
        }
+4 −10
Original line number Diff line number Diff line
@@ -74,13 +74,9 @@ public abstract class RemovalClient<S extends BiometricAuthenticator.Identifier,
        if (identifier == null) {
            Slog.e(TAG, "identifier was null, skipping onRemove()");
            try {
                if (getListener() != null) {
                getListener().onError(getSensorId(), getCookie(),
                        BiometricConstants.BIOMETRIC_ERROR_UNABLE_TO_REMOVE,
                        0 /* vendorCode */);
                } else {
                    Slog.e(TAG, "Error, listener was null, not sending onError callback");
                }
            } catch (RemoteException e) {
                Slog.w(TAG, "Failed to send error to client for onRemoved", e);
            }
@@ -93,9 +89,7 @@ public abstract class RemovalClient<S extends BiometricAuthenticator.Identifier,
                identifier.getBiometricId());

        try {
            if (getListener() != null) {
            getListener().onRemoved(identifier, remaining);
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "Failed to notify Removed:", e);
        }
Loading