Override front camera orientation for Camera1 & Camera2 APIs

Unfortunately the values that come from lower levels of the stack cause
the preview picture to be upside down in some cases. Force the
orientation so that the picture appears correct in all cases.

Unfortunately fixing this on lower levels hasn't been successful so the
solution in this layer has been chosen.

Issue: FP2A10-176
Change-Id: I4ec5e43ed2e160dd423152a4f078237fd851228c
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index c6e175d..d77fa29 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -39,6 +39,7 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.renderscript.Allocation;
 import android.renderscript.Element;
 import android.renderscript.RSIllegalArgumentException;
@@ -315,6 +316,16 @@
         } catch (RemoteException e) {
             Log.e(TAG, "Audio service is unavailable for queries");
         }
+
+        // Override camera orientation for front camera
+        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
+            String frontCamModule = SystemProperties.get("fp2.cam.front.sensor");
+            if (frontCamModule.equals("ov2685")) {
+                cameraInfo.orientation = 270;
+            } else if (frontCamModule.equals("ov5670")) {
+                cameraInfo.orientation = 90;
+            }
+        }
     }
     private native static void _getCameraInfo(int cameraId, CameraInfo cameraInfo);
 
diff --git a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
index 6953a5b..84962e4 100644
--- a/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
+++ b/core/java/android/hardware/camera2/legacy/LegacyMetadataMapper.java
@@ -34,6 +34,7 @@
 import android.hardware.camera2.utils.ArrayUtils;
 import android.hardware.camera2.utils.ListUtils;
 import android.hardware.camera2.utils.ParamsUtils;
+import android.os.SystemProperties;
 import android.util.Log;
 import android.util.Range;
 import android.util.Size;
@@ -173,6 +174,16 @@
         m.set(LENS_FACING, i.facing == CameraInfo.CAMERA_FACING_BACK ?
                 LENS_FACING_BACK : LENS_FACING_FRONT);
         m.set(SENSOR_ORIENTATION, i.orientation);
+
+        // Override camera orientation for front camera
+        if (i.facing == CameraInfo.CAMERA_FACING_FRONT) {
+            String frontCamModule = SystemProperties.get("fp2.cam.front.sensor");
+            if (frontCamModule.equals("ov2685")) {
+                m.set(SENSOR_ORIENTATION, 270);
+            } else if (frontCamModule.equals("ov5670")) {
+                m.set(SENSOR_ORIENTATION, 90);
+            }
+        }
     }
 
     private static void mapCharacteristicsFromParameters(CameraMetadataNative m,