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

Commit fce768e5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't check attention when in lockscreen" into qt-r1-dev

parents a1d096a7 49489768
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.util.StatsLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;
import com.android.server.wm.WindowManagerInternal;

import java.io.PrintWriter;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -101,6 +102,9 @@ public class AttentionDetector {
    @VisibleForTesting
    protected AttentionManagerInternal mAttentionManager;

    @VisibleForTesting
    protected WindowManagerInternal mWindowManager;

    @VisibleForTesting
    protected PackageManager mPackageManager;

@@ -142,6 +146,7 @@ public class AttentionDetector {
        mPackageManager = context.getPackageManager();
        mContentResolver = context.getContentResolver();
        mAttentionManager = LocalServices.getService(AttentionManagerInternal.class);
        mWindowManager = LocalServices.getService(WindowManagerInternal.class);
        mMaximumExtensionMillis = context.getResources().getInteger(
                com.android.internal.R.integer.config_attentionMaximumExtension);
        mMaxAttentionApiTimeoutMillis = context.getResources().getInteger(
@@ -165,14 +170,10 @@ public class AttentionDetector {
    }

    public long updateUserActivity(long nextScreenDimming) {
        if (nextScreenDimming == mLastActedOnNextScreenDimming) {
            return nextScreenDimming;
        }
        if (!mIsSettingEnabled) {
            return nextScreenDimming;
        }

        if (!isAttentionServiceSupported()) {
        if (nextScreenDimming == mLastActedOnNextScreenDimming
                || !mIsSettingEnabled
                || !isAttentionServiceSupported()
                || mWindowManager.isKeyguardShowingAndNotOccluded()) {
            return nextScreenDimming;
        }

+15 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.service.attention.AttentionService;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.wm.WindowManagerInternal;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,6 +59,8 @@ public class AttentionDetectorTest extends AndroidTestCase {
    @Mock
    private AttentionManagerInternal mAttentionManagerInternal;
    @Mock
    private WindowManagerInternal mWindowManagerInternal;
    @Mock
    private Runnable mOnUserAttention;
    private TestableAttentionDetector mAttentionDetector;
    private long mAttentionTimeout;
@@ -71,6 +75,7 @@ public class AttentionDetectorTest extends AndroidTestCase {
                PackageManager.PERMISSION_GRANTED);
        when(mAttentionManagerInternal.checkAttention(anyLong(), any()))
                .thenReturn(true);
        when(mWindowManagerInternal.isKeyguardShowingAndNotOccluded()).thenReturn(false);
        mAttentionDetector = new TestableAttentionDetector();
        mAttentionDetector.onWakefulnessChangeStarted(PowerManagerInternal.WAKEFULNESS_AWAKE);
        mAttentionDetector.setAttentionServiceSupported(true);
@@ -116,6 +121,15 @@ public class AttentionDetectorTest extends AndroidTestCase {
        assertThat(mNextDimming).isEqualTo(when);
    }

    @Test
    public void testOnUserActivity_doesntCheckIfInLockscreen() {
        when(mWindowManagerInternal.isKeyguardShowingAndNotOccluded()).thenReturn(true);

        long when = registerAttention();
        verify(mAttentionManagerInternal, never()).checkAttention(anyLong(), any());
        assertThat(mNextDimming).isEqualTo(when);
    }

    @Test
    public void testOnUserActivity_doesntCheckIfNotSufficientPermissions() {
        when(mPackageManager.checkPermission(any(), any())).thenReturn(
@@ -299,6 +313,7 @@ public class AttentionDetectorTest extends AndroidTestCase {
        TestableAttentionDetector() {
            super(AttentionDetectorTest.this.mOnUserAttention, new Object());
            mAttentionManager = mAttentionManagerInternal;
            mWindowManager = mWindowManagerInternal;
            mPackageManager = AttentionDetectorTest.this.mPackageManager;
            mContentResolver = getContext().getContentResolver();
            mMaximumExtensionMillis = 10000L;