自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
網域選取服務
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
針對搭載 Android 15 以上版本的裝置,您可以使用 DomainSelectionService
系統 API,在 IMS 服務和舊版服務之間透過電路交換網路實作網域選取功能。DomainSelectionService
是 Android 平台與供應商提供的網域選取實作項目之間的明確介面。這個介面可讓供應商實作提供信號資訊,例如在網路掃描中,傳出通話和 SMS 的網域,以及網路類型偏好設定。
圖 1. 網域選取功能的架構圖
範例和來源
Android 在 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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-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)."]]