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

Commit 4b33b471 authored by Lucas Silva's avatar Lucas Silva
Browse files

Update UiModeManagerService to not trigger dreaming if dreams are

suppressed.

Bug: 246472225
Test: atest UiModeManagerServiceTest
Test: flashed device and docked, verified we don't dream while
suppressed

Change-Id: I769fe08cf056d5fc2285cc667d491c153068eb42
parent cb69035c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -341,4 +341,10 @@ public abstract class PowerManagerInternal {
     * device is not awake.
     */
    public abstract void nap(long eventTime, boolean allowWake);

    /**
     * Returns true if ambient display is suppressed by any app with any token. This method will
     * return false if ambient display is not available.
     */
    public abstract boolean isAmbientDisplaySuppressed();
}
+16 −3
Original line number Diff line number Diff line
@@ -152,6 +152,8 @@ final class UiModeManagerService extends SystemService {

    // flag set by resource, whether to start dream immediately upon docking even if unlocked.
    private boolean mStartDreamImmediatelyOnDock = true;
    // flag set by resource, whether to disable dreams when ambient mode suppression is enabled.
    private boolean mDreamsDisabledByAmbientModeSuppression = false;
    // flag set by resource, whether to enable Car dock launch when starting car mode.
    private boolean mEnableCarDockLaunch = true;
    // flag set by resource, whether to lock UI mode to the default one or not.
@@ -364,6 +366,11 @@ final class UiModeManagerService extends SystemService {
        mStartDreamImmediatelyOnDock = startDreamImmediatelyOnDock;
    }

    @VisibleForTesting
    void setDreamsDisabledByAmbientModeSuppression(boolean disabledByAmbientModeSuppression) {
        mDreamsDisabledByAmbientModeSuppression = disabledByAmbientModeSuppression;
    }

    @Override
    public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) {
        mCurrentUser = to.getUserIdentifier();
@@ -424,6 +431,8 @@ final class UiModeManagerService extends SystemService {
        final Resources res = context.getResources();
        mStartDreamImmediatelyOnDock = res.getBoolean(
                com.android.internal.R.bool.config_startDreamImmediatelyOnDock);
        mDreamsDisabledByAmbientModeSuppression = res.getBoolean(
                com.android.internal.R.bool.config_dreamsDisabledByAmbientModeSuppressionConfig);
        mNightMode = res.getInteger(
                com.android.internal.R.integer.config_defaultNightMode);
        mDefaultUiModeType = res.getInteger(
@@ -1827,8 +1836,12 @@ final class UiModeManagerService extends SystemService {
        // Send the new configuration.
        applyConfigurationExternallyLocked();

        final boolean dreamsSuppressed = mDreamsDisabledByAmbientModeSuppression
                && mLocalPowerManager.isAmbientDisplaySuppressed();

        // If we did not start a dock app, then start dreaming if appropriate.
        if (category != null && !dockAppStarted && (mStartDreamImmediatelyOnDock
        if (category != null && !dockAppStarted && !dreamsSuppressed && (
                mStartDreamImmediatelyOnDock
                        || mWindowManager.isKeyguardShowingAndNotOccluded()
                        || !mPowerManager.isInteractive())) {
            mInjector.startDreamWhenDockedIfAppropriate(getContext());
+5 −0
Original line number Diff line number Diff line
@@ -6695,6 +6695,11 @@ public final class PowerManagerService extends SystemService
        public void nap(long eventTime, boolean allowWake) {
            napInternal(eventTime, Process.SYSTEM_UID, allowWake);
        }

        @Override
        public boolean isAmbientDisplaySuppressed() {
            return mAmbientDisplaySuppressionController.isSuppressed();
        }
    }

    /**
+33 −0
Original line number Diff line number Diff line
@@ -1371,6 +1371,39 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
        verify(mInjector).startDreamWhenDockedIfAppropriate(mContext);
    }

    @Test
    public void dreamWhenDocked_ambientModeSuppressed_suppressionEnabled() {
        mUiManagerService.setStartDreamImmediatelyOnDock(true);
        mUiManagerService.setDreamsDisabledByAmbientModeSuppression(true);

        when(mLocalPowerManager.isAmbientDisplaySuppressed()).thenReturn(true);
        triggerDockIntent();
        verifyAndSendResultBroadcast();
        verify(mInjector, never()).startDreamWhenDockedIfAppropriate(mContext);
    }

    @Test
    public void dreamWhenDocked_ambientModeSuppressed_suppressionDisabled() {
        mUiManagerService.setStartDreamImmediatelyOnDock(true);
        mUiManagerService.setDreamsDisabledByAmbientModeSuppression(false);

        when(mLocalPowerManager.isAmbientDisplaySuppressed()).thenReturn(true);
        triggerDockIntent();
        verifyAndSendResultBroadcast();
        verify(mInjector).startDreamWhenDockedIfAppropriate(mContext);
    }

    @Test
    public void dreamWhenDocked_ambientModeNotSuppressed_suppressionEnabled() {
        mUiManagerService.setStartDreamImmediatelyOnDock(true);
        mUiManagerService.setDreamsDisabledByAmbientModeSuppression(true);

        when(mLocalPowerManager.isAmbientDisplaySuppressed()).thenReturn(false);
        triggerDockIntent();
        verifyAndSendResultBroadcast();
        verify(mInjector).startDreamWhenDockedIfAppropriate(mContext);
    }

    private void triggerDockIntent() {
        final Intent dockedIntent =
                new Intent(Intent.ACTION_DOCK_EVENT)