Android11 开机默认旋转90度

Android11系统设置:开机默认竖屏显示的配置修改
该文详细介绍了如何通过修改QCS6125平台Android11系统的源代码,实现从开机Logo到开机动画均默认为竖屏显示。主要涉及修改SurfaceFlinger、SettingsProvider、RotationPolicy、DisplayRotation及BootAnimation等组件的相关配置,包括设置DisplayDevice的初始旋转角度、用户旋转设置、屏幕旋转策略以及开机动画的显示方向。

硬件平台: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格式素材自行旋转为竖屏,编译到系统即可。

需求搞定~~~~~~

Android 11Android R)中,**默认开机动画(bootanimation)** 是由系统镜像中的 `bootanimation.zip` 文件控制的。其源码和资源文件的位置、构建方式如下: --- ## ✅ 默认开机动画的源码位置 ### 1. **核心代码:BootAnimation 服务实现** > 负责加载并播放动画的服务程序。 ```bash frameworks/base/cmds/bootanimation/ ``` #### 主要文件: - `BootAnimation.cpp` —— 核心逻辑,负责读取 `bootanimation.zip` 并渲染帧动画 - `BootAnimation.h` - `Android.mk` 或 `Android.bp` —— 构建配置 这个本地服务会: - 检查是否存在 `/data/local/bootanimation.zip` - 如果不存在,则使用 `/system/media/bootanimation.zip` - 支持多目录帧动画、音频(部分厂商扩展) --- ### 2. **默认开机动画资源文件(AOSP 默认动画)** > AOSP 提供了一个简单的“ANDROID”文字动画。 ```bash packages/wallpapers/BootAnimations/Default/ ``` #### 目录结构示例: ``` Default/ ├── bootanimation.zip # 实际动画压缩包 ├── desc.txt # 描述文件(可选) └── parts/ # 分层动画素材(如 part0, part1) ``` > 注意:这个 `bootanimation.zip` 的内容通常是: > > - `desc.txt`:定义分辨率、帧率、循环等 > - `part0/`:第一段动画(例如旋转ANDROID 字样) > - 可选 `part1/`:第二段(如循环部分) --- ### 3. **如何被构建进系统?** 该动画通过以下机制打包到最终系统镜像中: #### 修改:`build/make/target/product/core.mk` 会包含类似语句: ```makefile PRODUCT_COPY_FILES += \ packages/wallpapers/BootAnimations/Default/android_bootanimation.zip:/system/media/bootanimation.zip ``` 或者更常见的是直接命名: ```makefile # 在某个产品配置中指定 PRODUCT_PRODUCT_PROPERTIES += \ ro.bootanim.enable=true # 动画文件复制规则 $(call inherit-product, $(SRC_TARGET_DIR)/product/animation_product.mk) ``` 但大多数情况下,设备厂商会**覆盖默认动画**,所以你看到的手机品牌动画(小米、三星等)都不是 AOSP 默认的。 --- ## 🔍 如何确认当前使用的动画? 你可以通过 adb 查看实际存在的文件: ```bash adb shell ls /system/media/bootanimation.zip adb shell unzip -l /system/media/bootanimation.zip ``` 输出示例: ``` Archive: bootanimation.zip Length Date Time Name --------- ---------- ----- ---- 0 01-01-2021 00:00 part0/ 1234 01-01-2021 00:00 part0/desc.txt 56789 01-01-2021 00:00 part0/0001.png ... ``` --- ## 🛠 自定义或替换开机动画的方法 ### 方法一:替换 `/system/media/bootanimation.zip` 1. 准备一个符合格式的 `bootanimation.zip` 2. 推送到系统分区: ```bash adb root adb remount adb push your_bootanimation.zip /system/media/bootanimation.zip adb reboot ``` ### 方法二:在 vendor 层自定义 很多 OEM 厂商会在自己的产品目录下定义: ```bash vendor/<company>/<device>/product/etc/advanced_bootanimation.zip ``` 并通过 `.mk` 文件复制到 `/system/media/bootanimation.zip` --- ## 📝 bootanimation.zip 结构说明 一个标准的 `bootanimation.zip` 包含: ``` bootanimation.zip ├── desc.txt # 描述文件:width x height x fps ├── part0/ # 第一部分动画帧(必选) │ ├── 0001.png │ └── ... ├── part1/ # 第二部分(可选,不循环) └── audio.wav # 可选音频(部分设备支持) ``` ### `desc.txt` 示例: ``` 480 800 15 p 1 0 part0 p 0 10 part1 ``` 含义: - 分辨率:480x800,帧率:15fps - `p 1 0 part0`:循环播放 part0 - `p 0 10 part1`:播放一次 part1,延迟 10 帧后开始 --- ## ❗ 注意事项(Android 11 特性) 从 Android 10 开始,Google 引入了 **`DisplayHardware` 和 HWC2**,对启动动画时序有影响。 此外: - 一些设备启用 **splash screen(闪屏)** 替代传统 bootanimation - Pixel 设备可能使用内核级 splash 图片(不在 framework 层) - 若 `ro.bootanim.disable=1`,则不会启动 BootAnimation 服务 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值