DO NOT MERGE libcameraservice: Provide flag for overriding camera output to portrait.
Apps commonly do not handle landscape orientation cameras correctly. In
order to prevent stretching and rotation issues in these apps, this
patch adds a flag to override the behavior of these landscape cameras
to produce a portrait image instead by changing the SENSOR_ORIENTATION
reported by CameraCharacteristics and applying a 90 degree rotate and
crop.
Change-Id: I64ed52812326edc11f1cdb6bfbdbe75fcb8b1fb8
Bug: 250678880
Test: Ran on foldable device with several camera apps to verify behavior.
diff --git a/camera/CameraBase.cpp b/camera/CameraBase.cpp
index 24c9108..0a5bc12 100644
--- a/camera/CameraBase.cpp
+++ b/camera/CameraBase.cpp
@@ -23,6 +23,7 @@
#include <cutils/properties.h>
#include <android/hardware/ICameraService.h>
+#include <com/android/internal/compat/IPlatformCompatNative.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
@@ -161,7 +162,8 @@
template <typename TCam, typename TCamTraits>
sp<TCam> CameraBase<TCam, TCamTraits>::connect(int cameraId,
const String16& clientPackageName,
- int clientUid, int clientPid, int targetSdkVersion)
+ int clientUid, int clientPid, int targetSdkVersion,
+ bool overrideToPortrait)
{
ALOGV("%s: connect", __FUNCTION__);
sp<TCam> c = new TCam(cameraId);
@@ -171,8 +173,9 @@
binder::Status ret;
if (cs != nullptr) {
TCamConnectService fnConnectService = TCamTraits::fnConnectService;
+ ALOGI("Connect camera (legacy API) - overrideToPortrait %d", overrideToPortrait);
ret = (cs.get()->*fnConnectService)(cl, cameraId, clientPackageName, clientUid,
- clientPid, targetSdkVersion, /*out*/ &c->mCamera);
+ clientPid, targetSdkVersion, overrideToPortrait, /*out*/ &c->mCamera);
}
if (ret.isOk() && c->mCamera != nullptr) {
IInterface::asBinder(c->mCamera)->linkToDeath(c);
@@ -273,10 +276,11 @@
// this can be in BaseCamera but it should be an instance method
template <typename TCam, typename TCamTraits>
status_t CameraBase<TCam, TCamTraits>::getCameraInfo(int cameraId,
+ bool overrideToPortrait,
struct hardware::CameraInfo* cameraInfo) {
const sp<::android::hardware::ICameraService> cs = getCameraService();
if (cs == 0) return UNKNOWN_ERROR;
- binder::Status res = cs->getCameraInfo(cameraId, cameraInfo);
+ binder::Status res = cs->getCameraInfo(cameraId, overrideToPortrait, cameraInfo);
return res.isOk() ? OK : res.serviceSpecificErrorCode();
}