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

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

Merge "Fix AuthServiceTest for multi-user systems" into main

parents 1837fcf4 d3721ee5
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.annotation.UserIdInt;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -92,6 +93,8 @@ public class AuthServiceTest {

    private static final String TEST_OP_PACKAGE_NAME = "test_package";

    private final @UserIdInt int mUserId = UserHandle.getCallingUserId();

    private AuthService mAuthService;

    @Rule
@@ -257,12 +260,11 @@ public class AuthServiceTest {
        final Binder token = new Binder();
        final PromptInfo promptInfo = new PromptInfo();
        final long sessionId = 0;
        final int userId = 0;

        mAuthService.mImpl.authenticate(
                token,
                sessionId,
                userId,
                mUserId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                promptInfo);
@@ -270,7 +272,7 @@ public class AuthServiceTest {
        verify(mBiometricService).authenticate(
                eq(token),
                eq(sessionId),
                eq(userId),
                eq(mUserId),
                eq(mReceiver),
                eq(TEST_OP_PACKAGE_NAME),
                eq(promptInfo));
@@ -286,12 +288,11 @@ public class AuthServiceTest {
        final Binder token = new Binder();
        final PromptInfo promptInfo = new PromptInfo();
        final long sessionId = 0;
        final int userId = 0;

        mAuthService.mImpl.authenticate(
                token,
                sessionId,
                userId,
                mUserId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                promptInfo);
@@ -299,7 +300,7 @@ public class AuthServiceTest {
        verify(mBiometricService, never()).authenticate(
                eq(token),
                eq(sessionId),
                eq(userId),
                eq(mUserId),
                eq(mReceiver),
                eq(TEST_OP_PACKAGE_NAME),
                eq(promptInfo));
@@ -313,12 +314,11 @@ public class AuthServiceTest {

        final PromptInfo promptInfo = new PromptInfo();
        final long sessionId = 0;
        final int userId = 0;

        mAuthService.mImpl.authenticate(
                null /* token */,
                sessionId,
                userId,
                mUserId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                promptInfo);
@@ -338,7 +338,7 @@ public class AuthServiceTest {
        mAuthService.mImpl.authenticate(
                token,
                0, /* sessionId */
                0, /* userId */
                mUserId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                new PromptInfo());
@@ -356,7 +356,7 @@ public class AuthServiceTest {
        mAuthService.mImpl.authenticate(
                token,
                0, /* sessionId */
                0, /* userId */
                mUserId,
                mReceiver,
                TEST_OP_PACKAGE_NAME,
                new PromptInfo());
@@ -414,20 +414,19 @@ public class AuthServiceTest {
        mAuthService = new AuthService(mContext, mInjector);
        mAuthService.onStart();

        final int userId = 0;
        final int expectedResult = BIOMETRIC_SUCCESS;
        final int authenticators = 0;
        when(mBiometricService.canAuthenticate(anyString(), anyInt(), anyInt(), anyInt()))
                .thenReturn(expectedResult);

        final int result = mAuthService.mImpl
                .canAuthenticate(TEST_OP_PACKAGE_NAME, userId, authenticators);
                .canAuthenticate(TEST_OP_PACKAGE_NAME, mUserId, authenticators);

        assertEquals(expectedResult, result);
        waitForIdle();
        verify(mBiometricService).canAuthenticate(
                eq(TEST_OP_PACKAGE_NAME),
                eq(userId),
                eq(mUserId),
                eq(UserHandle.getCallingUserId()),
                eq(authenticators));
    }
@@ -440,18 +439,17 @@ public class AuthServiceTest {
        mAuthService = new AuthService(mContext, mInjector);
        mAuthService.onStart();

        final int userId = 0;
        final boolean expectedResult = true;
        when(mBiometricService.hasEnrolledBiometrics(anyInt(), anyString())).thenReturn(
                expectedResult);

        final boolean result = mAuthService.mImpl.hasEnrolledBiometrics(userId,
        final boolean result = mAuthService.mImpl.hasEnrolledBiometrics(mUserId,
                TEST_OP_PACKAGE_NAME);

        assertEquals(expectedResult, result);
        waitForIdle();
        verify(mBiometricService).hasEnrolledBiometrics(
                eq(userId),
                eq(mUserId),
                eq(TEST_OP_PACKAGE_NAME));
    }

@@ -528,13 +526,12 @@ public class AuthServiceTest {
        mAuthService = new AuthService(mContext, mInjector);
        mAuthService.onStart();

        final int userId = 0;
        final int authenticators = BiometricManager.Authenticators.BIOMETRIC_STRONG;

        mAuthService.mImpl.getLastAuthenticationTime(userId, authenticators);
        mAuthService.mImpl.getLastAuthenticationTime(mUserId, authenticators);

        waitForIdle();
        verify(mBiometricService).getLastAuthenticationTime(eq(userId), eq(authenticators));
        verify(mBiometricService).getLastAuthenticationTime(eq(mUserId), eq(authenticators));
    }

    private static void setInternalAndTestBiometricPermissions(