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

Commit ed20a8a5 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
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
parents 74e9e231 4b33b471
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)