嵌入式爱好者

嵌入式爱好者 门户 知识库 查看内容

T507——android10屏幕旋转的方法

2023-7-17 09:20| 发布者: 香飘飘~~~| 查看: 199| 评论: 0

类目:  >  知识库     文档编号: 1053

系统开机默认横屏显示的核心核心类
frameworks/base/cmds/bootanimation/BootAnimation.cpp
frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
frameworks/native/services/su**ceflinger/CompositionEngine/src/OutputLayer.cpp
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java
 
开机默认横屏包含开机动画默认横屏和系统旋转方向默认横屏
 
一、在frameworks/native
diff --git a/services/su**ceflinger/DisplayDevice.cpp b/services/su**ceflinger/DisplayDevice.cpp
index 4a13bfb..2f5854c 100644
--- a/services/su**ceflinger/DisplayDevice.cpp
+++ b/services/su**ceflinger/DisplayDevice.cpp
@@ -87,7 +87,8 @@
     setPowerMode(args.initialPowerMode);
 
     // initialize the display orientation transform.
-    setProjection(DisplayState::eOrientationDefault, Rect::INVALID_RECT, Rect::INVALID_RECT);
+    //setProjection(DisplayState::eOrientationDefault, Rect::INVALID_RECT, Rect::INVALID_RECT);
+    setProjection(DisplayState::eOrientation270, Rect::INVALID_RECT, Rect::INVALID_RECT);
 }
 
 DisplayDevice::~DisplayDevice() = default;

 

二、在frameworks/base

diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index ffa3d03..c5b5040 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -300,6 +300,20 @@
     if (status)
         return -1;
 
+//aaron add
+    if (eOrientation270) {
+        int temp = dinfo.h;
+        dinfo.h = dinfo.w;
+        dinfo.w = temp;
+    }
+    Rect destRect(dinfo.w, dinfo.h);
+
+    Su**ceComposerClient::Transaction t;
+    t.setDisplayProjection(mDisplayToken, eOrientation270, destRect, destRect);
+    t.apply();
+    //end
+
+
     // create the native su**ce
     int curWidth = dinfo.w;
     int curHeight = dinfo.h;
@@ -310,10 +324,12 @@
     sp<Su**ceControl> control = session()->createSu**ce(String8("BootAnimation"),
             /*dinfo.w*/curWidth, /*dinfo.h*/curHeight, PIXEL_FORMAT_RGB_565);
 
-    Su**ceComposerClient::Transaction t;
+    //Su**ceComposerClient::Transaction t;
     t.setLayer(control, 0x40000000)
         .apply();
 
+
+
     sp<Su**ce> s = control->getSu**ce();
 
     // initialize opengl and egl
@@ -1142,7 +1158,7 @@
         Su**ceComposerClient::Transaction t;
         t.setPosition(mFlingerSu**ceControl, 0, -mTargetInset)
                 .setCrop(mFlingerSu**ceControl, Rect(0, mTargetInset, mWidth, mHeight));
-        t.setDisplayProjection(mDisplayToken, 0 /* orientation */, layerStackRect, displayRect);
+        t.setDisplayProjection(mDisplayToken, 0/* orientation */, layerStackRect, displayRect);
         t.apply();
 
         mTargetInset = mCurrentInset = 0;
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index a95686a..45d5f58 100644
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -124,6 +124,14 @@
     virtual status_t    readyToRun();
     virtual void        onFirstRef();
     virtual void        binderDied(const wp<IBinder>& who);
+//aaron add
+    enum {
+        eOrientationDefault     = 0,
+        eOrientation90          = 1,
+        eOrientation180         = 2,
+        eOrientation270         = 3,
+    };
+
 
     bool                updateIsTimeAccurate();
 
diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java
index 13425e5..9bc4d1d 100644
--- a/core/java/com/android/internal/view/RotationPolicy.java
+++ b/core/java/com/android/internal/view/RotationPolicy.java
@@ -42,7 +42,8 @@
     private static final String TAG = "RotationPolicy";
     private static final int CURRENT_ROTATION = -1;
 
-    public static final int NATURAL_ROTATION = Su**ce.ROTATION_0;
+   // public static final int NATURAL_ROTATION = Su**ce.ROTATION_0;
+public static final int NATURAL_ROTATION = Su**ce.ROTATION_270;
 
     private RotationPolicy() {
     }
@@ -207,4 +208,4 @@
 
         public abstract void onChange();
     }
-}
\ No newline at end of file
+}
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index 7b81d9a..db84d33 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -112,7 +112,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>
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index b3ff9d0..5509569 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2266,6 +2266,8 @@
                     R.bool.def_dim_screen);
             loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
                     R.integer.def_screen_off_timeout);
+loadIntegerSetting(stmt, Settings.System.USER_ROTATION,
+                    R.integer.def_user_rotation);
 
             // Set default cdma DTMF type
             loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index cb38bac..92a5be8 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -362,7 +362,8 @@
      *
      * @see #updateRotationUnchecked()
      */
-    private int mRotation = 0;
+    //private int mRotation = 0;
+private int mRotation = 3;
 
     /**
      * Last applied orientation of the display.
@@ -1371,6 +1372,7 @@
      *         UNFREEZE THE SCREEN.
      */
     boolean updateRotationUnchecked(boolean forceUpdate) {
+       
         ScreenRotationAnimation screenRotationAnimation;
         if (!forceUpdate) {
             if (mDeferredRotationPauseCount > 0) {
@@ -1405,7 +1407,7 @@
             return false;
         }
 
-        final int oldRotation = mRotation;


+        final int oldRotation = mWmService.mBootAnimationStopped ? mRotation:ROTATION_270;
         final int lastOrientation = mLastOrientation;
         final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation);
         if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Computed rotation=" + rotation + " for display id="
@@ -1596,7 +1598,9 @@
      * Do not call if {@link WindowManagerService#mDisplayReady} == false.
      */
     private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) {
-        // Use the effective "visual" dimensions based on current rotation
+
+     
+// Use the effective "visual" dimensions based on current rotation
         final boolean rotated = (mRotation == ROTATION_90 || mRotation == ROTATION_270);
         final int dw = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
         final int dh = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
@@ -1605,10 +1609,11 @@
         final WmDisplayCutout wmDisplayCutout = calculateDisplayCutoutForRotation(mRotation);
         final DisplayCutout displayCutout = wmDisplayCutout.getDisplayCutout();
 
-        final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mRotation, uiMode,
+        final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mWmService.mBootAnimationStopped ?mRotation:ROTATION_270, uiMode,
                 displayCutout);
-        final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mRotation, uiMode,
+        final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mWmService.mBootAnimationStopped ?mRotation:ROTATION_270, uiMode,
                 displayCutout);
+
         mDisplayInfo.rotation = mRotation;
         mDisplayInfo.logicalWidth = dw;
         mDisplayInfo.logicalHeight = dh;
@@ -2782,6 +2787,7 @@
     @Override
     public void writeToProto(ProtoOutputStream proto, long fieldId,
             @WindowTraceLogLevel int logLevel) {
+    proto.write(ROTATION, mWmService.mBootAnimationStopped ? mRotation:ROTATION_270);
         // Critical log level logs only visible elements to mitigate performance overheard
         if (logLevel == WindowTraceLogLevel.CRITICAL && !isVisible()) {
             return;
diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java
index f2879ce..ab782c8 100644
--- a/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -93,7 +93,8 @@
 
     private int mAllowAllRotations = -1;
     private int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
-    private int mUserRotation = Su**ce.ROTATION_0;
+    //private int mUserRotation = Su**ce.ROTATION_0;
+    private int mUserRotation = Su**ce.ROTATION_270;
 
     /**
      * Flag that indicates this is a display that may run better when fixed to user rotation.
@@ -703,7 +704,8 @@
                 if (preferredRotation >= 0) {
                     return preferredRotation;
                 }
-                return Su**ce.ROTATION_0;
+                //return Su**ce.ROTATION_0;
+         return Su**ce.ROTATION_270;
         }
     }

 


 

 

 

 



已解决

未解决

只是看看
上一篇:OK3588作为U盘

最新评论

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-7-6 18:36

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部