Android 12.0 系统开机设置默认横屏显示
Posted 安卓兼职framework应用工程师
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 12.0 系统开机设置默认横屏显示相关的知识,希望对你有一定的参考价值。
目录
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 12.0 系统开机设置默认横屏显示的主要内容,如果未能解决你的问题,请参考以下文章