Compare commits
No commits in common. "3b868e4f9abeb8e4746f1be83e2a66bfdfd46da0" and "ef622740573d3d2fea0cac410a3e0f9991b096e5" have entirely different histories.
3b868e4f9a
...
ef62274057
5 changed files with 22 additions and 42 deletions
|
@ -162,15 +162,13 @@ open class DefaultEuiccChannelManager(
|
||||||
override suspend fun <R> withEuiccChannel(
|
override suspend fun <R> withEuiccChannel(
|
||||||
physicalSlotId: Int,
|
physicalSlotId: Int,
|
||||||
portId: Int,
|
portId: Int,
|
||||||
fn: suspend (EuiccChannel) -> R
|
fn: (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 withContext(Dispatchers.IO) {
|
return fn(wrapper)
|
||||||
fn(wrapper)
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
wrapper.invalidateWrapper()
|
wrapper.invalidateWrapper()
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,15 +71,9 @@ 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(
|
suspend fun <R> withEuiccChannel(physicalSlotId: Int, portId: Int, fn: (EuiccChannel) -> R): R
|
||||||
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,6 +6,7 @@ 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
|
||||||
|
@ -51,7 +52,6 @@ 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,12 +127,10 @@ 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", logicalSlotId)
|
putExtra("logicalSlotId", channel.logicalSlotId)
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +162,7 @@ open class EuiccManagementFragment : Fragment(), EuiccProfilesChangedListener,
|
||||||
preferenceRepository.disableSafeguardFlow.stateIn(lifecycleScope)
|
preferenceRepository.disableSafeguardFlow.stateIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
val profiles = withEuiccChannel { channel ->
|
val profiles = withContext(Dispatchers.IO) {
|
||||||
logicalSlotId = channel.logicalSlotId
|
|
||||||
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
euiccChannelManager.notifyEuiccProfilesChanged(channel.logicalSlotId)
|
||||||
channel.lpa.profiles.operational
|
channel.lpa.profiles.operational
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,6 @@ 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) {
|
||||||
|
@ -172,16 +171,13 @@ class ProfileDownloadFragment : BaseMaterialDialogFragment(),
|
||||||
}?.let { formatFreeSpace(it) }
|
}?.let { formatFreeSpace(it) }
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
profileDownloadFreeSpace.text = getString(
|
profileDownloadFreeSpace.text = getString(R.string.profile_download_free_space,
|
||||||
R.string.profile_download_free_space,
|
str ?: getText(R.string.unknown))
|
||||||
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,11 +40,6 @@ 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