Loading core/java/android/service/dreams/DreamService.java +54 −43 Original line number Diff line number Diff line Loading @@ -455,7 +455,7 @@ public class DreamService extends Service implements Window.Callback { // Simply wake up in the case the device is not locked. if (!keyguardManager.isKeyguardLocked()) { wakeUp(); wakeUp(false); return true; } Loading @@ -477,11 +477,11 @@ public class DreamService extends Service implements Window.Callback { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on keyEvent"); wakeUp(); wakeUp(false); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (mDebug) Slog.v(mTag, "Waking up on back key"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchKeyEvent(event); Loading @@ -492,7 +492,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchKeyShortcutEvent(KeyEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on keyShortcutEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchKeyShortcutEvent(event); Loading @@ -505,7 +505,7 @@ public class DreamService extends Service implements Window.Callback { // but finish()es on any other kind of activity if (!mInteractive && event.getActionMasked() == MotionEvent.ACTION_UP) { if (mDebug) Slog.v(mTag, "Waking up on touchEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchTouchEvent(event); Loading @@ -516,7 +516,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchTrackballEvent(MotionEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on trackballEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchTrackballEvent(event); Loading @@ -527,7 +527,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchGenericMotionEvent(MotionEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on genericMotionEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchGenericMotionEvent(event); Loading Loading @@ -925,7 +925,11 @@ public class DreamService extends Service implements Window.Callback { } } private synchronized void updateDoze() { /** * Updates doze state. Note that this must be called on the mHandler. */ private void updateDoze() { mHandler.post(() -> { if (mDreamToken == null) { Slog.w(mTag, "Updating doze without a dream token."); return; Loading @@ -951,6 +955,7 @@ public class DreamService extends Service implements Window.Callback { // system server died } } }); } /** Loading @@ -966,6 +971,7 @@ public class DreamService extends Service implements Window.Callback { */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public void stopDozing() { mHandler.post(() -> { if (mDozing) { mDozing = false; try { Loading @@ -974,6 +980,7 @@ public class DreamService extends Service implements Window.Callback { // system server died } } }); } /** Loading Loading @@ -1201,7 +1208,7 @@ public class DreamService extends Service implements Window.Callback { @Override public void onExitRequested() { // Simply finish dream when exit is requested. mHandler.post(() -> finish()); mHandler.post(() -> finishInternal()); } @Override Loading Loading @@ -1299,9 +1306,13 @@ public class DreamService extends Service implements Window.Callback { * </p> */ public final void finish() { mHandler.post(this::finishInternal); } private void finishInternal() { // If there is an active overlay connection, signal that the dream is ending before // continuing. Note that the overlay cannot rely on the unbound state, since another dream // might have bound to it in the meantime. // continuing. Note that the overlay cannot rely on the unbound state, since another // dream might have bound to it in the meantime. if (mOverlayConnection != null) { mOverlayConnection.addConsumer(overlay -> { try { Loading Loading @@ -1357,7 +1368,7 @@ public class DreamService extends Service implements Window.Callback { * </p> */ public final void wakeUp() { wakeUp(false); mHandler.post(()-> wakeUp(false)); } /** Loading Loading @@ -1559,7 +1570,7 @@ public class DreamService extends Service implements Window.Callback { if (mActivity != null && !mActivity.isFinishing()) { mActivity.finishAndRemoveTask(); } else { finish(); finishInternal(); } mDreamToken = null; Loading Loading @@ -1719,7 +1730,7 @@ public class DreamService extends Service implements Window.Callback { // the window reference in order to fully release the DreamActivity. mWindow = null; mActivity = null; finish(); finishInternal(); } if (mOverlayConnection != null && mDreamStartOverlayConsumer != null) { Loading services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java +1 −0 Original line number Diff line number Diff line Loading @@ -328,6 +328,7 @@ public class TestDreamEnvironment { case DREAM_STATE_STARTED -> startDream(); case DREAM_STATE_WOKEN -> wakeDream(); } mTestableLooper.processAllMessages(); } while (mCurrentDreamState < state); return true; Loading Loading
core/java/android/service/dreams/DreamService.java +54 −43 Original line number Diff line number Diff line Loading @@ -455,7 +455,7 @@ public class DreamService extends Service implements Window.Callback { // Simply wake up in the case the device is not locked. if (!keyguardManager.isKeyguardLocked()) { wakeUp(); wakeUp(false); return true; } Loading @@ -477,11 +477,11 @@ public class DreamService extends Service implements Window.Callback { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on keyEvent"); wakeUp(); wakeUp(false); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (mDebug) Slog.v(mTag, "Waking up on back key"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchKeyEvent(event); Loading @@ -492,7 +492,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchKeyShortcutEvent(KeyEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on keyShortcutEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchKeyShortcutEvent(event); Loading @@ -505,7 +505,7 @@ public class DreamService extends Service implements Window.Callback { // but finish()es on any other kind of activity if (!mInteractive && event.getActionMasked() == MotionEvent.ACTION_UP) { if (mDebug) Slog.v(mTag, "Waking up on touchEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchTouchEvent(event); Loading @@ -516,7 +516,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchTrackballEvent(MotionEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on trackballEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchTrackballEvent(event); Loading @@ -527,7 +527,7 @@ public class DreamService extends Service implements Window.Callback { public boolean dispatchGenericMotionEvent(MotionEvent event) { if (!mInteractive) { if (mDebug) Slog.v(mTag, "Waking up on genericMotionEvent"); wakeUp(); wakeUp(false); return true; } return mWindow.superDispatchGenericMotionEvent(event); Loading Loading @@ -925,7 +925,11 @@ public class DreamService extends Service implements Window.Callback { } } private synchronized void updateDoze() { /** * Updates doze state. Note that this must be called on the mHandler. */ private void updateDoze() { mHandler.post(() -> { if (mDreamToken == null) { Slog.w(mTag, "Updating doze without a dream token."); return; Loading @@ -951,6 +955,7 @@ public class DreamService extends Service implements Window.Callback { // system server died } } }); } /** Loading @@ -966,6 +971,7 @@ public class DreamService extends Service implements Window.Callback { */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) public void stopDozing() { mHandler.post(() -> { if (mDozing) { mDozing = false; try { Loading @@ -974,6 +980,7 @@ public class DreamService extends Service implements Window.Callback { // system server died } } }); } /** Loading Loading @@ -1201,7 +1208,7 @@ public class DreamService extends Service implements Window.Callback { @Override public void onExitRequested() { // Simply finish dream when exit is requested. mHandler.post(() -> finish()); mHandler.post(() -> finishInternal()); } @Override Loading Loading @@ -1299,9 +1306,13 @@ public class DreamService extends Service implements Window.Callback { * </p> */ public final void finish() { mHandler.post(this::finishInternal); } private void finishInternal() { // If there is an active overlay connection, signal that the dream is ending before // continuing. Note that the overlay cannot rely on the unbound state, since another dream // might have bound to it in the meantime. // continuing. Note that the overlay cannot rely on the unbound state, since another // dream might have bound to it in the meantime. if (mOverlayConnection != null) { mOverlayConnection.addConsumer(overlay -> { try { Loading Loading @@ -1357,7 +1368,7 @@ public class DreamService extends Service implements Window.Callback { * </p> */ public final void wakeUp() { wakeUp(false); mHandler.post(()-> wakeUp(false)); } /** Loading Loading @@ -1559,7 +1570,7 @@ public class DreamService extends Service implements Window.Callback { if (mActivity != null && !mActivity.isFinishing()) { mActivity.finishAndRemoveTask(); } else { finish(); finishInternal(); } mDreamToken = null; Loading Loading @@ -1719,7 +1730,7 @@ public class DreamService extends Service implements Window.Callback { // the window reference in order to fully release the DreamActivity. mWindow = null; mActivity = null; finish(); finishInternal(); } if (mOverlayConnection != null && mDreamStartOverlayConsumer != null) { Loading
services/tests/dreamservicetests/src/com/android/server/dreams/TestDreamEnvironment.java +1 −0 Original line number Diff line number Diff line Loading @@ -328,6 +328,7 @@ public class TestDreamEnvironment { case DREAM_STATE_STARTED -> startDream(); case DREAM_STATE_WOKEN -> wakeDream(); } mTestableLooper.processAllMessages(); } while (mCurrentDreamState < state); return true; Loading