Boot of Android Wireless Module

Source: Internet
Author: User
Tags home screen

Http://tech.sina.com.cn/s/2010-01-14/19281215405.shtml

The initialization process of the wireless module during the boot process. If the SIM card lock is enabled or the PIN is locked, you must enter the pin or Puk, however, this unlock action can only be performed after the system initialization is complete. (How do I enter the password before the graphic system is initialized ?) After the system initialization is complete, WM. systemready () will be called to notify you. At this time, we will do what we should do.

The initialization process of the wireless module during the boot process:

Rild calls the functions in the reference implementation Reference-ril.c (hardware \ RIL \ reference-RIL:

Const ril_radiofunctions * ril_init (const struct ril_env * ENV, int argc, char ** argv)

Ret = pthread_create (& s_tid_mainloop, & ATTR, mainloop, null );

Static void * mainloop (void * PARAM)

Ret = at_open (FD, onunsolicited );

Ril_requesttimedcallback (initializecallback, null, & timeval_0 );

The cat is initialized in the initializecallback function.

Static void initializecallback (void * PARAM)

{

Atresponse * p_response = NULL;

Int err;

Setradiostate (radio_state_off );

At_handshake ();

/* Note: We don't check errors here. Everything important will

Be handled in onattimeout and onatreaderclosed */

/* Atchannel is tolerant of ECHO but it must */

/* Have verbose result codes */

At_send_command ("ate0q0v1", null );

/* No auto-answer */

At_send_command ("ats0 = 0", null );

/* Extended errors */

At_send_command ("at + cmee = 1", null );

/* Network registration events */

Err = at_send_command ("at + CREG = 2", & p_response );

/* Some handsets -- In tethered mode -- don't support CREG = 2 */

If (ERR <0 | p_response-> success = 0 ){

At_send_command ("at + CREG = 1", null );

}

At_response_free (p_response );

/* GPRS registration events */

At_send_command ("at + cgreg = 1", null );

/* Call Waiting notifications */

At_send_command ("at + ccwa = 1", null );

/* Alternating Voice/Data off */

At_send_command ("at + cmod = 0", null );

/* Not muted */

At_send_command ("at + cmut = 0", null );

/* + Cssu unsolicited supp service specifications */

At_send_command ("at + cssn = 0, 1", null );

/* No connected line identification */

At_send_command ("at + Colp = 0", null );

/* Hex Character Set */

At_send_command ("at + CSCs = \" hex \ "", null );

/* Ussd unsolicited */

At_send_command ("at + cusd = 1", null );

/* Enable + cgev GPRS event configurations, but don't buffer */

At_send_command ("at + cgerep = 1, 0", null );

/* Sms pdu mode */

At_send_command ("at + cmgf = 0", null );

# Ifdef use_ti_commands

At_send_command ("at % CPI = 3", null );

/* Ti specific -- notifications when SMS is ready (currently ignored )*/

At_send_command ("at % cstat = 1", null );

# Endif/* use_ti_commands */

/* Assume radio is off on Error */

If (isradioon ()> 0 ){

Setradiostate (radio_state_sim_not_ready );

}

}

By default, it is assumed that the RF module is good,

Setradiostate (radio_state_sim_not_ready) is used to trigger the initialization of the wireless module.

Initialize the wireless module through static void onradiopoweron.

First, pollsimstate (null) is used to poll the SIM card status.

Static void pollsimstate (void * PARAM)

{

Atresponse * p_response;

Int ret;

If (sState! = Radio_state_sim_not_ready ){

// No longer valid to poll

Return;

}

Switch (getsimstatus ()){

Case ril_sim_absent:

Case ril_sim_pin:

Case ril_sim_puk:

Case ril_sim_network_personalization:

Default:

Setradiostate (radio_state_sim_locked_or_absent );

Return;

Case ril_sim_not_ready:

Ril_requesttimedcallback (pollsimstate, null, & timeval_simpoll );

Return;

Case ril_sim_ready:

Setradiostate (radio_state_sim_ready );

Return;

}

}

The function used to read the SIM card status is getsimstatus ()

Err = at_send_command_singleline ("at + cpin? "," + Cpin: ", & p_response );

It sends the AT command at + cpin to the cat? To query the status of the wireless module.

SIM card status polling function pollsimstate until the SIM card status is obtained.

When the SIM card status is ready, set the sState variable:

Radio_state_sim_ready. In this case, the static void onsimready () function is called to further initialize the wireless module.

The at command is as follows:

At_send_command_singleline ("at + CSMs = 1", "+ CSMs:", null );

At_send_command ("at + cnmi = 1, 2, 1, 1", null );

If the SIM card lock is enabled or the PIN is locked, the pin or Puk is required. However, this unlock action must be completed after the system initialization is complete.

. (How do I enter the password before the graphic system is initialized ?) After the system initialization is complete, WM. systemready () will be called to notify you.

At this time, we will do what we should do.

WM. systemready () calls will trigger the unlock interface. The specific process is as follows:

Because there are: windowmanagerservice WM = NULL; so WM. systemready ()

The function in windowmanagerservice is called:

Public void systemready (){

Mpolicy. systemready ();

}

Windowmanagerservice includes:

Final windowmanagerpolicy mpolicy = policymanager. makenewwindowmanager ();

Policymanager. makenewwindowmanager calls the functions in the file policymanager. Java:

Public static windowmanagerpolicy makenewwindowmanager (){

Return spolicy. makenewwindowmanager ();

}

Spolicy. makenewwindowmanager calls the functions in the policy. Java file:

Public phonewindowmanager makenewwindowmanager (){

Return new phonewindowmanager ();

}

Because phonewindowmanager inherits from windowmanagerpolicy

Therefore, mpolicy. systemready () finally calls the function in the phonewindowmanager. Java file:

Public void systemready ()

Mkeyguardmediator. onsystemready ();

Dokeyguard ();

Showlocked ();

Message MSG = mhandler. obtainmessage (show );

Mhandler. sendmessage (MSG );

Send the show message.

Message Processing functions in the keyguardviewmediator. Java file:

Public void handlemessage (Message MSG) processes the show message.

If MSG. What is equal to show, execute:

Handleshow ();

Private void handleshow ()

...

Mcallback. onkeyguardshow ();

Mkeyguardviewmanager. Show ();

Mshowing = true;

Mkeyguardviewmanager. Show () calls the functions in the keyguardviewmanager. Java file:

Public synchronized void show ()

...

Mkeyguardview = mkeyguardviewproperties. createkeyguardview (mcontext, mupdatemonitor, this );

...

Mkeyguardviewproperties. createkeyguardview calls the file lockpatternkeyguardviewproperties. Java

Functions in:

Public keyguardviewbase createkeyguardview (context,

Keyguardupdatemonitor updatemonitor,

Keyguardwindowcontroller Controller ){

Return new lockpatternkeyguardview (context, updatemonitor,

Mlockpatternutils, Controller );

}

New lockpatternkeyguardview calls the constructor like lockpatternkeyguardview:

Public lockpatternkeyguardview (

Context context,

Keyguardupdatemonitor updatemonitor,

Lockpatternutils,

Keyguardwindowcontroller Controller)

...

Mlockscreen = createlockscreen ();

Addview (mlockscreen );

Final unlockmode = getunlockmode ();

Munlockscreen = createunlockscreenfor (unlockmode );

Munlockscreenmode = unlockmode;

Addview (munlockscreen );

Updatescreen (mmode );

Execute the above program and then bring up the unlock interface. getunlockmode gets the lock type. There are usually three types:

Enum unlockmode {

Pattern, // pattern lock

Simpin, // enter the pin or Puk

Account // account lock

}

Through the above process, we can know that during the system initialization phase when rild is started, rild communicates with the cat and initializes the cat.

Saves a series of network statuses.

==========

Analysis of the flight mode switching process in standby mode:

The flight mode switching is complicated. When the status changes, it involves switching the status of a large module:

GSM module, bluetooth module, and WiFi module.

The enabler layer in flight mode sends a broadcast message: action_airplane_mode_changed

Private void setairplanemodeon (Boolean enabling ){

Mcheckboxpref. setenabled (false );

Mcheckboxpref. setsummary (enabling? R. String. airplane_mode_turning_on

: R. String. airplane_mode_turning_off );

// Change the system setting

Settings. system. putint (mcontext. getcontentresolver (), settings. system. airplane_mode_on,

Enabling? 1: 0 );

// Post the intent

Intent intent = new intent (intent. action_airplane_mode_changed );

Intent. putextra ("State", enabling );

Mcontext. sendbroadcast (intent );

}

Because the GSM, Bluetooth, and Wi-Fi modules have registered the monitoring of action_airplane_mode_changed messages, they receive

After the message is sent, the module switches over.

Bluetoothdeviceservice. Java

Enable Bluetooth: Enable (false );

Disable Bluetooth: Disable (false );

Phoneapp. Java (packages \ apps \ phone \ SRC \ com \ Android \ phone)

Set the status of the GSM module to phone. setradiopower (Enabled );

Wifiservice. Java

Set the WiFi status setwifienabledblocking (wifienabled, false, process. myuid ());

===

Analysis of GSM module switching process:

Phone. setradiopower (Enabled) calls:

Functions in file gsmphone. Java:

Public void setradiopower (Boolean power)

Msst. setradiopower (power );

Because servicestatetracker msst is available;

Msst. setradiopower calls the functions in the file servicestatetracker. Java:

Public void setradiopower (Boolean power)

Mdesiredpowerstate = power;

Setpowerstatetodesired ();

Cm. setradiopower (true, null );

Or

Cm. setradiopower (false, null );

Because:

Commandsinterface cm;

Public final class RIL extends basecommands implements commandsinterface

Therefore, CM. setradiopower calls the functions in the file RIL. Java:

Public void setradiopower (Boolean on, message result)

Rilrequest RR = rilrequest. Obtain (ril_request_radio_power, result );

Rr. MP. writeint (1 );

...

Send (RR)

Send the ril_request_radio_power request to rild to enable or disable the GSM module.

Rild data receiving process:

Run the following command to receive ril_request_radio_power:

Requestradiopower (data, datalen, t );

Then, send the request to the wireless module based on the conditions.

The main at Commands include:

Err = at_send_command ("at + cfun = 0", & p_response );

Err = at_send_command ("at + cfun = 1", & p_response );

===

Analysis of bluetooth module switching process:

Enable (false );

Enable the function in the callback thdeviceservice. Java file by using Bluetooth:

Public synchronized Boolean enable (Boolean savesetting)

Seteffecthstate (effecthdevice. effecth_state_turning_on );

Menablethread = new enablethread (savesetting );

Menablethread. Start ();

----

Disable (false)

Disable functions in the call file by using Bluetooth:

Public synchronized Boolean disable (Boolean savesetting)

Seteffecthstate (effecthdevice. effecth_state_turning_off );

===

Analysis of wifi module switching process:

Message for changing the WiFi status: wifi_state_changed_action

Setwifienabledstate (enable? Wifi_state_enabling: wifi_state_disabling, UID );

Update WiFi status:

Private void updatewifistate ()

If you want to enable WiFi, the message will be sent:

Sendenablemessage (true, false, mlastenableuid );

Sendstartmessage (strongestlockmode = wifimanager. wifi_mode_scan_only );

Mwifihandler. sendemptymessage (message_stop_wifi );

Process command messages in a message loop:

Public void handlemessage (Message MSG)

If enabling WiFi: setwifienabledblocking (true, MSG. arg1 = 1, MSG. arg2 );

Enable WiFi: mwifistatetracker. setscanonlymode (msg. arg1! = 0 );

Setwifienabledblocking (false, MSG. arg1 = 1, MSG. arg2 );

Disconnect mwifistatetracker. disconnectandstop ();

Procedure:

1> mount the WiFi DRIVER: wifinative. loaddriver ()

2> daemo supplicant: wifinative. startsupplicant ()

Procedure:

1> stop and return daemo supplicant: wifinative. stopsupplicant ()

2> uninstall the WiFi DRIVER: wifinative. unloaddriver ()

If the WiFi status is enabled by default, the constructor of the wifiservice service is as follows:

Wifiservice (context, wifistatetracker tracker)

Boolean wifienabled = getpersistedwifienabled ();

Setwifienabledblocking (wifienabled, false, process. myuid ());

The wifi module is enabled.

Read about wordend:
Android tutorial-solve WiFi connection instability
Create an android home screen widget from scratch
Android tips for solving app widget User Interaction

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.