FM framework:
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
- public RadioManager(@NonNull Context context) throws ServiceNotFoundException {
- mService = IRadioService.Stub.asInterface(
- ServiceManager.getServiceOrThrow(Context.RADIO_SERVICE));
- }
frameworks/base/core/java/android/hardware/radio/RadioManager.java
打开tuner设备,并设置callback
- public RadioTuner openTuner(int moduleId){
- TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler);
- ITuner tuner = mService.openTuner(moduleId, config, withAudio, halCallback);
- return new TunerAdapter(tuner, halCallback, config != null ? config.getType() : BAND_INVALID);
- }
接下来在frameworks/base/core/java/android/hardware/radio/TunerAdapter.java里做接口调用,比如
scan, step, tune, startBackgroundScan(没用到)
在frameworks/base/core/java/android/hardware/radio/TunerCallbackAdapter.java接收回调
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
- public class BroadcastRadioService extends SystemService
- public void onStart() {
- publishBinderService(Context.RADIO_SERVICE, mServiceImpl);
- }
frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java
- private IServiceNotification.Stub mServiceListener = new IServiceNotification.Stub() {
- @Override
- public void onRegistration(String fqName, String serviceName, boolean preexisting) {
- //这个会生成一个module
- RadioModule module = RadioModule.tryLoadingModule(moduleId, serviceName);
- }
- };
frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
这里是获取IBroadcastRadio service对象, 以便于直接调用到hal层
- public static @Nullable RadioModule tryLoadingModule(int idx, @NonNull String fqName) {
- IBroadcastRadio service = IBroadcastRadio.getService(fqName);
- return new RadioModule(service, prop);
- }
这里直接操作hal层的openSession函数, 在回调里返回hal的操作对象session
- public @NonNull TunerSession openSession(@NonNull android.hardware.radio.ITunerCallback userCb)
- throws RemoteException {
- synchronized (mLock) {
- mService.openSession(mHalTunerCallback, (result, session) -> {
- Convert.throwOnError("openSession", result);
- hwSession.value = session;
- });
- TunerSession tunerSession = new TunerSession(this, mHalTunerSession, userCb);
- mAidlTunerSessions.add(tunerSession);
-
- return tunerSession;
- }
- }
frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java 在这里会向hal层调用tune、scan等接口
vendor/qisi/proprietary/interfaces/broadcastradio/2.0/BroadcastRadio.cpp
这里是将hal层的session操作对象返回到framework层
- Return<void> BroadcastRadio::openSession(const sp
& callback, - openSession_cb _hidl_cb) {
- sp
newSession = new TunerSession(*this, callback); -
- mSession = newSession;
-
- _hidl_cb(Result::OK, newSession);
- return {};
- }
4、回调的数据 hardware/interfaces/broadcastradio/2.0/types.hal
- /**
- * A set of identifiers necessary to tune to a given station.
- *
- * This can hold a combination of various identifiers, like:
- * - AM/FM frequency,
- * - HD Radio subchannel,
- * - DAB service ID.
- *
- * The type of radio technology is determined by the primary identifier - if the
- * primary identifier is for DAB, the program is DAB. However, a program of a
- * specific radio technology may have additional secondary identifiers for other
- * technologies, i.e. a satellite program may have FM fallback frequency,
- * if a station broadcasts both via satellite and FM.
- *
- * The identifiers from VENDOR_START..VENDOR_END range have limited
- * serialization capabilities: they are serialized locally, but ignored by the
- * cloud services. If a program has primary id from vendor range, it's not
- * synchronized with other devices at all.
- */
- struct ProgramSelector {
- /**
- * Primary program identifier.
- *
- * This identifier uniquely identifies a station and can be used for
- * equality check.
- *
- * It can hold only a subset of identifier types, one per each
- * radio technology:
- * - analogue AM/FM: AMFM_FREQUENCY;
- * - FM RDS: RDS_PI;
- * - HD Radio: HD_STATION_ID_EXT;
- * - DAB: DAB_SID_EXT;
- * - Digital Radio Mondiale: DRMO_SERVICE_ID;
- * - SiriusXM: SXM_SERVICE_ID;
- * - vendor-specific: VENDOR_START..VENDOR_END.
- *
- * The list may change in future versions, so the implementation must obey,
- * but not rely on it.
- */
- ProgramIdentifier primaryId;
-
- /**
- * Secondary program identifiers.
- *
- * These identifiers are supplementary and can speed up tuning process,
- * but the primary ID must be sufficient (i.e. RDS PI is enough to select
- * a station from the list after a full band scan).
- *
- * Two selectors with different secondary IDs, but the same primary ID are
- * considered equal. In particular, secondary IDs vector may get updated for
- * an entry on the program list (ie. when a better frequency for a given
- * station is found).
- */
- vec<ProgramIdentifier> secondaryIds;
- };
-
-
-
- /**
- * Program (channel, station) information.
- *
- * Carries both user-visible information (like station name) and technical
- * details (tuning selector).
- */
- struct ProgramInfo {
- /**
- * An identifier used to point at the program (primarily to tune to it).
- *
- * This field is required - its type field must not be set to
- * IdentifierType::INVALID.
- */
- ProgramSelector selector;
-
- /**
- * Identifier currently used for program selection.
- *
- * It allows to determine which technology is currently used for reception.
- *
- * Some program selectors contain tuning information for different radio
- * technologies (i.e. FM RDS and DAB). For example, user may tune using
- * a ProgramSelector with RDS_PI primary identifier, but the tuner hardware
- * may choose to use DAB technology to make actual tuning. This identifier
- * must reflect that.
- *
- * This field is required for currently tuned program only.
- * For all other items on the program list, its type field must be
- * initialized to IdentifierType::INVALID.
- *
- * Only primary identifiers for a given radio technology are valid:
- * - AMFM_FREQUENCY for analog AM/FM;
- * - RDS_PI for FM RDS;
- * - HD_STATION_ID_EXT;
- * - DAB_SID_EXT;
- * - DRMO_SERVICE_ID;
- * - SXM_SERVICE_ID;
- * - VENDOR_*;
- * - more might come in next minor versions of this HAL.
- */
- ProgramIdentifier logicallyTunedTo;
-
- /**
- * Identifier currently used by hardware to physically tune to a channel.
- *
- * Some radio technologies broadcast the same program on multiple channels,
- * i.e. with RDS AF the same program may be broadcasted on multiple
- * alternative frequencies; the same DAB program may be broadcast on
- * multiple ensembles. This identifier points to the channel to which the
- * radio hardware is physically tuned to.
- *
- * This field is required for currently tuned program only.
- * For all other items on the program list, its type field must be
- * initialized to IdentifierType::INVALID.
- *
- * Only physical identifiers are valid:
- * - AMFM_FREQUENCY;
- * - DAB_ENSEMBLE;
- * - DRMO_FREQUENCY;
- * - SXM_CHANNEL;
- * - VENDOR_*;
- * - more might come in next minor versions of this HAL.
- */
- ProgramIdentifier physicallyTunedTo;
-
- /**
- * Primary identifiers of related contents.
- *
- * Some radio technologies provide pointers to other programs that carry
- * related content (i.e. DAB soft-links). This field is a list of pointers
- * to other programs on the program list.
- *
- * This is not a list of programs that carry the same content (i.e.
- * DAB hard-links, RDS AF). Switching to programs from this list usually
- * require user action.
- *
- * Please note, that these identifiers do not have to exist on the program
- * list - i.e. DAB tuner may provide information on FM RDS alternatives
- * despite not supporting FM RDS. If the system has multiple tuners, another
- * one may have it on its list.
- *
- * This field is optional (can be empty).
- */
- vec<ProgramIdentifier> relatedContent;
-
- bitfield<ProgramInfoFlags> infoFlags;
-
- /**
- * Signal quality measured in 0% to 100% range to be shown in the UI.
- *
- * The purpose of this field is primarily informative, must not be used to
- * determine to which frequency should it tune to.
- */
- uint32_t signalQuality;
-
- /**
- * Program metadata (station name, PTY, song title).
- */
- vec<Metadata> metadata;
-
- /**
- * Vendor-specific information.
- *
- * It may be used for extra features, not supported by the platform,
- * for example: paid-service=true; bitrate=320kbps.
- */
- vec<VendorKeyValue> vendorInfo;
- };