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);
相关推荐
yufei-coder2 分钟前
C#基础语法
开发语言·c#·.net
数据龙傲天2 分钟前
1688商品API接口:电商数据自动化的新引擎
java·大数据·sql·mysql
长天一色2 分钟前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
_.Switch13 分钟前
Python机器学习模型的部署与维护:版本管理、监控与更新策略
开发语言·人工智能·python·算法·机器学习
醉颜凉16 分钟前
银河麒麟桌面操作系统修改默认Shell为Bash
运维·服务器·开发语言·bash·kylin·国产化·银河麒麟操作系统
NiNg_1_23422 分钟前
Vue3 Pinia持久化存储
开发语言·javascript·ecmascript
带带老表学爬虫30 分钟前
java数据类型转换和注释
java·开发语言
qianbo_insist33 分钟前
simple c++ 无锁队列
开发语言·c++
model200535 分钟前
android + tflite 分类APP开发-2
android·分类·tflite
千里码aicood37 分钟前
【2025】springboot教学评价管理系统(源码+文档+调试+答疑)
java·spring boot·后端·教学管理系统