Skip to content

Commit 75ec94d

Browse files
committed
feat: 新增 IMS User Agent 自定义功能
本次更新引入了对 IMS User Agent 字符串的自定义支持,并调整了构建配置。 - **功能新增**: - 在 `Feature` 枚举中添加了 `IMS_USER_AGENT` 选项,允许用户自定义 IMS User Agent。 - 更新 `ImsModifier` 和 `MainViewModel`,支持将自定义的 User Agent 应用于 `CarrierConfigManager.Ims.KEY_IMS_USER_AGENT_STRING` 配置。 - 同步更新了中英文 `strings.xml` 资源文件及 `README` 文档。 - **构建与代码优化**: - 将 `build.gradle.kts` 中的 Kotlin 编译器 `jvmTarget` 升级为 `JVM_21`。 - 微调 `ImsModifier` 中的代码逻辑,优化了对字符串非空判断的写法(使用 `== true` 替代 Elvis 运算符)。
1 parent 90e5f74 commit 75ec94d

File tree

8 files changed

+26
-2
lines changed

8 files changed

+26
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TurboIMS is a tool that allows you to enable or disable IMS features like Voice
3535
- **Customizable IMS Features**:
3636
- **Carrier Name**: Override the carrier name displayed on your device.
3737
- **Country ISO**: Force modify operator country code (Requires Android 14+).
38+
- **IMS User Agent**: Override the IMS User Agent string.
3839
- **VoLTE (Voice over LTE)**: Enable high-definition voice calls over 4G.
3940
- **VoWiFi (Wi-Fi Calling)**: Make calls over Wi-Fi networks, with options for Wi-Fi only mode.
4041
- **VT (Video Calling)**: Enable IMS-based video calls.

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TurboIMS 是一个允许您在 Google Pixel 手机上启用或禁用 VoLTE(高
3535
- **可定制的 IMS 功能**:
3636
- **运营商名称**: 覆盖设备上显示的运营商名称。
3737
- **运营商国家码 (Country ISO)**: 强制修改运营商国家码 (需 Android 14+)。
38+
- **IMS User Agent**: 自定义 IMS User Agent 字符串。
3839
- **VoLTE (高清语音通话)**: 开启 4G 高清语音通话。
3940
- **VoWiFi (Wi-Fi 通话)**: 通过 Wi-Fi 网络拨打电话,并可选择仅 Wi-Fi 模式。
4041
- **VT (视频通话)**: 开启基于 IMS 的视频通话。

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ val appVersionName: String = libs.versions.app.version.get()
2626

2727
kotlin {
2828
compilerOptions {
29+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21)
2930
optIn.add("androidx.compose.material3.ExperimentalMaterial3Api")
3031
optIn.add("androidx.compose.material3.ExperimentalMaterial3ExpressiveApi")
3132
}

app/src/main/java/io/github/vvb2060/ims/model/Feature.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ enum class Feature(
2121
R.string.country_iso_desc,
2222
"",
2323
),
24+
IMS_USER_AGENT(
25+
FeatureValueType.STRING,
26+
R.string.ims_user_agent,
27+
R.string.ims_user_agent_desc,
28+
"",
29+
),
2430
VOLTE(
2531
FeatureValueType.BOOLEAN,
2632
R.string.volte,

app/src/main/java/io/github/vvb2060/ims/privileged/ImsModifier.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ImsModifier : Instrumentation() {
3131
fun buildBundle(
3232
carrierName: String?,
3333
countryISO: String?,
34+
imsUserAgent: String?,
3435
enableVoLTE: Boolean,
3536
enableVoWiFi: Boolean,
3637
enableVT: Boolean,
@@ -42,20 +43,27 @@ class ImsModifier : Instrumentation() {
4243
): Bundle {
4344
val bundle = Bundle()
4445
// 运营商名称
45-
if (carrierName?.isNotBlank() ?: false) {
46+
if (carrierName?.isNotBlank() == true) {
4647
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_NAME_OVERRIDE_BOOL, true)
4748
bundle.putString(CarrierConfigManager.KEY_CARRIER_NAME_STRING, carrierName)
4849
bundle.putString(CarrierConfigManager.KEY_CARRIER_CONFIG_VERSION_STRING, ":3")
4950
}
5051
// 运营商国家码
5152
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
52-
if (countryISO?.isNotBlank() ?: false) {
53+
if (countryISO?.isNotBlank() == true) {
5354
bundle.putString(
5455
CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING,
5556
countryISO
5657
)
5758
}
5859
}
60+
// IMS User Agent
61+
if (imsUserAgent?.isNotBlank() == true) {
62+
bundle.putString(
63+
CarrierConfigManager.Ims.KEY_IMS_USER_AGENT_STRING,
64+
imsUserAgent
65+
)
66+
}
5967

6068
// VoLTE 配置
6169
if (enableVoLTE) {

app/src/main/java/io/github/vvb2060/ims/viewmodel/MainViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class MainViewModel(private val application: Application) : AndroidViewModel(app
148148
if (selectedSim.subId == -1) null else map[Feature.CARRIER_NAME]?.data as String?
149149
val countryISO =
150150
if (selectedSim.subId == -1) null else map[Feature.COUNTRY_ISO]?.data as String?
151+
val imsUserAgent =
152+
if (selectedSim.subId == -1) null else map[Feature.IMS_USER_AGENT]?.data as String?
151153
val enableVoLTE = (map[Feature.VOLTE]?.data ?: true) as Boolean
152154
val enableVoWiFi = (map[Feature.VOWIFI]?.data ?: true) as Boolean
153155
val enableVT = (map[Feature.VT]?.data ?: true) as Boolean
@@ -160,6 +162,7 @@ class MainViewModel(private val application: Application) : AndroidViewModel(app
160162
val bundle = ImsModifier.buildBundle(
161163
carrierName,
162164
countryISO,
165+
imsUserAgent,
163166
enableVoLTE,
164167
enableVoWiFi,
165168
enableVT,

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<string name="carrier_name_desc">自定义运营商显示的名称,为空则不修改</string>
2929
<string name="country_iso">运营商国家码</string>
3030
<string name="country_iso_desc">自定义运营商国家码,为空则不修改</string>
31+
<string name="ims_user_agent">IMS User Agent</string>
32+
<string name="ims_user_agent_desc">自定义 IMS User Agent 字符串,为空则不修改</string>
3133
<string name="volte">VoLTE(4G 语音)</string>
3234
<string name="volte_desc">启用 4G 高清语音通话</string>
3335
<string name="vowifi">VoWiFi(WiFi 通话)</string>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<string name="carrier_name_desc">Customize carrier name</string>
2929
<string name="country_iso">Country ISO</string>
3030
<string name="country_iso_desc">Customize country ISO code</string>
31+
<string name="ims_user_agent">IMS User Agent</string>
32+
<string name="ims_user_agent_desc">Customize IMS User Agent string</string>
3133
<string name="volte">VoLTE (4G Voice)</string>
3234
<string name="volte_desc">Enable 4G HD voice calls</string>
3335
<string name="vowifi">VoWiFi (WiFi Calling)</string>

0 commit comments

Comments
 (0)