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

Commit f03ff614 authored by Diya Bera's avatar Diya Bera
Browse files

Check service before calling it

AuthenticationPolicyService is not available on watch, TV and auto. So
ServiceNotFoundException can be thrown on these devices via
BiometricService.Injector#getAuthenticationPolicyManager

Fixes: 423599294
Test: atest WatchRangingHelperTest
Flag: EXEMPT bug fix
Change-Id: I1c63538781061b97c492e1b3b895958f2403b8f5
parent 25fbdd63
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();