diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java index 20ccacc49fc68..393f039d91eae 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java @@ -63,50 +63,52 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ private final DreamOverlayStateController.Callback mOverlayStateCallback = new DreamOverlayStateController.Callback() { - @Override - public void onOverlayChanged() { - mExecutor.execute(() -> reloadOverlaysLocked()); - } - }; + @Override + public void onOverlayChanged() { + mExecutor.execute(() -> reloadOverlaysLocked()); + } + }; // The service listens to view changes in order to declare that input occurring in areas outside // the overlay should be passed through to the dream underneath. - private View.OnAttachStateChangeListener mRootViewAttachListener = + private final View.OnAttachStateChangeListener mRootViewAttachListener = new View.OnAttachStateChangeListener() { - @Override - public void onViewAttachedToWindow(View v) { - v.getViewTreeObserver() - .addOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener); - } + @Override + public void onViewAttachedToWindow(View v) { + v.getViewTreeObserver() + .addOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener); + } - @Override - public void onViewDetachedFromWindow(View v) { - v.getViewTreeObserver() - .removeOnComputeInternalInsetsListener(mOnComputeInternalInsetsListener); - } - }; + @Override + public void onViewDetachedFromWindow(View v) { + v.getViewTreeObserver() + .removeOnComputeInternalInsetsListener( + mOnComputeInternalInsetsListener); + } + }; // A hook into the internal inset calculation where we declare the overlays as the only // touchable regions. - private ViewTreeObserver.OnComputeInternalInsetsListener mOnComputeInternalInsetsListener = + private final ViewTreeObserver.OnComputeInternalInsetsListener + mOnComputeInternalInsetsListener = new ViewTreeObserver.OnComputeInternalInsetsListener() { - @Override - public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) { - if (mDreamOverlayContentView != null) { - inoutInfo.setTouchableInsets( - ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION); - final Region region = new Region(); - for (int i = 0; i < mDreamOverlayContentView.getChildCount(); i++) { - View child = mDreamOverlayContentView.getChildAt(i); - final Rect rect = new Rect(); - child.getGlobalVisibleRect(rect); - region.op(rect, Region.Op.UNION); - } + @Override + public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) { + if (mDreamOverlayContentView != null) { + inoutInfo.setTouchableInsets( + ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION); + final Region region = new Region(); + for (int i = 0; i < mDreamOverlayContentView.getChildCount(); i++) { + View child = mDreamOverlayContentView.getChildAt(i); + final Rect rect = new Rect(); + child.getGlobalVisibleRect(rect); + region.op(rect, Region.Op.UNION); + } - inoutInfo.touchableRegion.set(region); - } - } - }; + inoutInfo.touchableRegion.set(region); + } + } + }; @Inject public DreamOverlayService( @@ -163,7 +165,9 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ } window.setContentView(mDreamOverlayComponent.getDreamOverlayContainerView()); + mDreamOverlayContentView = mDreamOverlayComponent.getDreamOverlayContentView(); + mDreamOverlayContentView.addOnAttachStateChangeListener(mRootViewAttachListener); mDreamOverlayComponent.getDreamOverlayStatusBarViewController().init(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java index d0ec3f36427ca..904ee91c26421 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java @@ -191,4 +191,20 @@ public class DreamOverlayServiceTest extends SysuiTestCase { verify(mDreamOverlayStatusBarViewController).init(); } + + @Test + public void testRootViewAttachListenerIsAddedToDreamOverlayContentView() throws Exception { + final DreamOverlayService service = new DreamOverlayService(mContext, mMainExecutor, + mDreamOverlayStateController, mDreamOverlayStatusBarViewComponentFactory); + + final IBinder proxy = service.onBind(new Intent()); + final IDreamOverlay overlay = IDreamOverlay.Stub.asInterface(proxy); + + // Inform the overlay service of dream starting. + overlay.startDream(mWindowParams, mDreamOverlayCallback); + mMainExecutor.runAllReady(); + + verify(mDreamOverlayContentView).addOnAttachStateChangeListener( + any(View.OnAttachStateChangeListener.class)); + } }