Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c36c208b authored by Joe Bolinger's avatar Joe Bolinger Committed by Automerger Merge Worker
Browse files

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

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15368653

Change-Id: I2475846e6301e40929c4111f3d955f5321e8e7ff
parents e5904e25 15a8430f
Loading
Loading
Loading
Loading
+68 −14
Original line number Diff line number Diff line
@@ -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. */
+1 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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
Loading