美文网首页Android OS
系统窗口创建过程

系统窗口创建过程

作者: 古风子 | 来源:发表于2019-01-11 17:12 被阅读0次

    客户端通过以下方式添加系统窗口

    TextView textView = LayoutInflater.from(MainActivity.this).inflate(R.layout.window_view, null);
      TextView edit = (TextView) textView.findViewById(R.id.passwordEntry);
      edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
      
      WindowManager.LayoutParams mLp = new WindowManager.LayoutParams();
      mLp.type = WindowManager.LayoutParams.TYPE_TOAST;
      mLp.width = WindowManager.LayoutParams.MATCH_PARENT;
      mLp.height = WindowManager.LayoutParams.MATCH_PARENT;
      mLp.flags = WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
      | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
      | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
      mLp.format = PixelFormat.TRANSLUCENT;
      mLp.gravity = Gravity.BOTTOM;
      mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
      ((WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE)).addView(textView, mLp);
    

    之后系统的调用流程如下:

    windows.png

    WindowManagerServices$addWindow

        public int addWindow(Session session, IWindow client, int seq,
                WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
                Rect outContentInsets, Rect outStableInsets, Rect outOutsets,
                InputChannel outInputChannel) {
           // OP_TOAST_WINDOW
           if (win.mAppOp != AppOpsManager.OP_NONE) {
           //在这里进行直接拦截,如果是要拦截的toast,设置改window不可见
           if (WmInjector.isAdToastApp(attrs)) {
               win.setAppOpVisibilityLw(false);
           } else {
              int startOpResult = mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(),
                   win.getOwningPackage());
               if ((startOpResult != AppOpsManager.MODE_ALLOWED) &&
                    (startOpResult != AppOpsManager.MODE_DEFAULT)) {
                    win.setAppOpVisibilityLw(false);
               }
           }
            return res;
        }
    

    相关文章

      网友评论

        本文标题:系统窗口创建过程

        本文链接:https://www.haomeiwen.com/subject/ytnxdqtx.html