diff options
| author | 2022-03-01 21:59:44 +0000 | |
|---|---|---|
| committer | 2022-03-01 21:59:44 +0000 | |
| commit | 3a2940c8193ccffc30abd0c67ea0773c3189db0c (patch) | |
| tree | 91651b34ec0a9edac864b2ca798eb93b181e1c94 | |
| parent | 697c991ab601d11867185a2284532531d8d5c1f6 (diff) | |
| parent | 22e4422cd2fbc94d620b283cc6a99240292ad835 (diff) | |
Merge "Fix an IllegalStateException in dream overlays." into tm-dev
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java | 19 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java | 21 |
2 files changed, 40 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java index 7e1fce298fbd..ebc766635733 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/DreamOverlayService.java @@ -19,6 +19,8 @@ package com.android.systemui.dreams; import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowInsets; import android.view.WindowManager; @@ -177,9 +179,26 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ } mDreamOverlayContainerViewController.init(); + // Make extra sure the container view has been removed from its old parent (otherwise we + // risk an IllegalStateException in some cases when setting the container view as the + // window's content view and the container view hasn't been properly removed previously). + removeContainerViewFromParent(); mWindow.setContentView(mDreamOverlayContainerViewController.getContainerView()); final WindowManager windowManager = mContext.getSystemService(WindowManager.class); windowManager.addView(mWindow.getDecorView(), mWindow.getAttributes()); } + + private void removeContainerViewFromParent() { + View containerView = mDreamOverlayContainerViewController.getContainerView(); + if (containerView == null) { + return; + } + ViewGroup parentView = (ViewGroup) containerView.getParent(); + if (parentView == null) { + return; + } + Log.w(TAG, "Removing dream overlay container view parent!"); + parentView.removeView(containerView); + } } 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 2860b50c2295..b3d54590dc99 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/DreamOverlayServiceTest.java @@ -28,6 +28,7 @@ import android.service.dreams.DreamService; import android.service.dreams.IDreamOverlay; import android.service.dreams.IDreamOverlayCallback; import android.testing.AndroidTestingRunner; +import android.view.ViewGroup; import android.view.WindowManager; import android.view.WindowManagerImpl; @@ -99,6 +100,9 @@ public class DreamOverlayServiceTest extends SysuiTestCase { @Mock DreamPreviewComplication mPreviewComplication; + @Mock + ViewGroup mDreamOverlayContainerViewParent; + DreamOverlayService mService; @Before @@ -152,6 +156,23 @@ public class DreamOverlayServiceTest extends SysuiTestCase { } @Test + public void testDreamOverlayContainerViewRemovedFromOldParentWhenInitialized() + throws Exception { + when(mDreamOverlayContainerView.getParent()) + .thenReturn(mDreamOverlayContainerViewParent) + .thenReturn(null); + + final IBinder proxy = mService.onBind(new Intent()); + final IDreamOverlay overlay = IDreamOverlay.Stub.asInterface(proxy); + + // Inform the overlay service of dream starting. + overlay.startDream(mWindowParams, mDreamOverlayCallback); + mMainExecutor.runAllReady(); + + verify(mDreamOverlayContainerViewParent).removeView(mDreamOverlayContainerView); + } + + @Test public void testShouldShowComplicationsFalseByDefault() { mService.onBind(new Intent()); |