Android 11 -- 关于dialog和悬浮窗导致SystemUI状态栏下拉频繁闪烁(窗口焦点问题)

发布时间 2023-11-21 17:11:01作者: 僵小七

bug描述:如果当前app是全屏的属性,导致状态栏隐藏且有dialog 弹出时,
这个情况下想下拉显示状态栏,会导致状态栏频繁闪烁。

//services/core/java/com/android/server/wm/DisplayPolicy.java

//更新系统状态栏的属性
int updateSystemUiVisibilityLw() {
        // If there is no window focused, there will be nobody to handle the events
        // anyway, so just hang on in whatever state we're in until things settle down.
        //只有焦点窗口才能控制系统栏,没有焦点的窗口,不会响应这些事件
        WindowState winCandidate = (mFocusedWindow != null) ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
        
        //所以可以在这里打印日志,看出现bug时焦点窗口的情况,然后分析
        android.util.Log.d("TAG",(mFocusedWindow != null)+"");
        android.util.Log.d("TAG",mFocusedWindow.toString()+"");//打印当前获取焦点的窗口信息:app的包名
        
        if (winCandidate == null) {
            return 0;
        }

        //add
        if (mFocusedWindow != null) {
            if (mFocusedWindow.getAttrs().token == null) {
                winCandidate = mTopFullscreenOpaqueWindowState;
            }
        }
        //end

        // The immersive mode confirmation should never affect the system bar visibility, otherwise
        // it will unhide the navigation bar and hide itself.
        if (winCandidate.getAttrs().token == mImmersiveModeConfirmation.getWindowToken()) {
            ...........
        }
            ................
        }

参考