Recently in the study of the FM module, FM is a learning module that can be seen from the upper layer.
The upper layer is the FM's push-button operation and the interface display, which calls to the FM low-level driver to achieve the function of radio listening.
FM Start-up process: such as:
First enter the Fmradio.java class, OnCreate initialize some data, draw the FM interface, start the FM in the OnStart () method to start the Fmradioservice.java (call Bindtoservice (this, OSC) method).
Register under FM settings (send a set broadcast after Setup, update the status of the Fmradio Class).
Load initialization data, get frequency address
Newpresetstation ("", Fmsharedpreferences.gettunedfrequency ());
In the Bindtoservice (This,osc) method, start StartService (the same service only oncreate once), Restart Bindservice (this has the benefit of pressing the return key service does not go OnDestroy method) Bindservice Onbind back a IBinder object to Fmradio class Serviceconnection Onserviceco Nnected method, call the Enableradio () method.
Call Fmradio.java's Isantennaavailable () method in the Enableraido method to make a headset judgment, the antenna is judged whether it is available, Controlled by a plug-in pull-out broadcast receive (Registerheadsetlistener () method in Fmradio) action (Intent.action_headset_plug)
mheadsetplugged = (Intent.getintextra ("state", 0) = = 1); Equals 1 indicates the headset is available and equals 0 is available.
Call Fmradio Method Fmon (Mservice.fmon ())
Interface available Enableradioonoffui ()
private void Enableradio () {misscaning = false; Misseeking = false; Missearching = false; Boolean bstatus = false; if (Ishdmion ()) {ShowDialog (dialog_cmd_failed_hdmi_on); }else {<span style= "font-family:kaiti_gb2312;" > </span>if (mservice! = null) {try {if (false = = Mservice.isfmon ()) && IsA Ntennaavailable ()) {bstatus = Mservice.fmon (); if (bstatus) {Tuneradio (fmsharedpreferences.gettunedfrequency ()); Enableradioonoffui (); }else {log.e (LogTag, "Mservice.fmon failed"); mcommandfailed = Cmd_fmon; if (iscallactive ()) {Enableradioonoffui (); ShowDialog (dialog_cmd_failed_call_on); }else {showDialog (dialog_cmd_failed); } }}else {Enableradioonoffui (); }}catch (RemoteException e) {e.printstacktrace (); } } } }
Initialize the Fmreceiver reference mreceiver = Newfmreceiver (fmradio_device_fd_string, FmCallbacks) in the Fmradioservice.java Fmon () method;
Remove the setting properties of the saved region frequency
Fmconfig config =fmsharedpreferences.getfmconfiguration ();
Really accept FM sound in
Bstatus =mreceiver.enable (Fmsharedpreferences.getfmconfiguration ());
Isspeakerenabled () speaker available, user-set speaker
Set the ringtone path
Boolean state =mreceiver.setanalogmode (Analogmode); Analogmode Analog Set Low power
Bstatus = Setlowpowermode (false);
The phone is not in the idle form too
int state = Getcallstate ();
Fmactiononcallstate (state);
Activate FM STARTFM (), set headset, etc. to accept FM sound
Audiosystem.setforceuse (Audiosystem.for_media,audiosystem.force_none);
FM Device available
Audiosystem.setdeviceconnectionstate (AUDIOSYSTEM.DEVICE_OUT_FM,
Audiosystem.device_state_available, "");
Registering the processing of a remote group
Bstatus = mreceiver.registerrdsgroupprocessing (fmreceiver.fm_rx_rds_grp_rt_ebl|
fmreceiver.fm_rx_rds_grp_ps_ebl|
fmreceiver.fm_rx_rds_grp_af_ebl|
FMRECEIVER.FM_RX_RDS_GRP_PS_SIMPLE_EBL);
can automatically jump to the selected frequency
Bstatus =enableautoaf (Fmsharedpreferences.getautoafswitch ());
Set the built-in antenna to 0
Fmtransceiver.java
Fmreceiverjni.setcontrolnative (SFd, V4l2_cid_private_tavarua_antenna,iantenna)
Mreceiver.setinternalantenna (False)
Summarize:
1. Due to the different Android version, the major manufacturers of FM made a different custom, the code is a difference, but the overall framework has not changed;
2.FM for Google fully open source code, code path in vendor/qcom;
3.FM differs from other applications, to be continued ....
Vendor catalogue (manufacturer custom content)
|--Aosp (Android Open source project)
| '--Products (some board-level rules)
|--HTC (HTC Company)
| |--Common-open (General section)
| | '--AKMD (the tool for extracting IMG)
| |--Dream-open (G1 open section)
| |--Prebuilt-open (pre-compiled open section)
| '--Sapphire-open (Sapphire This model is open content)
|--Pv-open (Nothing)
|--qcom (The inside is basically empty)
'--sample (samples provided by Google)
|--Apps (Apps)
| |--Client (user)
| '--Upgrade (upgrade)
|--Frameworks (frame)
| '--platformlibrary (Platform library)
|--Products (product)
|--Sdk_addon (SDK additions section)
'--Skins (skin)
'--wvgameddpi (WVGA applicable picture)
Android FM module Learn one FM START process