高通安卓Q显示屏不同角度旋转竖屏横屏切换

由于项目需要,使用了竖屏当横屏用,所以需要将系统显示旋转90度,我们目前平台是基于高通QCM6125安卓10.0系统。为了方便以后其他角度的旋转,添加了persist.panel.orientation 属性来控制角度。

  1. 开机动画
frameworks/base/cmds/bootanimation/BootAnimation.cpp

@@ -279,11 +279,36 @@ status_t BootAnimation::readyToRun() {
     if (status)
         return -1;
 
+    char rAngleValue[PROPERTY_VALUE_MAX];
+    property_get("persist.panel.orientation", rAngleValue, "0");
+    int rAngle = atoi(rAngleValue);
+    SurfaceComposerClient::Transaction t;
+
+    if ( rAngle == 90) {
+        int temp = dinfo.h;
+        dinfo.h= dinfo.w;
+        dinfo.w= temp;
+        Rect destRect(dinfo.w, dinfo.h);
+        t.setDisplayProjection(mDisplayToken, 1, destRect, destRect);//orient=1
+        ALOGD("BootAnimation default set rotation to be 90...");
+     } else if (rAngle == 180) {
+        Rect destRect(dinfo.w, dinfo.h);
+        t.setDisplayProjection(mDisplayToken, 2, destRect, destRect);//orient=2
+        ALOGD("BootAnimation default set rotation to be 180...");
+     } else if (rAngle == 270) {
+        int temp = dinfo.h;
+        dinfo.h= dinfo.w;
+        dinfo.w= temp;
+        Rect destRect(dinfo.w, dinfo.h);
+        t.setDisplayProjection(mDisplayToken, 3, destRect, destRect);//orient=3
+        ALOGD("BootAnimation default set rotation to be 270...");
+    }
+
   // create the native surface
     sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
             dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
 
-    SurfaceComposerClient::Transaction t;
+    //SurfaceComposerClient::Transaction t;
     t.setLayer(control, 0x40000000)
         .apply();

  1. 进入桌面后
frameworks/base/core/java/com/android/internal/view/RotationPolicy.java
import android.os.UserHandle;
+import android.os.SystemProperties;
 import android.provider.Settings;
 import android.util.Log;
 import android.view.Display;
@@ -42,7 +43,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 = SystemProperties.getInt("persist.panel.orientation", 0) / 90;
private RotationPolicy() {
frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
+import android.os.SystemProperties;
 import android.util.ArraySet;
 import android.util.DisplayMetrics;
 import android.util.Slog;
@@ -361,7 +362,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
      *
      * @see #updateRotationUnchecked()
      */
-    private int mRotation = 0;
+    private int mRotation = SystemProperties.getInt("persist.panel.orientation", 0) / 90;
 
     /**
      * Last applied orientation of the display.
@@ -1370,6 +1371,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
 *         UNFREEZE THE SCREEN.
      */
     boolean updateRotationUnchecked(boolean forceUpdate) {
+
+        if(true){
+            return true;
+        }
         ScreenRotationAnimation screenRotationAnimation;
         if (!forceUpdate) {
             if (mDeferredRotationPauseCount > 0) {

updateRotationUnchecked方法里不直接返回true,会出现进入桌面一瞬间竖屏再转横屏。
3. 系统导航栏位置
将系统导航栏位置固定在底部,如果不需要这里不用修改。

frameworks\base\services\core\java\com\android\server\wm\DisplayPolicy.java
@NavigationBarPosition
     int navigationBarPosition(int displayWidth, int displayHeight, int displayRotation) {
-        if (navigationBarCanMove() && displayWidth > displayHeight) {
+        /*if (navigationBarCanMove() && displayWidth > displayHeight) {
             if (displayRotation == Surface.ROTATION_270) {
                 return NAV_BAR_LEFT;
            } else if (displayRotation == Surface.ROTATION_90) {
                 return NAV_BAR_RIGHT;
             }
-        }
+        }*/
         return NAV_BAR_BOTTOM;
     }

  1. recovery ui
bootable/recovery/minui/graphics.cpp
@@ -401,6 +401,19 @@ int gr_init() {
} else {  // "ROTATION_NONE" or unknown string
     gr_rotate(GRRotation::NONE);
   }
+  
+  int rotation_user =
+      android::base::GetIntProperty("persist.panel.orientation", 0);
+  if(90 == rotation_user){
+         rotation = GRRotation::RIGHT;
+  }else if(180 == rotation_user){
+         rotation = GRRotation::DOWN;
+  }else if(270 == rotation_user){
+         rotation = GRRotation::LEFT;
+  }else{
+         rotation = GRRotation::NONE;
+  } 
+  
if (gr_draw->pixel_bytes != 4) {
  1. mk文件里设置persist.panel.orientation默认值,选配0/90/180/270
  2. LK阶段开机图片
    高通使用splash.img存储LK的开机动画,在device/qcom/common/display/logo/logo.png
    添加对应分辨率的图片,手动旋转相应的角度后,重新打包编译splash.img下载进去。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值