Compare commits
1 commit
85dfd44b4f
...
9541c14112
Author | SHA1 | Date | |
---|---|---|---|
9541c14112 |
2 changed files with 25 additions and 13 deletions
|
@ -26,6 +26,7 @@ import kotlinx.coroutines.runBlocking
|
|||
open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
||||
companion object {
|
||||
enum class Compatibility {
|
||||
NOT_SUPPORTED,
|
||||
COMPATIBLE,
|
||||
NOT_COMPATIBLE,
|
||||
}
|
||||
|
@ -36,14 +37,21 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
)
|
||||
}
|
||||
|
||||
private val conclusion: TextView by lazy { requireView().requireViewById(R.id.quick_availability_conclusion) }
|
||||
private val conclusion: TextView by lazy {
|
||||
requireView().requireViewById(R.id.quick_availability_conclusion)
|
||||
}
|
||||
|
||||
private val resultSlots: TextView by lazy { requireView().requireViewById(R.id.quick_availability_result_slots) }
|
||||
private val resultSlots: TextView by lazy {
|
||||
requireView().requireViewById(R.id.quick_availability_result_slots)
|
||||
}
|
||||
|
||||
private val resultNotes: TextView by lazy { requireView().requireViewById(R.id.quick_availability_result_notes) }
|
||||
|
||||
private val hidden: CheckBox by lazy { requireView().requireViewById(R.id.quick_availability_hidden) }
|
||||
private val resultNotes: TextView by lazy {
|
||||
requireView().requireViewById(R.id.quick_availability_result_notes)
|
||||
}
|
||||
|
||||
private val hidden: CheckBox by lazy {
|
||||
requireView().requireViewById(R.id.quick_availability_hidden)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -58,7 +66,9 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
lifecycleScope.launch { onCompatibilityUpdate() }
|
||||
lifecycleScope.launch {
|
||||
onCompatibilityUpdate(getCompatibilityCheckResult())
|
||||
}
|
||||
}
|
||||
|
||||
fun onContinueToApp() {
|
||||
|
@ -69,8 +79,7 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
(requireActivity() as QuickAvailabilityActivity).launchMainActivity()
|
||||
}
|
||||
|
||||
suspend fun onCompatibilityUpdate() {
|
||||
val result = getCompatibilityCheckResult()
|
||||
fun onCompatibilityUpdate(result: CompatibilityResult) {
|
||||
conclusion.text = formatConclusion(result)
|
||||
if (result.compatibility != Compatibility.COMPATIBLE) return
|
||||
resultSlots.isVisible = true
|
||||
|
@ -82,11 +91,11 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
}
|
||||
|
||||
suspend fun getCompatibilityCheckResult(): CompatibilityResult {
|
||||
val seService = connectSEService(requireContext())
|
||||
if (!seService.isConnected) {
|
||||
return CompatibilityResult(Compatibility.NOT_COMPATIBLE)
|
||||
val service = connectSEService(requireContext())
|
||||
if (!service.isConnected) {
|
||||
return CompatibilityResult(Compatibility.NOT_SUPPORTED)
|
||||
}
|
||||
val slots = seService.readers.filter { it.isSIM }.mapNotNull { reader ->
|
||||
val slots = service.readers.filter { it.isSIM }.mapNotNull { reader ->
|
||||
try {
|
||||
// Note: we ONLY check the default ISD-R AID, because this test is for the _device_,
|
||||
// NOT the eUICC. We don't care what AID a potential eUICC might use, all we need to
|
||||
|
@ -99,7 +108,6 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
// SecurityException is only thrown when Channel is constructed, which means everything else needs to succeed
|
||||
reader.slotIndex
|
||||
} catch (_: Exception) {
|
||||
// Ignore
|
||||
null
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +121,9 @@ open class QuickAvailabilityFragment : Fragment(), OpenEuiccContextMarker {
|
|||
val usbHost = requireContext().packageManager
|
||||
.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
|
||||
val resId = when (result.compatibility) {
|
||||
Compatibility.NOT_SUPPORTED ->
|
||||
R.string.quick_availability_not_supported
|
||||
|
||||
Compatibility.COMPATIBLE ->
|
||||
R.string.quick_availability_compatible
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<!-- Quick Availability -->
|
||||
<string name="quick_availability">Quick Availability</string>
|
||||
<string name="quick_availability_compatible">Your smartphone can use %s compatible cards</string>
|
||||
<string name="quick_availability_not_supported">Your smartphone is not supported with %s</string>
|
||||
<string name="quick_availability_not_compatible">Your smartphone is not compatible with %s</string>
|
||||
<string name="quick_availability_not_compatible_but_usb">Your smartphone is not compatible with %s, but can be managed using a USB smart card reader</string>
|
||||
<string name="quick_availability_result_slots">SIM card slots accessible: %s</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue