Android 2.2 data connection process

Source: Internet
Author: User

The entire data connection process mainly relies on dataconnection and its corresponding CDMA and GSM subclasses.

The data connection contains several states. The constructor must add these states and specify an initial state. The following code

293 addstate (mdefaultstate );
294 addstate (minactivestate, mdefaultstate );
295 addstate (mactivatingstate, mdefaultstate );
296 addstate (mactivestate, mdefaultstate );
297 addstate (mdisconnectingstate, mdefaultstate );
298 addstate (mdisconnectingbaddnsstate, mdefaultstate );
299 setinitialstate (minactivestate );

Set the initialization status to minactivestate, which indicates that the connection is not activated.

Private dcinactivestate minactivestate = new dcinactivestate ();

All status classes are inherited from hierarchicalstate, just like

Private class dcinactivestate extends hierarchicalstate

Status can be converted to each other, receive messages, and disconnect

When a connection is required

Public void connect (Message oncompletedmsg, apnsetting APN); or

Public void connect (Message oncompletedmsg). The former specifies the APN settings, and the latter is null.

Both methods send messages to the current status.

Sendmessage (obtainmessage (event_connect, new connectionparams (APN, oncompletedmsg); or

Sendmessage (obtainmessage (event_connect, new connectionparams (null, oncompletedmsg )));

Minactivestate after receiving the message

554 case event_connect:
555 if (DBG) log ("dcinactivestate MSG. What = event_connect ");
556 connectionparams CP = (connectionparams) msg. OBJ;
557 CP. Tag = mtag;
558 onconnect (CP );
559 transitionto (mactivatingstate );
560 retval = true;
561 break;
Onconnect (CP) is an abstract function. It is implemented in gsmdataconnection and CDMA dataconnection. In onconnect (CP) of CDMA dataconnection, the method in RIL. Java is called:

98 message MSG = obtainmessage (event_setup_data_connection_done, CP );
99 msg. OBJ = CP;

101 phone. mcm. setupdatacall (integer. tostring (rilconstants. setup_data_tech_cdma ),
102 integer. tostring (dataprofile), CP. APN. APN, CP. APN. user,
103 cp. APN. Password, integer. tostring (rilconstants. setup_data_auth_pap_chap), MSG );

In this way, after the request is sent to the RIL layer, it is converted to the mactivatingstate state, and the next step is to wait for the RIL layer to respond.

Learning RIL from the previous blog will form an asynchronous result and bind it to the message for sending.

Asyncresult. formessage (RR. mresult, RET, null );

Rr. mresult. sendtotarget ();

The above mactivationstate will receive

589 case event_setup_data_connection_done:
590 if (DBG) log ("dcactivatingstate MSG. What = event_setup_data_connection_done ");
591
592 AR = (asyncresult) msg. OBJ;
593 CP = (connectionparams) Ar. userobj;
594
595 setupresult result = onsetupconnectioncompleted (AR );
596 switch (result ){
597 case success:
598 // all is well
599 mactivestate. setenternotificationparams (CP, failcause. None );
600 transitionto (mactivestate );
601 break;
602 case err_badcommand:
603 // vendor RIL rejected the command and didn't connect.
604 // transition to inactive but send notifications after
605 // we 've entered the minactive state.
606 minactivestate. setenternotificationparams (CP, result. mfailcause );
607 transitionto (minactivestate );
608 break;
609 case err_baddns:
610 // connection succeeded but DNS info is bad So disconnect
611 EventLog. writeevent (eventlogtags. pdp_bad_dns_address, dnsservers [0]);
612 teardowndata (CP );
613 transitionto (mdisconnectingbaddnsstate );
614 break;
615 case err_other:
616 // request the failure cause and process in this state
617 phone. mcm. getlastdatacallfailcause (
618 obtainmessage (event_get_last_fail_done, CP ));
619 break;
620 case err_stale:
621 // request is stale, ignore.
622 break;
Default 623:
624 throw new runtimeexception ("unkown setupresult, shocould not happen ");
625}
626 retval = true;
627 break;

 

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.