Android11 配置开机默认横屏显示

Android11 配置开机默认横屏显示,第1张

软件平台:Android11

硬件平台:Mtk8788

        Android系统默认是竖屏显示的,但一些品类比如平板等需要开机logo开始就横屏显示,之前在android低版本开发过,高版本再次开发了这个功能,补丁有不小出入,特此记录:

--- a/cmds/bootanimation/BootAnimation.cpp

+++ b/cmds/bootanimation/BootAnimation.cpp

@@ -387,9 +387,11 @@ status_t BootAnimation::readyToRun() {

resolution = limitSurfaceSize(resolution.width, resolution.height);

// 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

// multiple ids can be set with comma (,) as separator, for example:

--- a/core/java/com/android/internal/view/RotationPolicy.java

+++ b/core/java/com/android/internal/view/RotationPolicy.java

@@ -42,7 +42,7 @@ 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() {

}

--- a/services/core/java/com/android/server/wm/DisplayRotation.java

+++ b/services/core/java/com/android/server/wm/DisplayRotation.java

@@ -120,7 +120,7 @@ public class DisplayRotation {

* @see #updateRotationUnchecked

*/

@Surface.Rotation

- private int mRotation;

+ private int mRotation = 1;

@VisibleForTesting

int mLandscapeRotation; // default landscape

@@ -1242,7 +1242,7 @@ public class DisplayRotation {

if (preferredRotation >= 0) {

return preferredRotation;

}

- return Surface.ROTATION_0;

+ return Surface.ROTATION_90;

}

}

其次修改native层代码,frameworks/native/目录:

--- a/services/surfaceflinger/DisplayDevice.cpp

+++ b/services/surfaceflinger/DisplayDevice.cpp

@@ -91,7 +91,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)

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;

@@ -170,6 +170,9 @@ 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);

}

--- a/services/surfaceflinger/SurfaceFlinger.cpp

+++ b/services/surfaceflinger/SurfaceFlinger.cpp

@@ -4282,7 +4282,7 @@ 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;

增量编译,刷机验证即可。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/992840.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存