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

Commit 79379c19 authored by Brian Duddie's avatar Brian Duddie
Browse files

Move FaceDownDetector sensor config to background

Avoid slowing down main thread by posting sensor enable/disable
operations to the background thread.

Bug: 411515601
Test: FaceDownDetector can register/unregister sensors
Test: FaceDownDetector can detect face down and turn off display
Flag: EXEMPT bugfix
Change-Id: Ib68b1b24c3bd678068d0655a3cc30f9ae39588fa
parent 2f5a928e
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.provider.DeviceConfig;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.FrameworkStatsLog;

import java.io.PrintWriter;
@@ -205,12 +206,13 @@ public class FaceDownDetector implements SensorEventListener {
        final boolean shouldBeActive = mInteractive && mIsEnabled && !sawRecentInteraction;
        if (mActive != shouldBeActive) {
            if (shouldBeActive) {
                BackgroundThread.getHandler().post(() -> {
                    mSensorManager.registerListener(
                            this,
                            mAccelerometer,
                            SensorManager.SENSOR_DELAY_NORMAL,
                        mSensorMaxLatencyMicros
                );
                            mSensorMaxLatencyMicros);
                });
                if (mPreviousResultType == SCREEN_OFF_RESULT) {
                    logScreenOff();
                }
@@ -219,7 +221,9 @@ public class FaceDownDetector implements SensorEventListener {
                    mPreviousResultType = SCREEN_OFF_RESULT;
                    mPreviousResultTime = currentTime;
                }
                BackgroundThread.getHandler().post(() -> {
                    mSensorManager.unregisterListener(this);
                });
                mFaceDown = false;
                mOnFlip.accept(false);
            }