自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
网域选择服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
对于搭载 Android 15 或更高版本的设备,您可以使用 DomainSelectionService
系统 API 在 IMS 服务和基于电路交换网络的旧版服务之间实现网域选择。DomainSelectionService
是在 Android 平台与供应商提供的网域选择实现之间明确定义的接口。借助此接口,供应商实现可以向平台提供信号信息,例如去电和短信所在的网域以及网络扫描中的网络类型偏好设置。
图 1. 网域选择功能的架构图
示例和源代码
Android 在 AOSP 的 TelephonyDomainSelectionService
中提供了网域选择功能的参考实现。如需查看 DomainSelectionService
API 的详细文档,请参阅 DomainSelectionService
以及该 API 中的其他类。
实现
如需在 Android 设备上实现网域选择功能,必须按以下步骤操作:
创建一个网域选择应用。相应服务必须在 AndroidManifest.xml
文件中进行定义。
向设备叠加层添加配置,以便让平台绑定到 DomainSelectionService
实现。
支持网域选择功能所需的无线 HAL 接口。
本部分详细介绍了这些步骤。
在 AndroidManifest.xml 中添加服务条目
如需让网域选择应用向框架注册 DomainSelectionService
服务,请使用以下格式在清单文件中添加服务条目:
<service
android:name="com.example.domainselection.DomainSelectionService"
android:directBootAware="true"
android:persistent="true"
…
android:permission="android.permission.BIND_DOMAIN_SELECTION_SERVICE"
…
<intent-filter>
<action android:name="android.telephony.DomainSelectionService"/>
</intent-filter>
…
</service>
AndroidManifest.xml
中的服务定义必须定义以下属性,网域选择功能才能正常运行。
directBootAware="true"
:在用户解锁设备之前,允许该服务被发现并由电话应用运行。在用户解锁设备之前,该服务无法访问设备加密的存储空间。如需了解详情,请参阅支持直接启动模式和文件级加密。
persistent="true"
:允许该服务持久化运行,不因系统回收内存而终止。只有在相应的应用作为系统应用进行构建时,此属性才有效。
permission="android.permission.BIND_DOMAIN_SELECTION_SERVICE"
:确保只有被授予 BIND_DOMAIN_SELECTION_SERVICE
权限的进程才能绑定到相应的应用。这样可以防止恶意应用绑定到该服务,因为框架只会向系统应用授予这项权限。
此外,该服务还必须指定具有 android.telephony.DomainSelectionService
操作的 intent-filter
元素。这样,框架就可以找到 DomainSelectionService
服务。
在设备叠加层中定义配置
如需让平台安全地绑定到 DomainSelectionService
服务,请向设备叠加层添加以下配置:
由于 Android 不支持使用第三方可下载 DomainSelectionService
实现的应用,因此网域选择应用必须是位于 /system_ext/priv-app/
或 /product/priv-app/
文件夹中的系统应用。该框架会验证相应实现的软件包名称是否与设备叠加层值匹配,以确保仅绑定受信任的预安装应用。
支持无线 HAL 接口
如需启用网域选择功能,请支持以下所需的无线 HAL 接口:
IRadioNetwork
void setEmergencyMode(int serial, EmergencyMode emcModeType);
void triggerEmergencyNetworkScan(int serial,
EmergencyNetworkScanTrigger request);
void cancelEmergencyNetworkScan(int serial, boolean resetScan);
void exitEmergencyMode(int serial);
IRadioNetworkIndication
void emergencyNetworkScanResult(RadioIndicationType type,
EmergencyRegResult result);
验证
如需测试电话框架是否正确响应 DomainSelectionService
接口,请在 DomainSelectionServiceTestOnMockModem
中运行 CTS 测试。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Domain selection service\n\nFor devices running Android 15 or higher, you can\nimplement domain selection\nbetween the IMS service and legacy services over circuit switched networks using\nthe [`DomainSelectionService`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/telephony/java/android/telephony/DomainSelectionService.java) system API. `DomainSelectionService`\nis a well-defined interface between the Android platform and a vendor provided\ndomain selection implementation. This interface lets the vendor implementation\nprovide signaling information, such as the domain that outgoing calls and SMS\nare placed and network type preference in network scanning, to the platform.\n\n**Figure 1.** Architecture diagram for the domain selection feature\n\nExamples and source\n-------------------\n\nAndroid provides a reference implementation for the domain selection feature in\nAOSP at [`TelephonyDomainSelectionService`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Telephony/src/com/android/services/telephony/domainselection/). For detailed\ndocumentation for the `DomainSelectionService` API, see\n[`DomainSelectionService`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/telephony/java/android/telephony/DomainSelectionService.java) and the other classes in the API.\n\nImplementation\n--------------\n\nTo implement the domain selection feature on an Android device, the following\nsteps are required:\n\n1. Create a domain selection app. The service must be defined in the\n `AndroidManifest.xml` file.\n\n2. Add a configuration to the device overlay to let the platform bind to the\n `DomainSelectionService` implementation.\n\n3. Support the required radio HAL interfaces for the domain selection feature.\n\nThis section provides further details of these steps.\n\n### Add service entry in AndroidManifest.xml\n\nFor your domain selection app to register the `DomainSelectionService` service\nwith the framework, add a service entry in the manifest file using the following\nformat: \n\n \u003cservice\n android:name=\"com.example.domainselection.DomainSelectionService\"\n android:directBootAware=\"true\"\n android:persistent=\"true\"\n ...\n android:permission=\"android.permission.BIND_DOMAIN_SELECTION_SERVICE\"\n ...\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.telephony.DomainSelectionService\"/\u003e\n \u003c/intent-filter\u003e\n ...\n \u003c/service\u003e\n\nThe service definition in `AndroidManifest.xml` must define the following\nattributes for the domain selection feature to operate.\n\n- `directBootAware=\"true\"`: Lets the service be discovered and run by\n telephony before the user unlocks the device. The service can't access\n *device-encrypted* storage before the user unlocks the device. For more\n information,\n see [Support Direct Boot mode](https://developer.android.com/privacy-and-security/direct-boot) and [File-Based Encryption](/docs/security/features/encryption/file-based).\n\n- `persistent=\"true\"`: Lets the service be run persistently and not be\n killed by the system to reclaim memory. This attribute works *only* if the\n app is built as a system app.\n\n- `permission=\"android.permission.BIND_DOMAIN_SELECTION_SERVICE\"`: Ensures\n that only a process that has the `BIND_DOMAIN_SELECTION_SERVICE` permission\n granted to it can bind to the app. This prevents a rogue app from binding to\n the service, because only system apps can be granted the permission by the\n framework.\n\nThe service must also specify the `intent-filter` element with the\n`android.telephony.DomainSelectionService` action. This lets the framework find\nthe `DomainSelectionService` service.\n\n### Define configuration in device overlay\n\nFor the platform to securely bind to the `DomainSelectionService` service, add\nthe following configuration to the device overlay:\n\n- [`config_domain_selection_service_component_name`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Telephony/res/values/config.xml?q=config_domain_selection_service_component_name): The component name (a flattened `ComponentName` string) for the `DomainSelectionService` service\n\nBecause Android doesn't support apps with third-party downloadable\n`DomainSelectionService` implementations, the domain selection app must be a\nsystem app that resides in the `/system_ext/priv-app/` or `/product/priv-app/`\nfolder. The framework verifies whether the package name of the implementation\nmatches the device overlay value to ensure only trusted, preinstalled apps are\nbound.\n\n### Support radio HAL interfaces\n\nTo enable the domain selection feature, support the following required radio HAL\ninterfaces:\n\n- [`IRadioNetwork`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/radio/aidl/android/hardware/radio/network/IRadioNetwork.aidl)\n\n void setEmergencyMode(int serial, EmergencyMode emcModeType);\n void triggerEmergencyNetworkScan(int serial,\n EmergencyNetworkScanTrigger request);\n void cancelEmergencyNetworkScan(int serial, boolean resetScan);\n void exitEmergencyMode(int serial);\n\n- [`IRadioNetworkIndication`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/radio/aidl/android/hardware/radio/network/IRadioNetworkIndication.aidl)\n\n void emergencyNetworkScanResult(RadioIndicationType type,\n EmergencyRegResult result);\n\nValidation\n----------\n\nTo test that the telephony framework properly responds to the\n`DomainSelectionService` interface, run the CTS tests in\n[`DomainSelectionServiceTestOnMockModem`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/tests/telephony/current/src/android/telephony/cts/DomainSelectionServiceTestOnMockModem.java)."]]