43 lines
1.3 KiB
Kotlin
43 lines
1.3 KiB
Kotlin
package im.angry.openeuicc.core
|
|
|
|
import android.content.Context
|
|
import android.se.omapi.SEService
|
|
import android.util.Log
|
|
import im.angry.openeuicc.util.*
|
|
import java.lang.IllegalArgumentException
|
|
|
|
open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccChannelFactory {
|
|
private var seService: SEService? = null
|
|
|
|
private suspend fun ensureSEService() {
|
|
if (seService == null) {
|
|
seService = connectSEService(context)
|
|
}
|
|
}
|
|
|
|
override suspend fun tryOpenEuiccChannel(port: UiccPortInfoCompat): EuiccChannel? {
|
|
if (port.portIndex != 0) {
|
|
Log.w(DefaultEuiccChannelManager.TAG, "OMAPI channel attempted on non-zero portId, this may or may not work.")
|
|
}
|
|
|
|
ensureSEService()
|
|
|
|
Log.i(DefaultEuiccChannelManager.TAG, "Trying OMAPI for physical slot ${port.card.physicalSlotIndex}")
|
|
try {
|
|
return EuiccChannel(port, OmapiApduInterface(seService!!, port))
|
|
} catch (e: IllegalArgumentException) {
|
|
// Failed
|
|
Log.w(
|
|
DefaultEuiccChannelManager.TAG,
|
|
"OMAPI APDU interface unavailable for physical slot ${port.card.physicalSlotIndex}."
|
|
)
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
override fun cleanup() {
|
|
seService?.shutdown()
|
|
seService = null
|
|
}
|
|
} |