Android P系统修改状态栏记录

1、强制永久显示状态栏(不被app隐藏)
代码路径:\frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java

/** {@inheritDoc} */
@Override
public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,WindowState attached, WindowState imeTarget) {
        final boolean affectsSystemUi = win.canAffectSystemUiFlags();
        if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": affectsSystemUi=" + affectsSystemUi);
        applyKeyguardPolicyLw(win, imeTarget);
		//modify start 220190808
        //final int fl = PolicyControl.getWindowFlags(win, attrs);
		int fl = PolicyControl.getWindowFlags(win, attrs);
		fl |= FLAG_FORCE_NOT_FULLSCREEN;				//增加FLAG_FORCE_NOT_FULLSCREEN编辑,强制不全屏
		//modify  end 220190808

		 //省略一部分代码
         //...
        if (mTopFullscreenOpaqueWindowState == null && affectsSystemUi) {
          if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
              mForceStatusBar = true;									//mForceStatusBar = true,强制显示状态栏
          }
          if (attrs.type == TYPE_DREAM) {
              // If the lockscreen was showing when the dream started then wait
              // for the dream to draw before hiding the lockscreen.
              if (!mDreamingLockscreen
                      || (win.isVisibleLw() && win.hasDrawnLw())) {
                  mShowingDream = true;
                  appWindow = true;
              }
          }

          // For app windows that are not attached, we decide if all windows in the app they
          // represent should be hidden or if we should hide the lockscreen. For attached app
          // windows we defer the decision to the window it is attached to.
          if (appWindow && attached == null) {
              if (attrs.isFullscreen() && inFullScreenOrSplitScreenSecondaryWindowingMode) {
                  if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
                  mTopFullscreenOpaqueWindowState = win;
                  if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
                      mTopFullscreenOpaqueOrDimmingWindowState = win;
                  }
                  if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
                      mAllowLockscreenWhenOn = true;
                  }
              }
          }
      }
         //省略一部分代码
         //...
}

2、固定状态栏无背景View,背景色无变化
代码路径:\frameworks\base\core\java\com\android\internal\policy\DecorView.java

private void updateColorViewInt(final ColorViewState state, int sysUiVis, int color,
            int dividerColor, int size, boolean verticalBar, boolean seascape, int sideMargin,
            boolean animate, boolean force) {
         //省略一部分代码
         //...
		//add by sunxiaolin
		//增加view= null,showView=true逻辑,使其进入以下代码分支
		view = null;
		showView = true;
        if (view == null) {
            if (showView) {
                state.view = view = new View(mContext);
                setColor(view, color, dividerColor, verticalBar, seascape);
                view.setTransitionName(state.attributes.transitionName);
                view.setId(state.attributes.id);
                visibilityChanged = true;
                view.setVisibility(INVISIBLE);
                state.targetVisibility = VISIBLE;
			//modify by sunxiaolin
			//做测试,增加的状态栏View的颜色为红色,方便测试查看,状态栏底层View为空色
			color = Color.RED;
			visibilityChanged = false;
			setColor(view, color, dividerColor, verticalBar, seascape);
			view.setVisibility(VISIBLE);
			Log.d(TAG, "sunxiaolin,updateColorViewInt mWindow.getAttributes().flags(0x" + Integer.toHexString(mWindow.getAttributes().flags) + ")");
			Log.d(TAG, "sunxiaolin,updateColorViewInt state.present=" + state.present);
                LayoutParams lp = new LayoutParams(resolvedWidth, resolvedHeight,
                        resolvedGravity);
                if (seascape) {
                    lp.leftMargin = sideMargin;
                } else {
                    lp.rightMargin = sideMargin;
                }
				Log.d(TAG, "sunxiaolin,updateColorViewInt do nothing");
				Log.d(TAG, "sunxiaolin,updateColorViewInt do nothing");
				//去掉添加View,即没有状态栏View背景。这样状态栏背景固定为无背景
                //addView(view, lp);
                //updateColorViewTranslations();
            }
        }
         //省略一部分代码
         //...
}

你可能感兴趣的:(android笔记,android9.0,背景,状态栏,显示,隐藏)