Android 2.3 dial-up Access process from the source point of view analysis _android

Source: Internet
Author: User
Tags stub
Typically, if we want to use the SIM card Dial-up feature, we need to do a simple configuration in the setup, steps are as follows
Settings-"Wireless and network-" mobile network-(enabled data/data roaming/access point name/2G network/network operator only)
We have to select the "Enabled Data" option, and then configure the access point name can be used after the Internet, of course, some settings have been based on your SIM card type default set up the access point, this time you only select "Enabled Data" item can complete the Internet function settings.
What do these setup steps do? We are now analyzing from the point of view of the source code.

1. First, we find the "mobile network" settings UI-------Settings.java (/packages/apps/phone/src/com/android/phone/settings.java)
Settings.java:
The relevant code for the data enabled option is as follows:
Copy Code code as follows:

......
else if (preference = = mbuttondataenabled) {
if (DBG) log ("onpreferencetreeclick:preference = = mbuttondataenabled.");
Connectivitymanager cm =
(Connectivitymanager) Getsystemservice (Context.connectivity_service);
Cm.setmobiledataenabled (mbuttondataenabled.ischecked ());
return true;
}
......

Code, we get a Connectivitymanager object and call the object's Setmobiledataenable (Boolean B) method, set it according to the parameters passed in, and we look at the Connectivitymanager class.

2. Connectivitymanager.java (/frameworks/base/core/java/android/net/connectivitymanager.java)
This time, the data has entered the frameworks layer.
The Setmobiledataenable () method code is as follows:
Copy Code code as follows:

Iconnectivitymanager Mservice;
......
Public Connectivitymanager (Iconnectivitymanager service) {
if (service = = null) {
throw New IllegalArgumentException (
"Connectivitymanager () cannot be constructed with null service");
}
Mservice = Service;
}
......
public void Setmobiledataenabled (Boolean enabled) {
try {
mservice.setmobiledataenabled (enabled);
catch (RemoteException e) {
}
}

Here we need to know the Iconnectivitymanager class, Is a Java class that is automatically generated based on the Iconnectivitymanager.aidl interface, and we have a service that inherits the class's inner class: Stub, the service that we do on our own for dial-up access is connectivityservice. , so according to Aidl just, we know that the Mservice in the code is actually the object of the Connectivityservice class, So the code here is actually calling the Setmobiledataenable () method of the Connectivityservice object.

3. Connectivityservice.java (/frameworks/./base/services/java/com/android/server/connectivityservice.java)
The Setmobiledataenable () method code is as follows:
Copy Code code as follows:

public void Setmobiledataenabled (Boolean enabled) {
Enforcechangepermission ();
if (DBG) slog.d (TAG, "setmobiledataenabled (" + enabled +) ");
Mhandler.sendmessage (Mhandler.obtainmessage (Event_set_mobile_data,
(enabled?) enabled:disabled), 0);
}

Here sent a message out, Mhandler received the message later:
Copy Code code as follows:

Case Event_set_mobile_data:
{
Boolean enabled = (Msg.arg1 = = enabled);
Handlesetmobiledata (enabled);
Break
}

When you receive this message, call the Handlesetmobiledata () method:
Copy Code code as follows:

Private Networkstatetracker mnettrackers[];
......
private void Handlesetmobiledata (Boolean enabled) {
......
if (enabled) {
if (Mnettrackers[connectivitymanager.type_mobile]!= null) {
if (DBG) {
SLOG.D (TAG, "starting up" + mnettrackers[connectivitymanager.type_mobile]);
}
Mnettrackers[connectivitymanager.type_mobile].reconnect ();
}
......
}
}

If the "enabled data" option has been selected, then the parameter "Enabled" that is passed in should be "true", so the IF statement block in the code is processed, which is executed:
Copy Code code as follows:

Mnettrackers[connectivitymanager.type_mobile].reconnect ();

And in Connectivitymanager, Type_mobile is 0, so here's the equivalent of calling the
Copy Code code as follows:

Mnettracker[0].reconnect ()

However, Networkstatetracker is an abstract class, so the specific thing is to be given to its subclass Mobiledatastatetracker.java to do it.

4. Mobiledatastatetracker.java (/frameworks/base/core/java/android/net/mobiledatastatetracker.java)
This class contains a variety of data connections, including Mms,supl,dun,
The call flow inside the Mobiledatastatetracker.java is this:
Copy Code code as follows:

<pre Class=java name= "code" >mphoneservice = ITelephony.Stub.asInterface (Servicemanager.getservice ("Phone")); </PRE>......<BR>
Reconnect->mphoneservice.enableapntype (Apntype);<p></p>
<PRE></PRE>
Mphoneservice is the client of the Telephony service, and its server side is actually a Phoneinterfacemanager object
<P></P>
<p>5. Phoneinterfacemanager.java (/packages/apps/phone/src/com/android/phone/phoneinterfacemanager.java) <BR>
</P>
<P> look at the Enableapntype method of Phoneinterfacemanager:</p>
<p><pre Class=java name= "code" > public int enableapntype (String type) {
Enforcemodifypermission ();
return Mphone.enableapntype (type);
}
</PRE><P></P>
In this way, the request to connect APN is sent to the Telephony framework layer. APN is specified in the settings application, generally in your engineering directory of system/etc/apns-conf.xml files <BR>
<BR>
<p>6. The mphone above is the PhoneProxy object,</p>
<P> Call Process:</p>
<P>PhoneProxy.java:<BR>
</P>
<p><pre Class=java name= "code" >mactivephone.enableapntype (type) </PRE> Mactivephone is Gsmphone or Cdmaphone tracing interface Phonebase Object <BR>
<P></P>
<P>PhoneBase.java:</P>
<p><pre Class=java name= "code" >mdataconnection.enableapntype (type);</pre><p></p>
<P> call to Dataconnectiontracker Enableapntype method </P>
<P>DataConnectionTracker.java:<BR>
</P>
<p>enableapntype (String type)->setenabled->onenableapn->onenablenewapn<br>
</P>
<BR>
The &LT;P&GT;ONENABLENEWAPN method is implemented in Dataconnectiontracker derived classes Gsmdataconnectiontracker and Cdmadataconnectiontracker. This distinguishes the data connection flow of different types of phone. <BR>
</P>
<P> using GSM as an example, call process:onenablenewapn->cleanupconnection->conn.disconnect<br>
<BR>
</P>
Conn is a DataConnection object that identifies a single clock data connection, and you can see that this actually implements a data connection state machine. <BR>
<P> the state of the data connection in the DataConnection object is divided into:</p>
<p><pre Class=java name= "code" >dcdefaultstate, default state.
Dcinactivestate, not active.
Dcactivatingstate, activating State
Dcactivestate, activating status
Dcdisconnectingstate, breaking state
Dcdisconnectingbaddnsstate, disconnect status (because of bad DNS)
</PRE><P></P>
After the <P> connection succeeds, Notifydefaultdata calls the Notifydataconnection method to the Defaultphonenotifier. </P>
<p>defaultphonenotifier is the client of the Itelephonyregistry interface, Its service side is Telephonyregistry (com.android.server.TelephonyRegistry) </P>
<p>telephonyregistry Notifydataconnection method calls the following statement <BR>
<pre Class=java name= "code" > R.callback.ondataconnectionstatechanged (State, networktype); </pre><p ></P>
<p>r is the element in the current mrecords, and every call in the implementation callback,telephonyregistry that contains the Iphonestatelistener interface iterates through the elements in the mrecords, If an element registers a corresponding answering,</p>
<P> invokes a function of callback. </P>
The <P> client invokes the interception of the telephone status through the following way, taking Mphonestatelistener in Statusbarpolicy.java as an example:</p>
<P> ((Telephonymanager) Mcontext.getsystemservice (context.telephony_service)) </P>
<P> Listen (mphonestatelistener,<br>
Phonestatelistener.listen_service_state<br>
| Phonestatelistener.listen_signal_strengths<br>
| Phonestatelistener.listen_call_state<br>
| Phonestatelistener.listen_data_connection_state<br>
| phonestatelistener.listen_data_activity);<br>
</P>
<p>mphonestatelistener is a Phonestatelistener instance, Phonestatelistener implements the Iphonestatelistener interface, If you inherit Phonestatelistener, first you have to make sure that you are interested in listening </P>
<P> events, and then rewrite the corresponding method. Call the Listen method just like the above. </P>
The <p>telephonyregistry method, the listening action, the method that you have to rewrite corresponds to the following:</p>
The method of <p>telephonyregistry--------------------- The Listener action-------------------------------------------------------the callback in the Phonestatelistener subclass <BR>
</P>
<p>notifyservicestate----------phonestatelistener.listen_service_state-----------------public void Onse Rvicestatechanged (servicestate State) <BR>
</P>
<p>notifysignalstrength-------phonestatelistener.listen_signal_strengths-----------public void onsignals Trengthschanged (signalstrength signalstrength) <BR>
</P>
<p>notifycallstate----------------phonestatelistener.listen_call_state-------------------------public voi d oncallstatechanged (int state, String incomingnumber) <BR>
</P>
<p>notifydataconnection-------phonestatelistener.listen_data_connection_state---public void onDataConnecti onstatechanged (int state, int networktype) <BR>
</P>
<p>notifydataactivity--------------phonestatelistener.listen_data_activity-----------------------Public void ondataactivity (int direction) <BR>
</P>
<P> ..... </P>
<P> so the entire call chain is: defaultphonenotifier:notifydataconnection---------"Telephonyregistry : Notifydataconnection---------"</P>
<p>phonestatelistener.callback:ondataconnectionstatechanged--------------" The ondataconnectionstatechanged</p> of Phonestatelistener subclasses
<P> In addition, Telephonyregistry also emits a action_any_data_connection_state_changed that contains details of the data connection. </P>
<P><BR>
The Mobiledatastatetracker in the mobile data service receives this action, and the Boadcastreceiver class Mobiledatastatereceiver extracts information about the data connection, Then set a good state </P>
<pre Class=java name= "code" >setdetailedstate (detailedstate.connecting, Reason, apnname);
</PRE>
<p>mobiledatastatetracker sends event_state_changed messages to Connectivityservice based on state changes. </P>
<p>connectivityservice calls Handleconnect to perform related hype, including turning off the lower priority data connections, updating the status bar, and so on. <BR>
</P>
<P> There are a lot of places that have not been understood and will be resumed later. <BR>
</P>
<P><BR>
</P>
<P><BR>
</P>
<BR>
<P><BR>
<BR>
</P>

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.