From bfc555ea4a7c94d922cd605c85eecb90a7c6aa2d Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Fri, 29 Oct 2021 17:04:15 -0700 Subject: [PATCH] Pass Window to DreamOverlayService when attached. Previously, the DreamService would send the window attributes to the DreamOverlayService. However, it is possible that the Window isn't fully associated with a token at this stage. This change ensures the Window is only passed when the token is ready, tracked by when the DecorView is attached. Bug: 204605351 Test: atest DreamOverlayTest Change-Id: Ib1d25ba55edb648739aca22d861e9522102d0668 --- .../android/service/dreams/DreamService.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index 096595f30b05b..9e351691310d1 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -1173,6 +1173,16 @@ public class DreamService extends Service implements Window.Callback { @Override public void onViewAttachedToWindow(View v) { mDispatchAfterOnAttachedToWindow.run(); + + // Request the DreamOverlay be told to dream with dream's window parameters + // once the window has been attached. + mOverlayConnection.request(overlay -> { + try { + overlay.startDream(mWindow.getAttributes(), mOverlayCallback); + } catch (RemoteException e) { + Log.e(TAG, "could not send window attributes:" + e); + } + }); } @Override @@ -1185,16 +1195,6 @@ public class DreamService extends Service implements Window.Callback { } } }); - - // Request the DreamOverlay be told to dream with dream's window parameters once the service - // has connected. - mOverlayConnection.request(overlay -> { - try { - overlay.startDream(mWindow.getAttributes(), mOverlayCallback); - } catch (RemoteException e) { - Log.e(TAG, "could not send window attributes:" + e); - } - }); } private boolean getWindowFlagValue(int flag, boolean defaultValue) {