EncodeVirtualDisplayTest: avoid dangling reference to virtual display

In case doTestEncodeVirtual fails prematurely, the test releases the
virtual display while leaving the separate ColorSlideShow thread
running. If ColorSlideShow hasn't finished drawing frames, it will
attempt to draw on the already-removed virtual display, leading to
window manager crashes.

To fix this, we make sure the ColorSlideShow thread is finished before
releasing the virtual display.

This won't happen if the test shall pass in the first place, but when
such failures occur it will crash the test app and prevent all
subsequent test cases from being run.

Bug: 217787210
Test: atest android.media.cts.EncodeVirtualDisplayTest#testEncodeVirtualDisplay
Change-Id: I69a7249de93972c686688a35423b5cf6c32a6907
1 file changed