diff options
| author | 2021-03-23 15:28:03 -0700 | |
|---|---|---|
| committer | 2021-03-23 15:33:24 -0700 | |
| commit | 5309214dfc6767ba61a1d29031f920fb587b8d12 (patch) | |
| tree | 3eaa2e4743f9e553a789e531ed4b6611bf257662 | |
| parent | 8a5c4b51a393d72ae2cbfa051005493facb60cbc (diff) | |
6/n: Update UserAwareBiometricScheduler
1) Add and expose "onUserStopped", and invoke it from scheduler owners.
Originally we try to send the callback via
scheduler.getCurrentClient().onUserStopped(), but since the user-aware
scheduler does not keep this work in the queue (can revisit this
later), it needs to receive the callback some other way.
2) Does not schedule another "stopUserClient" if one is already there.
This avoid unnecessary stopUserClients from being added when one
is already running but another operation is added to the queue.
Test: atest com.android.server.biometrics
Test: atest CtsBiometricsTestCases
Test: Enroll, add new user, switch user, enroll
Bug: 181984005
Change-Id: I86922b83fa993c3ceae81acc2c31999d268014c9
3 files changed, 28 insertions, 31 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 c22db7804190..f015a80d338d 100644 --- a/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java +++ b/services/core/java/com/android/server/biometrics/sensors/UserAwareBiometricScheduler.java @@ -52,6 +52,8 @@ public class UserAwareBiometricScheduler extends BiometricScheduler { @NonNull private final UserSwitchCallback mUserSwitchCallback; @NonNull @VisibleForTesting final ClientFinishedCallback mClientFinishedCallback; + @Nullable private StopUserClient<?> mStopUserClient; + @VisibleForTesting class ClientFinishedCallback implements BaseClientMonitor.Callback { @Override @@ -113,11 +115,26 @@ public class UserAwareBiometricScheduler extends BiometricScheduler { Slog.d(getTag(), "[Starting User] " + startClient); startClient.start(mClientFinishedCallback); } else { - final BaseClientMonitor stopClient = mUserSwitchCallback - .getStopUserClient(currentUserId); - Slog.d(getTag(), "[Stopping User] current: " + currentUserId - + ", next: " + nextUserId + ". " + stopClient); - stopClient.start(mClientFinishedCallback); + if (mStopUserClient != null) { + Slog.d(getTag(), "[Waiting for StopUser] " + mStopUserClient); + } else { + mStopUserClient = mUserSwitchCallback + .getStopUserClient(currentUserId); + Slog.d(getTag(), "[Stopping User] current: " + currentUserId + + ", next: " + nextUserId + ". " + mStopUserClient); + mStopUserClient.start(mClientFinishedCallback); + } + } + } + + public void onUserStopped() { + if (mStopUserClient == null) { + Slog.e(getTag(), "Unexpected onUserStopped"); + return; } + + Slog.d(getTag(), "[OnUserStopped]: " + mStopUserClient); + mStopUserClient.onUserStopped(); + mStopUserClient = null; } } diff --git a/services/core/java/com/android/server/biometrics/sensors/face/aidl/Sensor.java b/services/core/java/com/android/server/biometrics/sensors/face/aidl/Sensor.java index 4baf95206374..768f464517b9 100644 --- a/services/core/java/com/android/server/biometrics/sensors/face/aidl/Sensor.java +++ b/services/core/java/com/android/server/biometrics/sensors/face/aidl/Sensor.java @@ -119,14 +119,14 @@ public class Sensor { @NonNull private final String mTag; @NonNull - private final BiometricScheduler mScheduler; + private final UserAwareBiometricScheduler mScheduler; private final int mSensorId; private final int mUserId; @NonNull private final Callback mCallback; HalSessionCallback(@NonNull Context context, @NonNull Handler handler, @NonNull String tag, - @NonNull BiometricScheduler scheduler, int sensorId, int userId, + @NonNull UserAwareBiometricScheduler scheduler, int sensorId, int userId, @NonNull Callback callback) { mContext = context; mHandler = handler; @@ -433,17 +433,7 @@ public class Sensor { @Override public void onSessionClosed() { - mHandler.post(() -> { - final BaseClientMonitor client = mScheduler.getCurrentClient(); - if (!(client instanceof FaceStopUserClient)) { - Slog.e(mTag, "onSessionClosed for wrong consumer: " - + Utils.getClientName(client)); - return; - } - - final FaceStopUserClient stopUserClient = (FaceStopUserClient) client; - stopUserClient.onUserStopped(); - }); + mHandler.post(mScheduler::onUserStopped); } } diff --git a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/Sensor.java b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/Sensor.java index 40ddfe91fbd0..cd12d02ceef2 100644 --- a/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/Sensor.java +++ b/services/core/java/com/android/server/biometrics/sensors/fingerprint/aidl/Sensor.java @@ -118,13 +118,13 @@ class Sensor { @NonNull private final Context mContext; @NonNull private final Handler mHandler; @NonNull private final String mTag; - @NonNull private final BiometricScheduler mScheduler; + @NonNull private final UserAwareBiometricScheduler mScheduler; private final int mSensorId; private final int mUserId; @NonNull private final Callback mCallback; HalSessionCallback(@NonNull Context context, @NonNull Handler handler, @NonNull String tag, - @NonNull BiometricScheduler scheduler, int sensorId, int userId, + @NonNull UserAwareBiometricScheduler scheduler, int sensorId, int userId, @NonNull Callback callback) { mContext = context; mHandler = handler; @@ -412,17 +412,7 @@ class Sensor { @Override public void onSessionClosed() { - mHandler.post(() -> { - final BaseClientMonitor client = mScheduler.getCurrentClient(); - if (!(client instanceof FingerprintStopUserClient)) { - Slog.e(mTag, "onSessionClosed for wrong consumer: " - + Utils.getClientName(client)); - return; - } - - final FingerprintStopUserClient stopUserClient = (FingerprintStopUserClient) client; - stopUserClient.onUserStopped(); - }); + mHandler.post(mScheduler::onUserStopped); } } |