Compare commits

...

6 commits

Author SHA1 Message Date
dc6b3a4810 feat: support disabling refresh after switch in settings
peter: Reworked strings and i18 translations. Also removed the ad-hoc
function in favor of a lambda.
2025-03-16 21:04:28 -04:00
e08f8beb45 feat: add iQOO stk launch support (#179)
![image](/attachments/b2aac119-c488-41e6-a39f-eab8559cd63b)

Reviewed-on: PeterCxy/OpenEUICC#179
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-03-17 00:01:22 +01:00
6b169c505d fix: crash (priv) (#177)
resolves #178

```
1741836445.585 10331 13748 13748 E AndroidRuntime: FATAL EXCEPTION: main
1741836445.585 10331 13748 13748 E AndroidRuntime: Process: im.angry.openeuicc, PID: 13748
1741836445.585 10331 13748 13748 E AndroidRuntime: java.lang.RuntimeException: PrivilegedEuiccContextMarker shall only be used on Fragments or UI types that derive from Context
1741836445.585 10331 13748 13748 E AndroidRuntime: 	at im.angry.openeuicc.util.PrivilegedEuiccContextMarker$DefaultImpls.getPrivilegedEuiccMarkerContext(PrivilegedUtils.kt:18)
```

Reviewed-on: PeterCxy/OpenEUICC#177
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-03-17 00:01:06 +01:00
33d383a3ce ui: wizard: Keep screen on during the download process 2025-03-16 17:54:54 -04:00
291869207a We don't need a public wake lock 2025-03-16 17:35:46 -04:00
a6286ed097 feat: Acquire partial wake lock for all foreground tasks
All of our foreground tasks require the CPU to be at least awake to make
any progress. We could keep the screen on but we really only need the
partial wake lock to make sure progress is made.
2025-03-16 17:32:09 -04:00
15 changed files with 80 additions and 37 deletions

View file

@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:enableOnBackInvokedCallback="true"

View file

@ -4,6 +4,7 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Binder
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
@ -11,6 +12,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import im.angry.openeuicc.common.R
import im.angry.openeuicc.core.EuiccChannel
import im.angry.openeuicc.core.EuiccChannelManager
import im.angry.openeuicc.util.*
import kotlinx.coroutines.Dispatchers
@ -91,6 +93,12 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
}
val euiccChannelManager: EuiccChannelManager by euiccChannelManagerDelegate
private val wakeLock: PowerManager.WakeLock by lazy {
(getSystemService(POWER_SERVICE) as PowerManager).run {
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this::class.simpleName)
}
}
/**
* The state of a "foreground" task (named so due to the need to startForeground())
*/
@ -275,6 +283,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
updateForegroundNotification(title, iconRes)
wakeLock.acquire(10 * 60 * 1000L /*10 minutes*/)
try {
withContext(Dispatchers.IO + NonCancellable) { // Any LPA-related task must always complete
this@EuiccChannelManagerService.task()
@ -290,6 +300,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
postForegroundTaskFailureNotification(failureTitle)
}
} finally {
wakeLock.release()
if (isActive) {
stopSelf()
}
@ -446,30 +457,34 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
iccid: String,
enable: Boolean, // Enable or disable the profile indicated in iccid
reconnectTimeoutMillis: Long = 0 // 0 = do not wait for reconnect
): ForegroundTaskSubscriberFlow =
) =
launchForegroundTask(
getString(R.string.task_profile_switch),
getString(R.string.task_profile_switch_failure),
R.drawable.ic_task_switch
) {
euiccChannelManager.beginTrackedOperation(slotId, portId) {
val (res, refreshed) = euiccChannelManager.withEuiccChannel(
slotId,
portId
) { channel ->
if (!channel.lpa.switchProfile(iccid, enable, refresh = true)) {
// Sometimes, we *can* enable or disable the profile, but we cannot
// send the refresh command to the modem because the profile somehow
// makes the modem "busy". In this case, we can still switch by setting
// refresh to false, but then the switch cannot take effect until the
// user resets the modem manually by toggling airplane mode or rebooting.
Pair(channel.lpa.switchProfile(iccid, enable, refresh = false), false)
} else {
Pair(true, true)
val (response, refreshed) =
euiccChannelManager.withEuiccChannel(slotId, portId) { channel ->
val refresh = preferenceRepository.refreshAfterSwitchFlow.first()
val response = channel.lpa.switchProfile(iccid, enable, refresh)
if (response || !refresh) {
Pair(response, refresh)
} else {
// refresh failed, but refresh was requested
// Sometimes, we *can* enable or disable the profile, but we cannot
// send the refresh command to the modem because the profile somehow
// makes the modem "busy". In this case, we can still switch by setting
// refresh to false, but then the switch cannot take effect until the
// user resets the modem manually by toggling airplane mode or rebooting.
Pair(
channel.lpa.switchProfile(iccid, enable, refresh = false),
false
)
}
}
}
if (!res) {
if (!response) {
throw RuntimeException("Could not switch profile")
}

View file

@ -78,6 +78,9 @@ open class SettingsFragment: PreferenceFragmentCompat() {
requirePreference<CheckBoxPreference>("pref_developer_ignore_tls_certificate")
.bindBooleanFlow(preferenceRepository.ignoreTLSCertificateFlow)
requirePreference<CheckBoxPreference>("pref_developer_refresh_after_switch")
.bindBooleanFlow(preferenceRepository.refreshAfterSwitchFlow)
requirePreference<CheckBoxPreference>("pref_developer_euicc_memory_reset")
.bindBooleanFlow(preferenceRepository.euiccMemoryResetFlow)
}

View file

@ -3,6 +3,7 @@ package im.angry.openeuicc.ui.wizard
import android.app.assist.AssistContent
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.ProgressBar
@ -251,6 +252,14 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
supportFragmentManager.beginTransaction().setCustomAnimations(enterAnim, exitAnim)
.replace(R.id.step_fragment_container, nextFrag)
.commit()
// Sync screen on state
if (nextFrag.keepScreenOn) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
refreshButtons()
}
@ -280,6 +289,8 @@ class DownloadWizardActivity: BaseEuiccAccessActivity() {
protected val state: DownloadWizardState
get() = (requireActivity() as DownloadWizardActivity).state
open val keepScreenOn = false
abstract val hasNext: Boolean
abstract val hasPrev: Boolean
abstract fun createNextFragment(): DownloadWizardStepFragment?

View file

@ -59,6 +59,9 @@ class DownloadWizardProgressFragment : DownloadWizardActivity.DownloadWizardStep
private val adapter = ProgressItemAdapter()
// We don't want to turn off the screen during a download
override val keepScreenOn = true
private var isDone = false
override val hasNext: Boolean

View file

@ -31,6 +31,7 @@ internal object PreferenceKeys {
// ---- Developer Options ----
val DEVELOPER_OPTIONS_ENABLED = booleanPreferencesKey("developer_options_enabled")
val REFRESH_AFTER_SWITCH = booleanPreferencesKey("refresh_after_switch")
val UNFILTERED_PROFILE_LIST = booleanPreferencesKey("unfiltered_profile_list")
val IGNORE_TLS_CERTIFICATE = booleanPreferencesKey("ignore_tls_certificate")
val EUICC_MEMORY_RESET = booleanPreferencesKey("euicc_memory_reset")
@ -48,6 +49,7 @@ open class PreferenceRepository(private val context: Context) {
val verboseLoggingFlow = bindFlow(PreferenceKeys.VERBOSE_LOGGING, false)
// ---- Developer Options ----
val refreshAfterSwitchFlow = bindFlow(PreferenceKeys.REFRESH_AFTER_SWITCH, true)
val developerOptionsEnabledFlow = bindFlow(PreferenceKeys.DEVELOPER_OPTIONS_ENABLED, false)
val unfilteredProfileListFlow = bindFlow(PreferenceKeys.UNFILTERED_PROFILE_LIST, false)
val ignoreTLSCertificateFlow = bindFlow(PreferenceKeys.IGNORE_TLS_CERTIFICATE, false)
@ -60,13 +62,10 @@ open class PreferenceRepository(private val context: Context) {
class PreferenceFlowWrapper<T> private constructor(
private val context: Context,
private val key: Preferences.Key<T>,
inner: Flow<T>
inner: Flow<T>,
) : Flow<T> by inner {
internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) : this(
context,
key,
context.dataStore.data.map { it[key] ?: defaultValue }
)
internal constructor(context: Context, key: Preferences.Key<T>, defaultValue: T) :
this(context, key, context.dataStore.data.map { it[key] ?: defaultValue })
suspend fun updatePreference(value: T) {
context.dataStore.edit { it[key] = value }

View file

@ -54,6 +54,9 @@ interface OpenEuiccContextMarker {
val appContainer: AppContainer
get() = openEuiccApplication.appContainer
val preferenceRepository: PreferenceRepository
get() = appContainer.preferenceRepository
val telephonyManager: TelephonyManager
get() = appContainer.telephonyManager
}

View file

@ -143,6 +143,7 @@
<string name="pref_advanced_logs">ログ</string>
<string name="pref_advanced_logs_desc">アプリの最新デバッグログを表示します</string>
<string name="pref_developer">開発者オプション</string>
<string name="pref_developer_refresh_after_switch_desc">プロファイルを切り替えた後にモデムに更新コマンドを送信するかどうか。クラッシュが発生する場合は、これを無効にしてみてください。</string>
<string name="pref_developer_unfiltered_profile_list">フィルタリングされていないプロファイル一覧を表示</string>
<string name="pref_developer_unfiltered_profile_list_desc">非運用のプロファイルも含めます</string>
<string name="pref_developer_ignore_tls_certificate">SM-DP+ TLS 証明書を無視する</string>
@ -162,4 +163,5 @@
<string name="euicc_memory_reset_invoke_button">消去する</string>
<string name="pref_developer_euicc_memory_reset">eUICC の消去を可能にする</string>
<string name="pref_developer_euicc_memory_reset_desc">この操作は、デフォルトでは非表示になっている危険な操作です。代わりに、すべての構成ファイルを手動で削除することもできます。</string>
<string name="pref_developer_refresh_after_switch">モデムに更新コマンドを送信</string>
</resources>

View file

@ -145,6 +145,7 @@
<string name="pref_advanced_language">语言</string>
<string name="pref_advanced_language_desc">选择 App 语言</string>
<string name="pref_developer">开发者选项</string>
<string name="pref_developer_refresh_after_switch_desc">切换配置文件后是否向基带发送刷新命令。如果发现崩溃,请尝试禁用此功能。</string>
<string name="pref_developer_unfiltered_profile_list">显示未经过滤的配置文件列表</string>
<string name="pref_developer_unfiltered_profile_list_desc">在配置文件列表中包括非生产环境的配置文件</string>
<string name="pref_developer_ignore_tls_certificate">无视 SM-DP+ 的 TLS 证书</string>
@ -162,4 +163,5 @@
<string name="euicc_memory_reset_invoke_button">擦除</string>
<string name="pref_developer_euicc_memory_reset">允许擦除 eUICC</string>
<string name="pref_developer_euicc_memory_reset_desc">此操作是默认隐藏的危险操作。作为替代方案,您可以手动删除所有配置文件。</string>
<string name="pref_developer_refresh_after_switch">向基带发送刷新命令</string>
</resources>

View file

@ -145,6 +145,7 @@
<string name="pref_advanced_language">語言</string>
<string name="pref_advanced_language_desc">選擇 App 語言</string>
<string name="pref_developer">開發人員選項</string>
<string name="pref_developer_refresh_after_switch_desc">切換設定檔後是否向基帶發送刷新命令。如果發現崩潰,請嘗試停用此功能。</string>
<string name="pref_developer_unfiltered_profile_list">顯示未經過濾的設定檔列表</string>
<string name="pref_developer_unfiltered_profile_list_desc">在設定檔列表中包括非生產環境的設定檔</string>
<string name="pref_developer_ignore_tls_certificate">忽略 SM-DP+ 的 TLS 證書</string>
@ -162,4 +163,5 @@
<string name="euicc_memory_reset_invoke_button">擦除</string>
<string name="pref_developer_euicc_memory_reset">允許擦除 eUICC</string>
<string name="pref_developer_euicc_memory_reset_desc">此操作是預設隱藏的危險操作。作為替代方案,您可以手動刪除所有設定檔。</string>
<string name="pref_developer_refresh_after_switch">向基帶發送刷新命令</string>
</resources>

View file

@ -181,6 +181,8 @@
<string name="pref_advanced_logs">Logs</string>
<string name="pref_advanced_logs_desc">View recent debug logs of the application</string>
<string name="pref_developer">Developer Options</string>
<string name="pref_developer_refresh_after_switch">Send refresh command to modem</string>
<string name="pref_developer_refresh_after_switch_desc">Whether to send a refresh command to the modem after switching profiles. Try disabling this if you see crashes.</string>
<string name="pref_developer_unfiltered_profile_list">Show unfiltered profile list</string>
<string name="pref_developer_unfiltered_profile_list_desc">Include non-production profiles in the list</string>
<string name="pref_developer_ignore_tls_certificate">Ignore SM-DP+ TLS certificate</string>

View file

@ -57,6 +57,12 @@
app:title="@string/pref_developer"
app:iconSpaceReserved="false">
<CheckBoxPreference
app:iconSpaceReserved="false"
app:key="pref_developer_refresh_after_switch"
app:summary="@string/pref_developer_refresh_after_switch_desc"
app:title="@string/pref_developer_refresh_after_switch" />
<CheckBoxPreference
app:iconSpaceReserved="false"
app:key="pref_developer_unfiltered_profile_list"

View file

@ -5,12 +5,14 @@
<item>com.android.stk/.StkMainHide</item>
<item>com.android.stk/.StkListActivity</item>
<item>com.android.stk/.StkLauncherListActivity</item>
<item>com.android.stk/.StkSelectionActivity</item>
</string-array>
<string-array name="sim_toolkit_slot_1">
<item>com.android.stk/.StkMain1</item>
<item>com.android.stk/.PrimaryStkMain</item>
<item>com.android.stk/.StkLauncherActivity</item>
<item>com.android.stk/.StkLauncherActivity_Chn</item>
<item>com.android.stk/.StkLauncherActivity1</item>
<item>com.android.stk/.StkLauncherActivityI</item>
<item>com.android.stk/.OppoStkLauncherActivity1</item>
<item>com.android.stk/.OplusStkLauncherActivity1</item>

View file

@ -10,9 +10,8 @@ import java.lang.IllegalArgumentException
class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFactory(context),
PrivilegedEuiccContextMarker {
private val tm by lazy {
(context.applicationContext as OpenEuiccApplication).appContainer.telephonyManager
}
override val openEuiccMarkerContext: Context
get() = context
@Suppress("NAME_SHADOWING")
override suspend fun tryOpenEuiccChannel(port: UiccPortInfoCompat): EuiccChannel? {
@ -35,7 +34,7 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
intrinsicChannelName = null,
TelephonyManagerApduInterface(
port,
tm,
telephonyManager,
context.preferenceRepository.verboseLoggingFlow
),
context.preferenceRepository.verboseLoggingFlow,

View file

@ -10,16 +10,9 @@ import java.util.concurrent.Executors
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
interface PrivilegedEuiccContextMarker {
val privilegedEuiccMarkerContext: Context
get() = when (this) {
is Context -> this
is Fragment -> requireContext()
else -> throw RuntimeException("PrivilegedEuiccContextMarker shall only be used on Fragments or UI types that derive from Context")
}
val preferenceRepository: PrivilegedPreferenceRepository
get() = privilegedEuiccMarkerContext.preferenceRepository as PrivilegedPreferenceRepository
interface PrivilegedEuiccContextMarker : OpenEuiccContextMarker {
override val preferenceRepository: PrivilegedPreferenceRepository
get() = appContainer.preferenceRepository as PrivilegedPreferenceRepository
}
suspend fun Context.bindServiceSuspended(intent: Intent, flags: Int): Pair<IBinder?, () -> Unit> =