diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt index 66b31bc..6d810cf 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt @@ -2,7 +2,6 @@ package im.angry.openeuicc.ui.wizard import android.os.Bundle import android.view.View -import android.view.inputmethod.InputMethodManager import android.widget.Button import android.widget.ProgressBar import androidx.activity.OnBackPressedCallback @@ -85,7 +84,6 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() { val bars = insets.getInsets( WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() - or WindowInsetsCompat.Type.ime() ) v.updatePadding(bars.left, 0, bars.right, bars.bottom) val newParams = navigation.layoutParams @@ -134,8 +132,6 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() { } private fun onPrevPressed() { - hideIme() - if (currentFragment?.hasPrev == true) { val prevFrag = currentFragment?.createPrevFragment() if (prevFrag == null) { @@ -147,8 +143,6 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() { } private fun onNextPressed() { - hideIme() - if (currentFragment?.hasNext == true) { currentFragment?.beforeNext() val nextFrag = currentFragment?.createNextFragment() @@ -198,13 +192,6 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() { } } - private fun hideIme() { - currentFocus?.let { - val imm = getSystemService(InputMethodManager::class.java) - imm.hideSoftInputFromWindow(it.windowToken, 0) - } - } - abstract class DownloadWizardStepFragment : Fragment(), OpenEuiccContextMarker { protected val state: DownloadWizardState get() = (requireActivity() as DownloadWizardActivity).state diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt index 5fa8002..eb36710 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardDetailsFragment.kt @@ -22,7 +22,7 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF private lateinit var confirmationCode: TextInputLayout private lateinit var imei: TextInputLayout - private fun saveState() { + override fun beforeNext() { state.smdp = smdp.editText!!.text.toString().trim() // Treat empty inputs as null -- this is important for the download step state.matchingId = matchingId.editText!!.text.toString().trim().ifBlank { null } @@ -30,8 +30,6 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF state.imei = imei.editText!!.text.toString().ifBlank { null } } - override fun beforeNext() = saveState() - override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment = DownloadWizardProgressFragment() @@ -63,11 +61,6 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF updateInputCompleteness() } - override fun onPause() { - super.onPause() - saveState() - } - private fun updateInputCompleteness() { inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches() refreshButtons() diff --git a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt index 5510fb0..3723aea 100644 --- a/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt +++ b/app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardSlotSelectFragment.kt @@ -111,7 +111,7 @@ class DownloadWizardSlotSelectFragment : DownloadWizardActivity.DownloadWizardSt } catch (e: Exception) { "" }, - channel.lpa.profiles.enabled?.displayName, + channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled }?.displayName, channel.intrinsicChannelName, ) } diff --git a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt index 9f95412..0fe44c1 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/LPAUtils.kt @@ -16,10 +16,9 @@ val LocalProfileInfo.isEnabled: Boolean get() = state == LocalProfileInfo.State.Enabled val List.operational: List - get() = filter { it.profileClass == LocalProfileInfo.Clazz.Operational } - -val List.enabled: LocalProfileInfo? - get() = find { it.isEnabled } + get() = filter { + it.profileClass == LocalProfileInfo.Clazz.Operational + } val List.hasMultipleChips: Boolean get() = distinctBy { it.slotId }.size > 1 @@ -40,7 +39,7 @@ fun LocalProfileAssistant.switchProfile( * See EuiccManager.waitForReconnect() */ fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean = - profiles.enabled?.let { + profiles.find { it.isEnabled }?.let { Log.i(TAG, "Disabling active profile ${it.iccid}") disableProfile(it.iccid, refresh) } ?: true @@ -53,7 +52,7 @@ fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean = * disable. */ fun LocalProfileAssistant.disableActiveProfileKeepIccId(refresh: Boolean): String? = - profiles.enabled?.let { + profiles.find { it.isEnabled }?.let { Log.i(TAG, "Disabling active profile ${it.iccid}") if (disableProfile(it.iccid, refresh)) { it.iccid diff --git a/app-common/src/main/java/im/angry/openeuicc/util/UiUtils.kt b/app-common/src/main/java/im/angry/openeuicc/util/UiUtils.kt index a73d7fe..c8e481c 100644 --- a/app-common/src/main/java/im/angry/openeuicc/util/UiUtils.kt +++ b/app-common/src/main/java/im/angry/openeuicc/util/UiUtils.kt @@ -1,6 +1,5 @@ package im.angry.openeuicc.util -import android.content.ClipData import android.content.Context import android.content.Intent import android.content.res.Resources @@ -82,8 +81,6 @@ fun T.setupLogSaving( getLogFileName: () -> String, getLogText: () -> String ): () -> Unit { - var lastFileName = "untitled" - val launchSaveIntent = registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri -> if (uri == null) return@registerForActivityResult @@ -104,12 +101,10 @@ fun T.setupLogSaving( setMessage(R.string.logs_saved_message) setNegativeButton(R.string.no) { _, _ -> } setPositiveButton(R.string.yes) { _, _ -> - val intent = Intent(Intent.ACTION_SEND).apply { + val intent = Intent().apply { + action = Intent.ACTION_SEND type = "text/plain" - clipData = ClipData.newUri(context.contentResolver, lastFileName, uri) - putExtra(Intent.EXTRA_TITLE, lastFileName) putExtra(Intent.EXTRA_STREAM, uri) - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } context.startActivity(Intent.createChooser(intent, null)) @@ -118,7 +113,6 @@ fun T.setupLogSaving( } return { - lastFileName = getLogFileName() - launchSaveIntent.launch(lastFileName) + launchSaveIntent.launch(getLogFileName()) } } \ No newline at end of file diff --git a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt index 02b3baf..3c522c5 100644 --- a/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt +++ b/app/src/main/java/im/angry/openeuicc/service/OpenEuiccService.kt @@ -186,10 +186,13 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { ) } - return@withEuiccChannelManager try { - euiccChannelManager.withEuiccChannel(slotId, port) { channel -> + try { + return@withEuiccChannelManager euiccChannelManager.withEuiccChannel( + slotId, + port + ) { channel -> val filteredProfiles = - if (preferenceRepository.unfilteredProfileListFlow.first()) + if (runBlocking { preferenceRepository.unfilteredProfileListFlow.first() }) channel.lpa.profiles else channel.lpa.profiles.operational @@ -221,7 +224,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { ) } } catch (e: EuiccChannelManager.EuiccChannelNotFoundException) { - GetEuiccProfileInfoListResult( + return@withEuiccChannelManager GetEuiccProfileInfoListResult( RESULT_FIRST_USER, arrayOf(), true @@ -243,7 +246,11 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { // Check that the profile has been disabled on all slots val enabledAnywhere = ports.any { port -> euiccChannelManager.withEuiccChannel(slotId, port) { channel -> - channel.lpa.profiles.enabled?.iccid == iccid + val profile = channel.lpa.profiles.find { + it.iccid == iccid + } ?: return@withEuiccChannel false + + profile.state == LocalProfileInfo.State.Enabled } } @@ -347,8 +354,8 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker { // iccid == null means disabling val foundIccid = euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel -> - channel.lpa.profiles.enabled?.iccid - } ?: return@withEuiccChannelManager RESULT_FIRST_USER + channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled } + }?.iccid ?: return@withEuiccChannelManager RESULT_FIRST_USER Pair(foundIccid, false) } else { Pair(iccid, true)