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

Commit 6a7cdb09 authored by Coco Duan's avatar Coco Duan
Browse files

Allow non-doze dreams to be windowless

Support wallpaper dream to be windowless and use
keyguard as the view. Transitions look alike AOD.
Add the logic to stop dreaming after unlocking
via bouncer.
Allow SystemUI dreams to be windowless.

Bug: b/285059232
Test: atest KeyguardViewMediatorTest; on device
Change-Id: I3348a7d9c8c437c87a8049d879209e620c80771d
parent 241b6944
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.service.dreams;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
@@ -630,7 +632,7 @@ public class DreamService extends Service implements Window.Callback {
    }

    /**
     * Marks this dream as windowless. Only available to doze dreams.
     * Marks this dream as windowless. It should be called in {@link #onCreate} method.
     *
     * @hide
     *
@@ -640,7 +642,7 @@ public class DreamService extends Service implements Window.Callback {
    }

    /**
     * Returns whether this dream is windowless. Only available to doze dreams.
     * Returns whether this dream is windowless.
     *
     * @hide
     */
@@ -1230,8 +1232,10 @@ public class DreamService extends Service implements Window.Callback {

        mDreamToken = dreamToken;
        mCanDoze = canDoze;
        if (mWindowless && !mCanDoze) {
            throw new IllegalStateException("Only doze dreams can be windowless");
        // This is not a security check to prevent malicious dreams but a guard rail to stop
        // third-party dreams from being windowless and not working well as a result.
        if (mWindowless && !mCanDoze && !isCallerSystemUi()) {
            throw new IllegalStateException("Only doze or SystemUI dreams can be windowless.");
        }

        mDispatchAfterOnAttachedToWindow = () -> {
@@ -1366,6 +1370,11 @@ public class DreamService extends Service implements Window.Callback {
        }
    }

    private boolean isCallerSystemUi() {
        return checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE)
                == PERMISSION_GRANTED;
    }

    private int applyFlags(int oldFlags, int flags, int mask) {
        return (oldFlags&~mask) | (flags&mask);
    }
+1 −1
Original line number Diff line number Diff line
@@ -2764,7 +2764,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,

            // It's possible that the device was unlocked (via BOUNCER or Fingerprint) while
            // dreaming. It's time to wake up.
            if (mDreamOverlayShowing) {
            if (mDreamOverlayShowing || mUpdateMonitor.isDreaming()) {
                mPM.wakeUp(mSystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
                        "com.android.systemui:UNLOCK_DREAMING");
            }
+22 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
@@ -318,6 +319,27 @@ public class KeyguardViewMediatorTest extends SysuiTestCase {
        assertFalse(mViewMediator.isAnimatingScreenOff());
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void wakeupFromDreamingWhenKeyguardHides() {
        mViewMediator.onSystemReady();
        TestableLooper.get(this).processAllMessages();

        // Given device is dreaming
        when(mUpdateMonitor.isDreaming()).thenReturn(true);

        // When keyguard is going away
        mKeyguardStateController.notifyKeyguardGoingAway(true);

        // And keyguard is disabled which will call #handleHide
        mViewMediator.setKeyguardEnabled(false);
        TestableLooper.get(this).processAllMessages();

        // Then dream should wake up
        verify(mPowerManager).wakeUp(anyLong(), anyInt(),
                eq("com.android.systemui:UNLOCK_DREAMING"));
    }

    @Test
    @TestableLooper.RunWithLooper(setAsMainLooper = true)
    public void restoreBouncerWhenSimLockedAndKeyguardIsGoingAway() {