Loading core/java/android/service/dreams/DreamService.java +13 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 * Loading @@ -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 */ Loading Loading @@ -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 = () -> { Loading Loading @@ -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); } Loading packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +1 −1 Original line number Diff line number Diff line Loading @@ -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"); } Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading Loading
core/java/android/service/dreams/DreamService.java +13 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 * Loading @@ -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 */ Loading Loading @@ -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 = () -> { Loading Loading @@ -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); } Loading
packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +1 −1 Original line number Diff line number Diff line Loading @@ -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"); } Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +22 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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() { Loading