Compare commits
2 commits
ef62274057
...
3b868e4f9a
Author | SHA1 | Date | |
---|---|---|---|
3b868e4f9a | |||
95b24e6151 |
5 changed files with 42 additions and 22 deletions
|
@ -162,13 +162,15 @@ open class DefaultEuiccChannelManager(
|
||||||
override suspend fun <R> withEuiccChannel(
|
override suspend fun <R> withEuiccChannel(
|
||||||
physicalSlotId: Int,
|
physicalSlotId: Int,
|
||||||
portId: Int,
|
portId: Int,
|
||||||
fn: (EuiccChannel) -> R
|
fn: suspend (EuiccChannel) -> R
|
||||||
): R {
|
): R {
|
||||||
val channel = findEuiccChannelByPortBlocking(physicalSlotId, portId)
|
val channel = findEuiccChannelByPortBlocking(physicalSlotId, portId)
|
||||||
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
|
?: throw EuiccChannelManager.EuiccChannelNotFoundException()
|
||||||
val wrapper = EuiccChannelWrapper(channel)
|
val wrapper = EuiccChannelWrapper(channel)
|
||||||
try {
|
try {
|
||||||
return fn(wrapper)
|
return withContext(Dispatchers.IO) {
|
||||||
|
fn(wrapper)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
wrapper.invalidateWrapper()
|
wrapper.invalidateWrapper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,9 +71,15 @@ interface EuiccChannelManager {
|
||||||
* The reference is not supposed to be held outside of the callback. This is enforced via
|
* The reference is not supposed to be held outside of the callback. This is enforced via
|
||||||
* a wrapper object.
|
* a wrapper object.
|
||||||
*
|
*
|
||||||
|
* The callback is run on Dispatchers.IO by default.
|
||||||
|
*
|
||||||
* If a channel for that slot / port is not found, EuiccChannelNotFoundException is thrown
|
* If a channel for that slot / port is not found, EuiccChannelNotFoundException is thrown
|
||||||
*/
|
*/
|
||||||
suspend fun <R> withEuiccChannel(physicalSlotId: Int, portId: Int, fn: (EuiccChannel) -> R): R
|
suspend fun <R> withEuiccChannel(
|
||||||
|
physicalSlotId: Int,
|
||||||
|
portId: Int,
|
||||||
|
fn: suspend (EuiccChannel) -> R
|
||||||
|
): R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidate all EuiccChannels previously cached by this Manager
|
* Invalidate all EuiccChannels previously cached by this Manager
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.content.ClipboardManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.method.PasswordTransformationMethod
|
import android.text.method.PasswordTransformationMethod
|
||||||
import android.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuInflater
|
import android.view.MenuInflater
|
||||||
|
@ -52,6 +51,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
|
||||||
private lateinit var swipeRefresh: SwipeRefreshLayout
|
private lateinit var swipeRefresh: SwipeRefreshLayout
|
||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var profileList: RecyclerView
|
private lateinit var profileList: RecyclerView
|
||||||
|
private var logicalSlotId: Int = -1
|
||||||
|
|
||||||
private val adapter = EuiccProfileAdapter()
|
private val adapter = EuiccProfileAdapter()
|
||||||
|
|
||||||
|
@ -127,10 +127,12 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
override fun onOptionsItemSelected(item: MenuItem): Boolean =
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.show_notifications -> {
|
R.id.show_notifications -> {
|
||||||
|
if (logicalSlotId != -1) {
|
||||||
Intent(requireContext(), NotificationsActivity::class.java).apply {
|
Intent(requireContext(), NotificationsActivity::class.java).apply {
|
||||||
putExtra("logicalSlotId", channel.logicalSlotId)
|
putExtra("logicalSlotId", logicalSlotId)
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +164,8 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
|
||||||
preferenceRepository.disableSafeguardFlow.stateIn(lifecycleScope)
|
preferenceRepository.disableSafeguardFlow.stateIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
val profiles = withContext(Dispatchers.IO) {
|
val profiles = withEuiccChannel { channel ->
|
||||||
|
logicalSlotId = channel.logicalSlotId
|
||||||
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
||||||
channel.lpa.profiles.operational
|
channel.lpa.profiles.operational
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withEuiccChannel { channel ->
|
||||||
val imei = try {
|
val imei = try {
|
||||||
telephonyManager.getImei(channel.logicalSlotId) ?: ""
|
telephonyManager.getImei(channel.logicalSlotId) ?: ""
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -171,13 +172,16 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
}?.let { formatFreeSpace(it) }
|
}?.let { formatFreeSpace(it) }
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
profileDownloadFreeSpace.text = getString(R.string.profile_download_free_space,
|
profileDownloadFreeSpace.text = getString(
|
||||||
str ?: getText(R.string.unknown))
|
R.string.profile_download_free_space,
|
||||||
|
str ?: getText(R.string.unknown)
|
||||||
|
)
|
||||||
profileDownloadIMEI.editText!!.text =
|
profileDownloadIMEI.editText!!.text =
|
||||||
Editable.Factory.getInstance().newEditable(imei)
|
Editable.Factory.getInstance().newEditable(imei)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
return super.onCreateDialog(savedInstanceState).also {
|
return super.onCreateDialog(savedInstanceState).also {
|
||||||
|
|
|
@ -40,6 +40,11 @@ val <T> T.channel: EuiccChannel where T: Fragment, T: EuiccChannelFragmentMarker
|
||||||
get() =
|
get() =
|
||||||
euiccChannelManager.findEuiccChannelByPortBlocking(slotId, portId)!!
|
euiccChannelManager.findEuiccChannelByPortBlocking(slotId, portId)!!
|
||||||
|
|
||||||
|
suspend fun <T, R> T.withEuiccChannel(fn: suspend (EuiccChannel) -> R): R where T : Fragment, T : EuiccChannelFragmentMarker {
|
||||||
|
ensureEuiccChannelManager()
|
||||||
|
return euiccChannelManager.withEuiccChannel(slotId, portId, fn)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun <T> T.ensureEuiccChannelManager() where T: Fragment, T: EuiccChannelFragmentMarker =
|
suspend fun <T> T.ensureEuiccChannelManager() where T: Fragment, T: EuiccChannelFragmentMarker =
|
||||||
(requireActivity() as BaseEuiccAccessActivity).euiccChannelManagerLoaded.await()
|
(requireActivity() as BaseEuiccAccessActivity).euiccChannelManagerLoaded.await()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue