Android tutorial on the full analysis of the boot process _android

Source: Internet
Author: User

This article details the android boot process. Share to everyone for your reference, specific as follows:

The initialization process of the wireless module during power-on; If the SIM card lock is turned on or the pin is locked, a pin or PUK will be required, but the unlock action must be performed after the system initialization completes. (The graphics system has not yet initialized how to enter the password ah?) Wm.systemready () will be called to notify you when the system initialization is complete. Do what you have to do at this time.

Initialization of the wireless module during power-on:

Rild calls the reference implementation REFERENCE-RIL.C (Hardware\ril\reference-ril) functions:

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 was 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'll 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_c
Ommand ("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 notifications * * 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 notifications, 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 the SMS is ready (currently ignored)/At_send_command ("At%cstat=1", NULL);
Ot_ready);

 }
}

The default is to assume that the RF module is good,
The initialization of the wireless module is triggered by Setradiostate (Radio_state_sim_not_ready).

The wireless module is initialized with the static void Onradiopoweron ().

First through Pollsimstate (NULL); 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 to read the status of the SIM card is: Getsimstatus ()

Err = At_send_command_singleline ("At+cpin?", "+cpin:", &p_response);

It sent the AT command to the cat At+cpin? To query the status of the wireless module, if the wireless module is not ready, then he continues to invoke the 1 seconds

The SIM card status polling function Pollsimstate until the SIM status is obtained.

When the SIM card status is ready, the variable sstate is set through Setradiostate (Radio_state_sim_ready) as:

Radio_state_sim_ready, a function of static void Onsimready () is invoked to further initialize the wireless module.

The AT command sent is:

At_send_command_singleline ("At+csms=1", "+csms:", NULL);
At_send_command ("at+cnmi=1,2,2,1,1", NULL);

If the SIM card lock is turned on, or the pin is locked, a pin or PUK will be required, but the unlock action must be performed after the system initialization is complete. (The graphics system has not yet initialized how to enter the password ah?) Wm.systemready () will be called to notify you when the system initialization is complete. Do what you have to do at this time.

The call to Wm.systemready () triggers the Unlock interface. The specific process is as follows:

Since there are: windowmanagerservice wm = NULL;
So Wm.systemready ()
The function in the Windowmanagerservice is called:

public void Systemready () {
mpolicy.systemready ();
}

The Windowmanagerservice are:

Copy Code code as follows:
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 file Policy.java:

Public Phonewindowmanager Makenewwindowmanager () {return
new Phonewindowmanager ();
}

Because Phonewindowmanager inherits from Windowmanagerpolicy
So Mpolicy.systemready () finally calls the function in the file Phonewindowmanager.java:

public void Systemready ()
mkeyguardmediator.onsystemready ();
Dokeyguard ();
Showlocked ();
msg = Mhandler.obtainmessage (show);
Mhandler.sendmessage (msg);

Send a message to show.

Message handler functions in file Keyguardviewmediator.java:

The show message was processed by public void Handlemessage (msg).
If Msg.what equals show then execute:

Handleshow ();
private void Handleshow () ...
Mcallback.onkeyguardshow ();
Mkeyguardviewmanager.show ();
Mshowing = true;

Mkeyguardviewmanager.show () calls a function in the file Keyguardviewmanager.java:

Public synchronized void Show () ...
Mkeyguardview = Mkeyguardviewproperties.createkeyguardview (Mcontext, Mupdatemonitor, this);
...

Mkeyguardviewproperties.createkeyguardview calls the functions in the file Lockpatternkeyguardviewproperties.java:

Public Keyguardviewbase Createkeyguardview,
keyguardupdatemonitor updatemonitor,
Keyguardwindowcontroller controller) {return
to new Lockpatternkeyguardview (context, Updatemonitor,
Mlockpatternutils, controller);


The new Lockpatternkeyguardview calls the constructor of the class Lockpatternkeyguardview:

Public Lockpatternkeyguardview,
keyguardupdatemonitor updatemonitor,
Lockpatternutils lockpatternutils,
keyguardwindowcontroller Controller) ...
Mlockscreen = Createlockscreen ();
AddView (mlockscreen);
Final Unlockmode Unlockmode = Getunlockmode ();
Munlockscreen = Createunlockscreenfor (unlockmode);
Munlockscreenmode = Unlockmode;
AddView (munlockscreen);
Updatescreen (Mmode);

Execute the above program and then eject the unlock interface, Getunlockmode get the lock type, usually three kinds:

Enum Unlockmode {
patterns,//pattern lock
simpin,//input PIN or PUK
account//ID lock
}

Through the above process we can know that in the system initialization phase when the Rild, Rild and Cat communication, and the cat initialization. Saved a series of States for the network.

In standby state, flight mode switching process analysis:

Flight mode switching is more complex, it involves a large module state switching when the state changes:

GSM module, Bluetooth module, WiFi module.

The enabler layer of flight mode sends broadcast messages: 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 GSM, Bluetooth, the WiFi module registers the action_airplane_mode_changed message monitoring separately, therefore receives this message, the module will carry on the switch.

Bluetoothdeviceservice.java

Turn on Bluetooth: Enable (false);
Turn off Bluetooth: Disable (FALSE);
Phoneapp.java (Packages\apps\phone\src\com\android\phone)
Set GSM module status phone.setradiopower (enabled);
Wifiservice.java
Set WiFi status setwifienabledblocking (wifienabled, False, Process.myuid ());

GSM Module Switching Process Analysis:

The Phone.setradiopower (enabled) call is:

Functions in File Gsmphone.java:

public void Setradiopower ("Boolean power")
Msst.setradiopower (Power);

Because there are servicestatetracker msst;

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 there are:

Commandsinterface cm;
Public final class RIL extends Basecommands implements Commandsinterface

So cm.setradiopower is calling the function in the file Ril.java:

public void Setradiopower (Boolean in, message result)
Rilrequest rr = Rilrequest.obtain (Ril_request_radio_power, result);
Rr.mp.writeInt (1);
...
Send (RR)

Turn the GSM module on or off by sending a ril_request_radio_power request to rild.

Rild Data receiving process:

Received Ril_request_radio_power execution:

Requestradiopower (data, datalen, T);

Then send the module to the wireless module to open and close the request according to the condition

The main at commands are:

Err = At_send_command ("at+cfun=0", &p_response);
Err = At_send_command ("At+cfun=1", &p_response);

Bluetooth module Switching Process Analysis:

Enable (false);

Bluetooth opens the function in the call file Bluetoothdeviceservice.java:

Public synchronized Boolean enable (Boolean SaveSetting)
setbluetoothstate (bluetoothdevice.bluetooth_state_ TURNING_ON);
Menablethread = new Enablethread (savesetting);
Menablethread.start ();
----
Disable (FALSE)

Bluetooth turns off functions in the call file:

Public Synchronized Boolean Disable (Boolean savesetting)
setbluetoothstate (bluetoothdevice.bluetooth_state_ Turning_off);

WiFi Module Switching process analysis:

Broadcast WiFi status change message: Wifi_state_changed_action

Copy Code code as follows:
Setwifienabledstate (enable?) Wifi_state_enabling:wifi_state_disabling, UID);

Update WiFi Status:

private void Updatewifistate ()

If you need to enable WiFi then send:

Sendenablemessage (True, false, Mlastenableuid);
Sendstartmessage (Strongestlockmode = = wifimanager.wifi_mode_scan_only);
Mwifihandler.sendemptymessage (Message_stop_wifi);

Processing command messages in a message loop:

public void Handlemessage (msg)

If enabled to Wifi:setwifienabledblocking (true, msg.arg1 = = 1, msg.arg2);

Open WiFi:

Mwifistatetracker.setscanonlymode (msg.arg1!= 0);
Setwifienabledblocking (false, Msg.arg1 = = 1, msg.arg2);

Disconnect

Mwifistatetracker.disconnectandstop ();

Open process steps:

1> load WiFi drive: Wifinative.loaddriver ()
2> Start back Daemo supplicant:WifiNative.startSupplicant ()
To close process steps:
1> Stop back Daemo supplicant:WifiNative.stopSupplicant ()
2> Uninstall WiFi drive: Wifinative.unloaddriver ()

If the WiFi status defaults to the constructor for the Wifiservice service:

Wifiservice (context context, Wifistatetracker Tracker)
Boolean wifienabled = getpersistedwifienabled ();
Setwifienabledblocking (wifienabled, False, Process.myuid ());

will open the WiFi module.

For more information on Android-related content readers can view the site topics: "Android Database Operating skills summary", "Android programming activity Operation Skills Summary", "Android File Operation skills Summary", " Android programming development of the SD card operation method Summary, "Android Development introduction and Advanced Course", "Android Resource Operation skills Summary", "Android View tips Summary" and "Android Control usage Summary"

I hope this article will help you with the Android program.

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.