Fix an IllegalStateException in dream overlays.
Test: atest DreamOverlayServiceTest Bug: 219908617 Change-Id: Id4eb877def0d1633cdc544881ea254d0b00263ae
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -151,6 +155,23 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
||||
verify(mDreamOverlayContainerViewController).init();
|
||||
}
|
||||
|
||||
@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());
|
||||
|
||||
Reference in New Issue
Block a user