Search in sources :

Example 1 with EacPinStatus

use of org.openecard.sal.protocol.eac.gui.EacPinStatus in project open-ecard by ecsec.

the class EacNavigator method next.

@Override
public StepResult next() {
    // if cancel call has been issued, abort the whole process
    if (this.guiService.isCancelled()) {
        // prevent index out of bounds
        int i = idx == -1 ? 0 : idx > steps.size() ? steps.size() - 1 : idx;
        return new AndroidResult(steps.get(i), ResultStatus.CANCEL, Collections.EMPTY_LIST);
    }
    // handle step display
    if (idx == -1) {
        idx++;
        return new AndroidResult(steps.get(idx), ResultStatus.OK, Collections.EMPTY_LIST);
    } else if (idx == 0) {
        idx++;
        Step cvcStep = steps.get(0);
        Step chatStep = steps.get(1);
        try {
            this.guiService.loadValuesFromSteps(cvcStep, chatStep);
            List<OutputInfoUnit> outInfo = this.guiService.getSelection();
            return new AndroidResult(chatStep, ResultStatus.OK, outInfo);
        } catch (InterruptedException ex) {
            return new AndroidResult(chatStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else if (idx == 1) {
        idx++;
        Step pinStep = steps.get(2);
        if (pinFirstUse) {
            pinFirstUse = false;
        } else {
            this.guiService.setPinCorrect(false);
        }
        // get blocked status from dynamic context
        DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        EacPinStatus blockedStatus = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
        if (blockedStatus == EacPinStatus.BLOCKED || blockedStatus == EacPinStatus.DEACTIVATED) {
            this.guiService.sendPinStatus(blockedStatus);
            return new AndroidResult(pinStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
        // ask user for the pin
        try {
            List<OutputInfoUnit> outInfo = this.guiService.getPinResult(pinStep);
            writeBackValues(pinStep.getInputInfoUnits(), outInfo);
            return new AndroidResult(pinStep, ResultStatus.OK, outInfo);
        } catch (InterruptedException ex) {
            return new AndroidResult(pinStep, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else if (idx == 2) {
        idx++;
        Step s = steps.get(idx);
        // get blocked status from dynamic context
        DynamicContext ctx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        EacPinStatus blockedStatus = (EacPinStatus) ctx.get(EACProtocol.PIN_STATUS);
        if (blockedStatus == EacPinStatus.BLOCKED || blockedStatus == EacPinStatus.DEACTIVATED) {
            this.guiService.setPinCorrect(false);
            this.guiService.sendPinStatus(blockedStatus);
            return new AndroidResult(s, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
        if ("PROTOCOL_GUI_STEP_PROCESSING".equals(s.getID())) {
            this.guiService.setPinCorrect(true);
            return new AndroidResult(s, ResultStatus.OK, Collections.EMPTY_LIST);
        } else {
            this.guiService.setPinCorrect(false);
            return new AndroidResult(s, ResultStatus.CANCEL, Collections.EMPTY_LIST);
        }
    } else {
        Step s = steps.get(idx);
        idx++;
        return new AndroidResult(s, ResultStatus.OK, Collections.EMPTY_LIST);
    }
}
Also used : AndroidResult(org.openecard.gui.android.AndroidResult) ArrayList(java.util.ArrayList) List(java.util.List) OutputInfoUnit(org.openecard.gui.definition.OutputInfoUnit) Step(org.openecard.gui.definition.Step) EacPinStatus(org.openecard.sal.protocol.eac.gui.EacPinStatus) DynamicContext(org.openecard.common.DynamicContext)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 DynamicContext (org.openecard.common.DynamicContext)1 AndroidResult (org.openecard.gui.android.AndroidResult)1 OutputInfoUnit (org.openecard.gui.definition.OutputInfoUnit)1 Step (org.openecard.gui.definition.Step)1 EacPinStatus (org.openecard.sal.protocol.eac.gui.EacPinStatus)1