Merge "Unsubscribe from ALS events when UDFPS does not have an active touch." into sc-dev

This commit is contained in:
Joe Bolinger
2021-07-23 19:34:37 +00:00
committed by Android (Google) Code Review
9 changed files with 89 additions and 22 deletions

View File

@@ -48,6 +48,64 @@ public abstract class LoggableMonitor {
private boolean mLightSensorEnabled = false; private boolean mLightSensorEnabled = false;
private boolean mShouldLogMetrics = true; private boolean mShouldLogMetrics = true;
/**
* Probe for loggable attributes that can be continuously monitored, such as ambient light.
*
* Disable probes when the sensors are in states that are not interesting for monitoring
* purposes to save power.
*/
protected interface Probe {
/** Ensure the probe is actively sampling for new data. */
void enable();
/** Stop sampling data. */
void disable();
}
/**
* Client monitor callback that exposes a probe.
*
* Disables the probe when the operation completes.
*/
protected static class CallbackWithProbe<T extends Probe>
implements BaseClientMonitor.Callback {
private final boolean mStartWithClient;
private final T mProbe;
public CallbackWithProbe(@NonNull T probe, boolean startWithClient) {
mProbe = probe;
mStartWithClient = startWithClient;
}
@Override
public void onClientStarted(@NonNull BaseClientMonitor clientMonitor) {
if (mStartWithClient) {
mProbe.enable();
}
}
@Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor, boolean success) {
mProbe.disable();
}
@NonNull
public T getProbe() {
return mProbe;
}
}
private class ALSProbe implements Probe {
@Override
public void enable() {
setLightSensorLoggingEnabled(getAmbientLightSensor(mSensorManager));
}
@Override
public void disable() {
setLightSensorLoggingEnabled(null);
}
}
// report only the most recent value // report only the most recent value
// consider com.android.server.display.utils.AmbientFilter or similar if need arises // consider com.android.server.display.utils.AmbientFilter or similar if need arises
private volatile float mLastAmbientLux = 0; private volatile float mLastAmbientLux = 0;
@@ -285,21 +343,17 @@ public abstract class LoggableMonitor {
return latency; return latency;
} }
/** Get a callback to start/stop ALS capture when client runs. */ /**
* Get a callback to start/stop ALS capture when client runs.
*
* If the probe should not run for the entire operation, do not set startWithClient and
* start/stop the problem when needed.
*
* @param startWithClient if probe should start automatically when the operation starts.
*/
@NonNull @NonNull
protected BaseClientMonitor.Callback createALSCallback() { protected CallbackWithProbe<Probe> createALSCallback(boolean startWithClient) {
return new BaseClientMonitor.Callback() { return new CallbackWithProbe<>(new ALSProbe(), startWithClient);
@Override
public void onClientStarted(@NonNull BaseClientMonitor clientMonitor) {
setLightSensorLoggingEnabled(getAmbientLightSensor(mSensorManager));
}
@Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor,
boolean success) {
setLightSensorLoggingEnabled(null);
}
};
} }
/** The sensor to use for ALS logging. */ /** The sensor to use for ALS logging. */

View File

@@ -98,7 +98,7 @@ class FaceAuthenticationClient extends AuthenticationClient<ISession> implements
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override

View File

@@ -109,7 +109,8 @@ public class FaceEnrollClient extends EnrollClient<ISession> {
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(mPreviewHandleDeleterCallback, createALSCallback(), callback); return new CompositeCallback(mPreviewHandleDeleterCallback,
createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override

View File

@@ -88,7 +88,7 @@ class FaceAuthenticationClient extends AuthenticationClient<IBiometricsFace> {
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override

View File

@@ -69,7 +69,7 @@ public class FaceEnrollClient extends EnrollClient<IBiometricsFace> {
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override

View File

@@ -55,6 +55,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
@NonNull private final LockoutCache mLockoutCache; @NonNull private final LockoutCache mLockoutCache;
@Nullable private final IUdfpsOverlayController mUdfpsOverlayController; @Nullable private final IUdfpsOverlayController mUdfpsOverlayController;
@NonNull private final FingerprintSensorPropertiesInternal mSensorProps; @NonNull private final FingerprintSensorPropertiesInternal mSensorProps;
@NonNull private final CallbackWithProbe<Probe> mALSProbeCallback;
@Nullable private ICancellationSignal mCancellationSignal; @Nullable private ICancellationSignal mCancellationSignal;
private boolean mIsPointerDown; private boolean mIsPointerDown;
@@ -75,6 +76,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
mLockoutCache = lockoutCache; mLockoutCache = lockoutCache;
mUdfpsOverlayController = udfpsOverlayController; mUdfpsOverlayController = udfpsOverlayController;
mSensorProps = sensorProps; mSensorProps = sensorProps;
mALSProbeCallback = createALSCallback(false /* startWithClient */);
} }
@Override @Override
@@ -92,7 +94,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(mALSProbeCallback, callback);
} }
@Override @Override
@@ -170,7 +172,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
try { try {
mIsPointerDown = true; mIsPointerDown = true;
mState = STATE_STARTED; mState = STATE_STARTED;
mALSProbeCallback.getProbe().enable();
getFreshDaemon().onPointerDown(0 /* pointerId */, x, y, minor, major); getFreshDaemon().onPointerDown(0 /* pointerId */, x, y, minor, major);
if (getListener() != null) { if (getListener() != null) {
getListener().onUdfpsPointerDown(getSensorId()); getListener().onUdfpsPointerDown(getSensorId());
} }
@@ -184,7 +188,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
try { try {
mIsPointerDown = false; mIsPointerDown = false;
mState = STATE_STARTED_PAUSED; mState = STATE_STARTED_PAUSED;
mALSProbeCallback.getProbe().disable();
getFreshDaemon().onPointerUp(0 /* pointerId */); getFreshDaemon().onPointerUp(0 /* pointerId */);
if (getListener() != null) { if (getListener() != null) {
getListener().onUdfpsPointerUp(getSensorId()); getListener().onUdfpsPointerUp(getSensorId());
} }

View File

@@ -84,7 +84,7 @@ class FingerprintEnrollClient extends EnrollClient<ISession> implements Udfps {
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override

View File

@@ -54,6 +54,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<IBiometricsFi
private final LockoutFrameworkImpl mLockoutFrameworkImpl; private final LockoutFrameworkImpl mLockoutFrameworkImpl;
@Nullable private final IUdfpsOverlayController mUdfpsOverlayController; @Nullable private final IUdfpsOverlayController mUdfpsOverlayController;
@NonNull private final FingerprintSensorPropertiesInternal mSensorProps; @NonNull private final FingerprintSensorPropertiesInternal mSensorProps;
@NonNull private final CallbackWithProbe<Probe> mALSProbeCallback;
private boolean mIsPointerDown; private boolean mIsPointerDown;
@@ -74,6 +75,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<IBiometricsFi
mLockoutFrameworkImpl = lockoutTracker; mLockoutFrameworkImpl = lockoutTracker;
mUdfpsOverlayController = udfpsOverlayController; mUdfpsOverlayController = udfpsOverlayController;
mSensorProps = sensorProps; mSensorProps = sensorProps;
mALSProbeCallback = createALSCallback(false /* startWithClient */);
} }
@Override @Override
@@ -91,7 +93,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<IBiometricsFi
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(mALSProbeCallback, callback);
} }
@Override @Override
@@ -188,7 +190,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient<IBiometricsFi
public void onPointerDown(int x, int y, float minor, float major) { public void onPointerDown(int x, int y, float minor, float major) {
mIsPointerDown = true; mIsPointerDown = true;
mState = STATE_STARTED; mState = STATE_STARTED;
mALSProbeCallback.getProbe().enable();
UdfpsHelper.onFingerDown(getFreshDaemon(), x, y, minor, major); UdfpsHelper.onFingerDown(getFreshDaemon(), x, y, minor, major);
if (getListener() != null) { if (getListener() != null) {
try { try {
getListener().onUdfpsPointerDown(getSensorId()); getListener().onUdfpsPointerDown(getSensorId());
@@ -202,7 +206,9 @@ class FingerprintAuthenticationClient extends AuthenticationClient<IBiometricsFi
public void onPointerUp() { public void onPointerUp() {
mIsPointerDown = false; mIsPointerDown = false;
mState = STATE_STARTED_PAUSED; mState = STATE_STARTED_PAUSED;
mALSProbeCallback.getProbe().disable();
UdfpsHelper.onFingerUp(getFreshDaemon()); UdfpsHelper.onFingerUp(getFreshDaemon());
if (getListener() != null) { if (getListener() != null) {
try { try {
getListener().onUdfpsPointerUp(getSensorId()); getListener().onUdfpsPointerUp(getSensorId());

View File

@@ -77,7 +77,7 @@ public class FingerprintEnrollClient extends EnrollClient<IBiometricsFingerprint
@NonNull @NonNull
@Override @Override
protected Callback wrapCallbackForStart(@NonNull Callback callback) { protected Callback wrapCallbackForStart(@NonNull Callback callback) {
return new CompositeCallback(createALSCallback(), callback); return new CompositeCallback(createALSCallback(true /* startWithClient */), callback);
} }
@Override @Override