Source:
public static Camera bindToLifecycle(@NonNull LifecycleOwner lifecycleOwner, @NonNull CameraSelector cameraSelector, @NonNull UseCase... useCases) { Threads.checkMainThread(); CameraX cameraX = checkInitialized(); UseCaseGroupLifecycleController useCaseGroupLifecycleController = cameraX.getOrCreateUseCaseGroup(lifecycleOwner); UseCaseGroup useCaseGroupToBind = useCaseGroupLifecycleController.getUseCaseGroup(); Collection<UseCaseGroupLifecycleController> controllers = cameraX.mUseCaseGroupRepository.getUseCaseGroups(); for (UseCase useCase : useCases) { for (UseCaseGroupLifecycleController controller : controllers) { UseCaseGroup useCaseGroup = controller.getUseCaseGroup(); if (useCaseGroup.contains(useCase) && useCaseGroup != useCaseGroupToBind) { throw new IllegalStateException( String.format( "Use case %s already bound to a different lifecycle.", useCase)); } } } CameraSelector.Builder selectorBuilder = CameraSelector.Builder.fromSelector(cameraSelector); for (UseCase useCase : useCases) { CameraSelector selector = useCase.getUseCaseConfig().getCameraSelector(null); if (selector != null) { for (CameraIdFilter filter : selector.getCameraFilterSet()) { if (filter instanceof LensFacingCameraIdFilter) { continue; } selectorBuilder.appendFilter(filter); } } } CameraSelector newCameraSelector = selectorBuilder.build(); String newCameraId = CameraX.getCameraWithCameraSelector(newCameraSelector); CameraInternal camera = cameraX.getCameraRepository().getCamera(newCameraId); for (UseCase useCase : useCases) { useCase.onBind(camera, newCameraSelector); } calculateSuggestedResolutions(lifecycleOwner, newCameraId, useCases); for (UseCase useCase : useCases) { useCaseGroupToBind.addUseCase(useCase); for (String cameraId : useCase.getAttachedCameraIds()) { attach(cameraId, useCase); } } useCaseGroupLifecycleController.notifyState(); return camera; }

Target:
public static Camera bindToLifecycle(@NonNull LifecycleOwner lifecycleOwner, @NonNull CameraSelector cameraSelector, @NonNull UseCase... useCases) { Threads.checkMainThread(); CameraX cameraX = checkInitialized(); UseCaseGroupLifecycleController useCaseGroupLifecycleController = cameraX.getOrCreateUseCaseGroup(lifecycleOwner); UseCaseGroup useCaseGroupToBind = useCaseGroupLifecycleController.getUseCaseGroup(); Collection<UseCaseGroupLifecycleController> controllers = cameraX.mUseCaseGroupRepository.getUseCaseGroups(); for (UseCase useCase : useCases) { for (UseCaseGroupLifecycleController controller : controllers) { UseCaseGroup useCaseGroup = controller.getUseCaseGroup(); if (useCaseGroup.contains(useCase) && useCaseGroup != useCaseGroupToBind) { throw new IllegalStateException( String.format( "Use case %s already bound to a different lifecycle.", useCase)); } } } CameraSelector.Builder selectorBuilder = CameraSelector.Builder.fromSelector(cameraSelector); for (UseCase useCase : useCases) { CameraSelector selector = useCase.getUseCaseConfig().getCameraSelector(null); if (selector != null) { for (CameraIdFilter filter : selector.getCameraFilterSet()) { if (filter instanceof LensFacingCameraIdFilter) { continue; } selectorBuilder.appendFilter(filter); } } } String newCameraId = CameraX.getCameraWithCameraSelector(selectorBuilder.build()); CameraInternal camera = cameraX.getCameraRepository().getCamera(newCameraId); for (UseCase useCase : useCases) { useCase.onBind(camera); } calculateSuggestedResolutions(lifecycleOwner, newCameraId, useCases); for (UseCase useCase : useCases) { useCaseGroupToBind.addUseCase(useCase); for (String cameraId : useCase.getAttachedCameraIds()) { attach(cameraId, useCase); } } useCaseGroupLifecycleController.notifyState(); return camera; }