merge in jb-mr2-zeroday-release history after reset to jb-mr2-dev
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java
index ed42de8..44af425 100644
--- a/src/com/android/camera/Util.java
+++ b/src/com/android/camera/Util.java
@@ -39,6 +39,7 @@
 import android.net.Uri;
 import android.os.Build;
 import android.os.ParcelFileDescriptor;
+import android.provider.Settings;
 import android.telephony.TelephonyManager;
 import android.util.DisplayMetrics;
 import android.util.FloatMath;
@@ -375,6 +376,11 @@
         return x;
     }
 
+    public static boolean systemRotationLocked(Activity activity) {
+        return Settings.System.getInt(activity.getContentResolver(),
+                Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
+    }
+
     public static int getDisplayRotation(Activity activity) {
         int rotation = activity.getWindowManager().getDefaultDisplay()
                 .getRotation();
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 2c654fc..2eb3d1b 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -583,6 +583,11 @@
                 // back to use SurfaceTexture for preview and we need to stop then start
                 // the preview. This will cause the preview flicker since the preview
                 // will not be continuous for a short period of time.
+
+                // Get orientation directly from display rotation to make sure it's up
+                // to date. OnConfigurationChanged callback usually kicks in a bit later, if
+                // device is rotated during recording.
+                mDisplayRotation = Util.getDisplayRotation(mActivity);
                 ((CameraScreenNail) mActivity.mCameraScreenNail).animateCapture(mDisplayRotation);
 
                 mUI.enablePreviewThumb(true);
@@ -1537,7 +1542,9 @@
         mUI.enableCameraControls(false);
 
         mMediaRecorderRecording = true;
-        mActivity.getOrientationManager().lockOrientation();
+        if (!Util.systemRotationLocked(mActivity)) {
+            mActivity.getOrientationManager().lockOrientation();
+        }
         mRecordingStartTime = SystemClock.uptimeMillis();
         mUI.showRecordingUI(true, mParameters.isZoomSupported());
 
@@ -1612,7 +1619,9 @@
                 fail = true;
             }
             mMediaRecorderRecording = false;
-            mActivity.getOrientationManager().unlockOrientation();
+            if (!Util.systemRotationLocked(mActivity)) {
+                mActivity.getOrientationManager().unlockOrientation();
+            }
 
             // If the activity is paused, this means activity is interrupted
             // during recording. Release the camera as soon as possible because