其他分享
首页 > 其他分享> > 直播系统代码,强制点开全屏视频时横屏展示

直播系统代码,强制点开全屏视频时横屏展示

作者:互联网

直播系统代码,强制点开全屏视频时横屏展示实现的相关代码
屏幕方向旋转
当系统状态改变,需要重新更新方向时,就会调用

\frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
会执行displayContent.updateRotationUnchecked()

    @Override
    public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
        updateRotationUnchecked(alwaysSendConfiguration, forceRelayout);
    }

    private void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) {
        ProtoLog.v(WM_DEBUG_ORIENTATION, "updateRotationUnchecked:"
                        + " alwaysSendConfiguration=%b forceRelayout=%b",
                alwaysSendConfiguration, forceRelayout);

        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateRotation");

        long origId = Binder.clearCallingIdentity();

        try {
            synchronized (mGlobalLock) {
                boolean layoutNeeded = false;
                final int displayCount = mRoot.mChildren.size();
                for (int i = 0; i < displayCount; ++i) {
                    final DisplayContent displayContent = mRoot.mChildren.get(i);
                    Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "updateRotation: display");
                    final boolean rotationChanged = displayContent.updateRotationUnchecked();
                    Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);

\frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java

/**
     * Update rotation of the display.
     *
     * @return {@code true} if the rotation has been changed.  In this case YOU MUST CALL
     *         {@link #sendNewConfiguration} TO UNFREEZE THE SCREEN.
     */
    boolean updateRotationUnchecked() {
        return mDisplayRotation.updateRotationUnchecked(false /* forceUpdate */);
    }

强制横屏

\frameworks\base\services\core\java\com\android\server\wm\DisplayRotation.java
修改updateRotationUnchecked(),直接返回

    boolean updateRotationUnchecked(boolean forceUpdate) {
        if(true){
            return true;
        }
        final int displayId = mDisplayContent.getDisplayId();
        if (!forceUpdate) {
            if (mDeferredRotationPauseCount > 0) {
                // Rotation updates have been paused temporarily. Defer the update until updates
                // have been resumed.
                ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, rotation is paused.");
                return false;
            }
   
\frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java

修改 getOrientation(),直接返回横屏,无视activity的android:screenOrientation属性
否则可能会出现应用先竖屏再旋转为横屏的现象

/**
     * In the general case, the orientation is computed from the above app windows first. If none of
     * the above app windows specify orientation, the orientation is computed from the child window
     * container, e.g. {@link ActivityRecord#getOrientation(int)}.
     */
    @ScreenOrientation
    @Override
    int getOrientation() {
        if(true){
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        }
        mLastOrientationSource = null;

        if (mIgnoreRotationForApps) {
            return SCREEN_ORIENTATION_USER;
        }

以上就是直播系统代码,强制点开全屏视频时横屏展示实现的相关代码, 更多内容欢迎关注之后的文章

标签:java,updateRotationUnchecked,点开,boolean,时横屏,全屏,forceRelayout,return,alwaysSendCo
来源: https://blog.csdn.net/yb1314111/article/details/122452792