Unverified Commit 26fe44b9 authored by Neil Crossley's avatar Neil Crossley Committed by GitHub
Browse files

Merge pull request #24 from ecsec/eacgui-interruption

Eacgui interruption fixes.
parents e98fa125 b0d7357a
......@@ -302,8 +302,8 @@ public class PACEStep implements ProtocolStep<DIDAuthenticate, DIDAuthenticateRe
needsTermination = true;
}
}
// terminate activation thread
if (needsTermination) {
// terminate activation thread if it has not been interrupted already
if (needsTermination && guiResult != ResultStatus.INTERRUPTED) {
Thread actThread = (Thread) dynCtx2.get(TR03112Keys.ACTIVATION_THREAD);
if (actThread != null) {
LOG.debug("Interrupting activation thread.");
......@@ -399,6 +399,14 @@ public class PACEStep implements ProtocolStep<DIDAuthenticate, DIDAuthenticateRe
LOG.error(ex.getMessage(), ex);
response.setResult(WSHelper.makeResultError(ECardConstants.Minor.App.INCORRECT_PARM, ex.getMessage()));
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
dynCtx.put(EACProtocol.AUTHENTICATION_DONE, false);
Thread guiThread = (Thread) dynCtx.get(TR03112Keys.OPEN_USER_CONSENT_THREAD);
if (guiThread != null) {
guiThread.interrupt();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
response.setResult(WSHelper.makeResultUnknownError(e.getMessage()));
......
......@@ -42,7 +42,9 @@ import org.openecard.android.system.ServiceResponse;
import org.openecard.android.utils.NfcUtils;
import org.openecard.common.event.EventObject;
import org.openecard.common.event.EventType;
import org.openecard.common.event.IfdEventObject;
import org.openecard.common.interfaces.EventCallback;
import org.openecard.common.sal.state.CardStateEntry;
import org.openecard.common.util.CombinedPromise;
import org.openecard.common.util.Promise;
import org.openecard.gui.android.AndroidGui;
......@@ -144,6 +146,14 @@ public abstract class AbstractActivationHandler <T extends Activity, GUI extends
// add callback to this abstract activity when card is removed
cardRecognized = false;
// check card states for already inserted card and call recognised handler
CardStateEntry availableCard = getAvailableCard();
if (availableCard != null) {
insertionHandler.signalEvent(EventType.CARD_INSERTED, new IfdEventObject(availableCard.handleCopy()));
cardDetectHandler.signalEvent(EventType.RECOGNIZED_CARD_ACTIVE, new IfdEventObject(availableCard.handleCopy()));
}
octx.getEventDispatcher().add(insertionHandler, EventType.CARD_REMOVED, EventType.CARD_INSERTED);
octx.getEventDispatcher().add(cardDetectHandler, EventType.RECOGNIZED_CARD_ACTIVE);
octx.getEventDispatcher().add(removalHandler, EventType.CARD_REMOVED);
......@@ -168,6 +178,27 @@ public abstract class AbstractActivationHandler <T extends Activity, GUI extends
}
}
private CardStateEntry getAvailableCard() {
// look in card states for a card matching our criteria
Set<String> types = getSupportedCards();
if (types != null) {
for (String type : types) {
ConnectionHandleType query = new ConnectionHandleType();
ConnectionHandleType.RecognitionInfo rinfo = new ConnectionHandleType.RecognitionInfo();
rinfo.setCardType(type);
query.setRecognitionInfo(rinfo);
CardStateEntry entry = octx.getCardStates().getEntry(query);
if (entry != null) {
return entry;
}
}
return null;
} else {
return octx.getCardStates().getEntry(new ConnectionHandleType());
}
}
@Nullable
private Class<?> forClassName(@Nullable String className) {
if (className != null) {
......@@ -200,11 +231,7 @@ public abstract class AbstractActivationHandler <T extends Activity, GUI extends
public void onStop() {
// make sure nothing is running anymore
Thread at = authThread;
if (at != null) {
authThread = null; // prevent calling handler at all, we are shutting down
cancelAuthenticationInt(at, false, false);
}
cancelAuthenticationInt(authThread, false);
// remove callback which is set onStart
if (octx != null) {
......@@ -358,24 +385,24 @@ public abstract class AbstractActivationHandler <T extends Activity, GUI extends
@Override
public void cancelAuthentication(boolean runInThread) {
cancelAuthenticationInt(authThread, true, runInThread);
cancelAuthenticationInt(authThread, runInThread);
}
private void cancelAuthenticationInt(Thread at, boolean showFailure, boolean runInNewThread) {
private void cancelAuthenticationInt(Thread at, boolean runInNewThread) {
if (at != null) {
if (at == authThread) {
authThread = null;
}
// define function
Runnable fun = () -> {
try {
LOG.info("Stopping Authentication thread ...");
at.interrupt();
// cancel task and handle event
if (showFailure) {
String msg = "";
ActivationResult r = new ActivationResult(ActivationResultCode.INTERRUPTED, msg);
handleActivationResult(r);
}
String msg = "";
ActivationResult result = new ActivationResult(ActivationResultCode.INTERRUPTED, msg);
onAuthenticationInterrupted(result);
LOG.info("Stopping Authentication thread ...");
at.interrupt();
at.join();
LOG.info("Authentication thread has stopped.");
......
......@@ -56,13 +56,12 @@ public interface ActivationCallbackInterface <GUI extends AndroidGui> {
/**
* Callback for card removed events.
* This method can be used to directly see when a card gets removed from the system.
* <p>Causes for removal are either:
* <p>Causes for removal are either:</p>
* <ul>
* <li>User removed the card</li>
* <li>Card gets disconnected after a finished eID process</li>
* <li>Card is removed from the system due to an error</li>
* </ul>
* </p>
* <p>Given the various options why a card could have been removed, it is important to take the result of the
* eID process (cf. {@link #onAuthenticationSuccess(ActivationResult)} etc.) into consideration.</p>
*/
......
......@@ -146,7 +146,7 @@ public class EacGuiImpl implements EacGui {
@Override
public synchronized void cancel() {
LOG.debug("Cancel of Android EAC GUI called.", new Exception("Print Stacktrace"));
LOG.debug("Cancel of Android EAC GUI called.");
if (! cancelPromise.isDelivered() && ! cancelPromise.isCancelled()) {
cancelPromises(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment