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

Commit 1761fce0 authored by Alex Salo's avatar Alex Salo
Browse files

Fix whenToCheck returned by AttentionDetector

There could be a situation in which updateUserActivity would not be
called within [dim_t-3s(attention_timeout), dim_t], in which case we
will miss the "bad" event. Fix that by returning the computed
whenToCheck value, which is nextScreenDimming-attention_timeout.

Test: manually with logging
Bug: 111939367
Change-Id: I66e4a1e86582afe06a277ba8dbb127583940ea19
parent a0d18b60
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ public class AttentionDetector {
            if (DEBUG) {
                Slog.d(TAG, "Do not check for attention yet, wait " + (whenToCheck - now));
            }
            return nextScreenDimming;
            return whenToCheck;
        } else if (whenToStopExtending < whenToCheck) {
            if (DEBUG) {
                Slog.d(TAG, "Let device sleep to avoid false results and improve security "
+9 −0
Original line number Diff line number Diff line
@@ -97,6 +97,15 @@ public class AttentionDetectorTest extends AndroidTestCase {
        verify(mAttentionManagerInternal, never()).checkAttention(anyInt(), anyLong(), any());
    }

    @Test
    public void testUpdateUserActivity_schedulesTheNextCheck() {
        long now = SystemClock.uptimeMillis();
        mNextDimming = now;
        mAttentionDetector.onUserActivity(now, PowerManager.USER_ACTIVITY_EVENT_TOUCH);
        long nextTimeout = mAttentionDetector.updateUserActivity(mNextDimming + 5000L);
        assertThat(nextTimeout).isEqualTo(mNextDimming + 5000L);
    }

    @Test
    public void testOnUserActivity_ignoresAfterMaximumExtension() {
        long now = SystemClock.uptimeMillis();