Before summarizing the lock screen code, there are two main ideas to keep in mind
A) Keyguardhostview is the interface we are going to show, so no matter what the method, we need to add this keyguardhostview to the window and fill it up, it's all a matter of detail.
B) So the question is, how do we usually add a view to the window?
There are two types of answers: 1 Windowmanager.addview () 2 layoutinflater.inflate (ResID, Parentview, True), and both of these methods are useful in the lock screen code.
-----------------------------------------------Gorgeous split-line-------------------------------------------------------------------
Next, use a diagram to explain the process.
-------------------------------is a lovely dividing line--------------------------------------------------------
you can see, First call two wrapper classes from the Phonewindowmanager Systemready method (keyguardservicedelegate.java Keyguardservicewrapper.java) is then called to Onsystemready in Keyguardservice.java, which in turn invokes the total dispatch of the lock screen code to make the Keyguardviewmediator.java. It is the CEO of the lock screen. As we know, the CEO is generally not too involved in code issues, just assign, coordinate work, customer/supply chain communication. The mexternallyenabled variable in Keyguardviewmediator.java is the bargaining chip that the director negotiates with the client, if the customer third party passes the Keyguardmanager.diablekeyguard () Method disables the System lock screen, this variable will be set to false, thus does not draw the system lock screen interface, otherwise, will be the task big hand throw directly to general manager Keyguardviewmanager.java. The code is as follows:
<span style= "FONT-SIZE:12PX;" >/** * Enable the Keyguard if the settings is appropriate. */private void dokeyguardlocked (Bundle options) {Boolean issimsecure = Mupdatemonitor.issimpinsecure (); M:if Another app is disabling us (except Sim Secure) and then don ' t show if (!mexternallyenabled &&!is Simsecure) | | Poweroffalarmmanager.isalarmboot ()) {if (DEBUG) keyguardutils.xlogd (TAG, "dokeyguard:not showing because external ly disabled "); Return } 。。。 showlocked (options); } private void Handleshow (Bundle options) {... Mkeyguardviewmanager.show (options); 。。。 With the above code, all the tasks have been put into Keyguardviewmanager.java's head, and then see how this general manager works /** * Show the keyguard. would handle creating and attaching to the view manager * lazily.   ; */ public synchronized void Show (Bundle options) { if (DEBUG) log.d (TAG, "Show ()"; mkeyguardview= "+ Mkeyguardview); Boolean enablescreenrotation = Keyguardutils.shouldenablescreenrotation (Mcontext); if (DEBUG) LOG.D ( TAG, "Show () query screen rotation after"); //m:incoming Indicator for Keygu ARD Rotation @{ keyguardupdatemonitor.getinstance (mContext). Setquerybasetime (); //@} <span style= "color: #FF0000;" >maybecreatekeyguardlocked (Enablescreenrotation, False, options);</span> if (DEBUG) log.d (TAG, "Show () maybecreatekeyguardlocked Finish "); Maybeenablescreenrotation (ENABLESCReenrotation); //Disable Common aspects of the system/status/navigation bars That is not appropriate or //useful on any keyguard screens but can be re-shown by dialogs or show_when_locked //activities. Other disabled bits is handled by the Keyguardviewmediator talking // directly to the status bar service. int visflags = View.status_bar_disable_ home; if (Shouldenabletranslucentdecor ()) { mwindowlayoutparams.flags |= WindowManager.LayoutParams.FLAG_ translucent_status | windowmanager.layoutparams.flag_translucent_navigation; } if (DEBUG) log.d (TAG, "show:setsystemuivisibility" ("+ integer.tohexstring (visflags) +") ) "); mkeyguardhost.setsystemuivisibility (visFlags); mviewmanager.updateviewlayout (Mkeyguardhost, Mwindowlayoutparams); mkeyguardhost.setvisibility (view.visible); <span style= "color: #FF0000;" >mkeyguardview.show ();</span> mKeyguardView.requestFocus (); if (DEBUG) log.d (TAG, "Show () exit; mkeyguardview= "+ mkeyguardview); } key code so all the analysis, <span style=" color: #009900; " >//one thing you need to notice in advance mkeyguardhost is just an empty View,mkeyguardview is the real keyguardhostview</span>boolean enableScreenrotation is used to determine if screen rotation is allowed, keyguardupdatemonitor.getinstance (mcontext). Setquerybasetime (); This line code is to reset the query time. such as missed calls, unread text messages, etc., the reason for re-set is to imitate the iphone, Draw lock screen, query unread information/missed phone number is for this lock screen received unread information/missed calls
Maybecreatekeyguardlocked (Enablescreenrotation, False, options); I rub ~ finally to the key code, this method is really to create a lock screen method, to see hosting bar private void maybecreatekeyguardlocked (Boolean Enablescreenrotation, Boolean force, Bundle Options) { if (mkeyguardhost! = null) { mkeyguardhost.savehierarchystate (Mstatecontainer); } if (mkeyguardhost = = null) { if (DEBUG) log.d (TAG, "Keyguard host is null, creating it ..."); & nbsp; <span style= "color: #990000;" >mkeyguardhost = new Viewmanagerhost (mcontext);</span> int flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_Screen | windowmanager.layoutparams.flag_layout_inset_decor | windowmanager.layoutparams.flag_force_not_fullscreen | windowmanager.layoutparams.flag_show_wallpaper; if (!mneedsinput) { Flags |= windowmanager.layoutparams.flag_alt_focusable_im; } Final int stretch = viewgroup.layoutparams.match_parent; final int type = windowmanager.layoutparams.type_keyguard; windowmanager.layoutparams LP = new Windowmanager.layoutparams ( stretch, stretch, type, flags, pixelformat.translucent); Lp.softInputMode = windowmanager.layoutparams.soft_input_adjust_resize; lp.windowanimations = r.style.animation_lockscreen; lp.screenorientation = enablescreenrotation? Activityinfo.screen_orientation_user: activityinfo.screen_orientation_nosensor; if ( ActivitymANAGER.ISHIGHENDGFX ()) { Lp.flags |= windowmanager.layoutparams.flag_hardware_accelerated; Lp.privateflags |= windowmanager.layoutparams.private_flag_force_hardware_accelerated; } lp.privateflags |= windowmanager.layoutparams.private_flag_set_needs_menu_key; //M:poke user activity when operating keyguard & nbsp; //lp.inputfeatures |= windowmanager.layoutparams.input_feature_disable_user_activity; lp.settitle ("Keyguard"); Mwindowlayoutparams = lp; ///m:skip Add Keyguardhost to Viewmanager in at case & nbsp; if (! keyguardviewmediator.iskeyguardinactivity) { <span style= "color: #CC0000;" >mviewmanager.addview (MKEYGUARDHOST, LP);</span> } else { if (DEBUG) LOG.D (TAG, "Skip add Mkeyguardhost to Mviewmanager for testing"); } Keyguardupdatemonitor.getinstance (Mcontext). REgistercallback (Mbackgroundchanger); } //M:if force and Keyguardview are not NULL, we should relase memory hold by old KEYGUARDVIEW&NBSP;&NBSP;&NBSP;&NB sp; if (Force && Mkeyguardview! = null) { mkeyguardview.cleanup (); } if (force | | mkeyguardview = = NULL) { & nbsp; mkeyguardhost.setcustombackground (null); mkeyguardhost.removeallviews (); <span style= "color: #CC0000;" >inflatekeyguardview (options);</span> Mkeyguardview.requestfocus (); } Updateuseractivitytimeoutinwindowlayoutparams (); Mviewmanager.updateviewlayout (Mkeyguardhost, Mwindowlayoutparams); Mkeyguardhost.restorehierarchystate (Mstatecontainer); }
Here in red code throughMviewmanager.addview (mkeyguardhost, LP);Add the Mkeyguardhost (empty view) of the initial session to the window by Windowmanager.addview
And then in the passInflatekeyguardview (options);method to add the real keyguardhostview to the mkeyguardhost, see the code:
private void Inflatekeyguardview (Bundle options) {
M:add for Power-off Alarm @{
int resId = R.id.keyguard_host_view;
int layoutid = R.layout.keyguard_host_view;
if (Poweroffalarmmanager.isalarmboot ()) {
ResId = R.id.power_off_alarm_host_view;
LayoutID = R.layout.mtk_power_off_alarm_host_view;
}
/// @}
View v = Mkeyguardhost.findviewbyid (resId);
if (v! = null) {
Mkeyguardhost.removeview (v);
}
M:save New Orientation
Mcreateorientation = Mcontext.getresources (). GetConfiguration (). Orientation;
MCREATESCREENWIDTHDP = Mcontext.getresources (). GetConfiguration (). SCREENWIDTHDP;
MCREATESCREENHEIGHTDP = Mcontext.getresources (). GetConfiguration (). SCREENHEIGHTDP;
Final Layoutinflater inflater = Layoutinflater.from (Mcontext);
View view = Inflater.inflate (LayoutID, Mkeyguardhost, true);
Mkeyguardview = (Keyguardhostview) View.findviewbyid (resId);
Mkeyguardview.setlockpatternutils (mlockpatternutils);
Mkeyguardview.setviewmediatorcallback (Mviewmediatorcallback);
Mkeyguardview.initializeswitchinguserstate (Options! = null &&
Options.getboolean (Is_switching_user));
HACK
The Keyguard view'll has set up window, flags in Onfinishinflate before we set
The view mediator callback. Make sure it knows the correct IME state.
if (mviewmediatorcallback! = null) {
Start of Cube26 Code
if (mlockscreennotifications)
Mnotificationview.setviewmediator (Mviewmediatorcallback);
End of Cube26 Code
Keyguardpasswordview KPV = (keyguardpasswordview) Mkeyguardview.findviewbyid (
R.id.keyguard_password_view);
if (KPV! = null) {
Mviewmediatorcallback.setneedsinput (Kpv.needsinput ());
}
}
if (options! = null) {
int widgettoshow = Options.getint (Lockpatternutils.keyguard_show_appwidget,
APPWIDGETMANAGER.INVALID_APPWIDGET_ID);
if (widgettoshow! = appwidgetmanager.invalid_appwidget_id) {
Mkeyguardview.gotowidget (widgettoshow);
}
}
}
The red mark, by Layoutinflater.inflate (ResId, Parentview, true), willR.layout.keyguard_host_viewAdd to Mkeyguardhost in this empty view
Since this real Keyguardhostview has been added to the window and is displayed in the top level through each of the Layoutparam, the follow-up is how to display it, and how it is displayed, such as Slide,swipe,password
And so on, these are all details, and subsequent blogs will continue to analyze
android4.4 's Keyguard Experience