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

Commit d9cf18e3 authored by Roman Birg's avatar Roman Birg Committed by Gerrit Code Review
Browse files

DreamManager: be aware of device lid



If the device lid controls whether the screen goes to sleep, the
DreamManager (and so also DozeMode) should be aware and not try to
activate itself if the cover is closed.

Change-Id: Ie855a8a403548bcabbf1e0824e5cb128110066c2
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 363abfb8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34,4 +34,6 @@ interface IDreamManager {
    void finishSelf(in IBinder token, boolean immediate);
    void startDozing(in IBinder token, int screenState, int screenBrightness);
    void stopDozing(in IBinder token);
    void setLidState(int state);
    int getLidState();
}
+26 −17
Original line number Diff line number Diff line
@@ -6727,8 +6727,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {

    private void applyLidSwitchState() {
        mPowerManager.setKeyboardVisibility(isBuiltInKeyboardVisible());
        if (mLidControlsSleep) {
            IDreamManager dreamManager = getDreamManager();
            if (dreamManager != null) {
                try {
                    dreamManager.setLidState(mLidState);
                } catch (RemoteException e) {
                }
            }

        if (mLidState == LID_CLOSED && mLidControlsSleep) {
            if (mLidState == LID_CLOSED) {
                if (mFocusedWindow != null && (mFocusedWindow.getAttrs().flags
                        & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
                    // if an application requests that the screen be turned on
@@ -6750,6 +6758,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                updateWakeGestureListenerLp();
            }
        }
    }

    void updateUiMode() {
        if (mUiModeManager == null) {
+62 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.dreams;

import static android.Manifest.permission.BIND_DREAM_SERVICE;

import android.view.WindowManagerPolicy;
import com.android.internal.util.DumpUtils;
import com.android.server.FgThread;
import com.android.server.SystemService;
@@ -84,6 +85,7 @@ public final class DreamManagerService extends SystemService {
    private boolean mCurrentDreamIsWaking;
    private int mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN;
    private int mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
    private int mLidState = WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;

    public DreamManagerService(Context context) {
        super(context);
@@ -225,7 +227,8 @@ public final class DreamManagerService extends SystemService {
        }

        synchronized (mLock) {
            if (mCurrentDreamToken == token && mCurrentDreamCanDoze) {
            if (mCurrentDreamToken == token && mCurrentDreamCanDoze
                    && mLidState != WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED) {
                mCurrentDreamDozeScreenState = screenState;
                mCurrentDreamDozeScreenBrightness = screenBrightness;
                mPowerManagerInternal.setDozeOverrideFromDreamManager(
@@ -238,6 +241,40 @@ public final class DreamManagerService extends SystemService {
        }
    }

    private int getLidStateInternal() {
        return mLidState;
    }

    private void setLidStateInternal(int state) {
        synchronized (mLock) {
            mLidState = state;
        }
        switch (state) {
            case WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT:
                // do nothing
                break;
            case WindowManagerPolicy.WindowManagerFuncs.LID_OPEN:
                synchronized (mLock) {
                    mPowerManagerInternal.setDozeOverrideFromDreamManager(
                            Display.STATE_UNKNOWN, PowerManager.BRIGHTNESS_DEFAULT);
                }
                break;
            case WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED:
                // mimicing logic from stopDozingInternal(), stop any thing when the lid is closed.
                synchronized (mLock) {
                    if (mCurrentDreamIsDozing) {
                        mCurrentDreamIsDozing = false;
                        if (mDozeWakeLock.isHeld()) {
                            mDozeWakeLock.release();
                        }
                        mPowerManagerInternal.setDozeOverrideFromDreamManager(
                                Display.STATE_OFF, PowerManager.BRIGHTNESS_OFF);
                    }
                }
                break;
        }
    }

    private void stopDozingInternal(IBinder token) {
        if (DEBUG) {
            Slog.d(TAG, "Dream requested to stop dozing: " + token);
@@ -639,6 +676,30 @@ public final class DreamManagerService extends SystemService {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override
        public void setLidState(int lidState) {
            checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);

            final long ident = Binder.clearCallingIdentity();
            try {
                setLidStateInternal(lidState);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override
        public int getLidState() {
            checkPermission(Manifest.permission.READ_DREAM_STATE);

            final long ident = Binder.clearCallingIdentity();
            try {
                return getLidStateInternal();
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

    private final class LocalService extends DreamManagerInternal {