@Test public void unpackerExtractsInteropCallbacks() { ImageCaptureConfig.Builder imageCaptureConfigBuilder = new ImageCaptureConfig.Builder(); CaptureCallback captureCallback = mock(CaptureCallback.class); CameraDevice.StateCallback deviceCallback = mock(CameraDevice.StateCallback.class); CameraCaptureSession.StateCallback sessionStateCallback = mock(CameraCaptureSession.StateCallback.class); CameraEventCallbacks cameraEventCallbacks = mock(CameraEventCallbacks.class); when(cameraEventCallbacks.clone()).thenReturn(cameraEventCallbacks); new Camera2Config.Extender(imageCaptureConfigBuilder) .setSessionCaptureCallback(captureCallback) .setDeviceStateCallback(deviceCallback) .setSessionStateCallback(sessionStateCallback) .setCameraEventCallback(cameraEventCallbacks); SessionConfig.Builder sessionBuilder = new SessionConfig.Builder(); mUnpacker.unpack(imageCaptureConfigBuilder.build(), sessionBuilder); SessionConfig sessionConfig = sessionBuilder.build(); CameraCaptureCallback interopCallback = sessionConfig.getSingleCameraCaptureCallbacks().get(0); assertThat(((CaptureCallbackContainer) interopCallback).getCaptureCallback()) .isEqualTo(captureCallback); assertThat(sessionConfig.getSingleCameraCaptureCallbacks()) .containsExactly(interopCallback); assertThat(sessionConfig.getRepeatingCameraCaptureCallbacks()) .containsExactly(interopCallback); assertThat(sessionConfig.getDeviceStateCallbacks()).containsExactly(deviceCallback); assertThat(sessionConfig.getSessionStateCallbacks()) .containsExactly(sessionStateCallback); assertThat( new Camera2Config(sessionConfig.getImplementationOptions()).getCameraEventCallback( null)).isEqualTo(cameraEventCallbacks); }
@Override public void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder) { SessionConfig defaultSessionConfig = config.getDefaultSessionConfig( null); Config implOptions = OptionsBundle.emptyBundle(); int templateType = SessionConfig.defaultEmptySessionConfig().getTemplateType(); if (defaultSessionConfig != null) { templateType = defaultSessionConfig.getTemplateType(); builder.addAllDeviceStateCallbacks(defaultSessionConfig.getDeviceStateCallbacks()); builder.addAllSessionStateCallbacks(defaultSessionConfig.getSessionStateCallbacks()); builder.addAllRepeatingCameraCaptureCallbacks( defaultSessionConfig.getRepeatingCameraCaptureCallbacks()); implOptions = defaultSessionConfig.getImplementationOptions(); } builder.setImplementationOptions(implOptions); final Camera2Config camera2Config = new Camera2Config(config); builder.setTemplateType(camera2Config.getCaptureRequestTemplate(templateType)); builder.addDeviceStateCallback( camera2Config.getDeviceStateCallback( CameraDeviceStateCallbacks.createNoOpCallback())); builder.addSessionStateCallback( camera2Config.getSessionStateCallback( CameraCaptureSessionStateCallbacks.createNoOpCallback())); builder.addCameraCaptureCallback( CaptureCallbackContainer.create( camera2Config.getSessionCaptureCallback( Camera2CaptureCallbacks.createNoOpCallback()))); MutableOptionsBundle cameraEventConfig = MutableOptionsBundle.create(); cameraEventConfig.insertOption(Camera2Config.CAMERA_EVENT_CALLBACK_OPTION, camera2Config.getCameraEventCallback(CameraEventCallbacks.createEmptyCallback())); builder.addImplementationOptions(cameraEventConfig); Camera2Config.Builder configBuilder = new Camera2Config.Builder(); for (Option<?> option : camera2Config.getCaptureRequestOptions()) { @SuppressWarnings("unchecked") Option<Object> typeErasedOption = (Option<Object>) option; @SuppressWarnings("unchecked") CaptureRequest.Key<Object> key = (CaptureRequest.Key<Object>) option.getToken(); configBuilder.setCaptureRequestOption(key, camera2Config.retrieveOption(typeErasedOption)); } builder.addImplementationOptions(configBuilder.build()); }
Camera2SessionOptionUnpacker implements SessionConfig.OptionUnpacker { @Override public void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder) { SessionConfig defaultSessionConfig = config.getDefaultSessionConfig( null); Config implOptions = OptionsBundle.emptyBundle(); int templateType = SessionConfig.defaultEmptySessionConfig().getTemplateType(); if (defaultSessionConfig != null) { templateType = defaultSessionConfig.getTemplateType(); builder.addAllDeviceStateCallbacks(defaultSessionConfig.getDeviceStateCallbacks()); builder.addAllSessionStateCallbacks(defaultSessionConfig.getSessionStateCallbacks()); builder.addAllRepeatingCameraCaptureCallbacks( defaultSessionConfig.getRepeatingCameraCaptureCallbacks()); implOptions = defaultSessionConfig.getImplementationOptions(); } builder.setImplementationOptions(implOptions); final Camera2Config camera2Config = new Camera2Config(config); builder.setTemplateType(camera2Config.getCaptureRequestTemplate(templateType)); builder.addDeviceStateCallback( camera2Config.getDeviceStateCallback( CameraDeviceStateCallbacks.createNoOpCallback())); builder.addSessionStateCallback( camera2Config.getSessionStateCallback( CameraCaptureSessionStateCallbacks.createNoOpCallback())); builder.addCameraCaptureCallback( CaptureCallbackContainer.create( camera2Config.getSessionCaptureCallback( Camera2CaptureCallbacks.createNoOpCallback()))); MutableOptionsBundle cameraEventConfig = MutableOptionsBundle.create(); cameraEventConfig.insertOption(Camera2Config.CAMERA_EVENT_CALLBACK_OPTION, camera2Config.getCameraEventCallback(CameraEventCallbacks.createEmptyCallback())); builder.addImplementationOptions(cameraEventConfig); Camera2Config.Builder configBuilder = new Camera2Config.Builder(); for (Option<?> option : camera2Config.getCaptureRequestOptions()) { @SuppressWarnings("unchecked") Option<Object> typeErasedOption = (Option<Object>) option; @SuppressWarnings("unchecked") CaptureRequest.Key<Object> key = (CaptureRequest.Key<Object>) option.getToken(); configBuilder.setCaptureRequestOption(key, camera2Config.retrieveOption(typeErasedOption)); } builder.addImplementationOptions(configBuilder.build()); } }
Camera2SessionOptionUnpacker implements SessionConfig.OptionUnpacker { @Override public void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder) { SessionConfig defaultSessionConfig = config.getDefaultSessionConfig( null); Config implOptions = OptionsBundle.emptyBundle(); int templateType = SessionConfig.defaultEmptySessionConfig().getTemplateType(); if (defaultSessionConfig != null) { templateType = defaultSessionConfig.getTemplateType(); builder.addAllDeviceStateCallbacks(defaultSessionConfig.getDeviceStateCallbacks()); builder.addAllSessionStateCallbacks(defaultSessionConfig.getSessionStateCallbacks()); builder.addAllRepeatingCameraCaptureCallbacks( defaultSessionConfig.getRepeatingCameraCaptureCallbacks()); implOptions = defaultSessionConfig.getImplementationOptions(); } builder.setImplementationOptions(implOptions); final Camera2Config camera2Config = new Camera2Config(config); builder.setTemplateType(camera2Config.getCaptureRequestTemplate(templateType)); builder.addDeviceStateCallback( camera2Config.getDeviceStateCallback( CameraDeviceStateCallbacks.createNoOpCallback())); builder.addSessionStateCallback( camera2Config.getSessionStateCallback( CameraCaptureSessionStateCallbacks.createNoOpCallback())); builder.addCameraCaptureCallback( CaptureCallbackContainer.create( camera2Config.getSessionCaptureCallback( Camera2CaptureCallbacks.createNoOpCallback()))); MutableOptionsBundle cameraEventConfig = MutableOptionsBundle.create(); cameraEventConfig.insertOption(Camera2Config.CAMERA_EVENT_CALLBACK_OPTION, camera2Config.getCameraEventCallback(CameraEventCallbacks.createEmptyCallback())); builder.addImplementationOptions(cameraEventConfig); Camera2Config.Builder configBuilder = new Camera2Config.Builder(); for (Option<?> option : camera2Config.getCaptureRequestOptions()) { @SuppressWarnings("unchecked") Option<Object> typeErasedOption = (Option<Object>) option; @SuppressWarnings("unchecked") CaptureRequest.Key<Object> key = (CaptureRequest.Key<Object>) option.getToken(); configBuilder.setCaptureRequestOption(key, camera2Config.retrieveOption(typeErasedOption)); } builder.addImplementationOptions(configBuilder.build()); }  }
Camera2SessionOptionUnpacker implements SessionConfig.OptionUnpacker { @Override public void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder) { SessionConfig defaultSessionConfig = config.getDefaultSessionConfig( null); Config implOptions = OptionsBundle.emptyBundle(); int templateType = SessionConfig.defaultEmptySessionConfig().getTemplateType(); if (defaultSessionConfig != null) { templateType = defaultSessionConfig.getTemplateType(); builder.addAllDeviceStateCallbacks(defaultSessionConfig.getDeviceStateCallbacks()); builder.addAllSessionStateCallbacks(defaultSessionConfig.getSessionStateCallbacks()); builder.addAllRepeatingCameraCaptureCallbacks( defaultSessionConfig.getRepeatingCameraCaptureCallbacks()); implOptions = defaultSessionConfig.getImplementationOptions(); } builder.setImplementationOptions(implOptions); final Camera2Config camera2Config = new Camera2Config(config); builder.setTemplateType(camera2Config.getCaptureRequestTemplate(templateType)); builder.addDeviceStateCallback( camera2Config.getDeviceStateCallback( CameraDeviceStateCallbacks.createNoOpCallback())); builder.addSessionStateCallback( camera2Config.getSessionStateCallback( CameraCaptureSessionStateCallbacks.createNoOpCallback())); builder.addCameraCaptureCallback( CaptureCallbackContainer.create( camera2Config.getSessionCaptureCallback( Camera2CaptureCallbacks.createNoOpCallback()))); MutableOptionsBundle cameraEventConfig = MutableOptionsBundle.create(); cameraEventConfig.insertOption(Camera2Config.CAMERA_EVENT_CALLBACK_OPTION, camera2Config.getCameraEventCallback(CameraEventCallbacks.createEmptyCallback())); builder.addImplementationOptions(cameraEventConfig); Camera2Config.Builder configBuilder = new Camera2Config.Builder(); for (Option<?> option : camera2Config.getCaptureRequestOptions()) { @SuppressWarnings("unchecked") Option<Object> typeErasedOption = (Option<Object>) option; @SuppressWarnings("unchecked") CaptureRequest.Key<Object> key = (CaptureRequest.Key<Object>) option.getToken(); configBuilder.setCaptureRequestOption(key, camera2Config.retrieveOption(typeErasedOption)); } builder.addImplementationOptions(configBuilder.build()); }  @Override void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder); }
Camera2SessionOptionUnpacker implements SessionConfig.OptionUnpacker { @Override public void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder) { SessionConfig defaultSessionConfig = config.getDefaultSessionConfig( null); Config implOptions = OptionsBundle.emptyBundle(); int templateType = SessionConfig.defaultEmptySessionConfig().getTemplateType(); if (defaultSessionConfig != null) { templateType = defaultSessionConfig.getTemplateType(); builder.addAllDeviceStateCallbacks(defaultSessionConfig.getDeviceStateCallbacks()); builder.addAllSessionStateCallbacks(defaultSessionConfig.getSessionStateCallbacks()); builder.addAllRepeatingCameraCaptureCallbacks( defaultSessionConfig.getRepeatingCameraCaptureCallbacks()); implOptions = defaultSessionConfig.getImplementationOptions(); } builder.setImplementationOptions(implOptions); final Camera2Config camera2Config = new Camera2Config(config); builder.setTemplateType(camera2Config.getCaptureRequestTemplate(templateType)); builder.addDeviceStateCallback( camera2Config.getDeviceStateCallback( CameraDeviceStateCallbacks.createNoOpCallback())); builder.addSessionStateCallback( camera2Config.getSessionStateCallback( CameraCaptureSessionStateCallbacks.createNoOpCallback())); builder.addCameraCaptureCallback( CaptureCallbackContainer.create( camera2Config.getSessionCaptureCallback( Camera2CaptureCallbacks.createNoOpCallback()))); MutableOptionsBundle cameraEventConfig = MutableOptionsBundle.create(); cameraEventConfig.insertOption(Camera2Config.CAMERA_EVENT_CALLBACK_OPTION, camera2Config.getCameraEventCallback(CameraEventCallbacks.createEmptyCallback())); builder.addImplementationOptions(cameraEventConfig); Camera2Config.Builder configBuilder = new Camera2Config.Builder(); for (Option<?> option : camera2Config.getCaptureRequestOptions()) { @SuppressWarnings("unchecked") Option<Object> typeErasedOption = (Option<Object>) option; @SuppressWarnings("unchecked") CaptureRequest.Key<Object> key = (CaptureRequest.Key<Object>) option.getToken(); configBuilder.setCaptureRequestOption(key, camera2Config.retrieveOption(typeErasedOption)); } builder.addImplementationOptions(configBuilder.build()); }  @Override void unpack(UseCaseConfig<?> config, final SessionConfig.Builder builder);  }