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

您所在的位置:网站首页 displaydevice Android 11 设置开机默认系统横屏显示

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

#Android 11 设置开机默认系统横屏显示| 来源: 网络整理| 查看: 265

?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; }

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

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

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3