Android Source code Analysis: Telephony part –phone process

Source: Internet
Author: User

Android Source code Analysis: Telephony part –phone Process
Red Wolf Blog

Com.android.phone process

It's like a background process, and it's running and always there. Its code is located at: Packages/apps/phone/src/com/android/phone

When there is a call, it reacts, such as displaying UI and ringtone cues, and when in a call, it shows incallscreen; when the Iteleohony interface calls to the phone process when dialing, It then interacts with the Gsmphone or Cdmaphone created by Phonefactory, and the call log is added to the database by phone.

The most important class is Phoneapp, which inherits from application, is the top-level phone application class and contains:

Phone phone;
Callnotifier notifier;
Ringer Ringer;
Bluetoothhandsfree Mbthandsfree;
Phoneinterfacemanager Phonemgr;

Part of the member variable code is omitted here

Private Incallscreen Mincallscreen;

Part of the member variable code is omitted here

Private Activity mpukentryactivity;
Private ProgressDialog Mpukentryprogressdialog;

Part of the member variable code is omitted here

Private Keyguardmanager Mkeyguardmanager;
Private Statusbarmanager Mstatusbarmanager;
private int mstatusbardisablecount;
Private Accelerometerlistener Maccelerometerlistener;

In the Froyo version, Phoneapp realizes the interference of the face to the phone, using a distance sensor to determine the distance between the face and the screen.

Callnotifier

Callnotifier is a handler that handles some of the messages that are actively escalated for Phoneapp. It monitors phone status changes from the telephony layer and various other events to react like various UI behaviors: Start the ring tone playback and caller ID display UI, play the call prompt when the call is being called, update the status bar prompt (via notificationmgr), add the call log, and so on.

Some registrantlist,callnotifier are available in phonebase to register themselves as an interested person, so that when the state changes, Callnotifier will be notified and then processed in the thread to respond to the UI. In its constructor, you can see the message event category that it handles, and the following code lists the types of messages that are partially processed (not listed for CDMA or GSM specific types of messages):

Mphone.registerfornewringingconnection (this, phone_new_ringing_connection, null);

Mphone.registerforprecisecallstatechanged (this, phone_state_changed, null);

Mphone.registerfordisconnect (this, phone_disconnect, null);

Mphone.registerforunknownconnection (this, phone_unknown_connection_appeared, null);

Mphone.registerforincomingring (this, phone_incoming_ring, null);

When a phone_new_ringing_connection type message arrives, it means that a ringing or waiting connection (connection) appears, At this point the Handlemessage function calls Onnewringingconnection to process. The latter checks whether the settings in the settings can answer the phone, then rings (see Incalltoneplayer) and displays the Incallscreen UI, see Phoneutils.showincomingcallui () and Phoneapp.displaycallscreen () two functions.

The ring tone hint during the call is completed by the thread class Incalltoneplayer.

When a message of the phone_incoming_ring type arrives, it means that the RIL layer is affected by the ring, where the ring tone is played. It uses the ringer.ring () function, which creates a thread to play the ring tone (see ringer.makelooper function).

When the phone_state_changed message is received, it indicates that the status of the phone has changed, such as ringing the phone after the call, the processing function is onphonestatechanged, such as confirming the stop ring tone again, update Status column status notification and so on.

When a phone_disconnect message is received, it indicates that the phone connection is hung up or ringcall broken. Its handler function is OnDisconnect. It cleans up the scene such as audio channel recovery, ringing confirmation of incoming calls, UI cleanup for Incallscreen, and the presence of missed calls in the status bar.

Phoneinterfacemanager

It inherits from the Itelephony.stub, realizes the server side Itelephony interface, its interface definition sees the file:

Frameworks/base/telephony/java/com/android/internal/telephony/itelephony.aidl

Telephonymanager interacts with it as a client through binder.

Notificationmgr

Notificationmgr is used as a static member function for Phoneapp for the phone process to notify the user of the message in the status bar, such as: Have missed calls, is calling, whether mute and other information. It uses the system-provided API classes Notificationmanager and Statusbarmanager to complete the notification function. Each notification corresponds to a function for notification, update notification, and cancellation. When a message is received, the handlemessage of Phoneapp handler updates the status bar information using Notificationmgr. The following code fragment is used to update the status bar's prompt information:

Case Event_update_incall_notification:
Notificationmgr.getdefault (). Updateincallnotification ();//Call prompt
Break
Case event_data_roaming_disconnected:
Notificationmgr.getdefault (). showdatadisconnectedroaming ();//due to roaming data connection disconnection prompt
Break
Case EVENT_DATA_ROAMING_OK:
Notificationmgr.getdefault (). hidedatadisconnectedroaming ();//Hide roaming disconnect prompt
Break

The hint for missed calls is to check for hints when Phoneapp creates the Notificationmgr object and invokes its initialization function.

Incallscreen

It is the activity when the phone is talking. When you have a call, start dialing, or are on a call, the Activity,ui interface is the corresponding view:

Inflate everything in incall_screen.xml and add it to the screen.
Setcontentview (R.layout.incall_screen);

Specify yourself as the Incallscreen of Phoneapp in its oncreate function:

App.setincallscreeninstance (this);

Incallscreen need to handle calls when the keyboard lock can directly answer the phone, whether there is a headset insertion, whether to answer the phone with Bluetooth, the need to listen and maintain the update call status and display to the user, need to support some features in the call process (such as the transmission of DTMF, teleconferencing, Separate calls) operation, OTA call, etc.

The Callcard is a call in the Incallscreen (which may be either the current calling or the hold-on calls).

When you need to answer a call or make a call, the top sends a intent, Then Incallscreen receives intent when its incallscreen.onnewintent function is called, parses intent, either calls Placecall to make a call, or calls Internalanswercall to answer the call.

Applications can issue intent for phone calls, such as when making calls in Twelvekeydialer.java, to create a intent:

void Placecall () {

Final String number = Mdigits.gettext (). toString ();

Boolean sendemptyflash = false;

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 the

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);

In the phone program, the Outgoingcallbroadcaster (file Outgoingcallbroadcaster.java) contains an internal class outgoingcallreceiver, which receives the phone call intent, and then sends it out after conversion, By the above Incallscreen receive processing, display the dial-up interface and make calls.

As Outgoingcallbroadcaster says, it receives call and call_privileged two kinds of intents, then broadcasts Action_new_outgoing_call intent, Let other applications have the opportunity to monitor these intent, and finally these call intent received their own conversion, start Incallscreen.

The following code is the intent conversion, and then intent is received by Incallscreen:

Intent newintent = new Intent (Intent.action_call, URI);

Newintent.putextra (intent.extra_phone_number, number);

Phoneutils.checkandcopyphoneproviderextras (Intent, newintent);

Newintent.setclass (context, incallscreen.class);

Newintent.addflags (Intent.flag_activity_new_task);

if (DBG) log.v (TAG, "doreceive (): Calling StartActivity:" + newintent);

Context.startactivity (newintent);

}

The purpose of this is to

Incalltouchui:

The function of the button during the call and the sliding listening function when the call is answered.

Manageconferenceutils: A tool for managing multiparty calls, including some UI elements. Achieve its functionality with Phoneutils.

Dtmftwelvekeydialer: A dial pad for sending DTMF when a call is in a state.

DTMFTWELVEKEYDIALERVIEW:DTMF Dial-up View layout class.

Incallcontrolstate maintains some status information, such as whether to enable the Speaker voice speakerphone, whether to add new calls, and so on. It is the data part of the MVC pattern.

Incallmenu is the call Status menu, which contains individual menu items:

Incallmenuitemview mmanageconference;
Incallmenuitemview Mshowdialpad;
Incallmenuitemview Mendcall;
Incallmenuitemview Maddcall;
Incallmenuitemview Mswapcalls;
Incallmenuitemview Mmergecalls;
Incallmenuitemview Mbluetooth;
Incallmenuitemview Mspeaker;
Incallmenuitemview Mmute;
Incallmenuitemview Mhold;
Incallmenuitemview Manswerandhold;
Incallmenuitemview Manswerandend;
Incallmenuitemview Manswer;
Incallmenuitemview Mignore;

Incallmenuitemview inherits from TextView, which represents the menu item when the phone is in a call state. Each menu item protects a text, an optional "green light", which represents open/close, and an optional icon on top of the text. Its member functions can assign values to them. When they are clicked, they are called in the function Incallscreen.handleonscreenbuttonclick or Incallscreen.onclick. The former is used for click events on Incalltouchui.

member functions for Incallscreen

Registerforphonestates: Used to register incallscreen for which states are interested. For GSM phones, these are registered:

Mphone.registerforprecisecallstatechanged (Mhandler, phone_state_changed, NULL);
Mphone.registerfordisconnect (Mhandler, phone_disconnect, NULL);
Mphone.registerformmiinitiate (Mhandler, phoneapp.mmi_initiate, NULL); Mphone.registerformmicomplete (Mhandler, phoneapp.mmi_complete, NULL);
Mphone.registerforsuppservicefailed (Mhandler, supp_service_failed, NULL);

When a message is received by a state change, the Mhandler responds to processing.

Application Dialer/contacts

Dialer program in Packages/apps/contacts, see Dialtactsactivity, it inherits from Tabactivity class, has four Tab:dialer, call log, Contacts and Favorites four tabs. Switch between tabs by implementing an interface Tabhost.ontabchangelistener.

This article link address: http://www.redwolf-blog.com/?p=1095

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.