forked from PeterCxy/OpenEUICC
Compare commits
4 commits
895899d03a
...
43f247a71b
Author | SHA1 | Date | |
---|---|---|---|
43f247a71b | |||
960f8855ad | |||
de3ae19a10 | |||
75d3894462 |
6 changed files with 44 additions and 24 deletions
|
@ -2,6 +2,7 @@ package im.angry.openeuicc.ui.wizard
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
|
@ -84,6 +85,7 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
|
||||||
val bars = insets.getInsets(
|
val bars = insets.getInsets(
|
||||||
WindowInsetsCompat.Type.systemBars()
|
WindowInsetsCompat.Type.systemBars()
|
||||||
or WindowInsetsCompat.Type.displayCutout()
|
or WindowInsetsCompat.Type.displayCutout()
|
||||||
|
or WindowInsetsCompat.Type.ime()
|
||||||
)
|
)
|
||||||
v.updatePadding(bars.left, 0, bars.right, bars.bottom)
|
v.updatePadding(bars.left, 0, bars.right, bars.bottom)
|
||||||
val newParams = navigation.layoutParams
|
val newParams = navigation.layoutParams
|
||||||
|
@ -132,6 +134,8 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPrevPressed() {
|
private fun onPrevPressed() {
|
||||||
|
hideIme()
|
||||||
|
|
||||||
if (currentFragment?.hasPrev == true) {
|
if (currentFragment?.hasPrev == true) {
|
||||||
val prevFrag = currentFragment?.createPrevFragment()
|
val prevFrag = currentFragment?.createPrevFragment()
|
||||||
if (prevFrag == null) {
|
if (prevFrag == null) {
|
||||||
|
@ -143,6 +147,8 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onNextPressed() {
|
private fun onNextPressed() {
|
||||||
|
hideIme()
|
||||||
|
|
||||||
if (currentFragment?.hasNext == true) {
|
if (currentFragment?.hasNext == true) {
|
||||||
currentFragment?.beforeNext()
|
currentFragment?.beforeNext()
|
||||||
val nextFrag = currentFragment?.createNextFragment()
|
val nextFrag = currentFragment?.createNextFragment()
|
||||||
|
@ -192,6 +198,13 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hideIme() {
|
||||||
|
currentFocus?.let {
|
||||||
|
val imm = getSystemService(InputMethodManager::class.java)
|
||||||
|
imm.hideSoftInputFromWindow(it.windowToken, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract class DownloadWizardStepFragment : Fragment(), OpenEuiccContextMarker {
|
abstract class DownloadWizardStepFragment : Fragment(), OpenEuiccContextMarker {
|
||||||
protected val state: DownloadWizardState
|
protected val state: DownloadWizardState
|
||||||
get() = (requireActivity() as DownloadWizardActivity).state
|
get() = (requireActivity() as DownloadWizardActivity).state
|
||||||
|
|
|
@ -22,7 +22,7 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
||||||
private lateinit var confirmationCode: TextInputLayout
|
private lateinit var confirmationCode: TextInputLayout
|
||||||
private lateinit var imei: TextInputLayout
|
private lateinit var imei: TextInputLayout
|
||||||
|
|
||||||
override fun beforeNext() {
|
private fun saveState() {
|
||||||
state.smdp = smdp.editText!!.text.toString().trim()
|
state.smdp = smdp.editText!!.text.toString().trim()
|
||||||
// Treat empty inputs as null -- this is important for the download step
|
// Treat empty inputs as null -- this is important for the download step
|
||||||
state.matchingId = matchingId.editText!!.text.toString().trim().ifBlank { null }
|
state.matchingId = matchingId.editText!!.text.toString().trim().ifBlank { null }
|
||||||
|
@ -30,6 +30,8 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
||||||
state.imei = imei.editText!!.text.toString().ifBlank { null }
|
state.imei = imei.editText!!.text.toString().ifBlank { null }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun beforeNext() = saveState()
|
||||||
|
|
||||||
override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
|
override fun createNextFragment(): DownloadWizardActivity.DownloadWizardStepFragment =
|
||||||
DownloadWizardProgressFragment()
|
DownloadWizardProgressFragment()
|
||||||
|
|
||||||
|
@ -61,6 +63,11 @@ class DownloadWizardDetailsFragment : DownloadWizardActivity.DownloadWizardStepF
|
||||||
updateInputCompleteness()
|
updateInputCompleteness()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
saveState()
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateInputCompleteness() {
|
private fun updateInputCompleteness() {
|
||||||
inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
|
inputComplete = Patterns.DOMAIN_NAME.matcher(smdp.editText!!.text).matches()
|
||||||
refreshButtons()
|
refreshButtons()
|
||||||
|
|
|
@ -111,7 +111,7 @@ class DownloadWizardSlotSelectFragment : DownloadWizardActivity.DownloadWizardSt
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
""
|
""
|
||||||
},
|
},
|
||||||
channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled }?.displayName,
|
channel.lpa.profiles.enabled?.displayName,
|
||||||
channel.intrinsicChannelName,
|
channel.intrinsicChannelName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,10 @@ val LocalProfileInfo.isEnabled: Boolean
|
||||||
get() = state == LocalProfileInfo.State.Enabled
|
get() = state == LocalProfileInfo.State.Enabled
|
||||||
|
|
||||||
val List<LocalProfileInfo>.operational: List<LocalProfileInfo>
|
val List<LocalProfileInfo>.operational: List<LocalProfileInfo>
|
||||||
get() = filter {
|
get() = filter { it.profileClass == LocalProfileInfo.Clazz.Operational }
|
||||||
it.profileClass == LocalProfileInfo.Clazz.Operational
|
|
||||||
}
|
val List<LocalProfileInfo>.enabled: LocalProfileInfo?
|
||||||
|
get() = find { it.isEnabled }
|
||||||
|
|
||||||
val List<EuiccChannel>.hasMultipleChips: Boolean
|
val List<EuiccChannel>.hasMultipleChips: Boolean
|
||||||
get() = distinctBy { it.slotId }.size > 1
|
get() = distinctBy { it.slotId }.size > 1
|
||||||
|
@ -39,7 +40,7 @@ fun LocalProfileAssistant.switchProfile(
|
||||||
* See EuiccManager.waitForReconnect()
|
* See EuiccManager.waitForReconnect()
|
||||||
*/
|
*/
|
||||||
fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean =
|
fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean =
|
||||||
profiles.find { it.isEnabled }?.let {
|
profiles.enabled?.let {
|
||||||
Log.i(TAG, "Disabling active profile ${it.iccid}")
|
Log.i(TAG, "Disabling active profile ${it.iccid}")
|
||||||
disableProfile(it.iccid, refresh)
|
disableProfile(it.iccid, refresh)
|
||||||
} ?: true
|
} ?: true
|
||||||
|
@ -52,7 +53,7 @@ fun LocalProfileAssistant.disableActiveProfile(refresh: Boolean): Boolean =
|
||||||
* disable.
|
* disable.
|
||||||
*/
|
*/
|
||||||
fun LocalProfileAssistant.disableActiveProfileKeepIccId(refresh: Boolean): String? =
|
fun LocalProfileAssistant.disableActiveProfileKeepIccId(refresh: Boolean): String? =
|
||||||
profiles.find { it.isEnabled }?.let {
|
profiles.enabled?.let {
|
||||||
Log.i(TAG, "Disabling active profile ${it.iccid}")
|
Log.i(TAG, "Disabling active profile ${it.iccid}")
|
||||||
if (disableProfile(it.iccid, refresh)) {
|
if (disableProfile(it.iccid, refresh)) {
|
||||||
it.iccid
|
it.iccid
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package im.angry.openeuicc.util
|
package im.angry.openeuicc.util
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
@ -81,6 +82,8 @@ fun <T : ActivityResultCaller> T.setupLogSaving(
|
||||||
getLogFileName: () -> String,
|
getLogFileName: () -> String,
|
||||||
getLogText: () -> String
|
getLogText: () -> String
|
||||||
): () -> Unit {
|
): () -> Unit {
|
||||||
|
var lastFileName = "untitled"
|
||||||
|
|
||||||
val launchSaveIntent =
|
val launchSaveIntent =
|
||||||
registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri ->
|
registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri ->
|
||||||
if (uri == null) return@registerForActivityResult
|
if (uri == null) return@registerForActivityResult
|
||||||
|
@ -101,10 +104,12 @@ fun <T : ActivityResultCaller> T.setupLogSaving(
|
||||||
setMessage(R.string.logs_saved_message)
|
setMessage(R.string.logs_saved_message)
|
||||||
setNegativeButton(R.string.no) { _, _ -> }
|
setNegativeButton(R.string.no) { _, _ -> }
|
||||||
setPositiveButton(R.string.yes) { _, _ ->
|
setPositiveButton(R.string.yes) { _, _ ->
|
||||||
val intent = Intent().apply {
|
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||||
action = Intent.ACTION_SEND
|
|
||||||
type = "text/plain"
|
type = "text/plain"
|
||||||
|
clipData = ClipData.newUri(context.contentResolver, lastFileName, uri)
|
||||||
|
putExtra(Intent.EXTRA_TITLE, lastFileName)
|
||||||
putExtra(Intent.EXTRA_STREAM, uri)
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.startActivity(Intent.createChooser(intent, null))
|
context.startActivity(Intent.createChooser(intent, null))
|
||||||
|
@ -113,6 +118,7 @@ fun <T : ActivityResultCaller> T.setupLogSaving(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
launchSaveIntent.launch(getLogFileName())
|
lastFileName = getLogFileName()
|
||||||
|
launchSaveIntent.launch(lastFileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -186,13 +186,10 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return@withEuiccChannelManager try {
|
||||||
return@withEuiccChannelManager euiccChannelManager.withEuiccChannel(
|
euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
|
||||||
slotId,
|
|
||||||
port
|
|
||||||
) { channel ->
|
|
||||||
val filteredProfiles =
|
val filteredProfiles =
|
||||||
if (runBlocking { preferenceRepository.unfilteredProfileListFlow.first() })
|
if (preferenceRepository.unfilteredProfileListFlow.first())
|
||||||
channel.lpa.profiles
|
channel.lpa.profiles
|
||||||
else
|
else
|
||||||
channel.lpa.profiles.operational
|
channel.lpa.profiles.operational
|
||||||
|
@ -224,7 +221,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: EuiccChannelManager.EuiccChannelNotFoundException) {
|
} catch (e: EuiccChannelManager.EuiccChannelNotFoundException) {
|
||||||
return@withEuiccChannelManager GetEuiccProfileInfoListResult(
|
GetEuiccProfileInfoListResult(
|
||||||
RESULT_FIRST_USER,
|
RESULT_FIRST_USER,
|
||||||
arrayOf(),
|
arrayOf(),
|
||||||
true
|
true
|
||||||
|
@ -246,11 +243,7 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
// Check that the profile has been disabled on all slots
|
// Check that the profile has been disabled on all slots
|
||||||
val enabledAnywhere = ports.any { port ->
|
val enabledAnywhere = ports.any { port ->
|
||||||
euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
|
euiccChannelManager.withEuiccChannel(slotId, port) { channel ->
|
||||||
val profile = channel.lpa.profiles.find {
|
channel.lpa.profiles.enabled?.iccid == iccid
|
||||||
it.iccid == iccid
|
|
||||||
} ?: return@withEuiccChannel false
|
|
||||||
|
|
||||||
profile.state == LocalProfileInfo.State.Enabled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,8 +347,8 @@ class OpenEuiccService : EuiccService(), OpenEuiccContextMarker {
|
||||||
// iccid == null means disabling
|
// iccid == null means disabling
|
||||||
val foundIccid =
|
val foundIccid =
|
||||||
euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel ->
|
euiccChannelManager.withEuiccChannel(foundSlotId, foundPortId) { channel ->
|
||||||
channel.lpa.profiles.find { it.state == LocalProfileInfo.State.Enabled }
|
channel.lpa.profiles.enabled?.iccid
|
||||||
}?.iccid ?: return@withEuiccChannelManager RESULT_FIRST_USER
|
} ?: return@withEuiccChannelManager RESULT_FIRST_USER
|
||||||
Pair(foundIccid, false)
|
Pair(foundIccid, false)
|
||||||
} else {
|
} else {
|
||||||
Pair(iccid, true)
|
Pair(iccid, true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue