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);
相关推荐
芦半山2 分钟前
「幽灵调用」背后的真相:一个隐藏多年的Android原生Bug
android
卡尔特斯26 分钟前
Android Kotlin 项目代理配置【详细步骤(可选)】
android·java·kotlin
ace望世界27 分钟前
安卓的ViewModel
android
白鲸开源27 分钟前
Ubuntu 22 下 DolphinScheduler 3.x 伪集群部署实录
java·ubuntu·开源
ace望世界27 分钟前
kotlin的委托
android
ytadpole35 分钟前
Java 25 新特性 更简洁、更高效、更现代
java·后端
纪莫1 小时前
A公司一面:类加载的过程是怎么样的? 双亲委派的优点和缺点? 产生fullGC的情况有哪些? spring的动态代理有哪些?区别是什么? 如何排查CPU使用率过高?
java·java面试⑧股
JavaGuide2 小时前
JDK 25(长期支持版) 发布,新特性解读!
java·后端
用户3721574261352 小时前
Java 轻松批量替换 Word 文档文字内容
java
白鲸开源2 小时前
教你数分钟内创建并运行一个 DolphinScheduler Workflow!
java