我正在开发一项功能,一旦安装了 Sim 并且应用程序获得了运营商权限,我需要为我们的订阅更新一些运营商配置。现在应用程序成功获得了运营商特权,但不知何故 CarrierService 没有被执行。 onLoadConfig 方法都没有被调用。
以下是我的服务
class SampleCarrierConfigService : CarrierService() {
override fun onLoadConfig(id: CarrierIdentifier?): PersistableBundle {
val config = PersistableBundle()
config.putBoolean(
CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL, true
)
config.putBoolean(
CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL, false
)
config.putInt(CarrierConfigManager.KEY_VOLTE_REPLACEMENT_RAT_INT, 6)
// Check CarrierIdentifier and add more config if needed…
return config
}
companion object {
private const val TAG = "SampleCarrierConfig"
}
init {
Log.d(TAG, "Service created")
}
}
这是我在清单中注册的方式
<service
android:name=".SampleCarrierConfigService"
android:label="carrier_config_service"
android:permission="android.permission.BIND_CARRIER_SERVICES">
<intent-filter>
<action android:name="android.service.carrier.CarrierService" />
</intent-filter>
<meta-data
android:name="android.service.carrier.LONG_LIVED_BINDING"
android:value="true" />
</service>
我在三星设备上遇到了这个问题。如果用户手动修改某些参数 CarrierService.onLoadConfig 也会停止工作。
这是一项特权。
您可以参考以下代码。
https://android.googlesource.com/platform/packages/apps/CarrierConfig/+/refs/heads/master/Android.bp
android_应用程序{ 名称:“运营商配置”, srcs: ["src/**/*.java"], platform_apis:正确, 证书:“平台”, 系统扩展特定:true, 特权:真实, 必填:[“privapp_whitelist_com.android.carrierconfig”], 优化: { proguard_flags_files: ["proguard.flags"], }, aaptflags: ["--keep-raw-values"], }