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

Commit 2356b57f authored by Lucas Silva's avatar Lucas Silva Committed by Automerger Merge Worker
Browse files

Merge "Update UiModeManagerService to not trigger dreaming if dreams are...

Merge "Update UiModeManagerService to not trigger dreaming if dreams are suppressed." into tm-qpr-dev am: ed20a8a5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20208359



Change-Id: I777a14d0b435e036d99045f89849ffd6085e443b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5bb88cdf ed20a8a5
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)