应用层
Demo路径:
packages/apps/Car/Radio
BootupReceiver类监听了ACTION_BOOT_COMPLETED,然后在onReceive里启动了RadioService.
CarRadioActivity作为主Activity,在onCreate里创建了mRadioController.
收音机主界面有个RadioDrawer(收音机抽屉).点击其中一个就会调用
mRadioController.openRadioBand(SUPPORTED_RADIO_BANDS[position]);
SUPPORTED_RADIO_BANDS定义
private static final int[] SUPPORTED_RADIO_BANDS = new int[] {
RadioManager.BAND_AM, RadioManager.BAND_FM };
虽然没看到实际界面,其实这个地方也就是选择AM或者FM,大家都玩过收音机,完全可以自己脑补!
openRadioBand@RadioController:
...
mRadioManager.openRadioBand(radioBand);
...
fuck这个mRadioManager并不是RadioManager类型的.而是com.android.car.radio.service.IRadioManager
总之实现是在这里:
./src/com/android/car/radio/RadioService.java
//openRadioBand@RadioService
...
openRadioBandInternal(radioBand);
...
openRadioBandInternal@RadioService
if (mRadioTuner != null) {
mRadioTuner.setConfiguration(config);
} else {
mRadioTuner = mRadioManager.openTuner(mModules.get(0).getId(), config, true,
mInternalRadioTunerCallback, null /* handler */);
}
这个mRadioManager才是真的android.hardware.radio.RadioManager的(Android的开发者命名的时候不怕我们混淆吗?).
framework层
先把用得到的几个类堆出来一下:
//The RadioManager class allows to control a broadcast radio tuner present on the //device.It provides data structures and methods to query for available radio modules,
//list their properties and open an interface to control tuning operations and receive callbacks when asynchronous operations complete or events occur.
base/core/java/android/hardware/radio/RadioManager.java
//Implements the RadioTuner interface by forwarding calls to radio service.
base/core/java/android/hardware/radio/TunerAdapter.java
/**
* RadioTuner interface provides methods to control a radio tuner on the device: selecting and
* configuring the active band, muting/unmuting, scanning and tuning, etc...
*
* Obtain a RadioTuner interface by calling {@link RadioManager#openTuner(int,
* RadioManager.BandConfig, boolean, RadioTuner.Callback, Handler)}.
* @hide
*/
base/core/java/android/hardware/radio/RadioTuner.java
//package底下,car相关
//A representation of a radio station.
//电台相关,比如说频道名字,频段之类的
apps/Car/libs/car-radio-service/src/com/android/car/radio/service/RadioStation.java
//A set of identifiers necessary to tune to a given station.
/* This can hold various identifiers, like
* - AM/FM frequency
* - HD Radio subchannel
* - DAB channel info
*/
base/core/java/android/hardware/radio/ProgramSelector.java
其中,最上层的RadioManager这个类.我们可以简单的提炼一下
public class RadioManager {
//列出给定广播无线电模块支持的属性,选项和无线电频段。
//调用RadioManager APIs的时候,每一个module都有唯一的ID用来定位自己.
//Module properties are returned by {@link #listModules(List )} method.
public static class ModuleProperties implements Parcelable
/** Radio band descriptor: an element in ModuleProperties bands array.