Android 10 TV系统 默认强制app横屏显示

Android 10 TV系统 默认强制app横屏显示

电视类 投影仪类 系统app默认横屏显示

需要默认强制app横屏显示:

需要在framework 源码中修改

framework/base/services/core/java/com/android/server/wm/WindowManagerService.java

java 复制代码
@Override
    public void setWindowingMode(int displayId, int mode) {
        if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "setWindowingMode()")) {
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }

        synchronized (mGlobalLock) {
            final DisplayContent displayContent = getDisplayContentOrCreate(displayId, null);
            if (displayContent == null) {
                Slog.w(TAG_WM, "Attempted to set windowing mode to a display that does not exist: "
                        + displayId);
                return;
            }

            int lastWindowingMode = displayContent.getWindowingMode();
            mDisplayWindowSettings.setWindowingModeLocked(displayContent, mode);

            reconfigureDisplayLocked(displayContent);

            if (lastWindowingMode != displayContent.getWindowingMode()) {
                // reconfigure won't detect this change in isolation because the windowing mode is
                // already set on the display, so fire off a new config now.
                mH.removeMessages(H.SEND_NEW_CONFIGURATION);

                final long origId = Binder.clearCallingIdentity();
                try {
                    // direct call since lock is shared.
                    sendNewConfiguration(displayId);
                } finally {
                    Binder.restoreCallingIdentity(origId);
                }
                // Now that all configurations are updated, execute pending transitions
                displayContent.executeAppTransition();
            }
        }
    }

reconfigureDisplayLocked 为锁定屏幕显示

java 复制代码
void reconfigureDisplayLocked(@NonNull DisplayContent displayContent) {
        reconfigureDisplayLocked(displayContent, false);
    }

    void reconfigureDisplayLocked(@NonNull DisplayContent displayContent, boolean forced) {
        if (!displayContent.isReady()) {
            return;
        }
        displayContent.configureDisplayPolicy();
        displayContent.setLayoutNeeded();

        boolean configChanged = displayContent.updateOrientationFromAppTokens();
        final Configuration currentDisplayConfig = displayContent.getConfiguration();
        mTempConfiguration.setTo(currentDisplayConfig);
        displayContent.computeScreenConfiguration(mTempConfiguration);
        configChanged |= currentDisplayConfig.diff(mTempConfiguration) != 0;

        if (configChanged || forced) {
            displayContent.mWaitingForConfig = true;
            startFreezingDisplayLocked(0 /* exitAnim */,
                    0 /* enterAnim */, displayContent);
            displayContent.sendNewConfiguration();
        }

        mWindowPlacerLocked.performSurfacePlacement();
    }

通过源码分析 调用displayContent.updateOrientationFromAppTokens() 来获取当前屏幕的方向

设置屏幕方向:

修改:

--- a/services/core/java/com/android/server/wm/DisplayContent.java

+++ b/services/core/java/com/android/server/wm/DisplayContent.java

@@ -1323,7 +1323,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

复制代码
 private boolean updateOrientationFromAppTokens(boolean forceUpdate) {
复制代码
     final int req = getOrientation();
复制代码
     final int req = Surface.ROTATION_0;
     if (req != mLastOrientation || forceUpdate) {
         mLastOrientation = req;
         mDisplayRotation.setCurrentOrientation(req);
相关推荐
厦门德仔24 分钟前
【WPF】WPF(样式)
android·java·wpf
大春儿的试验田25 分钟前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
Gappsong87427 分钟前
【Linux学习】Linux安装并配置Redis
java·linux·运维·网络安全
likeGhee31 分钟前
python缓存装饰器实现方案
开发语言·python·缓存
hqxstudying32 分钟前
Redis为什么是单线程
java·redis
whoarethenext39 分钟前
使用 C++/Faiss 加速海量 MFCC 特征的相似性搜索
开发语言·c++·faiss
RainbowSea43 分钟前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
项目題供诗44 分钟前
黑马python(二十五)
开发语言·python
逆风局?44 分钟前
Maven高级——分模块设计与开发
java·maven
周某某~1 小时前
maven详解
java·maven