Skip to content

Commit 9f3fec9

Browse files
committed
fix: support old carrierConfigManager.overrideConfig
1 parent 6e3655f commit 9f3fec9

1 file changed

Lines changed: 26 additions & 28 deletions

File tree

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

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.app.IActivityManager
55
import android.app.Instrumentation
66
import android.content.Context
77
import android.os.Bundle
8+
import android.os.PersistableBundle
89
import android.system.Os
910
import android.telephony.CarrierConfigManager
1011
import android.util.Log
@@ -15,52 +16,49 @@ const val TAG = "BrokerInstrumentation"
1516

1617
class BrokerInstrumentation : Instrumentation() {
1718
@SuppressLint("MissingPermission")
18-
private fun applyConfig(
19+
private fun overrideConfig(
1920
subId: Int,
20-
arguments: Bundle,
21+
overrideValues: PersistableBundle?,
2122
) {
22-
Log.i(TAG, "applyConfig")
2323
val am = IActivityManager.Stub.asInterface(ShizukuBinderWrapper(SystemServiceHelper.getSystemService(Context.ACTIVITY_SERVICE)))
24-
am.startDelegateShellPermissionIdentity(Os.getuid(), null)
2524
try {
25+
am.startDelegateShellPermissionIdentity(Os.getuid(), null)
2626
val configurationManager = this.context.getSystemService(CarrierConfigManager::class.java)
27-
val overrideValues = toPersistableBundle(arguments)
2827

2928
try {
30-
configurationManager.overrideConfig(subId, overrideValues, true)
29+
return configurationManager.overrideConfig(subId, overrideValues, true)
3130
} 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-
}
31+
} catch (e: NoSuchMethodError) {}
32+
33+
try {
34+
return configurationManager.overrideConfig(subId, overrideValues, false)
35+
} catch (e: SecurityException) {
36+
} catch (e: NoSuchMethodError) {}
37+
38+
configurationManager.overrideConfig(subId, overrideValues)
3839
} finally {
39-
Log.i(TAG, "applyConfig done")
4040
am.stopDelegateShellPermissionIdentity()
4141
}
4242
}
4343

44-
@SuppressLint("MissingPermission")
44+
private fun applyConfig(
45+
subId: Int,
46+
arguments: Bundle,
47+
) {
48+
Log.i(TAG, "applyConfig")
49+
try {
50+
this.overrideConfig(subId, toPersistableBundle(arguments))
51+
} finally {
52+
Log.i(TAG, "applyConfig done")
53+
}
54+
}
55+
4556
private fun clearConfig(subId: Int) {
4657
Log.i(TAG, "clearConfig")
47-
val am = IActivityManager.Stub.asInterface(ShizukuBinderWrapper(SystemServiceHelper.getSystemService(Context.ACTIVITY_SERVICE)))
48-
am.startDelegateShellPermissionIdentity(Os.getuid(), null)
4958
try {
50-
val configurationManager = this.context.getSystemService(CarrierConfigManager::class.java)
51-
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-
}
59+
this.overrideConfig(subId, null)
6160
} finally {
6261
Log.i(TAG, "clearConfig done")
63-
am.stopDelegateShellPermissionIdentity()
6462
}
6563
}
6664

0 commit comments

Comments
 (0)