WindowManager Suspension Window Type_toast

Source: Internet
Author: User

WindowManager AddView is defined in the interface Viewmanager, while WindowManager is also an interface, through ctrl+h look at the inheritance shutdown, found to be in Windowmanagerimpl inherits the WindowManager interface and implements the AddView method

Windowmanagerimpl.addview

Mglobal is an instance of Windowmanagerglobal, so the call is Windowmanagerglobal.addview ()


The code creates a Viewrootimpl instance root and calls Root.setview incoming view

The most critical code in Viewrootimpl.setview is


mwindowsession is of type Iwindowsession,mwindow is of type Iwindow.stub, This code is used Aidl make IPC, The actual call is Session.addtodisplay:


Mservice is a Windowmanagerservice, keep looking down .


Mpolicy is a member variable that is marked as final:

Final Windowmanagerpolicy Mpolicy =policymanager.makenewwindowmanager ();

Continue to see Policymanager.makenewwindowmanager, is actually Policy.makenewwindowmanager ()


Now we know Mpolicy is actually Phonewindowmanager, so

int Res =mpolicy.checkaddpermission (attrs, appop);

The code actually called is Phonewindowmanager.checkaddpermission ()


Type_toast does not check permission

Type_phone Checking System_alert_window Permissions

Type_toast the reason for not needing permission to display the suspended window has been found. , And then just AddWindow analysis of the method , keep reading the following sentence . :

Or in the Phonewindowmanager method ADJUSTWINDOWPARAMSLW ()

Note Here I've given three versions of the implementation,one is2.0to the2.3.7the implemented version,one is4.0.1to the4.3.1the implemented version,one is4.4the implemented version:

Android 2.0-2.3.7 Phonewindowmanager

public void Adjustwindowparamslw (Windowmanager.layoutparams attrs) {

Switch (attrs.type) {

Case Type_system_overlay:

Case Type_secure_system_overlay:

Case Type_toast:

These types of Windows can ' t receive input events.

Attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

Break

}

}

Android 4.0.1-4.3.1 Phonewindowmanager

public void Adjustwindowparamslw (Windowmanager.layoutparams attrs) {

Switch (attrs.type) {

Case Type_system_overlay:

Case Type_secure_system_overlay:

Case Type_toast:

These types of Windows can ' t receive input events.

Attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

Attrs.flags &= ~windowmanager.layoutparams.flag_watch_outside_touch;

Break

}

}

Android 4.4 Phonewindowmanager

@Override

public void Adjustwindowparamslw (Windowmanager.layoutparams attrs) {

Switch (attrs.type) {

Case Type_system_overlay:

Case Type_secure_system_overlay:

These types of Windows can ' t receive input events.

Attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

Attrs.flags &= ~windowmanager.layoutparams.flag_watch_outside_touch;

Break

}

}

 in the4.0.1before,when we useType_toast, Androidwill secretly add to usflag_not_focusableand theflag_not_touchable,4.0.1Start,it will be removed extra .Flag_watch_outside_touch,It's really a matter of nothing..and4.4Start, Type_toastwas removed from the,so from4.4Start,UseType_toastcan also receive touch events and key events.,and4.4I can only show it before.,cannot interact.

API Level and the following use Type_toast the reason for not receiving touch events is also found. .

WindowManager Suspension Window Type_toast

Related Article

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.