Skip to content

Commit ebdc5e1

Browse files
xieyangclaude
authored andcommitted
修复: Android 16 上 overrideConfig 导致系统电话进程崩溃
在 Android 16 (SDK 36) 上,调用 overrideConfig(persistent=true) 会导致 com.android.phone 系统进程崩溃,抛出 SecurityException。由于崩溃发生在 不同的进程中,应用的 try-catch 无法捕获该异常。 此修改通过检测 SDK 版本,在 Android 16+ 上直接使用 persistent=false, 从根本上避免崩溃。代价是重启后运营商配置会丢失,但可通过 Shizuku 重新应用,属于可接受的折衷方案。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0b4b5fe commit ebdc5e1

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

app/src/main/java/dev/bluehouse/enablevolte/BrokerInstrumentation.kt

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
44
import android.app.IActivityManager
55
import android.app.Instrumentation
66
import android.content.Context
7+
import android.os.Build
78
import android.os.Bundle
89
import android.system.Os
910
import android.telephony.CarrierConfigManager
@@ -26,15 +27,8 @@ class BrokerInstrumentation : Instrumentation() {
2627
val configurationManager = this.context.getSystemService(CarrierConfigManager::class.java)
2728
val overrideValues = toPersistableBundle(arguments)
2829

29-
try {
30-
configurationManager.overrideConfig(subId, overrideValues, true)
31-
} catch (e: SecurityException) {
32-
if (e.message?.contains("overrideConfig with persistent=true only can be invoked by system app") == true) {
33-
configurationManager.overrideConfig(subId, overrideValues, false)
34-
} else {
35-
throw e
36-
}
37-
}
30+
val persistent = Build.VERSION.SDK_INT < 36
31+
configurationManager.overrideConfig(subId, overrideValues, persistent)
3832
} finally {
3933
Log.i(TAG, "applyConfig done")
4034
am.stopDelegateShellPermissionIdentity()
@@ -49,15 +43,8 @@ class BrokerInstrumentation : Instrumentation() {
4943
try {
5044
val configurationManager = this.context.getSystemService(CarrierConfigManager::class.java)
5145

52-
try {
53-
configurationManager.overrideConfig(subId, null, true)
54-
} catch (e: SecurityException) {
55-
if (e.message?.contains("overrideConfig with persistent=true only can be invoked by system app") == true) {
56-
configurationManager.overrideConfig(subId, null, false)
57-
} else {
58-
throw e
59-
}
60-
}
46+
val persistent = Build.VERSION.SDK_INT < 36
47+
configurationManager.overrideConfig(subId, null, persistent)
6148
} finally {
6249
Log.i(TAG, "clearConfig done")
6350
am.stopDelegateShellPermissionIdentity()

app/src/main/java/dev/bluehouse/enablevolte/Moder.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ class SubscriptionModer(
171171

172172
private fun overrideConfigDirectly(bundle: Bundle?) {
173173
val iCclInstance = this.loadCachedInterface { carrierConfigLoader }
174+
val persistent = Build.VERSION.SDK_INT < 36
174175
if (bundle != null) {
175176
val args = toPersistableBundle(bundle)
176-
iCclInstance.overrideConfig(subscriptionId, args, true)
177+
iCclInstance.overrideConfig(subscriptionId, args, persistent)
177178
} else {
178-
iCclInstance.overrideConfig(subscriptionId, null, true)
179+
iCclInstance.overrideConfig(subscriptionId, null, persistent)
179180
}
180181
}
181182

0 commit comments

Comments
 (0)