Unsubscribe from ALS events when UDFPS does not have an active touch.

Add probe interface for finer grained controll of data source sampling.

Bug: 194322934
Fix: 194504328
Test: manual (statsd_testdrive 88)
Change-Id: Ia55144fee642178d5aea81438dea8157c07e0b73
This commit is contained in:
Joe Bolinger
2021-07-22 22:09:07 -07:00
parent e10f0d4c6a
commit 659b4ee91a
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 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
// consider com.android.server.display.utils.AmbientFilter or similar if need arises
private volatile float mLastAmbientLux = 0;
@@ -285,21 +343,17 @@ public abstract class LoggableMonitor {
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
protected BaseClientMonitor.Callback createALSCallback() {
return new BaseClientMonitor.Callback() {
@Override
public void onClientStarted(@NonNull BaseClientMonitor clientMonitor) {
setLightSensorLoggingEnabled(getAmbientLightSensor(mSensorManager));
}
@Override
public void onClientFinished(@NonNull BaseClientMonitor clientMonitor,
boolean success) {
setLightSensorLoggingEnabled(null);
}
};
protected CallbackWithProbe<Probe> createALSCallback(boolean startWithClient) {
return new CallbackWithProbe<>(new ALSProbe(), startWithClient);
}
/** The sensor to use for ALS logging. */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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