Merge "Fix an IllegalStateException in dream overlays." into tm-dev am: 3a2940c819
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17037278 Change-Id: Ie2c0f26c26195169e2e05ffcd9a17062bfe6fe77
This commit is contained in:
@@ -19,6 +19,8 @@ package com.android.systemui.dreams;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -177,9 +179,26 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
mDreamOverlayContainerViewController.init();
|
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());
|
mWindow.setContentView(mDreamOverlayContainerViewController.getContainerView());
|
||||||
|
|
||||||
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
|
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
|
||||||
windowManager.addView(mWindow.getDecorView(), mWindow.getAttributes());
|
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.IDreamOverlay;
|
||||||
import android.service.dreams.IDreamOverlayCallback;
|
import android.service.dreams.IDreamOverlayCallback;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.WindowManagerImpl;
|
import android.view.WindowManagerImpl;
|
||||||
|
|
||||||
@@ -99,6 +100,9 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
DreamPreviewComplication mPreviewComplication;
|
DreamPreviewComplication mPreviewComplication;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ViewGroup mDreamOverlayContainerViewParent;
|
||||||
|
|
||||||
DreamOverlayService mService;
|
DreamOverlayService mService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -151,6 +155,23 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
|||||||
verify(mDreamOverlayContainerViewController).init();
|
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
|
@Test
|
||||||
public void testShouldShowComplicationsFalseByDefault() {
|
public void testShouldShowComplicationsFalseByDefault() {
|
||||||
mService.onBind(new Intent());
|
mService.onBind(new Intent());
|
||||||
|
|||||||
Reference in New Issue
Block a user