Camera: Only override rotate&crop for Camera2 clients

Legacy camera clients can and will use 'setDisplayOrientation'
to explicitly set a preview stream transformation depending on
the sensor orientation and the device rotation.
To maintain backward compatibility and honor the client
configuration, avoid overriding rotate&crop in case we have a
legacy client connection.
Additionally do not override rotate&crop for stream configurations
that include SurfaceView(HW_COMPOSER) outputs.

Test: Manual using camera application
Bug: 201005727
Change-Id: I3e32049bdd560724840780f96372c177ed2f4d20
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 8ce732f..5795dcf 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -1834,8 +1834,9 @@
         // Set rotate-and-crop override behavior
         if (mOverrideRotateAndCropMode != ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
             client->setRotateAndCropOverride(mOverrideRotateAndCropMode);
-        } else if (CameraServiceProxyWrapper::isRotateAndCropOverrideNeeded(clientPackageName,
-                    orientation, facing)) {
+        } else if ((effectiveApiLevel == API_2) &&
+                CameraServiceProxyWrapper::isRotateAndCropOverrideNeeded(clientPackageName,
+                        orientation, facing) ) {
             client->setRotateAndCropOverride(ANDROID_SCALER_ROTATE_AND_CROP_90);
         }
 
@@ -2211,7 +2212,7 @@
     for (auto& current : clients) {
         if (current != nullptr) {
             const auto basicClient = current->getValue();
-            if (basicClient.get() != nullptr) {
+            if (basicClient.get() != nullptr && basicClient->canCastToApiClient(API_2)) {
                 if (CameraServiceProxyWrapper::isRotateAndCropOverrideNeeded(
                             basicClient->getPackageName(), basicClient->getCameraOrientation(),
                             basicClient->getCameraFacing())) {