Search in sources :

Example 1 with UserConsentNavigatorFactory

use of org.openecard.gui.android.UserConsentNavigatorFactory in project open-ecard by ecsec.

the class OpeneCardContext method initialize.

// /
// / Initialization & Shutdown
// /
void initialize() throws UnableToInitialize, NfcUnavailable, NfcDisabled, ApduExtLengthNotSupported {
    String errorMsg = SERVICE_RESPONSE_FAILED;
    if (initialized) {
        throw new UnableToInitialize(SERVICE_ALREADY_INITIALIZED);
    }
    if (appCtx == null) {
        throw new IllegalStateException(NO_APPLICATION_CONTEXT);
    }
    // initialize gui
    eacNavFac = new EacNavigatorFactory();
    List<UserConsentNavigatorFactory<?>> factories = Arrays.asList(eacNavFac, new InsertCardNavigatorFactory());
    gui = new AndroidUserConsent(factories);
    // set up nfc and android marshaller
    IFDProperties.setProperty(IFD_FACTORY_KEY, IFD_FACTORY_VALUE);
    WsdefProperties.setProperty(WSDEF_MARSHALLER_KEY, WSDEF_MARSHALLER_VALUE);
    NFCFactory.setContext(appCtx);
    try {
        boolean nfcAvailable = NFCFactory.isNFCAvailable();
        boolean nfcEnabled = NFCFactory.isNFCEnabled();
        boolean nfcExtendedLengthSupport = NfcUtils.supportsExtendedLength(appCtx);
        if (!nfcAvailable) {
            throw new NfcUnavailable();
        } else if (!nfcEnabled) {
            throw new NfcDisabled();
        } else if (!nfcExtendedLengthSupport) {
            throw new ApduExtLengthNotSupported(NFC_NO_EXTENDED_LENGTH_SUPPORT);
        }
        terminalFactory = IFDTerminalFactory.getInstance();
        LOG.info("Terminal factory initialized.");
    } catch (IFDException ex) {
        errorMsg = UNABLE_TO_INITIALIZE_TF;
        throw new UnableToInitialize(errorMsg, ex);
    }
    try {
        // set up client environment
        env = new ClientEnv();
        // set up dispatcher
        dispatcher = new MessageDispatcher(env);
        env.setDispatcher(dispatcher);
        LOG.info("Message Dispatcher initialized.");
        // set up management
        management = new TinyManagement(env);
        env.setManagement(management);
        LOG.info("Management initialized.");
        // set up event dispatcher
        eventDispatcher = new EventDispatcherImpl();
        env.setEventDispatcher(eventDispatcher);
        LOG.info("Event Dispatcher initialized.");
        // set up SALStateCallback
        cardStates = new CardStateMap();
        SALStateCallback salCallback = new SALStateCallback(env, cardStates);
        eventDispatcher.add(salCallback);
        // set up ifd
        ifd = new IFD();
        ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
        ifd.setGUI(gui);
        ifd.setEnvironment(env);
        env.setIFD(ifd);
        LOG.info("IFD initialized.");
        // set up card recognition
        try {
            recognition = new CardRecognitionImpl(env);
            recognition.setGUI(gui);
            env.setRecognition(recognition);
            LOG.info("CardRecognition initialized.");
        } catch (Exception ex) {
            errorMsg = CARD_REC_INIT_FAILED;
            throw ex;
        }
        // set up SAL
        TinySAL mainSAL = new TinySAL(env, cardStates);
        mainSAL.setGUI(gui);
        sal = new SelectorSAL(mainSAL, env);
        env.setSAL(sal);
        env.setCIFProvider(sal);
        LOG.info("SAL initialized.");
        ViewController viewController = new ViewController() {

            @Override
            public void showSettingsUI() {
            }

            @Override
            public void showDefaultViewUI() {
            }
        };
        // set up addon manager
        try {
            manager = new AddonManager(env, gui, cardStates, viewController, new ClasspathRegistry());
            mainSAL.setAddonManager(manager);
        } catch (Exception ex) {
            errorMsg = ADD_ON_INIT_FAILED;
            throw ex;
        }
        // Initialize the Event Dispatcher
        eventDispatcher.add(this, EventType.TERMINAL_ADDED, EventType.TERMINAL_REMOVED, EventType.CARD_INSERTED, EventType.CARD_RECOGNIZED, EventType.CARD_REMOVED);
        // start event dispatcher
        eventDispatcher.start();
        LOG.info("Event dispatcher started.");
        // initialize SAL
        try {
            WSHelper.checkResult(sal.initialize(new Initialize()));
        } catch (WSHelper.WSException ex) {
            errorMsg = ex.getMessage();
            throw ex;
        }
        // establish context
        try {
            EstablishContext establishContext = new EstablishContext();
            EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
            WSHelper.checkResult(establishContextResponse);
            contextHandle = establishContextResponse.getContextHandle();
            LOG.info("ContextHandle: {}", ByteUtils.toHexString(contextHandle));
        } catch (WSHelper.WSException ex) {
            errorMsg = ESTABLISH_IFD_CONTEXT_FAILED;
            throw ex;
        }
        initialized = true;
    } catch (Exception ex) {
        LOG.error(errorMsg, ex);
        throw new UnableToInitialize(errorMsg, ex);
    }
}
Also used : SALStateCallback(org.openecard.common.sal.state.SALStateCallback) EventDispatcherImpl(org.openecard.common.event.EventDispatcherImpl) IFD(org.openecard.ifd.scio.IFD) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) UnableToInitialize(org.openecard.android.ex.UnableToInitialize) Initialize(iso.std.iso_iec._24727.tech.schema.Initialize) NfcDisabled(org.openecard.android.ex.NfcDisabled) ClasspathRegistry(org.openecard.android.utils.ClasspathRegistry) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) EacNavigatorFactory(org.openecard.gui.android.EacNavigatorFactory) UserConsentNavigatorFactory(org.openecard.gui.android.UserConsentNavigatorFactory) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) TinySAL(org.openecard.sal.TinySAL) WSHelper(org.openecard.common.WSHelper) AndroidUserConsent(org.openecard.gui.android.AndroidUserConsent) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) PACEProtocolFactory(org.openecard.ifd.protocol.pace.PACEProtocolFactory) IFDException(org.openecard.ifd.scio.IFDException) ApduExtLengthNotSupported(org.openecard.android.ex.ApduExtLengthNotSupported) ClientEnv(org.openecard.common.ClientEnv) ViewController(org.openecard.gui.definition.ViewController) TinyManagement(org.openecard.management.TinyManagement) UnableToInitialize(org.openecard.android.ex.UnableToInitialize) IFDException(org.openecard.ifd.scio.IFDException) AddonManager(org.openecard.addon.AddonManager) InsertCardNavigatorFactory(org.openecard.gui.android.InsertCardNavigatorFactory) SelectorSAL(org.openecard.sal.SelectorSAL) NfcUnavailable(org.openecard.android.ex.NfcUnavailable)

Aggregations

EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)1 Initialize (iso.std.iso_iec._24727.tech.schema.Initialize)1 AddonManager (org.openecard.addon.AddonManager)1 ApduExtLengthNotSupported (org.openecard.android.ex.ApduExtLengthNotSupported)1 NfcDisabled (org.openecard.android.ex.NfcDisabled)1 NfcUnavailable (org.openecard.android.ex.NfcUnavailable)1 UnableToInitialize (org.openecard.android.ex.UnableToInitialize)1 ClasspathRegistry (org.openecard.android.utils.ClasspathRegistry)1 ClientEnv (org.openecard.common.ClientEnv)1 WSHelper (org.openecard.common.WSHelper)1 EventDispatcherImpl (org.openecard.common.event.EventDispatcherImpl)1 CardStateMap (org.openecard.common.sal.state.CardStateMap)1 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)1 AndroidUserConsent (org.openecard.gui.android.AndroidUserConsent)1 EacNavigatorFactory (org.openecard.gui.android.EacNavigatorFactory)1 InsertCardNavigatorFactory (org.openecard.gui.android.InsertCardNavigatorFactory)1 UserConsentNavigatorFactory (org.openecard.gui.android.UserConsentNavigatorFactory)1 ViewController (org.openecard.gui.definition.ViewController)1 PACEProtocolFactory (org.openecard.ifd.protocol.pace.PACEProtocolFactory)1