Java 电台应用示例 (packages/apps/Car/Radio) 可用作实现参考。应用服务启动时,它会请求电台管理器打开电台调谐器。然后,应用可以向电台调谐器发送请求,例如调到特定电台、频率或搜寻下一个可用的电台。应用通过电台中的电台管理器和电台调谐器接收更新,例如当前节目信息、电台节目列表、配置和供应商定义的参数。参考电台应用仅支持 AM 和 FM 电台。OEM 可以根据需要修改或更换电台应用。
电台管理器
当应用请求电台管理器打开调谐器时,电台管理器 (frameworks/base/core/java/android/hardware/radio/RadioManager.java) 会请求广播电台服务 (BRS) 打开调谐器会话,然后将该会话封装在电台调谐器 (frameworks/base/core/java/android/hardware/radio/RadioTuner.java) 中并返回给应用。电台调谐器会定义 API(例如调谐、步进和取消)。这些 API 可以从电台应用中调用,并向广播电台服务发送请求。在电台调谐器中定义的回调方法 (RadioTuner.Callback) 会从 BRS 向应用发送有关广播电台 HAL 的更新(例如当前节目信息、节目列表和供应商定义的参数)。
广播电台服务
广播电台服务 (frameworks/base/services/core/java/com/android/server/broadcastradio) 是广播电台 HAL 的客户端服务。BRS 使用广播电台 HAL 协调多个电台管理器。BRS 支持 HAL 接口定义语言 (HIDL) 和 Android 接口定义语言 (AIDL) 广播电台 HAL。如果存在任何 AIDL HAL 服务,BRS 就会关联到 AIDL HAL;否则,该服务会关联到 HIDL HAL。BRS 会为每个可用的 HAL 实例(例如 AM、FM 和 DAB)创建一个电台模块。
每个电台管理器都可以请求 BRS 根据电台类型在相应的电台模块上创建调谐器会话。每个调谐器会话都可以调用(在 HAL 接口中定义的)调谐、步进和取消等方法对相应的广播电台 HAL 实例执行操作。当一个调谐器会话收到 HAL 实例对 HAL 更新(例如当前节目信息、节目列表、配置标志和供应商参数)发出的回调时,系统会将有关更新的回调发送给与同一电台模块关联的所有电台调谐器。
广播电台 HAL
如需详细了解广播电台的 HIDL 和 AIDL 接口以及两者之间的区别,请参阅广播电台 HAL 接口。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Overview\n\nThe broadcast radio stack consists of the components illustrated in Figure 1.\n**Figure 1.** Broadcast Radio architecture.\n\nRadio reference app\n-------------------\n\nFor details about how to implement radio control, see\n[Radio control implementation](/docs/automotive/radio/radio-control-implementation).\n\nA sample Java radio app (`packages/apps/Car/Radio`) serves as a reference\nimplementation. When the app service starts, it requests Radio Manager to open a Radio Tuner. Then,\nthe app can send requests to the Radio Tuner, such as tuning to a specific radio station, frequency,\nor to seek the next available radio station. The app receives updates from the Radio Manager and\nRadio Tuner in Radio, such as current program information, radio program lists, configurations, and\nvendor-defined parameters. The reference Radio app only supports AM and FM radio. OEMs can modify or\nreplace the Radio app as desired.\n\nRadio Manager\n-------------\n\nWhen the app requests Radio Manager to open a tuner, the Radio Manager\n(`frameworks/base/core/java/android/hardware/radio/RadioManager.java`) requests the\nBroadcast Radio Service (BRS) to open a Tuner session and then wraps the session in a Radio Tuner\n(`frameworks/base/core/java/android/hardware/radio/RadioTuner.java`), which is returned\nto the app.\n\nThe Radio Tuner defines APIs (such as tune, step, and cancel) that can be called from radio apps\nand send requests to BRS. Callback methods (`RadioTuner.Callback`) defined in Radio\nTuner send updates about the broadcast radio HAL, such as current program information, program\nlists, and vendor-defined parameters, from the BRS to apps.\n\nBroadcast Radio Service\n-----------------------\n\nThe Broadcast Radio Service\n(`frameworks/base/services/core/java/com/android/server/broadcastradio`) is the client\nservice for Broadcast Radio HAL. The BRS coordinates multiple Radio Managers with Broadcast Radio\nHALs. The BRS supports\n[HAL interface definition language (HIDL)](/docs/core/architecture/hidl) and\n[Android interface definition language (AIDL)](/docs/core/architecture/aidl) broadcast\nradio HALs. The BRS links to the AIDL HAL when any AIDL HAL service exists;\notherwise, the service links to the HIDL HAL. The BRS creates a Radio Module\nfor each available HAL instance (such as AM, FM, and DAB).\n\nEach Radio Manager can request the BRS to create a tuner session on the\ncorresponding Radio Module, based on the type of radio. Each tuner session can call methods, such\nas tune, step, and cancel (defined in HAL interfaces) to perform operations on the\ncorresponding broadcast radio HAL instance. When one tuner session receives a callback from the HAL\ninstance on a HAL update, such as current program info, program list, configuration flags and,\nvendor parameters, callbacks about the update are sent to all Radio Tuners linked to the same\nRadio Module.\n\nBroadcast Radio HAL\n-------------------\n\n| In Android 13 and lower, versions of the BRS are provided in HIDL and AIDL. New features are added **only** to releases of Android 14 and higher.\n\nTo learn more about the HIDL and AIDL interfaces of broadcast radio and the differences between\nthe two, see\n[Broadcast Radio HAL interface](/docs/automotive/radio/broadcast-radio-hal)."]]