mPhoneService = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
......
Reconnect-> mphoneservice. enableapntype (apntype );
Mphoneservice is the client of the telephone service, and its server is actually a phoneinterfacemanager object
5. phoneinterfacemanager. Java (/packages/apps/phone/src/COM/Android/phone/phoneinterfacemanager. Java)
Check the enableapntype method of phoneinterfacemanager:
public int enableApnType(String type) { enforceModifyPermission(); return mPhone.enableApnType(type); }
In this way, the request to connect to the APN is sent to the Telephony framework layer. The APN is specified in the setup application, typically in the system/etc/apns-conf.xml file under your project directory
6. The above mphone is the phoneproxy object,
Call process:
Phoneproxy. Java:
mActivePhone.enableApnType(type)
Mactivephone is the phonebase object of the upstream interface of gsmphone or cdmaphone.
Phonebase. Java:
mDataConnection.enableApnType(type);
Call the enableapntype method of dataconnectiontracker.
Dataconnectiontracker. Java:
Enableapntype (string type)-> setenabled-> onenableapn-> onenablenewapn
The onenablenewapn method is implemented in the gsmdataconnectiontracker and CDMA dataconnectiontracker Derived classes of dataconnectiontracker to differentiate the data connection processes of different phone types.
Taking GSM as an example, the call process is onenablenewapn-> cleanupconnection-> conn. Disconnect.
Conn is a dataconnection object that identifies a data connection within one minute. It can be seen that a data connection state machine is actually implemented here.
The data connection status in the dataconnection object is divided:
Dcdefaultstate, default state. Dcinactivestate: inactive. Dcactivatingstate: the status of dcactivestate is being activated. The status of dcdisconnectingstate is being activated. The status of dcdisconnectingbaddnsstate is being disconnected (due to incorrect DNS)
After the connection is successful, yydefadata calls yultphonenotifier's notifydataconnection method.
Defaultphonenotifier is the client of the itelephonyregistry interface, and its server is telephonyregistry (COM. Android. server. telephonyregistry)
Telephonyregistry's notifydataconnection method calls the following statement:
r.callback.onDataConnectionStateChanged(state, networkType);
R is an element in the current mrecords and contains the implementation callback of the iphonestatelistener interface. Each call in telephonyregistry traverses the elements in mrecords. If an element registers a corresponding answer,
Call a callback function.
The client calls the listener to obtain the phone status in the following way. Take mphonestatelistener in statusbarpolicy. Java as an example:
(Telephonymanager) mcontext. getsystemservice (context. telephony_service ))
. Listen (mphonestatelistener,
Phonestatelistener. listen_service_state
| Phonestatelistener. listen_signal_strengths
| Phonestatelistener. listen_call_state
| Phonestatelistener. listen_data_connection_state
| Phonestatelistener. listen_data_activity );
Mphonestatelistener is a phonestatelistener instance. phonestatelistener implements the iphonestatelistener interface. If you inherit the phonestatelistener subclass, you must first determine the listener you are interested in.
Event, and then override the corresponding method. Call the listen method as above.
Telephonyregistry's methods, listener actions, and methods you want to override correspond to the following:
Telephonyregistry method --------------------- listener action ----------------------------------------------------------- callback in the phonestatelistener subclass
Notifyservicestate ---------- phonestatelistener. listen_service_state --------------- public void onservicestatechanged (servicestate state)
Policysignalstrength ------- phonestatelistener. listen_signal_strengths --------- -- Public void onsignalstrengthschanged (signalstrength)
Notifycallstate ---------------- phonestatelistener. listen_call_state ------------------------- public void oncallstatechanged (INT state, string incomingnumber)
Notifydataconnection ------- phonestatelistener. listen_data_connection_state --- public void ondataconnectionstatechanged (INT state, int networktype)
Notifydataactivity -------------- phonestatelistener. listen_data_activity ----------------------- public void ondataactivity (INT direction)
........
Therefore, the entire call chain is: defaultphonenotifier: notifydataconnection --------- telephonyregistry: yydataconnection ---------
Phonestatelistener. Callback: ondataconnectionstatechanged -------------- ondataconnectionstatechanged of the phonestatelistener subclass
In addition, telephonyregistry also sends an action_any_data_connection_state_changed, which contains detailed information about the data connection.
The mobiledatastatetracker in Mobile Data Service receives this action, and its boadcastreceiver class mobiledatastatereceiver extracts the data connection information and sets the status.
setDetailedState(DetailedState.CONNECTING, reason, apnName);
Mobiledatastatetracker sends the event_state_changed message to connectivityservice according to the status change.
Connectivityservice calls handleconnect to execute related hype, including disabling data connections with lower priority and updating the status bar.
Note: the latter part draws on http://blog.csdn.net/yinlijun2004/article/details/6656788.
There are still many areas that haven't been figured out, and we will continue later.