Skip to content

Commit

Permalink
Update devices reader repository
Browse files Browse the repository at this point in the history
Signed-off-by: Youssef Amrani <youssef.amrani@yamapps.fr>
  • Loading branch information
Yamapps committed Aug 30, 2021
1 parent 6a72b73 commit e1a0646
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 90 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ android {

packagingOptions {
exclude 'META-INF/NOTICE.md'
exclude 'META-INF/plugin_release.kotlin_module'
}

dataBinding {
Expand Down Expand Up @@ -113,6 +114,8 @@ dependencies {
implementation "org.eclipse.keyple:keyple-service-java-lib:2.0.0-SNAPSHOT"
implementation "org.eclipse.keyple:keyple-card-calypso-java-lib:2.0.0-SNAPSHOT"
implementation "org.eclipse.keyple:keyple-service-resource-java-lib:2.0.0-SNAPSHOT"
implementation "org.eclipse.keyple:keyple-util-java-lib:2.0.0-SNAPSHOT"
implementation "org.eclipse.keyple:keyple-common-java-api:2.0.0-SNAPSHOT"

implementation "org.calypsonet.terminal:calypsonet-terminal-reader-java-api:1.0.0-SNAPSHOT"
implementation "org.calypsonet.terminal:calypsonet-terminal-calypso-java-api:1.0.0-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.calypsonet.keyple.plugin.coppernic.Cone2PluginFactoryProvider
import org.calypsonet.keyple.plugin.coppernic.ParagonSupportedContactProtocols
import org.calypsonet.keyple.plugin.coppernic.ParagonSupportedContactlessProtocols
import org.calypsonet.terminal.reader.spi.CardReaderObservationExceptionHandlerSpi
import org.eclipse.keyple.core.service.ConfigurableReader
import org.eclipse.keyple.core.service.KeyplePluginException
import org.eclipse.keyple.core.service.ObservableReader
import org.eclipse.keyple.core.service.Plugin
Expand Down Expand Up @@ -72,22 +73,22 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
override suspend fun initCardReader(): Reader? {
val askPlugin =
SmartCardServiceProvider.getService().getPlugin(Cone2Plugin.PLUGIN_NAME)
val poReader = askPlugin?.getReader(Cone2ContactlessReader.READER_NAME)
poReader?.let {
val cardReader = askPlugin?.getReader(Cone2ContactlessReader.READER_NAME)
cardReader?.let {

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

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

this.cardReader = poReader
this.cardReader = cardReader
}

return poReader
return cardReader
}

@Throws(KeyplePluginException::class)
Expand All @@ -99,7 +100,7 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
}?.toMutableList() ?: mutableListOf()

samReaders.forEach {
it.activateProtocol(
(it as ConfigurableReader).activateProtocol(
getSamReaderProtocol(),
getSamReaderProtocol()
)
Expand Down Expand Up @@ -137,10 +138,10 @@ class CoppernicReaderRepositoryImpl @Inject constructor(private val applicationC
override fun getReaderConfiguratorSpi(): ReaderConfiguratorSpi = ReaderConfigurator()

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

samReaders.forEach {
it.deactivateProtocol(
(it as ConfigurableReader).deactivateProtocol(
getSamReaderProtocol()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ package org.calypsonet.keyple.demo.validation.di

import android.app.Activity
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.CardReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoPlugin
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoPluginFactoryProvider
import org.calypsonet.keyple.plugin.famoco.AndroidFamocoReader
import org.calypsonet.keyple.plugin.famoco.utils.ContactCardCommonProtocols
import org.calypsonet.terminal.reader.spi.CardReaderObservationExceptionHandlerSpi
import org.eclipse.keyple.core.service.ConfigurableReader
import org.eclipse.keyple.core.service.KeyplePluginException
import org.eclipse.keyple.core.service.ObservableReader
import org.eclipse.keyple.core.service.Plugin
import org.eclipse.keyple.core.service.Reader
import org.eclipse.keyple.core.service.SmartCardServiceProvider
Expand All @@ -32,10 +33,7 @@ import org.eclipse.keyple.plugin.android.nfc.AndroidNfcPlugin
import org.eclipse.keyple.plugin.android.nfc.AndroidNfcPluginFactoryProvider
import org.eclipse.keyple.plugin.android.nfc.AndroidNfcReader
import timber.log.Timber

/**
* @author youssefamrani
*/
import javax.inject.Inject

class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservationExceptionHandler: CardReaderObservationExceptionHandlerSpi) :
IReaderRepository {
Expand Down Expand Up @@ -70,23 +68,23 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
override suspend fun initCardReader(): Reader {
val readerPlugin =
SmartCardServiceProvider.getService().getPlugin(AndroidNfcPlugin.PLUGIN_NAME)
val poReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)
val cardReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)

poReader?.let {
cardReader?.let {
// with this protocol settings we activate the nfc for ISO1443_4 protocol
it.activateProtocol(
(it as ConfigurableReader).activateProtocol(
getContactlessIsoProtocol().readerProtocolName,
getContactlessIsoProtocol().applicationProtocolName
)

this.cardReader = poReader
this.cardReader = cardReader
}

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

return poReader
return cardReader
}

override suspend fun initSamReaders(): List<Reader> {
Expand All @@ -98,11 +96,6 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
if (samPlugin != null) {
val samReader = samPlugin.getReader(AndroidFamocoReader.READER_NAME)
samReader?.let {
it.activateProtocol(
getSamReaderProtocol(),
getSamReaderProtocol()
)

samReaders.add(it)
}
}
Expand Down Expand Up @@ -140,13 +133,7 @@ class FamocoReaderRepositoryImpl @Inject constructor(private val readerObservati
}

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

samReaders.forEach {
it.deactivateProtocol(
getSamReaderProtocol()
)
}
(cardReader as ConfigurableReader).deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

successMedia.stop()
successMedia.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
package org.calypsonet.keyple.demo.validation.di

import android.app.Activity
import javax.inject.Inject
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.CardReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.plugin.flowbird.FlowbirdPlugin
import org.calypsonet.keyple.plugin.flowbird.FlowbirdPluginFactoryProvider
import org.calypsonet.keyple.plugin.flowbird.FlowbirdUiManager
Expand All @@ -26,13 +25,15 @@ import org.calypsonet.keyple.plugin.flowbird.contact.SamSlot
import org.calypsonet.keyple.plugin.flowbird.contactless.FlowbirdContactlessReader
import org.calypsonet.keyple.plugin.flowbird.contactless.FlowbirdSupportContactlessProtocols
import org.calypsonet.terminal.reader.spi.CardReaderObservationExceptionHandlerSpi
import org.eclipse.keyple.core.service.ConfigurableReader
import org.eclipse.keyple.core.service.KeyplePluginException
import org.eclipse.keyple.core.service.ObservableReader
import org.eclipse.keyple.core.service.Plugin
import org.eclipse.keyple.core.service.Reader
import org.eclipse.keyple.core.service.SmartCardServiceProvider
import org.eclipse.keyple.core.service.resource.spi.ReaderConfiguratorSpi
import timber.log.Timber
import javax.inject.Inject

class FlowbirdReaderRepositoryImpl @Inject constructor(
private val readerObservationExceptionHandler: CardReaderObservationExceptionHandlerSpi
Expand Down Expand Up @@ -75,23 +76,23 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
override suspend fun initCardReader(): Reader {
val flowbirdPlugin =
SmartCardServiceProvider.getService().getPlugin(FlowbirdPlugin.PLUGIN_NAME)
val poReader = flowbirdPlugin?.getReader(FlowbirdContactlessReader.READER_NAME)
val cardReader = flowbirdPlugin?.getReader(FlowbirdContactlessReader.READER_NAME)

poReader?.let {
cardReader?.let {

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

this.cardReader = poReader
this.cardReader = cardReader
}

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

return poReader
return cardReader
}

@Throws(KeyplePluginException::class)
Expand All @@ -101,14 +102,6 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
!it.isContactless
}?.toMutableList() ?: mutableListOf()

if (!getSamReaderProtocol().isNullOrEmpty()) {
samReaders.forEach {
it.activateProtocol(
getSamReaderProtocol(),
getSamReaderProtocol()
)
}
}
return samReaders
}

Expand Down Expand Up @@ -138,15 +131,7 @@ class FlowbirdReaderRepositoryImpl @Inject constructor(
override fun getSamReaderProtocol(): String? = null

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

if (!getSamReaderProtocol().isNullOrEmpty()) {
samReaders.forEach {
it.deactivateProtocol(
getSamReaderProtocol()
)
}
}
(cardReader as ConfigurableReader).deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
}

override fun displayWaiting(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.calypsonet.keyple.demo.validation.di.mock.MockSamReader
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.terminal.reader.spi.CardReaderObservationExceptionHandlerSpi
import org.eclipse.keyple.core.service.ConfigurableReader
import org.eclipse.keyple.core.service.KeyplePluginException
import org.eclipse.keyple.core.service.ObservableReader
import org.eclipse.keyple.core.service.Plugin
Expand Down Expand Up @@ -62,23 +63,23 @@ class MockSamReaderRepositoryImpl @Inject constructor(private val readerObservat
override suspend fun initCardReader(): Reader {
val readerPlugin =
SmartCardServiceProvider.getService().getPlugin(AndroidNfcPlugin.PLUGIN_NAME)
val poReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)
val cardReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)

poReader?.let {
cardReader?.let {
// with this protocol settings we activate the nfc for ISO1443_4 protocol
it.activateProtocol(
(it as ConfigurableReader).activateProtocol(
getContactlessIsoProtocol().readerProtocolName,
getContactlessIsoProtocol().applicationProtocolName
)

this.cardReader = poReader
this.cardReader = cardReader
}

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

return poReader
return cardReader
}

@Throws(KeyplePluginException::class)
Expand All @@ -91,11 +92,6 @@ class MockSamReaderRepositoryImpl @Inject constructor(private val readerObservat
if (samPlugin != null) {
val samReader = samPlugin.getReader(MockSamReader.READER_NAME)
samReader?.let {
it.activateProtocol(
getSamReaderProtocol(),
getSamReaderProtocol()
)

samReaders.add(it)
}
}
Expand Down Expand Up @@ -135,7 +131,7 @@ class MockSamReaderRepositoryImpl @Inject constructor(private val readerObservat

override fun clear() {
// with this protocol settings we activate the nfc for ISO1443_4 protocol
(cardReader as ObservableReader).deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
(cardReader as ConfigurableReader).deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

successMedia.stop()
successMedia.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ internal class MockSamReaderAdapter :
return false
}

override fun isCurrentProtocol(readerProtocolName: String?): Boolean {
return true
}

override fun isProtocolSupported(readerProtocol: String?): Boolean {
return true
}

override fun activateProtocol(readerProtocol: String?) {
// Do nothing
}

override fun deactivateProtocol(readerProtocol: String?) {
// Do nothing
}

override fun getName(): String = READER_NAME

override fun onUnregister() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.calypsonet.keyple.demo.validation.R
import org.calypsonet.keyple.demo.validation.reader.IReaderRepository
import org.calypsonet.keyple.demo.validation.reader.CardReaderProtocol
import org.calypsonet.terminal.reader.spi.CardReaderObservationExceptionHandlerSpi
import org.eclipse.keyple.core.service.ConfigurableReader
import org.eclipse.keyple.core.service.KeyplePluginException
import org.eclipse.keyple.core.service.ObservableReader
import org.eclipse.keyple.core.service.Plugin
Expand Down Expand Up @@ -81,7 +82,7 @@ class OmapiReaderRepositoryImpl @Inject constructor(
cardReader = readerPlugin.getReader(AndroidNfcReader.READER_NAME)

// with this protocol settings we activate the nfc for ISO1443_4 protocol
cardReader?.activateProtocol(
(cardReader as ConfigurableReader).activateProtocol(
getContactlessIsoProtocol().readerProtocolName,
getContactlessIsoProtocol().applicationProtocolName
)
Expand Down Expand Up @@ -119,7 +120,7 @@ class OmapiReaderRepositoryImpl @Inject constructor(
}
samReaders.forEach {
if (getSamReaderProtocol()?.isNotEmpty() == true) {
it.activateProtocol(
(it as ConfigurableReader).activateProtocol(
getSamReaderProtocol(),
getSamReaderProtocol()
)
Expand Down Expand Up @@ -157,11 +158,11 @@ class OmapiReaderRepositoryImpl @Inject constructor(
override fun clear() {
if (getSamReaderProtocol()?.isNotEmpty() == true) {
samReaders.forEach {
it.deactivateProtocol(getSamReaderProtocol())
(it as ConfigurableReader).deactivateProtocol(getSamReaderProtocol())
}
}

cardReader?.deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)
(cardReader as ConfigurableReader).deactivateProtocol(getContactlessIsoProtocol().readerProtocolName)

successMedia.stop()
successMedia.release()
Expand Down

0 comments on commit e1a0646

Please sign in to comment.