屏幕的窗口层级

屏幕的窗口层级

参考:

窗口层级分为37层

上面的文档有介绍说“窗口层级分为37层”,这是怎么来的呢?

这个和类DisplayAreaPolicyBuilder有关,路径frameworks/base/services/core/java/com/android/server/wm/DisplayAreaPolicyBuilder.java

其中的内部类Feature.Builder,有个如下的属性:

private final boolean[] mLayers;

其初始化如下:

初始化
如下:

mLayers = new boolean[mPolicy.getMaxWindowLayer() + 1];

getMaxWindowLayer返回的是36

    default int getMaxWindowLayer() {
    
    
        return 36;
    }

所以就是37层了

DisplayAreaPolicyBuilder.Feature.Builder

DisplayAreaPolicy类的rootHierarchyaddFeature时,调用了很多Feature.Builder的方法,如:

Feature.Builder

all

            /**
             * Set that the feature applies to all window types.
             */
            Builder all() {
    
    
                Arrays.fill(mLayers, true);
                return this;
            }

mLayers中所以元素设置为true

upTo

            Builder upTo(int typeInclusive) {
    
    
                final int max = layerFromType(typeInclusive, false);
                for (int i = 0; i < max; i++) {
    
    
                    mLayers[i] = true;
                }
                set(typeInclusive, true);
                return this;
            }

layerFromType方法会获取typeInclusive对应的layer层级,然后将0-typeInclusive都设置为true
如上面的TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY,返回为32,即表示0-32都设置为true

        /**
         * Window type: Window for adding accessibility window magnification above other windows.
         * This will place the window in the overlay windows.
         * @hide
         */
        public static final int TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39;

TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY

except

            Builder except(int... types) {
    
    
                for (int i = 0; i < types.length; i++) {
    
    
                    int type = types[i];
                    set(type, false);
                }
                return this;
            }

表示将对应的layer设置为false

猜你喜欢

转载自blog.csdn.net/u014084081/article/details/131309700