Android 11 设置开机默认系统横屏显示

2023-11-09

实现 默认横屏有两套方案 :

第一种方式:目录 device/rockchip/rk356x/BoardConfig.mk

SF_PRIMARY_DISPLAY_ORIENTATION := 90

第二种方式:

Android系统默认是竖屏显示的,想要完成横屏显示,按以下步骤配置即可实现功能:

1.在目录frameworks/base/cmds/bootanimation/BootAnimation.cpp中修改

// create the native surface

sp control = session()->createSurface(String8("BootAnimation"),

- resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565);

+ resolution.getHeight(), resolution.getWidth(), PIXEL_FORMAT_RGB_565);

SurfaceComposerClient::Transaction t;

+ Rect destRect(resolution.getHeight(), resolution.getWidth());

+ t.setDisplayProjection(mDisplayToken, ui::ROTATION_90, destRect, destRect);

// this guest property specifies multi-display IDs to show the boot animation

2.在目录frameworks/base/core/java/com/android/internal/view/RotationPolicy.java修改

 public final class RotationPolicy {

private static final String TAG = "RotationPolicy";

private static final int CURRENT_ROTATION = -1;

- public static final int NATURAL_ROTATION = Surface.ROTATION_0;

+ public static final int NATURAL_ROTATION = Surface.ROTATION_90;

private RotationPolicy() {

}

3.在目录frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java修改

public class DisplayRotation {


- private int mRotation;

+ private int mRotation = 1;


int mLandscapeRotation; // default landscape

if (preferredRotation >= 0) {

return preferredRotation;}

- return Surface.ROTATION_0;

+ return Surface.ROTATION_90;


4.其次修改native层代码,frameworks/native/services/surfaceflinger/DisplayDevice.cpp

setPowerMode(args.initialPowerMode);

// initialize the display orientation transform.

- setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);

+ setProjection(ui::ROTATION_90, Rect::INVALID_RECT, Rect::INVALID_RECT);

}

DisplayDevice::~DisplayDevice() = default;
void DisplayDevice::setProjection(ui::Rotation orientation, Rect viewport, Rect

if (!frame.isValid()) {

// the destination frame can be invalid if it has never been set,

// in that case we assume the whole display frame.

+ if( displayWidth < displayHeight)

+ frame = Rect(displayHeight, displayWidth);

+ else

frame = Rect(displayWidth, displayHeight);

}

5.然后再在frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp

void SurfaceFlinger::onInitializeDisplays() {

DisplayState::eLayerStackChanged;

d.token = token;

d.layerStack = 0;

- d.orientation = ui::ROTATION_0;

+ d.orientation = ui::ROTATION_90;

d.frame.makeInvalid();

d.viewport.makeInvalid();

d.width = 0;

6.在frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java

注释掉上层横竖屏切换的逻辑

   boolean updateRotationUnchecked(boolean forceUpdate) {
		
          //注释这个 强制去掉横竖屏切换
		
       /*  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;
            }

            final ScreenRotationAnimation screenRotationAnimation =
                    mDisplayContent.getRotationAnimation();
            if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
                // Rotation updates cannot be performed while the previous rotation change animation
                // is still in progress. Skip this update. We will try updating again after the
                // animation is finished and the display is unfrozen.
                ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, animation in progress.");
                return false;
            }
            if (mService.mDisplayFrozen) {
                // Even if the screen rotation animation has finished (e.g. isAnimating returns
                // false), there is still some time where we haven't yet unfrozen the display. We
                // also need to abort rotation here.
                ProtoLog.v(WM_DEBUG_ORIENTATION,
                        "Deferring rotation, still finishing previous rotation");
                return false;
            }

            if (mDisplayContent.mFixedRotationTransitionListener
                    .isTopFixedOrientationRecentsAnimating()) {
                // During the recents animation, the closing app might still be considered on top.
                // In order to ignore its requested orientation to avoid a sensor led rotation (e.g
                // user rotating the device while the recents animation is running), we ignore
                // rotation update while the animation is running.
                return false;
            }
        }

        if (!mService.mDisplayEnabled) {
            // No point choosing a rotation if the display is not enabled.
            ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, display is not enabled.");
            return false;
        }

        final int oldRotation = mRotation;
        final int lastOrientation = mLastOrientation;
        final int rotation = rotationForOrientation(lastOrientation, oldRotation);
        ProtoLog.v(WM_DEBUG_ORIENTATION,
                "Computed rotation=%s (%d) for display id=%d based on lastOrientation=%s (%d) and "
                        + "oldRotation=%s (%d)",
                Surface.rotationToString(rotation), rotation,
                displayId,
                ActivityInfo.screenOrientationToString(lastOrientation), lastOrientation,
                Surface.rotationToString(oldRotation), oldRotation);

        ProtoLog.v(WM_DEBUG_ORIENTATION,
                "Display id=%d selected orientation %s (%d), got rotation %s (%d)", displayId,
                ActivityInfo.screenOrientationToString(lastOrientation), lastOrientation,
                Surface.rotationToString(rotation), rotation);

        if (oldRotation == rotation) {
            // No change.
            return false;
        }

        ProtoLog.v(WM_DEBUG_ORIENTATION,
                "Display id=%d rotation changed to %d from %d, lastOrientation=%d",
                        displayId, rotation, oldRotation, lastOrientation);

        if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
            mDisplayContent.mWaitingForConfig = true;
        }

        mRotation = rotation;

        mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
        mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
                mDisplayContent, WINDOW_FREEZE_TIMEOUT_DURATION);

        mDisplayContent.setLayoutNeeded();

        if (shouldRotateSeamlessly(oldRotation, rotation, forceUpdate)) {
            // The screen rotation animation uses a screenshot to freeze the screen while windows
            // resize underneath. When we are rotating seamlessly, we allow the elements to
            // transition to their rotated state independently and without a freeze required.
            prepareSeamlessRotation();
        } else {
            prepareNormalRotationAnimation();
        }

        // Give a remote handler (system ui) some time to reposition things.
        startRemoteRotation(oldRotation, mRotation); */

        return true;
    }

7.最后一步,也是最关键的一步 否则app会来回切换横竖屏

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

    @ScreenOrientation
    @Override
    int getOrientation() {
		 //add
+        if (true) {
+            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+        }//end
        mLastOrientationSource = null;

        if (mIgnoreRotationForApps) {
            return SCREEN_ORIENTATION_USER;
        }

        if (mWmService.mDisplayFrozen) {
            if (mWmService.mPolicy.isKeyguardLocked()) {
                // Use the last orientation the while the display is frozen with the keyguard
                // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
                // window. We don't want to check the show when locked window directly though as
                // things aren't stable while the display is frozen, for example the window could be
                // momentarily unavailable due to activity relaunch.
                ProtoLog.v(WM_DEBUG_ORIENTATION,
                        "Display id=%d is frozen while keyguard locked, return %d",
                        mDisplayId, getLastOrientation());
                return getLastOrientation();
            }
        }
        final int rootOrientation = mRootDisplayArea.getOrientation();
        mLastOrientationSource = mRootDisplayArea.getLastOrientationSource();
        return rootOrientation;
    }

说明:文中修改部分+号代表增加 -代表删除  

至此 开机默认开机横屏功能已经配置完成 !!!

觉得我写的好的兄弟给个赞!!!谢谢 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 11 设置开机默认系统横屏显示 的相关文章

随机推荐

  • 2023华为OD机试真题【开租建站】

    题目 当前IT部门支撑了子公司颗粒化业务 该部门需要实现为子公司快速开租建站的能力 建站是指在一个全新的环境部署一套IT服务 每个站点开站会由一系列部署任务项构成 每个任务项部署完成时间都是固定和相等的 设为1 部署任务项之间可能存在依赖
  • Excel:Excel中对特殊字符的转义和处理

    对引号转义 excel公式中用两个引号代表一个引号 abc abc 会得到abc abc abc 会得到字符串 abc 处理换行符 公式中如果需要字符串换行 这样写 换 CHAR 10 行 在单元格里输入换行符 用Alt Enter输入 在
  • pywinauto 使用

    Pywinauto是基于Python开发的 用于自动化测试的脚本模块 主要操作于Windows标准图形界面 它可以允许你很容易的发送鼠标 键盘动作给Windows的对话框和控件 其中 最主要功能为对windows标准控件的一系列动作可编程处
  • tiny-cnn执行过程分析(MNIST)

    在http blog csdn net fengbingchun article details 50573841中以MNIST为例对tiny cnn的使用进行了介绍 下面对其执行过程进行分析 支持两种损失函数 1 mean squared
  • JWT介绍

    JWT介绍 1 1 jwt原则 最简单理解 jwt本质就是 把用户信息通过加密后生成的一个字符串 JWT的原则是在服务器身份验证之后 将生成一个JSON对象并将其发送回用户 UserName Chongchong Role Admin Ex
  • Ubuntu安装scrapy

    先检查是否安装过lxml openSSL 没有的话 得安装依赖包了 安装lxml 参考官网安装 http lxml de installation html 如果python是2 x的 用以下命令 sudo apt get install
  • unity 动画控制

    播放控制 Animator animator animator speed 0 停止播放 animator speed 1 倒放 animator Play stateName 0 0 播放指定状态 stateName是Animator窗口
  • 使用opencv画一些几何形状:cv2.line(),cv2.circle(),cv2.rectangle(),cv2.putText()

    1 cv2 line 划线 cv2 line img 10 10 510 510 0 255 0 5 img 图像 起点坐标 终点坐标 颜色 线的宽度 2 cv2 circle 画圆 cv2 circle img 50 50 10 0 0
  • css自学框架之图片懒加载

    首先解释一下什么叫图片懒加载 图片懒加载是一种在页面加载时 延迟加载图片资源的技术 也就是说图片资源在需要的时候才会加载 就是在屏幕显示范围内加载图片 屏幕显示范围外图片不加载 一 关键函数 用到的关键函数 globalThis Inter
  • 我是废物...

    我是废物
  • 【数据手册】CH340G芯片使用介绍

    1 概述 CH340是一系列USB总线适配器 它通过USB总线提供串行 并行或IrDA接口 CH340G集成电路提供通用的MODEM信号 允许将UART添加到计算机上 或将现有的UART设备转换为USB接口 2 特征 全速USB接口 兼容U
  • Bugku-CTF (web 持续更新) ——新手ctf记录

    目录 1 滑稽 2 计算器 3 GET 4 POST GET和POST的区别 5 矛盾 6 alert 7 你必须让他停下 8 game1 9 网站被黑 10 本地管理员 X Forwarded For 11 eval 12 变量1 13
  • Linux下的bochs安装

    强烈建议使用ubuntu系统 apt get指令太好用了 安装各种依赖相当简单 1 首先到bochs网站上下载一个linux版本bochs 在安装之前需要安装一些依赖 sudo apt get install build essential
  • JavaScript原生实现事件监听及手动触发

    事件监听 标签中的onxxx 比如
  • AOM联盟:AV1完成1.0版定稿

    在2018年第一季度结束前 AOM联盟完成了AV1 1 0版定稿 这是这一新兴生态的最新胜利 文 包研 图 AOM官网发布消息 今天 AV1的规格 参考代码和绑定格式向开发者开放 来源 AOM官网 北京时间3月28日晚间消息 AOM联盟宣布
  • Docker存储卷(一)详解

    目录 什么是存储卷 为什么要用存储卷 Docker存储卷的特性 Docker为容器提供了两种存放数据的资源 storage driver Data Volume bind mount 实例 docker managed volume 实例
  • getevent/sendevent 使用说明

    这两天准备写一下input子系统的分析 过程中发现了两个好工具 呵呵 就是本文介绍的主角 getevent用于获取当前系统input设备的一些参数和实时事件的数据 sendevent用于发送input事件 这样在调试的时候遇到有的样机按键坏
  • Tensorflow分布式训练原理

    以下文章摘录自 机器学习观止 核心原理与实践 京东 https item jd com 13166960 html 当当 http product dangdang com 29218274 html 由于博客系统问题 部分公式 图片和格式
  • python中imread用法_Python matplotlib.pyplot.imread()用法及代码示例

    Matplotlib是Python中的一个库 它是数字的 NumPy库的数学扩展 Pyplot是Matplotlib模块的基于状态的接口 该模块提供了MATLAB like接口 matplotlib pyplot imread 功能 mat
  • Android 11 设置开机默认系统横屏显示

    实现 默认横屏有两套方案 第一种方式 目录 device rockchip rk356x BoardConfig mk SF PRIMARY DISPLAY ORIENTATION 90 第二种方式 Android系统默认是竖屏显示的 想要