diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 3dbe437a6c434..acf0677559fd2 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -76,7 +76,7 @@ import static android.system.OsConstants.*; *
Starting from API level 14, this method can be called when preview is * active. * + *
Note: Before API level 24, the default value for orientation is 0. Starting in + * API level 24, the default orientation will be such that applications in forced-landscape mode + * will have correct preview orientation, which may be either a default of 0 or + * 180. Applications that operate in portrait mode or allow for changing orientation must still + * call this method after each orientation change to ensure correct preview display in all + * cases.
+ * * @param degrees the angle that the picture will be rotated clockwise. - * Valid values are 0, 90, 180, and 270. The starting - * position is 0 (landscape). + * Valid values are 0, 90, 180, and 270. * @see #setPreviewDisplay(SurfaceHolder) */ public native final void setDisplayOrientation(int degrees); diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index 806fcc3619a1c..91f003d59c464 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -567,6 +567,45 @@ static jint android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, // save context in opaque field env->SetLongField(thiz, fields.context, (jlong)context.get()); + + // Update default display orientation in case the sensor is reverse-landscape + CameraInfo cameraInfo; + status_t rc = Camera::getCameraInfo(cameraId, &cameraInfo); + if (rc != NO_ERROR) { + return rc; + } + int defaultOrientation = 0; + switch (cameraInfo.orientation) { + case 0: + break; + case 90: + if (cameraInfo.facing == CAMERA_FACING_FRONT) { + defaultOrientation = 180; + } + break; + case 180: + defaultOrientation = 180; + break; + case 270: + if (cameraInfo.facing != CAMERA_FACING_FRONT) { + defaultOrientation = 180; + } + break; + default: + ALOGE("Unexpected camera orientation %d!", cameraInfo.orientation); + break; + } + if (defaultOrientation != 0) { + ALOGV("Setting default display orientation to %d", defaultOrientation); + rc = camera->sendCommand(CAMERA_CMD_SET_DISPLAY_ORIENTATION, + defaultOrientation, 0); + if (rc != NO_ERROR) { + ALOGE("Unable to update default orientation: %s (%d)", + strerror(-rc), rc); + return rc; + } + } + return NO_ERROR; }