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

Posted 青春给了狗

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 11 设置开机默认系统横屏显示相关的知识,希望对你有一定的参考价值。

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

第一种方式:目录 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;
    

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

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

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

Android系统-MTK_android12默认横屏

MTK平台通用,系统默认横屏,包含开机logo到进入系统,充电图标等默认横屏
开机logo这里没有提供patch,需手动修改为横屏的BOOT_LOGO定义为横屏的文件夹即可
Patch如下:

diff --git a/frameworks/base/cmds/bootanimation/BootAnimation.cpp b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
index 81a09d2038a..aa589e7351c 100644
--- a/frameworks/base/cmds/bootanimation/BootAnimation.cpp
+++ b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
@@ -413,11 +413,21 @@ status_t BootAnimation::readyToRun() 
     mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0);
     ui::Size resolution = displayMode.resolution;
     resolution = limitSurfaceSize(resolution.width, resolution.height);
+	int temp = resolution.height;
+    resolution.height= resolution.width;
+    resolution.width= temp;
     // create the native surface
     sp<SurfaceControl> control = session()->createSurfa

以上是关于Android 11 设置开机默认系统横屏显示的主要内容,如果未能解决你的问题,请参考以下文章

Android6.0设置开机启动默认横屏并兼顾自动旋转功能

Android系统-MTK_android12默认横屏

Android系统-MTK_android12默认横屏

android开机横屏请问怎么设置

Android系统-MSM8953_anroid10默认横屏

android2.2的锁屏界面,如何在开机时默认显示横屏