系统开机默认横屏显示的核心核心类
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/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java
开机默认横屏包含开机动画默认横屏和系统旋转方向默认横屏
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 4a13bfb..2f5854c 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/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;
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);
+
+ SurfaceComposerClient::Transaction t;
+ t.setDisplayProjection(mDisplayToken, eOrientation270, destRect, destRect);
+ t.apply();
+ //end
+
+
// create the native surface
int curWidth = dinfo.w;
int curHeight = dinfo.h;
@@ -310,10 +324,12 @@
sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
/*dinfo.w*/curWidth, /*dinfo.h*/curHeight, PIXEL_FORMAT_RGB_565);
- SurfaceComposerClient::Transaction t;
+ //SurfaceComposerClient::Transaction t;
t.setLayer(control, 0x40000000)
.apply();
+
+
sp<Surface> s = control->getSurface();
// initialize opengl and egl
@@ -1142,7 +1158,7 @@
SurfaceComposerClient::Transaction t;
t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset)
.setCrop(mFlingerSurfaceControl, 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 = Surface.ROTATION_0;
+ // public static final int NATURAL_ROTATION = Surface.ROTATION_0;
+public static final int NATURAL_ROTATION = Surface.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 = Surface.ROTATION_0;
+ //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.
@@ -703,7 +704,8 @@
if (preferredRotation >= 0) {
return preferredRotation;
}
- return Surface.ROTATION_0;
+ //return Surface.ROTATION_0;
+ return Surface.ROTATION_270;
}
}
本文详细介绍了如何在Android Q (10.0) 系统中实现开机默认横屏显示。主要涉及两个关键文件的修改:`DisplayDevice.cpp` 和 `BootAnimation.cpp`,通过改变显示设备的投影设置和启动动画的显示方向,实现系统启动时的横屏效果。此外,还涉及到`RotationPolicy.java`和`DisplayContent.java`等文件的调整,确保横屏设置的正确应用。
2662

被折叠的 条评论
为什么被折叠?



