Re-add test for replacing surface during video playback.

Bug: 5189863
Change-Id: Ie2ddd90d5a6469bf7320b9585a38a9c48c1846d2
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index dd5edd7..f195786 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -102,6 +102,45 @@
         playVideoTest(R.raw.testvideo, 352, 288);
     }
 
+    /**
+     * Test for reseting a surface during video playback
+     * After reseting, the video should continue playing
+     * from the time setDisplay() was called
+     */
+    public void testVideoSurfaceResetting() throws Exception {
+        playVideoTest(R.raw.testvideo, 352, 288);
+
+        mMediaPlayer.start();
+        Thread.sleep(SLEEP_TIME);
+
+        int posBefore = mMediaPlayer.getCurrentPosition();
+        mMediaPlayer.setDisplay(getActivity().getSurfaceHolder2());
+        int posAfter = mMediaPlayer.getCurrentPosition();
+
+        assertEquals(posAfter, posBefore);
+        assertTrue(mMediaPlayer.isPlaying());
+
+        Thread.sleep(SLEEP_TIME);
+
+        posBefore = mMediaPlayer.getCurrentPosition();
+        mMediaPlayer.setDisplay(null);
+        posAfter = mMediaPlayer.getCurrentPosition();
+
+        assertEquals(posAfter, posBefore);
+        assertTrue(mMediaPlayer.isPlaying());
+
+        Thread.sleep(SLEEP_TIME);
+
+        posBefore = mMediaPlayer.getCurrentPosition();
+        mMediaPlayer.setDisplay(getActivity().generateSurfaceHolder());
+        posAfter = mMediaPlayer.getCurrentPosition();
+
+        assertEquals(posAfter, posBefore);
+        assertTrue(mMediaPlayer.isPlaying());
+
+        Thread.sleep(SLEEP_TIME);
+    }
+
     public void testLocalVideo_MP4_H264_480x360_500kbps_25fps_AAC_Stereo_128kbps_44110Hz()
             throws Exception {
         playVideoTest(