From 0da0eaff5aa17c5ec12e633a19c4ca11d3a35daa Mon Sep 17 00:00:00 2001 From: Joshua Mccloskey Date: Wed, 11 Aug 2021 16:45:46 -0700 Subject: Destroy() client after onClientFinished. Destroy() must be called from BaseClientMonitor in order for it to properly unlink to death from the binder token. For ex. 1. AuthenticationClient created. 2. AuthenticationClient linksToDeath on binder token. 3. client dies(settings or another application), long after the onClientFinished() method has been called. 4. AuthenticationClient.onBinderDied() is invoked. 5. Cancel() being invoked on a stale cancellation signal. Test: Verified that the destroy() signal is being sent after fp/face authentication clients. Test: atest FrameworksServicesTests Bug: 193883067 Change-Id: I780e8c3a42359df3c57b469a40c25a3113ee6fd7 --- .../biometrics/sensors/BaseClientMonitor.java | 1 - .../biometrics/sensors/BiometricScheduler.java | 1 + .../biometrics/sensors/BiometricSchedulerTest.java | 22 ++++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/biometrics/sensors/BaseClientMonitor.java b/services/core/java/com/android/server/biometrics/sensors/BaseClientMonitor.java index e5e1385fa605..3eb6f4ae48a2 100644 --- a/services/core/java/com/android/server/biometrics/sensors/BaseClientMonitor.java +++ b/services/core/java/com/android/server/biometrics/sensors/BaseClientMonitor.java @@ -206,7 +206,6 @@ public abstract class BaseClientMonitor extends LoggableMonitor } mToken = null; } - mListener = null; } @Override diff --git a/services/core/java/com/android/server/biometrics/sensors/BiometricScheduler.java b/services/core/java/com/android/server/biometrics/sensors/BiometricScheduler.java index b20316e4c6df..feb9e2a5b03f 100644 --- a/services/core/java/com/android/server/biometrics/sensors/BiometricScheduler.java +++ b/services/core/java/com/android/server/biometrics/sensors/BiometricScheduler.java @@ -295,6 +295,7 @@ public class BiometricScheduler { @Override public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, boolean success) { mHandler.post(() -> { + clientMonitor.destroy(); if (mCurrentOperation == null) { Slog.e(getTag(), "[Finishing] " + clientMonitor + " but current operation is null, success: " + success diff --git a/services/tests/servicestests/src/com/android/server/biometrics/sensors/BiometricSchedulerTest.java b/services/tests/servicestests/src/com/android/server/biometrics/sensors/BiometricSchedulerTest.java index 8592166aae15..47eed48e030a 100644 --- a/services/tests/servicestests/src/com/android/server/biometrics/sensors/BiometricSchedulerTest.java +++ b/services/tests/servicestests/src/com/android/server/biometrics/sensors/BiometricSchedulerTest.java @@ -348,6 +348,17 @@ public class BiometricSchedulerTest { verify((Interruptable) interruptableMonitor, never()).cancel(); } + @Test + public void testClientDestroyed_afterFinish() { + final HalClientMonitor.LazyDaemon nonNullDaemon = () -> mock(Object.class); + final TestClientMonitor client = + new TestClientMonitor(mContext, mToken, nonNullDaemon); + mScheduler.scheduleClientMonitor(client); + client.mCallback.onClientFinished(client, true /* success */); + waitForIdle(); + assertTrue(client.wasDestroyed()); + } + private BiometricSchedulerProto getDump(boolean clearSchedulerBuffer) throws Exception { return BiometricSchedulerProto.parseFrom(mScheduler.dumpProtoState(clearSchedulerBuffer)); } @@ -427,6 +438,7 @@ public class BiometricSchedulerTest { private static class TestClientMonitor extends HalClientMonitor { private boolean mUnableToStart; private boolean mStarted; + private boolean mDestroyed; public TestClientMonitor(@NonNull Context context, @NonNull IBinder token, @NonNull LazyDaemon lazyDaemon) { @@ -465,6 +477,11 @@ public class BiometricSchedulerTest { } + @Override + public void destroy() { + mDestroyed = true; + } + public boolean wasUnableToStart() { return mUnableToStart; } @@ -472,6 +489,11 @@ public class BiometricSchedulerTest { public boolean hasStarted() { return mStarted; } + + public boolean wasDestroyed() { + return mDestroyed; + } + } private static void waitForIdle() { -- cgit v1.2.3-59-g8ed1b