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

Commit 6eefe300 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check service before calling it" into main

parents e5335d50 f03ff614
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.hardware.biometrics.IIdentityCheckStateListener.WatchRangingState;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.os.Handler;
import android.proximity.IProximityResultCallback;
@@ -47,7 +48,7 @@ public class WatchRangingHelper {
    }

    WatchRangingHelper(long authenticationRequestId,
            @NonNull AuthenticationPolicyManager authenticationPolicyManager,
            @Nullable AuthenticationPolicyManager authenticationPolicyManager,
            @NonNull Handler handler, WatchRangingListener listener) {
        mAuthenticationRequestId = authenticationRequestId;
        mAuthenticationPolicyManager = authenticationPolicyManager;
@@ -60,6 +61,11 @@ public class WatchRangingHelper {
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void startWatchRanging() {
        if (mAuthenticationPolicyManager == null) {
            Slog.e(TAG, "Authentication policy manager is null");
            return;
        }

        setWatchRangingState(WatchRangingState.WATCH_RANGING_STARTED);

        mAuthenticationPolicyManager.startWatchRangingForIdentityCheck(mAuthenticationRequestId,
@@ -90,6 +96,11 @@ public class WatchRangingHelper {
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void cancelWatchRanging() {
        if (mAuthenticationPolicyManager == null) {
            Slog.e(TAG, "Authentication policy manager is null");
            return;
        }

        mAuthenticationPolicyManager.cancelWatchRangingForRequestId(mAuthenticationRequestId);
    }

+14 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;

import android.content.Context;
import android.hardware.biometrics.IIdentityCheckStateListener.WatchRangingState;
@@ -74,6 +75,19 @@ public class WatchRangingHelperTest {
                IProximityResultCallback.class);
    }

    @Test
    public void testNullAuthenticationPolicyManager() {
        mWatchRangingHelper = new WatchRangingHelper(AUTHENTICATION_REQUEST_ID,
                null, new Handler(TestableLooper.get(this).getLooper()),
                watchRangingState -> {});

        mWatchRangingHelper.startWatchRanging();

        verifyNoInteractions(mAuthenticationPolicyService);
        assertThat(mWatchRangingHelper.getWatchRangingState()).isEqualTo(
                WatchRangingState.WATCH_RANGING_IDLE);
    }

    @Test
    public void testStartWatchRanging() throws RemoteException {
        mWatchRangingHelper.startWatchRanging();