Android phone application Overview
I. Overview
1. Phone application Main Interface
2. Outbound call Process
3. Access telephone Process
Ii. Phone application Main Interface
The main interface of the phone application consists of four parts: "phone", "Call log", "contacts", and "favorites.
Phone: a 12-key dial. Enter the phone number and click the phone icon to dial
Call log: stores historical records of incoming and outgoing calls.
Contacts: Stores telephone contacts.
Favorites: stores frequently-used phone contacts.
(1) "dialtactsactivity. Java" is the main entrance for the above four parts. In the oncreate () method, pass "setupdalertab ()", "setupcalllogtab ()", "setupcontactstab", and "setupfavoritesttab ()" Through hasphoneproviderextras () the above four methods are built to display the main interface entries of the four parts in the form of "tabhost. The above four functional interfaces are implemented in three parts: "twelvekeydialer. Java", "recentlistactity. Java", and "contactslistactivity. Java. Here, we will focus on the implementation of the "phone" section.
3. Outbound call Process
Go to the dialing program built by twelvekeydialer, enter the outgoing phone number, and click the dialing button. The implementation of dialing is implemented in placecall.
Intent intent = new intent (intent. action_call_privileged,
Uri. fromparts ("tel", number, null ));
If (number = NULL |! Textutils. isgraphic (number )){
// There is no number entered.
If (phoneiscdma () & phoneisoffhook ()){
// We only want to send this empty flash extra if we're CDMA and
// Phone is offhook (don't want to send if ringing or dialing)
Intent. putextra (extra_send_empty_flash, true );
Sendemptyflash = true;
} Else {
Playtone (tonegenerator. tone_prop_nack );
Return;
}
}
Intent. setflags (intent. flag_activity_new_task );
Startactivity (intent );
Find "intent. the actual character of action_call_privileged indicates that the intent jump class is outgoingcallbroadcaster. java. in this oncreate () method, determine the outgoing phone number and classify the number into "emergency number" and "non-emergency number": If it is an emergency number, it will be executed through intent. setclass (this, incallscreen. Class); startactivity (intent); if it is not an emergency number, it will be executed through new
Intent (intent. action_new_outgoing_call); sendorderedbroadcast (); jump to the internal class outgoingcallreceiver. Java to execute dialing.
In "outgoingcallreceiver", "doreceiver ()" checks whether the telephone network is a CDMA network, and further checks whether it is based on OTA call (this is not clear ?). Next, jump to the incallscreen class for call processing.
The "incallscreen" class constructs the call interface and the processing and response to the call. If this is the first call, oncreate () is executed. If it is not the first call, onnewintent () is executed (). since then, both methods have internalresolveintent (intent). This method obtains the call status, including the call status and incoming status. The placecall () method returns the outgoing call status. The returned result is defined by the incallinitstatus enumerated variable in incallscreen. Note: Call. Dial () in placecall () to establish a dialing connection with the framework layer.
Iv. Incoming call Process
First, call notification is implemented by phoneapp.
Phoneapp. Java-> oncreate ()-> callnotifier. Java-> handlemessage ()-> onnewringingconnection () receives a response from the RIL layer, and issues a ring tone or vibration.
When the phone calls sound or vibrate, continue to execute phoneutils. java-> showincomingcallui ()-> phoneapp. in Java-> void displaycallscreen (), startactivity () jumps to incallscreen. java.
Execute internalresolveintent (intent)-> internalanswercall ()-> phoneutils. answercall ()-> phone. Accept () to start answering the call.
2.
Android phone call Process
1 outgoingcallbroadcaster. Java
Click the dial button to enter the phone package for the call. In this case, the first function is outgoingcallbroadcaster. Java, which is an activity.
The life cycle of the activity shows that the oncreate () function should be called when the first entry is made. (Only this function is implemented in this class .) Parse this function:
1.1) first obtain the intent object and obtain the outgoing number.
1.2) then judge whether the number is an emergency number. If it is an emergency number, assign the callnow variable to true, start incallscreen, and send a broadcast. If the callnow parameter in the receiver is determined to be true, the system will directly finish the call, instead of repeatedly starting the incallscreen. If it is not an emergency number, assign the callnow variable to false and send the broadcast "intent. action_new_outgoing_call ".
2 outgoingcallreceiver. Java
After the broadcast is sent, outgoingcallpolicer will receive the message. This class is an internal class. In the outgoingcallbroadcaster class, the function is to receive the broadcast sent by outgoingcallbroadcaster and determine whether incallscreen has been enabled. If it is not started, perform initialization, for example, initializing Ota. After receiving the broadcast, retrieve the phone number and its URI from the intent. Set intent to action_call and carry the number and Uri. Start incallscreen. Close the activity.
Ota: over-the-air technology is a technology used to remotely manage SIM card data and applications through mobile communication (GSM or CDMA) Air interfaces. Air interfaces can adopt WAP, GPRS, CDMA 1X, and short message technologies. The Application of OTA technology enables mobile communication not only to provide voice and data services, but also to provide download for new services.
GSM: Global System for Mobile Communications. The Chinese language is the global mobile communication system, commonly known as "global communication ".
CDMA: Code Division Multiple Access, also known as code division multiple access, is a technology used in wireless communication. CDMA allows all users to use all the frequencies at the same time (1.2288 MHz ), in addition, the signal sent by other users is considered as a noise, and the problem of collision does not need to be taken into account. The advantages of CDMA include: the voice encoding technology provided in CDMA, which has better call quality than the current GSM, and can reduce the noise of the surrounding environment during user conversation to make the call clearer.
3 incallscreen. Java
The extends class has the acitilistener, and implements has the onclicklistener, ontouchlistener, and onquerycompletelistener. This class is mainly responsible for the call interface, and also responsible for handling various button events and touch time of menu items. At the same time, this class also rewrites the finish () method, so it is generally not finished, and it puts itself back into the stack when calling this method. Incallscreen can receive and start this intent.
3.1) oncreate (first time)
3.1.1) callscreenoncreate obtains the time when the call interface was created.
3.1.2) The phoneapp wakes up the background service program.
3.1.3) determine the current call status (idle = no call behavior, ringing = pending call or call, offhook = the phone is off hook. at least one call exists that is dialing, active or holding and no callare ringing or waiting .), if the call is in progress, no keyboard lock will appear. Next, set mphone and mforegroundcall/mbackgroundcall/mringcall.
3.1.4) getdomainthhandsfree sets a Bluetooth headset. If a Bluetooth headset exists, install the device.
3.1.5) initincallscreen loads various view structures.
3.1.6) broadcast various call statuses. (RegisterforprecisecallstAtechanged, registerfordisconnect, registerformmiinitiatereGisterformmicomplete, registerforcallwaiting, registerforsuppservicefaIled, registerforcdma otastatusChange)
3.1.7) internalresolveintent checks whether OTA technology is used and sets the call interface style.
3.1.8) callscreencreated record the time after the call interface is created
3.2) onnewintent (not the first time ).
We call this function when restarting an intent. Because we have completed the process around the only incallscreen instance, this program will happen if there is a call or power-off, except for the incallscreen created for the first time. If incallscreen is already in the foreground, this program will also happen.
3.2.1) setintent saves the intent so that we can get the intent in the future.
3.2.2) internalresolveintent
3.3) onresume
Perform initialization operations, such as obtaining a phoneapp object and unlocking the statusbar of keyguard notification to disable. You also have a built-in handler that can call back to process some events, such as phone_state_changed, phone_disconnect, and event_headset_plug_state_changed. At the same time, there is an independent broadcastreceiver processing action_headset_plug, such as inserting headphones.
3.3.1) in addition to handling incoming calls during lock.
3.3.2) disablestatusbar makes the status bar available when the call interface is in progress.
3.3.3) setignoretouchuseractiviTy ignores unintentional touch events during a call, so that these unintentional touch does not prevent the device from sleep.
3.3.4) registerreceiver listens for broadcasts
3.3.5) When startdialersession is in the foreground, a dialer session is maintained. First, determine whether to play a local ringtone. If necessary, determine whether dual-Tone Multi-frequency is available. If available, create a sound player.
3.3.6) isw.thaudioconnecteD. Determine whether a Bluetooth connection is enabled.
3.3.7) for CDMA calls, the OTA status is initialized. If OTA is used, the incallscreenmode is set to the OTA call model.
3.3.8) cleardisconnected cut off other network connections before checking the call status.
3.3.9) syncwithphonestate synchronizes the current status of the call interface with the phone. If the synchronization fails, dismissalldialogs (); ends the current call, endincallscreensession (); closes the display of the call interface.
3.3.10) set updatewakestate Based on the wake-up status and screen timeout of the current phone and the current status of the call interface.
3.3.11) enabletouchlock: When onresume, the "Touch lock" Stack is invisible. In particular, this check ensures that the screen will not be locked after the user calls to wake up by munu. However, if the dial is opened and the call timing is required, the "Touch lock" is overwritten.
4 profiler. Java
This class records the call time points.
Static long stimecallscreenrequested; // Call Interface request time
Static long stimecallscreenoncreate; // time when the call interface was created
Static long stimecallscreencreated; // time after the call interface is created
Static long stimeincomingcallpanelreQuested; // time when the call interface is requested
Static long stimeincomingcallpanelonCreate; // time when the call interface is created
Static long stimeincomingcallpanelcrEated; // the time after the call interface is created when the call is in progress
5. phoneutils. Java
Calls phone. getforegroundcall (), phone. getbackgroundcall (), phone. getringingcall (), and phone. Dial ().
5.1) placecall (phone, string number, Uri contactref)
Call the incoming phone number. This function is called by placecall in incallscreen.
The phone object of the parameter; the phone number that the user wants to call; The contactref parameter is either "Tel:" or "content: // contacts", depending on the call initialization, this parameter triggers a call. call_status_dialed, call_status_dialed_mmi, or call_status_failed is returned.
5.2) placecallvia (context, phone, string number, Uri contactref, Uri gatewayuri)
Call a third-party gateway call number. This function is called by placecall in incallscreen. If the phone number is an emergency number, the gsm mmi or CDMA code cannot be called. If the connection is established, this method sends out a synchronous call to stop querying incoming call information and enables local asynchronous query.
The phone object parameter; the context parameter executes the callerinfo query; the number that the user wants to call. If a connection cannot be established for the phone number, it is only used to create a phone card and update the call record; the contactref parameter is either "Tel:" or "content: // contacts", which triggers a call. The gatewayuri parameter is used to set the connection address, and call_status_dialed or call_status_failed is returned.
6. phoneapp. Java
This class is a common Java class, mainly responsible for generating top-level applications of phone objects. This is a virtual phone object, which obtains a phone object from the framework layer. This class is inherited from the application and can be resident in the memory. It and phoneutils work together to handle telephone operations. Perform global initialization in the oncreate method: Obtain the phone object icationicationmgr, powermanager, and simcard objects. At the same time, the built-in handler can call back to process various events, such as event_sim_absent, event_sim_network_locked, and event_update_incall_notification.
.
7 callnotifier. Java
Listen to changes in phone status and various events from the Telephony layer, and trigger any relevant UI behavior (such as starting ringtones and incoming call user interfaces, playing in call sounds, updating notifications, write call record entries ).
7.1) implemented in Constructors
Mphone. registerfornewringingconNection (this, phone_new_ring_connection, null );
Mphone. registerforprecisecallstAtechanged (this, phone_state_changed, null );
Mphone. registerfordisconnect (this, phone_disconnect, null );
Mphone. registerforunknownconnecTion (this, phone_unknown_connection_appeared, null );
In addition, for CDMA Communication, run the following command:
Mphone. registerforcdma otastatusChange (this, event_ota_provision_change, null );
Mphone. registerforcallwaiting (this, phone_cdma _call_waiting, null );
Mphone. registerfordisplayinfo (this, phone_state_displayinfo, null );
Mphone. registerforsignalinfo (this, phone_state_signalinfo, null );
Mphone. registerforincallvoiceprIvacyon (this, phone_enhanced_vp_on, null );
Mphone. registerforincallvoiceprIvacyoff (this, phone_enhanced_vp_off, null );
Mphone. registerforcdma fwdburstdTMF (this, phone_cdma _fwd_burst_dtmf, null );
Mphone. registerforcdma fwdcontdtMfstart (this, phone_cdma _fwd_cont_dtmf_start, null );
Mphone. registerforcdma fwdcontdtMfstop (this, phone_cdma _fwd_cont_dtmf_stop, null );
For the GSM type, run the following command:
Mphone. registerforringbacktone (this, phone_ringback_tone, null );
Mphone. registerforresendincallmUte (this, phone_resend_mute, null );
7.2) the entire class is serialized by the handlemessage function.