Camera2DeviceSurfaceManager implements CameraDeviceSurfaceManager { @Nullable @Override public Rational getCorrectedAspectRatio(@NonNull UseCaseConfig<?> useCaseConfig) { if (!mIsInitialized) { throw new IllegalStateException("CameraDeviceSurfaceManager is not initialized."); } String cameraId = getCameraIdFromConfig(useCaseConfig); SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null) { throw new IllegalArgumentException( "Fail to find supported surface info - CameraId:" + cameraId); } return supportedSurfaceCombination.getCorrectedAspectRatio(useCaseConfig); } Camera2DeviceSurfaceManager(Context context); @VisibleForTesting  Camera2DeviceSurfaceManager(Context context, CamcorderProfileHelper camcorderProfileHelper); @Override boolean checkSupported(
            String cameraId, List<SurfaceConfig> surfaceConfigList); @Override SurfaceConfig transformSurfaceConfig(String cameraId, int imageFormat, Size size); @Override Map<UseCase, Size> getSuggestedResolutions(
            String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases); @Override Size getMaxOutputSize(String cameraId, int imageFormat); @Override Size getPreviewSize(); @Override boolean requiresCorrectedAspectRatio(@NonNull UseCaseConfig<?> useCaseConfig); @Nullable @Override Rational getCorrectedAspectRatio(@NonNull UseCaseConfig<?> useCaseConfig);  }
@Test public void checkPreviewAspectRatioInLegacyDevice() { SupportedSurfaceCombination supportedSurfaceCombination = new SupportedSurfaceCombination( mContext, LEGACY_CAMERA_ID, mMockCamcorderProfileHelper); Rational targetAspectRatio = new Rational(9, 16); PreviewConfig.Builder previewConfigBuilder = new PreviewConfig.Builder(); previewConfigBuilder.setTargetAspectRatio(targetAspectRatio); previewConfigBuilder.setLensFacing(LensFacing.FRONT); PreviewConfig previewConfig = previewConfigBuilder.build(); Rational resultAspectRatio = mSurfaceManager.getCorrectedAspectRatio(previewConfig); Size maxJpegSize = supportedSurfaceCombination.getMaxOutputSizeByFormat(ImageFormat.JPEG); Rational maxJpegAspectRatio = new Rational(maxJpegSize.getHeight(), maxJpegSize.getWidth()); if (Build.VERSION.SDK_INT == 21) { assertFalse(targetAspectRatio.equals(maxJpegAspectRatio)); assertTrue(resultAspectRatio.equals(maxJpegAspectRatio)); } else { assertThat(resultAspectRatio).isNull(); } }