PrivilegedEuiccManagementFragment.kt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package im.angry.openeuicc.ui
  2. import android.view.View
  3. import android.view.ViewGroup
  4. import android.widget.Button
  5. import android.widget.PopupMenu
  6. import im.angry.openeuicc.R
  7. import im.angry.openeuicc.core.EuiccChannel
  8. import im.angry.openeuicc.util.*
  9. import net.typeblog.lpac_jni.LocalProfileInfo
  10. class PrivilegedEuiccManagementFragment : EuiccManagementFragment() {
  11. companion object {
  12. fun newInstance(
  13. slotId: Int,
  14. portId: Int,
  15. seId: EuiccChannel.SecureElementId
  16. ): EuiccManagementFragment =
  17. newInstanceEuicc(PrivilegedEuiccManagementFragment::class.java, slotId, portId, seId)
  18. }
  19. private var isMEP = false
  20. private var isRemovable = false
  21. override suspend fun onCreateFooterViews(
  22. parent: ViewGroup,
  23. profiles: List<LocalProfileInfo>
  24. ): List<View> =
  25. super.onCreateFooterViews(parent, profiles).let { footers ->
  26. withEuiccChannel { channel ->
  27. isMEP = channel.isMEP
  28. isRemovable = channel.port.card.isRemovable
  29. }
  30. if (isMEP) {
  31. val view = layoutInflater.inflate(R.layout.footer_mep, parent, false)
  32. view.requireViewById<Button>(R.id.footer_mep_slot_mapping).setOnClickListener {
  33. (requireActivity() as PrivilegedMainActivity).showSlotMappingFragment()
  34. }
  35. footers + view
  36. } else {
  37. footers
  38. }
  39. }
  40. override fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) {
  41. super.populatePopupWithProfileActions(popup, profile)
  42. if (!profile.isEnabled || isRemovable) return
  43. // Only show the disable option for non-removable eUICCs
  44. // Some devices without internal eUICCs have the "optimization" of ignoring SIM
  45. // slots without a valid profile. This can lead to "bricking" of external eUICCs
  46. // at least for that specific device.
  47. // TODO: Maybe we can still make this option available in some sort of "advanced" mode.
  48. popup.menu.findItem(im.angry.openeuicc.common.R.id.disable).isVisible = true
  49. }
  50. }