OpenEUICC/app-common/src/main/java/im/angry/openeuicc/core/DefaultEuiccChannelFactory.kt
Peter Cai 6977a32e80
All checks were successful
/ build-debug (push) Successful in 4m19s
refactor: EuiccChannel is not abstract
2024-03-17 11:19:37 -04:00

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
}
}