diff options
| author | 2021-07-01 16:25:28 -0700 | |
|---|---|---|
| committer | 2021-07-01 16:28:05 -0700 | |
| commit | 587ffaa9de1cfae1b291c44f89f2d8300b9722bb (patch) | |
| tree | 38646bb976600c2118b226e6cc9bc0c38e2d8650 | |
| parent | 9dff4b394fc345c2711a47c8d2ae5054472ad778 (diff) | |
Ensure current operation has not changed on start/stop user operations.
Fix: 192568023
Test: atest UserAwareBiometricSchedulerTest
Test: manual (no crash on boot)
Change-Id: I6ed9f60b093b3927596b2559b3b2f2a4a0ac2e6b
2 files changed, 43 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java b/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java index c4c98e362a43..e6e293eb9b4c 100644 --- a/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java +++ b/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java @@ -62,16 +62,22 @@ public class UserAwareBiometricScheduler extends BiometricScheduler {          @Override          public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, boolean success) {              mHandler.post(() -> { -                if (mOwner == clientMonitor && mOwner == mCurrentOperation.mClientMonitor) { -                    Slog.d(getTag(), "[Client finished] " -                            + clientMonitor + ", success: " + success); +                if (mOwner != clientMonitor) { +                    Slog.e(getTag(), "[Wrong client finished], actual: " +                            + clientMonitor + ", expected: " + mOwner); +                    return; +                } + +                Slog.d(getTag(), "[Client finished] " +                        + clientMonitor + ", success: " + success); +                if (mCurrentOperation != null && mCurrentOperation.mClientMonitor == mOwner) {                      mCurrentOperation = null; +                    startNextOperationIfIdle();                  } else { -                    Slog.e(getTag(), "[Client finished, but not current operation], actual: " -                            + mCurrentOperation + ", expected: " + mOwner); +                    // can usually be ignored (hal died, etc.) +                    Slog.d(getTag(), "operation is already null or different (reset?): " +                            + mCurrentOperation);                  } - -                startNextOperationIfIdle();              });          }      } @@ -125,9 +131,9 @@ public class UserAwareBiometricScheduler extends BiometricScheduler {                      new ClientFinishedCallback(startClient);              Slog.d(getTag(), "[Starting User] " + startClient); -            startClient.start(finishedCallback);              mCurrentOperation = new Operation(                      startClient, finishedCallback, Operation.STATE_STARTED); +            startClient.start(finishedCallback);          } else {              if (mStopUserClient != null) {                  Slog.d(getTag(), "[Waiting for StopUser] " + mStopUserClient); @@ -139,9 +145,9 @@ public class UserAwareBiometricScheduler extends BiometricScheduler {                  Slog.d(getTag(), "[Stopping User] current: " + currentUserId                          + ", next: " + nextUserId + ". " + mStopUserClient); -                mStopUserClient.start(finishedCallback);                  mCurrentOperation = new Operation(                          mStopUserClient, finishedCallback, Operation.STATE_STARTED); +                mStopUserClient.start(finishedCallback);              }          }      } diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java index 7ff253f3936e..3a9e629b6ed6 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/UserAwareBiometricSchedulerTest.java @@ -17,6 +17,8 @@  package com.android.server.biometrics.sensors;  import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame;  import static org.mockito.ArgumentMatchers.any;  import static org.mockito.Mockito.mock;  import static org.mockito.Mockito.never; @@ -133,6 +135,28 @@ public class UserAwareBiometricSchedulerTest {      }      @Test +    public void testScheduleOperation_whenNoUser_notStarted_andReset() { +        mCurrentUserId = UserHandle.USER_NULL; +        mStartOperationsFinish = false; + +        final BaseClientMonitor client = mock(BaseClientMonitor.class); +        when(client.getTargetUserId()).thenReturn(5); +        mScheduler.scheduleClientMonitor(client); +        waitForIdle(); + +        final TestStartUserClient startUserClient = +                (TestStartUserClient) mScheduler.mCurrentOperation.mClientMonitor; +        mScheduler.reset(); +        assertNull(mScheduler.mCurrentOperation); + +        final BiometricScheduler.Operation fakeOperation = new BiometricScheduler.Operation( +                mock(BaseClientMonitor.class), new BaseClientMonitor.Callback() {}); +        mScheduler.mCurrentOperation = fakeOperation; +        startUserClient.mCallback.onClientFinished(startUserClient, true); +        assertSame(fakeOperation, mScheduler.mCurrentOperation); +    } + +    @Test      public void testScheduleOperation_whenSameUser() {          mCurrentUserId = 10; @@ -173,7 +197,6 @@ public class UserAwareBiometricSchedulerTest {      }      private class TestUserStoppedCallback implements StopUserClient.UserStoppedCallback { -          int numInvocations;          @Override @@ -184,7 +207,6 @@ public class UserAwareBiometricSchedulerTest {      }      private class TestUserStartedCallback implements StartUserClient.UserStartedCallback<Object> { -          int numInvocations;          @Override @@ -221,6 +243,8 @@ public class UserAwareBiometricSchedulerTest {      private static class TestStartUserClient extends StartUserClient<Object, Object> {          private final boolean mShouldFinish; +        Callback mCallback; +          public TestStartUserClient(@NonNull Context context,                  @NonNull LazyDaemon<Object> lazyDaemon, @Nullable IBinder token, int userId,                  int sensorId, @NonNull UserStartedCallback<Object> callback, boolean shouldFinish) { @@ -236,6 +260,8 @@ public class UserAwareBiometricSchedulerTest {          @Override          public void start(@NonNull Callback callback) {              super.start(callback); + +            mCallback = callback;              if (mShouldFinish) {                  mUserStartedCallback.onUserStarted(getTargetUserId(), new Object());                  callback.onClientFinished(this, true /* success */);  |