Skip to content

Commit

Permalink
Reorganizing kotlin sources
Browse files Browse the repository at this point in the history
Added reading of another container in example
  • Loading branch information
ocfmem committed Feb 3, 2020
1 parent 8c3cde2 commit ba0a9f5
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 164 deletions.
5 changes: 5 additions & 0 deletions android/keyple-plugin/android-omapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ android {

}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

}


Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
package org.eclipse.keyple.plugin.android.omapi

import android.content.Context
import android.se.omapi.Reader
import android.se.omapi.SEService
import org.eclipse.keyple.core.seproxy.ReaderPlugin
import org.eclipse.keyple.core.seproxy.SeReader
import org.eclipse.keyple.core.seproxy.plugin.AbstractPlugin
import org.eclipse.keyple.plugin.android.omapi.se.AndroidSeOmapiPluginImpl
import timber.log.Timber
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/********************************************************************************
* Copyright (c) 2019 Calypso Networks Association https://www.calypsonet-asso.org/
*
* See the NOTICE file(s) distributed with this work for additional information regarding copyright
* ownership.
*
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.keyple.plugin.android.omapi

import android.content.Context
import android.content.pm.PackageManager
import org.eclipse.keyple.core.seproxy.AbstractPluginFactory
import org.eclipse.keyple.core.seproxy.ReaderPlugin
import org.eclipse.keyple.core.seproxy.exception.KeyplePluginInstantiationException

/**
* Build asynchronously the Android OMAPI plugin.
* Platform incompabilities are not managed
*/
class AndroidOmapiPluginFactory(private val context: Context) : AbstractPluginFactory() {

companion object{
private const val SIMALLIANCE_OMAPI_PACKAGE_NAME = "org.simalliance.openmobileapi.service"
}

override fun getPluginName(): String {
return AndroidOmapiPlugin.PLUGIN_NAME
}

//TODO throw error is Android is not compatible with OMAPI
@Throws(KeyplePluginInstantiationException::class)
override fun getPluginInstance(): ReaderPlugin{
return getReaderPluginRegardingOsVersion()
}

private fun getReaderPluginRegardingOsVersion(): ReaderPlugin{
return if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P)
org.eclipse.keyple.plugin.android.omapi.se.AndroidOmapiPluginImpl.init(context)
else
getReaderPluginRegardingPackages()
}

@Throws(KeyplePluginInstantiationException::class)
private fun getReaderPluginRegardingPackages(): ReaderPlugin{
return try {
context.packageManager
.getPackageInfo(SIMALLIANCE_OMAPI_PACKAGE_NAME, 0)
org.eclipse.keyple.plugin.android.omapi.simalliance.AndroidOmapiPluginImpl.init(context)
} catch (e2: PackageManager.NameNotFoundException) {
throw KeyplePluginInstantiationException("No OMAPI lib available within the OS")
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.keyple.plugin.android.omapi.simalliance;
*/
package org.eclipse.keyple.plugin.android.omapi

import org.simalliance.openmobileapi.SEService;


interface ISeServiceFactory {

SEService connectToSe(SEService.CallBack callBack);
internal interface ISeServiceFactory<T, V> {
fun connectToSe(callBack: V): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.eclipse.keyple.plugin.android.omapi.AndroidOmapiPlugin
import timber.log.Timber

@RequiresApi(android.os.Build.VERSION_CODES.P) //OS version providing android.se.omapi package
object AndroidSeOmapiPluginImpl: AndroidOmapiPlugin<Reader, SEService>(), SEService.OnConnectedListener {
object AndroidOmapiPluginImpl: AndroidOmapiPlugin<Reader, SEService>(), SEService.OnConnectedListener {

override fun connectToSe(context: Context) {
val seServiceFactory = SeServiceFactoryImpl(context.applicationContext)
Expand All @@ -24,14 +24,14 @@ object AndroidSeOmapiPluginImpl: AndroidOmapiPlugin<Reader, SEService>(), SEServ
override fun mapToSeReader(nativeReader: Reader): SeReader{
Timber.d("Reader available name : %s", nativeReader.name)
Timber.d("Reader available isSePresent : %S", nativeReader.isSecureElementPresent)
return AndroidSeOmapiReaderImpl(nativeReader, PLUGIN_NAME, nativeReader.name)
return AndroidOmapiReaderImpl(nativeReader, PLUGIN_NAME, nativeReader.name)
}

/**
* Warning. Do not call this method directly.
*
* Invoked by Open Mobile {@link SEService} when connected
* Instantiates {@link AndroidSeOmapiReaderImpl} for each SE Reader detected in the platform
* Instantiates {@link AndroidOmapiReaderImpl} for each SE Reader detected in the platform
*
* @param seService : connected omapi service
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.experimental.or
* with android.se.omapi
*/
@RequiresApi(android.os.Build.VERSION_CODES.P)
internal class AndroidSeOmapiReaderImpl(private val nativeReader: Reader, pluginName: String, readerName: String)
internal class AndroidOmapiReaderImpl(private val nativeReader: Reader, pluginName: String, readerName: String)
: AndroidOmapiReader(pluginName, readerName){

private var session: Session? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package org.eclipse.keyple.plugin.android.omapi.se
import android.content.Context
import android.se.omapi.SEService
import androidx.annotation.RequiresApi
import org.eclipse.keyple.plugin.android.omapi.ISeServiceFactory
import java.util.concurrent.Executors

class SeServiceFactoryImpl(val applicationContext: Context): ISeServiceFactory {

val TAG = SeServiceFactoryImpl::class.java.simpleName
class SeServiceFactoryImpl(private val applicationContext: Context): ISeServiceFactory<SEService, SEService.OnConnectedListener>{

@RequiresApi(android.os.Build.VERSION_CODES.P)
override fun connectToSe(onConnectedListener: SEService.OnConnectedListener): SEService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import timber.log.Timber
object AndroidOmapiPluginImpl: AndroidOmapiPlugin<Reader, SEService>(), SEService.CallBack {

override fun connectToSe(context: Context) {
val seServiceFactory = SeServiceFactoryImpl()
val seServiceFactory = SeServiceFactoryImpl(context)
seService = seServiceFactory.connectToSe(this)
Timber.i("OMAPI SEService version: %s", seService?.version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ import kotlin.experimental.or
* Implementation of the [AndroidOmapiReader] based on the [AbstractLocalReader]
* with org.simalliance.omapi
*/
private const val P2_SUPPORTED_MIN_VERSION = 3
internal class AndroidOmapiReaderImpl(private val nativeReader: Reader, pluginName: String,readerName: String)
: AndroidOmapiReader(pluginName, readerName){

companion object{
private const val P2_SUPPORTED_MIN_VERSION = 3
}

private var session: Session? = null
private var openChannel: Channel? = null
private val omapiVersion = nativeReader.seService.version.toFloat()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************************
* Copyright (c) 2018 Calypso Networks Association https://www.calypsonet-asso.org/
*
* See the NOTICE file(s) distributed with this work for additional information regarding copyright
* ownership.
*
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.keyple.plugin.android.omapi.simalliance

import org.simalliance.openmobileapi.SEService
import android.content.Context
import org.eclipse.keyple.plugin.android.omapi.ISeServiceFactory


internal class SeServiceFactoryImpl(private val applicationContext: Context): ISeServiceFactory<SEService, SEService.CallBack> {

override fun connectToSe(callBack: SEService.CallBack): SEService {
return SEService(applicationContext, callBack)
}
}
2 changes: 1 addition & 1 deletion java/example/calypso/android/omapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ buildscript {
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

project.group 'org.eclipse.keyple'

Expand Down

0 comments on commit ba0a9f5

Please sign in to comment.