• android FM的流程


    FM framework:

    1、适配层调用的最外面接口是Radiomanager


    frameworks/base/core/java/android/hardware/radio/RadioManager.java
    frameworks/base/core/java/android/hardware/radio/TunerCallbackAdapter.java
    下面是向上外层适配层回调的主要是三个接口, 都在TunerCallbackAdapter.java
    onTuneFailed, onCurrentProgramInfoChanged, onProgramListUpdated

    RadioManager.java→构造函数里获取radioservice

    1. public RadioManager(@NonNull Context context) throws ServiceNotFoundException {
    2. mService = IRadioService.Stub.asInterface(
    3. ServiceManager.getServiceOrThrow(Context.RADIO_SERVICE));
    4. }

    frameworks/base/core/java/android/hardware/radio/RadioManager.java

    打开tuner设备,并设置callback

    1. public RadioTuner openTuner(int moduleId){
    2. TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler);
    3. ITuner tuner = mService.openTuner(moduleId, config, withAudio, halCallback);
    4. return new TunerAdapter(tuner, halCallback, config != null ? config.getType() : BAND_INVALID);
    5. }
    接下来在frameworks/base/core/java/android/hardware/radio/TunerAdapter.java里做接口调用,比如

    scan, step, tune, startBackgroundScan(没用到)

    在frameworks/base/core/java/android/hardware/radio/TunerCallbackAdapter.java接收回调

    2、再往下, 是hal service的代码,分为hal和hal2


    frameworks/base/services/core/java/com/android/server/broadcastradio
    注意一下, hal1和hal2是而选一的
    hal1会调用native函数, native函数是在frameworks/base/services/core/jni/BroadcastRadio, 但是android11并不走hal1,
    所以也不通过native访问radio hal层

    hal是直接通过IServiceManager manager = IServiceManager.getService();

    frameworks/base/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java

    1. public class BroadcastRadioService extends SystemService
    2. public void onStart() {
    3. publishBinderService(Context.RADIO_SERVICE, mServiceImpl);
    4. }

    frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java

    1. private IServiceNotification.Stub mServiceListener = new IServiceNotification.Stub() {
    2. @Override
    3. public void onRegistration(String fqName, String serviceName, boolean preexisting) {
    4. //这个会生成一个module
    5. RadioModule module = RadioModule.tryLoadingModule(moduleId, serviceName);
    6. }
    7. };

    frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
    这里是获取IBroadcastRadio service对象, 以便于直接调用到hal层

    1. public static @Nullable RadioModule tryLoadingModule(int idx, @NonNull String fqName) {
    2. IBroadcastRadio service = IBroadcastRadio.getService(fqName);
    3. return new RadioModule(service, prop);
    4. }


    这里直接操作hal层的openSession函数, 在回调里返回hal的操作对象session

    1. public @NonNull TunerSession openSession(@NonNull android.hardware.radio.ITunerCallback userCb)
    2. throws RemoteException {
    3. synchronized (mLock) {
    4. mService.openSession(mHalTunerCallback, (result, session) -> {
    5. Convert.throwOnError("openSession", result);
    6. hwSession.value = session;
    7. });
    8. TunerSession tunerSession = new TunerSession(this, mHalTunerSession, userCb);
    9. mAidlTunerSessions.add(tunerSession);
    10. return tunerSession;
    11. }
    12. }
    frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java
    在这里会向hal层调用tune、scan等接口

    3、hal层


    vendor/qisi/proprietary/interfaces/broadcastradio/2.0/BroadcastRadio.cpp
    这里是将hal层的session操作对象返回到framework层

    1. Return<void> BroadcastRadio::openSession(const sp& callback,
    2. openSession_cb _hidl_cb) {
    3. sp newSession = new TunerSession(*this, callback);
    4. mSession = newSession;
    5. _hidl_cb(Result::OK, newSession);
    6. return {};
    7. }
    4、回调的数据
    hardware/interfaces/broadcastradio/2.0/types.hal
    1. /**
    2. * A set of identifiers necessary to tune to a given station.
    3. *
    4. * This can hold a combination of various identifiers, like:
    5. * - AM/FM frequency,
    6. * - HD Radio subchannel,
    7. * - DAB service ID.
    8. *
    9. * The type of radio technology is determined by the primary identifier - if the
    10. * primary identifier is for DAB, the program is DAB. However, a program of a
    11. * specific radio technology may have additional secondary identifiers for other
    12. * technologies, i.e. a satellite program may have FM fallback frequency,
    13. * if a station broadcasts both via satellite and FM.
    14. *
    15. * The identifiers from VENDOR_START..VENDOR_END range have limited
    16. * serialization capabilities: they are serialized locally, but ignored by the
    17. * cloud services. If a program has primary id from vendor range, it's not
    18. * synchronized with other devices at all.
    19. */
    20. struct ProgramSelector {
    21. /**
    22. * Primary program identifier.
    23. *
    24. * This identifier uniquely identifies a station and can be used for
    25. * equality check.
    26. *
    27. * It can hold only a subset of identifier types, one per each
    28. * radio technology:
    29. * - analogue AM/FM: AMFM_FREQUENCY;
    30. * - FM RDS: RDS_PI;
    31. * - HD Radio: HD_STATION_ID_EXT;
    32. * - DAB: DAB_SID_EXT;
    33. * - Digital Radio Mondiale: DRMO_SERVICE_ID;
    34. * - SiriusXM: SXM_SERVICE_ID;
    35. * - vendor-specific: VENDOR_START..VENDOR_END.
    36. *
    37. * The list may change in future versions, so the implementation must obey,
    38. * but not rely on it.
    39. */
    40. ProgramIdentifier primaryId;
    41. /**
    42. * Secondary program identifiers.
    43. *
    44. * These identifiers are supplementary and can speed up tuning process,
    45. * but the primary ID must be sufficient (i.e. RDS PI is enough to select
    46. * a station from the list after a full band scan).
    47. *
    48. * Two selectors with different secondary IDs, but the same primary ID are
    49. * considered equal. In particular, secondary IDs vector may get updated for
    50. * an entry on the program list (ie. when a better frequency for a given
    51. * station is found).
    52. */
    53. vec<ProgramIdentifier> secondaryIds;
    54. };
    55. /**
    56. * Program (channel, station) information.
    57. *
    58. * Carries both user-visible information (like station name) and technical
    59. * details (tuning selector).
    60. */
    61. struct ProgramInfo {
    62. /**
    63. * An identifier used to point at the program (primarily to tune to it).
    64. *
    65. * This field is required - its type field must not be set to
    66. * IdentifierType::INVALID.
    67. */
    68. ProgramSelector selector;
    69. /**
    70. * Identifier currently used for program selection.
    71. *
    72. * It allows to determine which technology is currently used for reception.
    73. *
    74. * Some program selectors contain tuning information for different radio
    75. * technologies (i.e. FM RDS and DAB). For example, user may tune using
    76. * a ProgramSelector with RDS_PI primary identifier, but the tuner hardware
    77. * may choose to use DAB technology to make actual tuning. This identifier
    78. * must reflect that.
    79. *
    80. * This field is required for currently tuned program only.
    81. * For all other items on the program list, its type field must be
    82. * initialized to IdentifierType::INVALID.
    83. *
    84. * Only primary identifiers for a given radio technology are valid:
    85. * - AMFM_FREQUENCY for analog AM/FM;
    86. * - RDS_PI for FM RDS;
    87. * - HD_STATION_ID_EXT;
    88. * - DAB_SID_EXT;
    89. * - DRMO_SERVICE_ID;
    90. * - SXM_SERVICE_ID;
    91. * - VENDOR_*;
    92. * - more might come in next minor versions of this HAL.
    93. */
    94. ProgramIdentifier logicallyTunedTo;
    95. /**
    96. * Identifier currently used by hardware to physically tune to a channel.
    97. *
    98. * Some radio technologies broadcast the same program on multiple channels,
    99. * i.e. with RDS AF the same program may be broadcasted on multiple
    100. * alternative frequencies; the same DAB program may be broadcast on
    101. * multiple ensembles. This identifier points to the channel to which the
    102. * radio hardware is physically tuned to.
    103. *
    104. * This field is required for currently tuned program only.
    105. * For all other items on the program list, its type field must be
    106. * initialized to IdentifierType::INVALID.
    107. *
    108. * Only physical identifiers are valid:
    109. * - AMFM_FREQUENCY;
    110. * - DAB_ENSEMBLE;
    111. * - DRMO_FREQUENCY;
    112. * - SXM_CHANNEL;
    113. * - VENDOR_*;
    114. * - more might come in next minor versions of this HAL.
    115. */
    116. ProgramIdentifier physicallyTunedTo;
    117. /**
    118. * Primary identifiers of related contents.
    119. *
    120. * Some radio technologies provide pointers to other programs that carry
    121. * related content (i.e. DAB soft-links). This field is a list of pointers
    122. * to other programs on the program list.
    123. *
    124. * This is not a list of programs that carry the same content (i.e.
    125. * DAB hard-links, RDS AF). Switching to programs from this list usually
    126. * require user action.
    127. *
    128. * Please note, that these identifiers do not have to exist on the program
    129. * list - i.e. DAB tuner may provide information on FM RDS alternatives
    130. * despite not supporting FM RDS. If the system has multiple tuners, another
    131. * one may have it on its list.
    132. *
    133. * This field is optional (can be empty).
    134. */
    135. vec<ProgramIdentifier> relatedContent;
    136. bitfield<ProgramInfoFlags> infoFlags;
    137. /**
    138. * Signal quality measured in 0% to 100% range to be shown in the UI.
    139. *
    140. * The purpose of this field is primarily informative, must not be used to
    141. * determine to which frequency should it tune to.
    142. */
    143. uint32_t signalQuality;
    144. /**
    145. * Program metadata (station name, PTY, song title).
    146. */
    147. vec<Metadata> metadata;
    148. /**
    149. * Vendor-specific information.
    150. *
    151. * It may be used for extra features, not supported by the platform,
    152. * for example: paid-service=true; bitrate=320kbps.
    153. */
    154. vec<VendorKeyValue> vendorInfo;
    155. };

  • 相关阅读:
    第三章:流程控制
    全域外卖推广怎么做才能赚钱?
    [docker] 网络连接
    CE修改器学习历程之普通变量的保存
    Vue3渲染&事件处理
    Shell自动化编程初识
    python实现简单的三维建模学习记录
    ubuntu20.04版本安装教程
    C#/VB.NET 将PDF转为PDF/X-1a:2001
    U2-Net——U-Net中套U-Net,套娃式的分割模型
  • 原文地址:https://blog.csdn.net/yudelian/article/details/126039280