1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.camera; 18 19 import org.junit.Test; 20 import org.junit.runner.RunWith; 21 import org.junit.runners.JUnit4; 22 23 import static com.google.common.truth.Truth.assertThat; 24 25 import androidx.test.InstrumentationRegistry; 26 27 import android.content.Context; 28 import android.hardware.camera2.CameraCharacteristics; 29 import android.hardware.camera2.CameraMetadata; 30 import android.view.Display; 31 import android.view.Surface; 32 33 import java.util.Map; 34 35 @RunWith(JUnit4.class) 36 public class CameraServiceProxyTest { 37 38 @Test testGetCropRotateScale()39 public void testGetCropRotateScale() { 40 41 Context ctx = InstrumentationRegistry.getContext(); 42 43 // Check resizeability and SDK 44 CameraServiceProxy.TaskInfo taskInfo = new CameraServiceProxy.TaskInfo(); 45 taskInfo.isResizeable = true; 46 taskInfo.displayId = Display.DEFAULT_DISPLAY; 47 taskInfo.isFixedOrientationLandscape = false; 48 taskInfo.isFixedOrientationPortrait = true; 49 // Resizeable apps should be ignored 50 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 51 Surface.ROTATION_90 , CameraCharacteristics.LENS_FACING_BACK, 52 /*ignoreResizableAndSdkCheck*/false)).isEqualTo( 53 CameraMetadata.SCALER_ROTATE_AND_CROP_NONE); 54 // Resizeable apps will be considered in case the ignore flag is set 55 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 56 Surface.ROTATION_90, CameraCharacteristics.LENS_FACING_BACK, 57 /*ignoreResizableAndSdkCheck*/true)).isEqualTo( 58 CameraMetadata.SCALER_ROTATE_AND_CROP_90); 59 taskInfo.isResizeable = false; 60 // Non-resizeable apps should be considered 61 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 62 Surface.ROTATION_90, CameraCharacteristics.LENS_FACING_BACK, 63 /*ignoreResizableAndSdkCheck*/false)).isEqualTo( 64 CameraMetadata.SCALER_ROTATE_AND_CROP_90); 65 // The ignore flag for non-resizeable should have no effect 66 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 67 Surface.ROTATION_90, CameraCharacteristics.LENS_FACING_BACK, 68 /*ignoreResizableAndSdkCheck*/true)).isEqualTo( 69 CameraMetadata.SCALER_ROTATE_AND_CROP_90); 70 // Non-fixed orientation should be ignored 71 taskInfo.isFixedOrientationLandscape = false; 72 taskInfo.isFixedOrientationPortrait = false; 73 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 74 Surface.ROTATION_90, CameraCharacteristics.LENS_FACING_BACK, 75 /*ignoreResizableAndSdkCheck*/true)).isEqualTo( 76 CameraMetadata.SCALER_ROTATE_AND_CROP_NONE); 77 // Check rotation and lens facing combinations 78 Map<Integer, Integer> backFacingMap = Map.of( 79 Surface.ROTATION_0, CameraMetadata.SCALER_ROTATE_AND_CROP_NONE, 80 Surface.ROTATION_90, CameraMetadata.SCALER_ROTATE_AND_CROP_90, 81 Surface.ROTATION_270, CameraMetadata.SCALER_ROTATE_AND_CROP_270, 82 Surface.ROTATION_180, CameraMetadata.SCALER_ROTATE_AND_CROP_180); 83 taskInfo.isFixedOrientationPortrait = true; 84 backFacingMap.forEach((key, value) -> { 85 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 86 key, CameraCharacteristics.LENS_FACING_BACK, 87 /*ignoreResizableAndSdkCheck*/true)).isEqualTo(value); 88 }); 89 Map<Integer, Integer> frontFacingMap = Map.of( 90 Surface.ROTATION_0, CameraMetadata.SCALER_ROTATE_AND_CROP_NONE, 91 Surface.ROTATION_90, CameraMetadata.SCALER_ROTATE_AND_CROP_270, 92 Surface.ROTATION_270, CameraMetadata.SCALER_ROTATE_AND_CROP_90, 93 Surface.ROTATION_180, CameraMetadata.SCALER_ROTATE_AND_CROP_180); 94 frontFacingMap.forEach((key, value) -> { 95 assertThat(CameraServiceProxy.getCropRotateScale(ctx, ctx.getPackageName(), taskInfo, 96 key, CameraCharacteristics.LENS_FACING_FRONT, 97 /*ignoreResizableAndSdkCheck*/true)).isEqualTo(value); 98 }); 99 } 100 } 101