PrivilegedEuiccManagementFragment.kt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.util.*
  8. import kotlinx.coroutines.Dispatchers
  9. import kotlinx.coroutines.withContext
  10. import net.typeblog.lpac_jni.LocalProfileInfo
  11. class PrivilegedEuiccManagementFragment: EuiccManagementFragment() {
  12. companion object {
  13. fun newInstance(slotId: Int, portId: Int): EuiccManagementFragment =
  14. newInstanceEuicc(PrivilegedEuiccManagementFragment::class.java, slotId, portId)
  15. }
  16. override suspend fun onCreateFooterViews(parent: ViewGroup): List<View> =
  17. // isMEP can map to a slow operation (UiccCardInfo.isMultipleEnabledProfilesSupported())
  18. // so let's do it in the IO context
  19. if (withContext(Dispatchers.IO) { channel.isMEP }) {
  20. val view = layoutInflater.inflate(R.layout.footer_mep, parent, false)
  21. view.requireViewById<Button>(R.id.footer_mep_slot_mapping).setOnClickListener {
  22. (requireActivity() as PrivilegedMainActivity).showSlotMappingFragment()
  23. }
  24. listOf(view)
  25. } else {
  26. listOf()
  27. }
  28. override fun populatePopupWithProfileActions(popup: PopupMenu, profile: LocalProfileInfo) {
  29. super.populatePopupWithProfileActions(popup, profile)
  30. if (profile.isEnabled && !channel.removable) {
  31. // Only show the disable option for non-removable eUICCs
  32. // Some devices without internal eUICCs have the "optimization" of ignoring SIM
  33. // slots without a valid profile. This can lead to "bricking" of external eUICCs
  34. // at least for that specific device.
  35. // TODO: Maybe we can still make this option available in some sort of "advanced" mode.
  36. popup.menu.findItem(im.angry.openeuicc.common.R.id.disable).isVisible = true
  37. }
  38. }
  39. }