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

Commit 7704a745 authored by Lucas Silva's avatar Lucas Silva
Browse files

Implement hub mode user activity timeout

When communal is showing, the user activity timeout will follow the
user's chosen screen timeout.

Fixes: 308845444
Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Test: atest NotificationShadeWindowControllerImplTest
Test: changed screen timeout, opened communal hub, verified device
doesn't timeout after 10s and instead follows chosen screen timeout

Change-Id: Ie200fa135c8367f9d7d35128605602ae3b1a0825
parent 83b4fe61
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -262,6 +262,12 @@ constructor(
        }

    companion object {
        /**
         * The user activity timeout which should be used when the communal hub is opened. A value
         * of -1 means that the user's chosen screen timeout will be used instead.
         */
        const val AWAKE_INTERVAL_MS = -1

        /**
         * Calculates the content size dynamically based on the total number of contents of that
         * type.
+30 −7
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dumpable;
import com.android.systemui.biometrics.AuthController;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.communal.domain.interactor.CommunalInteractor;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
@@ -118,6 +119,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
    private final Lazy<SelectedUserInteractor> mUserInteractor;
    private final Lazy<ShadeInteractor> mShadeInteractorLazy;
    private final SceneContainerFlags mSceneContainerFlags;
    private final Lazy<CommunalInteractor> mCommunalInteractor;
    private ViewGroup mWindowRootView;
    private LayoutParams mLp;
    private boolean mHasTopUi;
@@ -165,7 +167,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
            ShadeWindowLogger logger,
            Lazy<SelectedUserInteractor> userInteractor,
            UserTracker userTracker,
            SceneContainerFlags sceneContainerFlags) {
            SceneContainerFlags sceneContainerFlags,
            Lazy<CommunalInteractor> communalInteractor) {
        mContext = context;
        mWindowRootViewComponentFactory = windowRootViewComponentFactory;
        mWindowManager = windowManager;
@@ -184,6 +187,7 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        mAuthController = authController;
        mUserInteractor = userInteractor;
        mSceneContainerFlags = sceneContainerFlags;
        mCommunalInteractor = communalInteractor;
        mLastKeyguardRotationAllowed = mKeyguardStateController.isKeyguardScreenRotationAllowed();
        mLockScreenDisplayTimeout = context.getResources()
                .getInteger(R.integer.config_lockScreenDisplayTimeout);
@@ -325,6 +329,11 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
                mShadeInteractorLazy.get().isQsExpanded(),
                this::onQsExpansionChanged
        );
        collectFlow(
                mWindowRootView,
                mCommunalInteractor.get().isCommunalShowing(),
                this::onCommunalShowingChanged
        );
    }

    @Override
@@ -501,15 +510,22 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
    }

    private void applyUserActivityTimeout(NotificationShadeWindowState state) {
        if (state.isKeyguardShowingAndNotOccluded()
        final Boolean communalShowing = state.isCommunalShowingAndNotOccluded();
        final Boolean keyguardShowing = state.isKeyguardShowingAndNotOccluded();
        long timeout = -1;
        if ((communalShowing || keyguardShowing)
                && state.statusBarState == StatusBarState.KEYGUARD
                && !state.qsExpanded) {
            mLpChanged.userActivityTimeout = state.bouncerShowing
                    ? KeyguardViewMediator.AWAKE_INTERVAL_BOUNCER_MS : mLockScreenDisplayTimeout;
        } else {
            mLpChanged.userActivityTimeout = -1;
            if (state.bouncerShowing) {
                timeout = KeyguardViewMediator.AWAKE_INTERVAL_BOUNCER_MS;
            } else if (communalShowing) {
                timeout = CommunalInteractor.AWAKE_INTERVAL_MS;
            } else if (keyguardShowing) {
                timeout = mLockScreenDisplayTimeout;
            }
        }
        mLpChanged.userActivityTimeout = timeout;
    }

    private void applyInputFeatures(NotificationShadeWindowState state) {
        if (state.isKeyguardShowingAndNotOccluded()
@@ -607,7 +623,8 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
                state.forcePluginOpen,
                state.dozing,
                state.scrimsVisibility,
                state.backgroundBlurRadius
                state.backgroundBlurRadius,
                state.communalShowing
        );
    }

@@ -731,6 +748,12 @@ public class NotificationShadeWindowControllerImpl implements NotificationShadeW
        apply(mCurrentState);
    }

    @VisibleForTesting
    void onCommunalShowingChanged(Boolean showing) {
        mCurrentState.communalShowing = showing;
        apply(mCurrentState);
    }

    @Override
    public void setForceUserActivity(boolean forceUserActivity) {
        mCurrentState.forceUserActivity = forceUserActivity;
+11 −2
Original line number Diff line number Diff line
@@ -58,12 +58,17 @@ class NotificationShadeWindowState(
    @JvmField var dreaming: Boolean = false,
    @JvmField var scrimsVisibility: Int = 0,
    @JvmField var backgroundBlurRadius: Int = 0,
    @JvmField var communalShowing: Boolean = false,
) {

    fun isKeyguardShowingAndNotOccluded(): Boolean {
        return keyguardShowing && !keyguardOccluded
    }

    fun isCommunalShowingAndNotOccluded(): Boolean {
        return communalShowing && !keyguardOccluded
    }

    /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */
    val asStringList: List<String> by lazy {
        listOf(
@@ -93,7 +98,8 @@ class NotificationShadeWindowState(
            forcePluginOpen.toString(),
            dozing.toString(),
            scrimsVisibility.toString(),
            backgroundBlurRadius.toString()
            backgroundBlurRadius.toString(),
            communalShowing.toString(),
        )
    }

@@ -134,6 +140,7 @@ class NotificationShadeWindowState(
            dozing: Boolean,
            scrimsVisibility: Int,
            backgroundBlurRadius: Int,
            communalShowing: Boolean,
        ) {
            buffer.advance().apply {
                this.keyguardShowing = keyguardShowing
@@ -165,6 +172,7 @@ class NotificationShadeWindowState(
                this.dozing = dozing
                this.scrimsVisibility = scrimsVisibility
                this.backgroundBlurRadius = backgroundBlurRadius
                this.communalShowing = communalShowing
            }
        }

@@ -209,7 +217,8 @@ class NotificationShadeWindowState(
                "forcePluginOpen",
                "dozing",
                "scrimsVisibility",
                "backgroundBlurRadius"
                "backgroundBlurRadius",
                "communalShowing"
            )
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ import com.android.systemui.flags.Flags;
import com.android.systemui.flags.SystemPropertiesHelper;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.ui.viewmodel.DreamingToLockscreenTransitionViewModel;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.scene.FakeWindowRootViewComponent;
@@ -150,6 +151,7 @@ import kotlinx.coroutines.test.TestScope;
@TestableLooper.RunWithLooper
@SmallTest
public class KeyguardViewMediatorTest extends SysuiTestCase {
    private final KosmosJavaAdapter mKosmos = new KosmosJavaAdapter(this);
    private KeyguardViewMediator mViewMediator;

    private final TestScope mTestScope = TestScopeProvider.getTestScope();
@@ -265,7 +267,8 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
                mShadeWindowLogger,
                () -> mSelectedUserInteractor,
                mUserTracker,
                mSceneContainerFlags);
                mSceneContainerFlags,
                mKosmos::getCommunalInteractor);
        mFeatureFlags = new FakeFeatureFlags();
        mFeatureFlags.set(Flags.KEYGUARD_WM_STATE_REFACTOR, false);
        mSetFlagsRule.enableFlags(FLAG_REFACTOR_GET_CURRENT_USER);
+20 −1
Original line number Diff line number Diff line
@@ -301,7 +301,8 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase {
                mShadeWindowLogger,
                () -> mSelectedUserInteractor,
                mUserTracker,
                mSceneContainerFlags) {
                mSceneContainerFlags,
                () -> communalInteractor) {
                    @Override
                    protected boolean isDebuggable() {
                        return false;
@@ -448,6 +449,24 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase {
        assertThat((mLayoutParameters.getValue().flags & FLAG_ALT_FOCUSABLE_IM) != 0).isTrue();
    }

    @Test
    public void setCommunalShowing_userTimeout() {
        setKeyguardShowing();
        clearInvocations(mWindowManager);

        mNotificationShadeWindowController.onCommunalShowingChanged(true);
        verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture());
        assertThat(mLayoutParameters.getValue().userActivityTimeout)
                .isEqualTo(CommunalInteractor.AWAKE_INTERVAL_MS);
        clearInvocations(mWindowManager);

        // Bouncer showing over communal overrides communal value
        mNotificationShadeWindowController.setBouncerShowing(true);
        verify(mWindowManager).updateViewLayout(any(), mLayoutParameters.capture());
        assertThat(mLayoutParameters.getValue().userActivityTimeout)
                .isEqualTo(KeyguardViewMediator.AWAKE_INTERVAL_BOUNCER_MS);
    }

    @Test
    public void setKeyguardShowing_notFocusable_byDefault() {
        mNotificationShadeWindowController.setKeyguardShowing(false);
Loading