Avoid inline->fullscreen reload for html5 video.

Now when a user start inline play and then switch to full screen, there is no
reload any more.
Basically, we change mediaplayer as a static member, and detect possible
situation to skip the prepare work.

bug:5710646

Change-Id: Ida34cf2e919a6cc8e0d52cd1175d51b5f5d527f7
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index 5fa4bad..a17cb51 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -112,13 +112,14 @@
                 mBaseLayer = layer;
 
                 int currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
-                SurfaceTexture surfTexture = mHTML5VideoView.getSurfaceTexture(currentVideoLayerId);
+                SurfaceTexture surfTexture =
+                        HTML5VideoInline.getSurfaceTexture(currentVideoLayerId);
                 int textureName = mHTML5VideoView.getTextureName();
 
                 if (layer != 0 && surfTexture != null && currentVideoLayerId != -1) {
                     int playerState = mHTML5VideoView.getCurrentState();
                     if (mHTML5VideoView.getPlayerBuffering())
-                        playerState = HTML5VideoView.STATE_NOTPREPARED;
+                        playerState = HTML5VideoView.STATE_PREPARING;
                     boolean foundInTree = nativeSendSurfaceTexture(surfTexture,
                             layer, currentVideoLayerId, textureName,
                             playerState);
@@ -145,6 +146,7 @@
                 HTML5VideoViewProxy proxy, WebViewClassic webView) {
                 // Save the inline video info and inherit it in the full screen
                 int savePosition = 0;
+                boolean canSkipPrepare = false;
                 if (mHTML5VideoView != null) {
                     // We don't allow enter full screen mode while the previous
                     // full screen video hasn't finished yet.
@@ -156,15 +158,20 @@
                     // save the current position.
                     if (layerId == mHTML5VideoView.getVideoLayerId()) {
                         savePosition = mHTML5VideoView.getCurrentPosition();
+                        int playerState = mHTML5VideoView.getCurrentState();
+                        canSkipPrepare = (playerState == HTML5VideoView.STATE_PREPARING
+                                || playerState == HTML5VideoView.STATE_PREPARED
+                                || playerState == HTML5VideoView.STATE_PLAYING)
+                                && !mHTML5VideoView.isFullScreenMode();
                     }
-                    mHTML5VideoView.release();
+                    if (!canSkipPrepare) {
+                        mHTML5VideoView.reset();
+                    }
                 }
                 mHTML5VideoView = new HTML5VideoFullScreen(proxy.getContext(),
-                        layerId, savePosition);
+                        layerId, savePosition, canSkipPrepare);
                 mCurrentProxy = proxy;
-
                 mHTML5VideoView.setVideoURI(url, mCurrentProxy);
-
                 mHTML5VideoView.enterFullScreenVideoState(layerId, proxy, webView);
         }
 
@@ -217,8 +224,7 @@
                     if (!backFromFullScreenMode) {
                         mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
                     }
-                    // release the media player to avoid finalize error
-                    mHTML5VideoView.release();
+                    mHTML5VideoView.reset();
                 }
                 mCurrentProxy = proxy;
                 mHTML5VideoView = new HTML5VideoInline(videoLayerId, time);