Android11 开机默认旋转90度

硬件平台:QCS6125

软件平台:Android11

需求说明:开机自动旋转90度,改横屏显示为默认竖屏,从开机logo,开机动画开始就默认旋转。

直接上patch:

先修改SurfaceFlinger部分:

diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index ce38f251c..db5156822 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -92,7 +92,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_270, Rect::INVALID_RECT, Rect::INVALID_RECT);
 }
 
 DisplayDevice::~DisplayDevice() = default;
@@ -179,7 +179,10 @@ 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.
-        frame = Rect(displayWidth, displayHeight);
+        if( displayWidth < displayHeight)
+            frame = Rect(displayHeight, displayWidth);
+        else
+            frame = Rect(displayWidth, displayHeight);
     }
 
     if (viewport.isEmpty()) {
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 0d07abb1d..d76288005 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4963,7 +4963,7 @@ void SurfaceFlinger::onInitializeDisplays() {
              DisplayState::eLayerStackChanged;
     d.token = token;
     d.layerStack = 0;
-    d.orientation = ui::ROTATION_0;
+    d.orientation = ui::ROTATION_270;
     d.frame.makeInvalid();
     d.viewport.makeInvalid();
     d.width = 0;

第二步,修改SettingsProvider部分:

diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index 5f47cfe02af..2fc6c9949f5 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -111,7 +111,7 @@
     <bool name="def_accessibility_display_magnification_auto_update">true</bool>
 
     <!-- Default for Settings.System.USER_ROTATION -->
-    <integer name="def_user_rotation">0</integer>
+    <integer name="def_user_rotation">3</integer>
 
     <!-- Default for Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE. <=0 if no limit -->
     <integer name="def_download_manager_max_bytes_over_mobile">-1</integer>

默认settings键值配置为竖屏

第三步:修改RotationPolicy.java

diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java
index cfb2bf9df9e..f6825230a3f 100644
--- 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_270;
 
     private RotationPolicy() {
     }
@@ -204,4 +204,4 @@ public final class RotationPolicy {
 
         public abstract void onChange();
     }

第四步:修改DisplayRotation.java

diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index 5f0e6bb6064..b9205183929 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -124,7 +124,7 @@ public class DisplayRotation {
      * @see #updateRotationUnchecked
      */
     @Surface.Rotation
-    private int mRotation;
+    private int mRotation = 3;
 
     @VisibleForTesting
     int mLandscapeRotation;  // default landscape
@@ -181,7 +181,7 @@ public class DisplayRotation {
     private int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
 
     @Surface.Rotation
-    private int mUserRotation = Surface.ROTATION_0;
+    private int mUserRotation = Surface.ROTATION_270;
 
     /**
      * Flag that indicates this is a display that may run better when fixed to user rotation.
@@ -839,7 +839,7 @@ public class DisplayRotation {
         if (userRotation < Surface.ROTATION_0 || userRotation > Surface.ROTATION_270) {
             Slog.w(TAG, "Trying to restore an invalid user rotation " + userRotation
                     + " for " + mDisplayContent);
-            userRotation = Surface.ROTATION_0;
+            userRotation = Surface.ROTATION_270;
         }
         mUserRotationMode = userRotationMode;
         mUserRotation = userRotation;
@@ -1314,7 +1314,7 @@ public class DisplayRotation {
                 if (preferredRotation >= 0) {
                     return preferredRotation;
                 }
-                return Surface.ROTATION_0;
+                return Surface.ROTATION_270;
         }
     }
 
@@ -1469,7 +1469,7 @@ public class DisplayRotation {
 
             // Configure rotation lock.
             final int userRotation = Settings.System.getIntForUser(resolver,
-                    Settings.System.USER_ROTATION, Surface.ROTATION_0,
+                    Settings.System.USER_ROTATION, Surface.ROTATION_270,
                     UserHandle.USER_CURRENT);
             if (mUserRotation != userRotation) {
                 mUserRotation = userRotation;

第五步:修改开机动画部分

diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 301726d1aae..91f27b0d586 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -387,10 +387,14 @@ status_t BootAnimation::readyToRun() {
     resolution = limitSurfaceSize(resolution.width, resolution.height);
     // create the native surface
     sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
-            resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565);
+            resolution.getHeight(), resolution.getWidth(), PIXEL_FORMAT_RGB_565);
 
+    SLOGE("====== BootAnimation::readyToRun: height:%d; width: %d", resolution.getHeight(), resolution.getWidth());
     SurfaceComposerClient::Transaction t;
 
+    Rect destRect(resolution.getHeight(), resolution.getWidth());
+    t.setDisplayProjection(mDisplayToken, ui::ROTATION_270, 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:
     // setprop persist.boot.animation.displays 19260422155234049,19261083906282754

至此从开机动画开始往后的UI都修改为默认竖屏了,剩下的就是bootlogo部分,这部分只需要把bmp格式素材自行旋转为竖屏,编译到系统即可。

需求搞定~~~~~~

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值