@Test public void suggestedResolutionsForMixedUseCaseNotSupportedInLegacyDevice() { Rational aspectRatio = new Rational(16, 9); PreviewConfig.Builder previewConfigBuilder = new PreviewConfig.Builder(); VideoCaptureConfig.Builder videoCaptureConfigBuilder = new VideoCaptureConfig.Builder(); ImageCaptureConfig.Builder imageCaptureConfigBuilder = new ImageCaptureConfig.Builder(); previewConfigBuilder.setTargetAspectRatio(aspectRatio); videoCaptureConfigBuilder.setTargetAspectRatio(aspectRatio); imageCaptureConfigBuilder.setTargetAspectRatio(aspectRatio); imageCaptureConfigBuilder.setLensFacing(LensFacing.FRONT); ImageCapture imageCapture = new ImageCapture(imageCaptureConfigBuilder.build()); videoCaptureConfigBuilder.setLensFacing(LensFacing.FRONT); VideoCapture videoCapture = new VideoCapture(videoCaptureConfigBuilder.build()); previewConfigBuilder.setLensFacing(LensFacing.FRONT); Preview preview = new Preview(previewConfigBuilder.build()); List<UseCase> useCases = new ArrayList<>(); useCases.add(imageCapture); useCases.add(videoCapture); useCases.add(preview); boolean exceptionHappened = false; try { mSurfaceManager.getSuggestedResolutions(LEGACY_CAMERA_ID, null, useCases); } catch (IllegalArgumentException e) { exceptionHappened = true; } assertTrue(exceptionHappened); }
@Override public Map<UseCase, Size> getSuggestedResolutions( String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases) { if (newUseCases == null || newUseCases.isEmpty()) { throw new IllegalArgumentException("No new use cases to be bound."); } UseCaseSurfaceOccupancyManager.checkUseCaseLimitNotExceeded(originalUseCases, newUseCases); List<SurfaceConfig> surfaceConfigs = new ArrayList<>(); if (originalUseCases != null) { for (UseCase useCase : originalUseCases) { String useCaseCameraId = getCameraIdFromConfig(useCase.getUseCaseConfig()); Size resolution = useCase.getAttachedSurfaceResolution(useCaseCameraId); surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), resolution)); } } for (UseCase useCase : newUseCases) { surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), new Size(640, 480))); } SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null || !supportedSurfaceCombination.checkSupported(surfaceConfigs)) { throw new IllegalArgumentException( "No supported surface combination is found for camera device - Id : " + cameraId + ". May be attempting to bind too many use cases."); } return supportedSurfaceCombination.getSuggestedResolutions(originalUseCases, newUseCases); }
Camera2DeviceSurfaceManager implements CameraDeviceSurfaceManager { @Override public Map<UseCase, Size> getSuggestedResolutions( String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases) { if (newUseCases == null || newUseCases.isEmpty()) { throw new IllegalArgumentException("No new use cases to be bound."); } UseCaseSurfaceOccupancyManager.checkUseCaseLimitNotExceeded(originalUseCases, newUseCases); List<SurfaceConfig> surfaceConfigs = new ArrayList<>(); if (originalUseCases != null) { for (UseCase useCase : originalUseCases) { String useCaseCameraId = getCameraIdFromConfig(useCase.getUseCaseConfig()); Size resolution = useCase.getAttachedSurfaceResolution(useCaseCameraId); surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), resolution)); } } for (UseCase useCase : newUseCases) { surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), new Size(640, 480))); } SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null || !supportedSurfaceCombination.checkSupported(surfaceConfigs)) { throw new IllegalArgumentException( "No supported surface combination is found for camera device - Id : " + cameraId + ". May be attempting to bind too many use cases."); } return supportedSurfaceCombination.getSuggestedResolutions(originalUseCases, newUseCases); } }
Camera2DeviceSurfaceManager implements CameraDeviceSurfaceManager { @Override public Map<UseCase, Size> getSuggestedResolutions( String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases) { if (newUseCases == null || newUseCases.isEmpty()) { throw new IllegalArgumentException("No new use cases to be bound."); } UseCaseSurfaceOccupancyManager.checkUseCaseLimitNotExceeded(originalUseCases, newUseCases); List<SurfaceConfig> surfaceConfigs = new ArrayList<>(); if (originalUseCases != null) { for (UseCase useCase : originalUseCases) { String useCaseCameraId = getCameraIdFromConfig(useCase.getUseCaseConfig()); Size resolution = useCase.getAttachedSurfaceResolution(useCaseCameraId); surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), resolution)); } } for (UseCase useCase : newUseCases) { surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), new Size(640, 480))); } SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null || !supportedSurfaceCombination.checkSupported(surfaceConfigs)) { throw new IllegalArgumentException( "No supported surface combination is found for camera device - Id : " + cameraId + ". May be attempting to bind too many use cases."); } return supportedSurfaceCombination.getSuggestedResolutions(originalUseCases, newUseCases); } Camera2DeviceSurfaceManager(Context context); @VisibleForTesting  Camera2DeviceSurfaceManager(Context context, CamcorderProfileHelper camcorderProfileHelper); }
Camera2DeviceSurfaceManager implements CameraDeviceSurfaceManager { @Override public Map<UseCase, Size> getSuggestedResolutions( String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases) { if (newUseCases == null || newUseCases.isEmpty()) { throw new IllegalArgumentException("No new use cases to be bound."); } UseCaseSurfaceOccupancyManager.checkUseCaseLimitNotExceeded(originalUseCases, newUseCases); List<SurfaceConfig> surfaceConfigs = new ArrayList<>(); if (originalUseCases != null) { for (UseCase useCase : originalUseCases) { String useCaseCameraId = getCameraIdFromConfig(useCase.getUseCaseConfig()); Size resolution = useCase.getAttachedSurfaceResolution(useCaseCameraId); surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), resolution)); } } for (UseCase useCase : newUseCases) { surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), new Size(640, 480))); } SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null || !supportedSurfaceCombination.checkSupported(surfaceConfigs)) { throw new IllegalArgumentException( "No supported surface combination is found for camera device - Id : " + cameraId + ". May be attempting to bind too many use cases."); } return supportedSurfaceCombination.getSuggestedResolutions(originalUseCases, newUseCases); } 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); }
Camera2DeviceSurfaceManager implements CameraDeviceSurfaceManager { @Override public Map<UseCase, Size> getSuggestedResolutions( String cameraId, List<UseCase> originalUseCases, List<UseCase> newUseCases) { if (newUseCases == null || newUseCases.isEmpty()) { throw new IllegalArgumentException("No new use cases to be bound."); } UseCaseSurfaceOccupancyManager.checkUseCaseLimitNotExceeded(originalUseCases, newUseCases); List<SurfaceConfig> surfaceConfigs = new ArrayList<>(); if (originalUseCases != null) { for (UseCase useCase : originalUseCases) { String useCaseCameraId = getCameraIdFromConfig(useCase.getUseCaseConfig()); Size resolution = useCase.getAttachedSurfaceResolution(useCaseCameraId); surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), resolution)); } } for (UseCase useCase : newUseCases) { surfaceConfigs.add( transformSurfaceConfig(cameraId, useCase.getImageFormat(), new Size(640, 480))); } SupportedSurfaceCombination supportedSurfaceCombination = mCameraSupportedSurfaceCombinationMap.get(cameraId); if (supportedSurfaceCombination == null || !supportedSurfaceCombination.checkSupported(surfaceConfigs)) { throw new IllegalArgumentException( "No supported surface combination is found for camera device - Id : " + cameraId + ". May be attempting to bind too many use cases."); } return supportedSurfaceCombination.getSuggestedResolutions(originalUseCases, newUseCases); } 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);  }