Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
+ clean code (remov 'PO' from code)
+ Update MockSam variant fro keyple v2

Signed-off-by: Youssef Amrani <youssef.amrani@yamapps.fr>
  • Loading branch information
Yamapps committed Jul 30, 2021
1 parent 5db7117 commit 51815ad
Show file tree
Hide file tree
Showing 25 changed files with 505 additions and 290 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Mainly used to manage the lifecycle of the Keyple plugin.
This class is used to initialize the plugin and manage the card detection phase.
It is called on the different steps of the card reader activity lifecycle:
- onResume:
- Initialize the plugin (PO and SAM readers...)
- Initialize the plugin (Card and SAM readers...)
- Get the ticketing session
- Start NFC detection
- onPause:
Expand All @@ -295,8 +295,8 @@ The purpose of this class is to communicate with the card.

First it prepares the default selection that will be sent to the card when a card is detected by setting the AID(s) and the reader protocol(s) of the cards we want to detect and read.

Once a card is detected, the TicketingSession processes the default selection by retrieving the current CalypsoPO object.
This CalypsoPO contains information about the card (SerialNumber, PORevision...)
Once a card is detected, the TicketingSession processes the default selection by retrieving the current CalypsoCard object.
This CalypsoCard contains information about the card (SerialNumber, PORevision...)

Finally, this class is responsible for launching the control procedure and returning its result.

Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ dependencies {
famocoImplementation "org.eclipse.keyple:keyple-plugin-android-nfc-java-lib:$android_nfc_plugin_version"
famocoImplementation "org.calypsonet.keyple:keyple-plugin-cna-famoco-se-communication-java-lib:$famoco_plugin_version"


mockSamImplementation "org.eclipse.keyple:keyple-plugin-java-api:2.0.0-SNAPSHOT"
mockSamImplementation "org.eclipse.keyple:keyple-util-java-lib:2.0.0-SNAPSHOT"
mockSamImplementation "org.eclipse.keyple:keyple-common-java-api:2.0.0-SNAPSHOT"
mockSamImplementation "org.eclipse.keyple:keyple-plugin-android-nfc-java-lib:$android_nfc_plugin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.calypsonet.keyple.demo.validation.R
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.demo.validation.reader.PoReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.keyple.plugin.bluebird.BluebirdContactReader
import org.calypsonet.keyple.plugin.bluebird.BluebirdContactlessReader
import org.calypsonet.keyple.plugin.bluebird.BluebirdPlugin
Expand All @@ -43,7 +43,7 @@ class BluebirdReaderRepositoryImpl @Inject constructor(
private lateinit var successMedia: MediaPlayer
private lateinit var errorMedia: MediaPlayer

override var poReader: Reader? = null
override var cardReader: Reader? = null
override var samReaders: MutableList<Reader> = mutableListOf()

@Throws(KeyplePluginException::class)
Expand All @@ -65,25 +65,25 @@ class BluebirdReaderRepositoryImpl @Inject constructor(
SmartCardServiceProvider.getService().getPlugin(BluebirdPlugin.PLUGIN_NAME)

@Throws(KeyplePluginException::class)
override suspend fun initPoReader(): Reader {
override suspend fun initCardReader(): Reader {
val bluebirdPlugin =
SmartCardServiceProvider.getService().getPlugin(BluebirdPlugin.PLUGIN_NAME)
val poReader = bluebirdPlugin?.getReader(BluebirdContactlessReader.READER_NAME)
poReader?.let {
val cardReader = bluebirdPlugin?.getReader(BluebirdContactlessReader.READER_NAME)
cardReader?.let {

it.activateProtocol(
getContactlessIsoProtocol().readerProtocolName,
getContactlessIsoProtocol().applicationProtocolName
)

this.poReader = poReader
this.cardReader = cardReader
}

(poReader as ObservableReader).setReaderObservationExceptionHandler(
(cardReader as ObservableReader).setReaderObservationExceptionHandler(
readerObservationExceptionHandler
)

return poReader
return cardReader
}

@Throws(KeyplePluginException::class)
Expand Down Expand Up @@ -119,8 +119,8 @@ class BluebirdReaderRepositoryImpl @Inject constructor(
}
}

override fun getContactlessIsoProtocol(): PoReaderProtocol {
return PoReaderProtocol(
override fun getContactlessIsoProtocol(): CardReaderProtocol {
return CardReaderProtocol(
BluebirdSupportContactlessProtocols.NFC_ALL.key,
BluebirdSupportContactlessProtocols.NFC_ALL.key
)
Expand All @@ -132,7 +132,7 @@ class BluebirdReaderRepositoryImpl @Inject constructor(
override fun getSamRegex(): String = SAM_READER_NAME_REGEX

override fun clear() {
poReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
cardReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

samReaders.forEach {
it.deactivateProtocol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.calypsonet.keyple.demo.validation.R
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.demo.validation.reader.PoReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.keyple.plugin.coppernic.Cone2ContactReader
import org.calypsonet.keyple.plugin.coppernic.Cone2ContactlessReader
import org.calypsonet.keyple.plugin.coppernic.Cone2Plugin
Expand All @@ -47,7 +47,7 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
lateinit var successMedia: MediaPlayer
lateinit var errorMedia: MediaPlayer

override var poReader: Reader? = null
override var cardReader: Reader? = null
override var samReaders: MutableList<Reader> = mutableListOf()

@Throws(KeyplePluginException::class)
Expand All @@ -69,7 +69,7 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
override fun getPlugin(): Plugin = SmartCardServiceProvider.getService().getPlugin(Cone2Plugin.PLUGIN_NAME)

@Throws(KeyplePluginException::class)
override suspend fun initPoReader(): Reader? {
override suspend fun initCardReader(): Reader? {
val askPlugin =
SmartCardServiceProvider.getService().getPlugin(Cone2Plugin.PLUGIN_NAME)
val poReader = askPlugin?.getReader(Cone2ContactlessReader.READER_NAME)
Expand All @@ -84,7 +84,7 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
readerObservationExceptionHandler
)

this.poReader = poReader
this.cardReader = poReader
}

return poReader
Expand Down Expand Up @@ -123,8 +123,8 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
}
}

override fun getContactlessIsoProtocol(): PoReaderProtocol {
return PoReaderProtocol(
override fun getContactlessIsoProtocol(): CardReaderProtocol {
return CardReaderProtocol(
ParagonSupportedContactlessProtocols.ISO_14443.name,
ParagonSupportedContactlessProtocols.ISO_14443.name
)
Expand All @@ -137,7 +137,7 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
override fun getReaderConfiguratorSpi(): ReaderConfiguratorSpi = ReaderConfigurator()

override fun clear() {
poReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
cardReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

samReaders.forEach {
it.deactivateProtocol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import android.media.MediaPlayer
import javax.inject.Inject
import org.calypsonet.keyple.demo.validation.R
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.demo.validation.reader.PoReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoPlugin
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoPluginFactoryProvider
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoReader
Expand All @@ -43,7 +43,7 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
lateinit var successMedia: MediaPlayer
lateinit var errorMedia: MediaPlayer

override var poReader: Reader? = null
override var cardReader: Reader? = null
override var samReaders: MutableList<Reader> = mutableListOf()

@Throws(KeyplePluginException::class)
Expand All @@ -67,7 +67,7 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
SmartCardServiceProvider.getService().getPlugin(AndroidFamocoPlugin.PLUGIN_NAME)

@Throws(KeyplePluginException::class)
override suspend fun initPoReader(): Reader {
override suspend fun initCardReader(): Reader {
val readerPlugin =
SmartCardServiceProvider.getService().getPlugin(AndroidNfcPlugin.PLUGIN_NAME)
val poReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)
Expand All @@ -79,10 +79,10 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
getContactlessIsoProtocol().applicationProtocolName
)

this.poReader = poReader
this.cardReader = poReader
}

(poReader as org.eclipse.keyple.core.service.ObservableReader).setReaderObservationExceptionHandler(
(poReader as ObservableReader).setReaderObservationExceptionHandler(
readerObservationExceptionHandler
)

Expand Down Expand Up @@ -128,8 +128,8 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati

override fun getSamRegex(): String = SAM_READER_NAME_REGEX

override fun getContactlessIsoProtocol(): PoReaderProtocol {
return PoReaderProtocol(
override fun getContactlessIsoProtocol(): CardReaderProtocol {
return CardReaderProtocol(
ContactlessCardCommonProtocol.ISO_14443_4.name,
ContactlessCardCommonProtocol.ISO_14443_4.name
)
Expand All @@ -140,7 +140,7 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
}

override fun clear() {
poReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
cardReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

samReaders.forEach {
it.deactivateProtocol(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.demo.validation.reader.PoReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.keyple.plugin.flowbird.FlowbirdPlugin
import org.calypsonet.keyple.plugin.flowbird.FlowbirdPluginFactoryProvider
import org.calypsonet.keyple.plugin.flowbird.FlowbirdUiManager
Expand All @@ -39,7 +39,7 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
) :
IReaderRepository {

override var poReader: Reader? = null
override var cardReader: Reader? = null
override var samReaders: MutableList<Reader> = mutableListOf()

@Throws(KeyplePluginException::class)
Expand Down Expand Up @@ -72,7 +72,7 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
SmartCardServiceProvider.getService().getPlugin(FlowbirdPlugin.PLUGIN_NAME)

@Throws(KeyplePluginException::class)
override suspend fun initPoReader(): Reader {
override suspend fun initCardReader(): Reader {
val flowbirdPlugin =
SmartCardServiceProvider.getService().getPlugin(FlowbirdPlugin.PLUGIN_NAME)
val poReader = flowbirdPlugin?.getReader(FlowbirdContactlessReader.READER_NAME)
Expand All @@ -84,7 +84,7 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
getContactlessIsoProtocol().applicationProtocolName
)

this.poReader = poReader
this.cardReader = poReader
}

(poReader as ObservableReader).setReaderObservationExceptionHandler(
Expand Down Expand Up @@ -128,8 +128,8 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
}
}

override fun getContactlessIsoProtocol(): PoReaderProtocol {
return PoReaderProtocol(
override fun getContactlessIsoProtocol(): CardReaderProtocol {
return CardReaderProtocol(
FlowbirdSupportContactlessProtocols.ALL.key,
FlowbirdSupportContactlessProtocols.ALL.key
)
Expand All @@ -138,7 +138,7 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
override fun getSamReaderProtocol(): String? = null

override fun clear() {
poReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
cardReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

if (!getSamReaderProtocol().isNullOrEmpty()) {
samReaders.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ class CardReaderApi @Inject constructor(private var readerRepository: IReaderRep
}

/*
* Init PO reader
* Init Card reader
*/
val poReader: Reader?
val cardReader: Reader?
try {
poReader = readerRepository.initPoReader()
cardReader = readerRepository.initCardReader()
} catch (e: KeyplePluginException) {
Timber.e(e)
throw IllegalStateException(e.message)
Expand All @@ -82,7 +82,7 @@ class CardReaderApi @Inject constructor(private var readerRepository: IReaderRep
Timber.w("No SAM reader available")
}

poReader.let { reader ->
cardReader.let { reader ->
/* remove the observer if it already exist */
(reader as ObservableReader).addObserver(observer)

Expand All @@ -92,18 +92,18 @@ class CardReaderApi @Inject constructor(private var readerRepository: IReaderRep

fun startNfcDetection() {
/*
* Provide the Reader with the selection operation to be processed when a PO is
* Provide the Reader with the selection operation to be processed when a Card is
* inserted.
*/
ticketingSession?.prepareAndSetPoDefaultSelection()
ticketingSession?.prepareAndSetCardDefaultSelection()

(readerRepository.poReader as ObservableReader).startCardDetection(ObservableCardReader.DetectionMode.REPEATING)
(readerRepository.cardReader as ObservableReader).startCardDetection(ObservableCardReader.DetectionMode.REPEATING)
}

fun stopNfcDetection() {
try {
// notify reader that se detection has been switched off
(readerRepository.poReader as ObservableReader).stopCardDetection()
(readerRepository.cardReader as ObservableReader).stopCardDetection()
} catch (e: KeyplePluginException) {
Timber.e(e, "NFC Plugin not found")
} catch (e: Exception) {
Expand All @@ -117,8 +117,8 @@ class CardReaderApi @Inject constructor(private var readerRepository: IReaderRep

fun onDestroy(observer: CardReaderObserverSpi?) {
readerRepository.clear()
if (observer != null && readerRepository.poReader != null) {
(readerRepository.poReader as ObservableReader).removeObserver(observer)
if (observer != null && readerRepository.cardReader != null) {
(readerRepository.cardReader as ObservableReader).removeObserver(observer)
}

val smartCardService = SmartCardServiceProvider.getService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
package org.calypsonet.keyple.demo.validation.models

import android.os.Parcelable
import java.util.Date
import kotlinx.android.parcel.Parcelize
import java.util.Date

@Parcelize
data class CardReaderResponse(
val status: Status,
val nbTicketsLeft: Int? = null,
val contract: String?,
val cardType: String?,
val validation: Validation?,
val eventDate: Date? = null,
val passValidityEndDate: Date? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import org.eclipse.keyple.core.service.resource.spi.ReaderConfiguratorSpi

interface IReaderRepository {

var poReader: Reader?
var cardReader: Reader?
var samReaders: MutableList<Reader>

fun registerPlugin(activity: Activity)

suspend fun initPoReader(): Reader?
suspend fun initCardReader(): Reader?

suspend fun initSamReaders(): List<Reader>

fun getSamReader(): Reader?
fun getContactlessIsoProtocol(): PoReaderProtocol?
fun getContactlessIsoProtocol(): CardReaderProtocol?
fun getSamReaderProtocol(): String?
fun getPlugin(): Plugin
fun clear()
Expand All @@ -59,4 +59,4 @@ interface IReaderRepository {
fun displayResultFailed(): Boolean = false
}

data class PoReaderProtocol(val readerProtocolName: String, val applicationProtocolName: String)
data class CardReaderProtocol(val readerProtocolName: String, val applicationProtocolName: String)
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,14 @@ object CalypsoInfo {
*********************************/

/** AID Intercode **/
const val AID_HIS_STRUCTURE_5H_2H = "315449432e49434131"
const val AID_HIS_STRUCTURE_32H = "315449432E49434133"
const val AID_1TIC_ICA_1 = "315449432e49434131"
const val AID_1TIC_ICA_3 = "315449432E49434133"

/** AID NORMALIZED IDF **/
const val AID_NORMALIZED_IDF_05H = "A0000004040125090101"
const val AID_NORMALIZED_IDF = "A0000004040125090101"

/*********************************
* Card types
*********************************/
const val PO_TYPE_NAME_CALYPSO_02h = "Calypso_02h"
const val PO_TYPE_NAME_CALYPSO_05h = "Calypso_05h"
const val PO_TYPE_NAME_CALYPSO_32h = "Calypso_32h"
const val PO_TYPE_NAME_CALYPSO_OTHER = "Calypso_Other"
const val PO_TYPE_NAME_NAVIGO_05h = "Navigo_05h"
const val PO_TYPE_NAME_OTHER = "Unknown"
/** OTHER **/
const val AID_OTHER = "Other"

const val RECORD_NUMBER_1: Byte = 1
const val RECORD_NUMBER_2: Byte = 2
Expand Down
Loading

0 comments on commit 51815ad

Please sign in to comment.