IMS-VT: Fix race condition issue of no preview during VT call.

Sometimes camera is enabled and immediately disabled due to
onUiShowing callback. Due to the camera capabilities query
during initial camera enable request, camera dimensions are
received while camera is in OFF state. This causes
mPreviewSurfaceState to be set to something other than NONE.
Next time when UI is resumed, and onUiShowing callback is
invoked, camera is not enabled since mPreviewSurfaceState is
not NONE. This causes camera to remain disabled during VT call.
To fix this, register to onUiShowing before onStateChange so
that back to back camera enable and disable is avoided.
Also if camera capabilities are received in camera OFF state,
don't update mPreviewSurfaceState variable.

Change-Id: I1ce18dbc5c1d5f6f5abaa8db7eb14012a59499a1
CRs-Fixed: 2036068
diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
index 0b61102..b715e2d 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -303,6 +303,7 @@
 
         // Register for surface and video events from {@link InCallVideoCallListener}s.
         InCallVideoCallCallbackNotifier.getInstance().addSurfaceChangeListener(this);
+        InCallUiStateNotifier.getInstance().addListener(this, true );
         mCurrentVideoState = VideoProfile.STATE_AUDIO_ONLY;
         mCurrentCallState = Call.State.INVALID;
 
@@ -311,7 +312,6 @@
         onStateChange(inCallState, inCallState, CallList.getInstance());
         InCallVideoCallCallbackNotifier.getInstance().addVideoEventListener(this,
                 VideoUtils.isVideoCall(mCurrentVideoState));
-        InCallUiStateNotifier.getInstance().addListener(this, true );
     }
 
     /**
@@ -1279,6 +1279,15 @@
             return;
         }
 
+        if (shallTransmitStaticImage()) {
+            setPauseImage();
+        }
+
+        if (mPreviewSurfaceState == PreviewSurfaceState.NONE) {
+            Log.w(this, "onCameraDimensionsChange: capabilities received when camera is OFF.");
+            return;
+        }
+
         mPreviewSurfaceState = PreviewSurfaceState.CAPABILITIES_RECEIVED;
         Point previewDimensions = ui.getPreviewSize();
 
@@ -1295,10 +1304,6 @@
         changePreviewDimensions(width, height);
         ui.setPreviewRotation(mDeviceOrientation);
 
-        if (shallTransmitStaticImage()) {
-            setPauseImage();
-        }
-
         // Check if the preview surface is ready yet; if it is, set it on the {@code VideoCall}.
         // If it not yet ready, it will be set when when creation completes.
         if (ui.isPreviewVideoSurfaceCreated()) {