CtsVerifier: Fix camera FOV activity in portrait mode.

The FOV activity assumes a horizontal orientation of the camera sensor,
which is no longer always the case as the activity now allows multiple
orientations. This patch uses the SENSOR_ORIENTATION key to determine
whether we should be querying the horizontal of vertical fov of the
camera.

Bug: 233336083
Test: Ran test on both front and back cameras in both orientations.
Change-Id: I271f502584580e1056fd7eaefa3dd4a95c69b3ce
(cherry picked from commit ca91d0ba62f33c7f9e4b33195ae53b060920b4d7)
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
index 406a305..481dabb 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/fov/PhotoCaptureActivity.java
@@ -183,8 +183,9 @@
                     SelectableResolution resolution = mSupportedResolutions.get(position);
                     switchToCamera(resolution, false);
 
-                    // It should be guaranteed that the FOV is correctly updated after setParameters().
-                    mReportedFovPrePictureTaken = mCamera.getParameters().getHorizontalViewAngle();
+                    // It should be guaranteed that the FOV is correctly updated after
+                    // setParameters().
+                    mReportedFovPrePictureTaken = getCameraFov(resolution.cameraId);
 
                     mResolutionSpinnerIndex = position;
                     startPreview();
@@ -271,8 +272,8 @@
     @Override
     public void onPictureTaken(byte[] data, Camera camera) {
         File pictureFile = getPictureFile(this);
-        Camera.Parameters params = mCamera.getParameters();
-        mReportedFovDegrees = params.getHorizontalViewAngle();
+
+        mReportedFovDegrees = getCameraFov(mSelectedResolution.cameraId);
 
         // Show error if FOV does not match the value reported before takePicture().
         if (mReportedFovPrePictureTaken != mReportedFovDegrees) {
@@ -561,21 +562,25 @@
         return result;
     }
 
+    private int getDisplayRotation() {
+        int displayRotation = getDisplay().getRotation();
+        int displayRotationDegrees = 0;
+        switch (displayRotation) {
+            case Surface.ROTATION_0: displayRotationDegrees = 0; break;
+            case Surface.ROTATION_90: displayRotationDegrees = 90; break;
+            case Surface.ROTATION_180: displayRotationDegrees = 180; break;
+            case Surface.ROTATION_270: displayRotationDegrees = 270; break;
+        }
+        return displayRotationDegrees;
+    }
+
     private void calculateOrientations(Activity activity,
             int cameraId, android.hardware.Camera camera) {
         android.hardware.Camera.CameraInfo info =
                 new android.hardware.Camera.CameraInfo();
         android.hardware.Camera.getCameraInfo(cameraId, info);
-        int rotation = activity.getWindowManager().getDefaultDisplay()
-                .getRotation();
-        int degrees = 0;
-        switch (rotation) {
-            case Surface.ROTATION_0: degrees = 0; break;
-            case Surface.ROTATION_90: degrees = 90; break;
-            case Surface.ROTATION_180: degrees = 180; break;
-            case Surface.ROTATION_270: degrees = 270; break;
-        }
 
+        int degrees = getDisplayRotation();
         if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
             mJpegOrientation = (info.orientation + degrees) % 360;
             mPreviewOrientation = (360 - mJpegOrientation) % 360;  // compensate the mirror
@@ -603,4 +608,12 @@
         }
         return false;
     }
+
+    private float getCameraFov(int cameraId) {
+        if (mPreviewOrientation == 0 || mPreviewOrientation == 180) {
+            return mCamera.getParameters().getHorizontalViewAngle();
+        } else {
+            return mCamera.getParameters().getVerticalViewAngle();
+        }
+    }
 }