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);
相关推荐
会开花的二叉树1 分钟前
Reactor网络库的连接管理核心:Connection类
开发语言·网络·php
凯子坚持 c3 分钟前
C++基于微服务脚手架的视频点播系统---客户端(1)
开发语言·c++·微服务
袖清暮雨4 分钟前
Python爬虫(Scrapy框架)
开发语言·爬虫·python·scrapy
2401_8384725113 分钟前
C++中的装饰器模式实战
开发语言·c++·算法
咖啡啡不加糖14 分钟前
Grafana 监控服务指标使用指南:打造可视化监控体系
java·后端·grafana
€81116 分钟前
Java入门级教程26——序列化和反序列化,Redis存储Java对象、查询数据库与实现多消费者消息队列
java·拦截器·序列化和反序列化·数据库查询·redis存储java对象·多消费者消息队列
沐知全栈开发20 分钟前
PHP 数组
开发语言
雨季66623 分钟前
Flutter 三端应用实战:OpenHarmony “心流之泉”——在碎片洪流中,为你筑一眼专注的清泉
开发语言·前端·flutter·交互
多多*24 分钟前
Mysql数据库相关 事务 MVCC与锁的爱恨情仇 锁的层次架构 InnoDB锁分析
java·数据库·windows·sql·oracle·面试·哈希算法
YMWM_35 分钟前
python3中类的__call__()方法介绍
开发语言·python