开发平台基本信息
芯片: MSM8953
版本: Android 10.0
kernel: msm-4.9
问题描述
设备硬件的LCD屏幕是竖屏的,而实际产品是横屏设备,于是需要将设备强制横屏显示。我这套代码只用了一款产品,所以我这里就直接写死横屏了,如果有多产品的,要做好横竖屏适配。
解决方法
- 开机动画横屏
--- a/frameworks/base/cmds/bootanimation/BootAnimation.cpp
+++ b/frameworks/base/cmds/bootanimation/BootAnimation.cpp
@@ -279,6 +279,16 @@ status_t BootAnimation::readyToRun() {
if (status)
return -1;
+ int orientation = 1; // landscape
+ if (orientation) {
+ if (dinfo.h > dinfo.w) {
+ int temp = dinfo.h;
+ dinfo.h= dinfo.w;
+ dinfo.w= temp;
+ }
+ }
+ + // create the native surface
sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
- 系统横屏
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1322,7 +1322,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
private boolean updateOrientationFromAppTokens(boolean forceUpdate) {
- final int req = getOrientation();
- int req = getOrientation();
- req = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
if (req != mLastOrientation || forceUpdate) {
mLastOrientation = req;
mDisplayRotation.setCurrentOrientation(req);
--- a/frameworks/native/services/surfaceflinger/DisplayDevice.cpp
+++ b/frameworks/native/services/surfaceflinger/DisplayDevice.cpp
@@ -90,7 +90,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
setPowerMode(args.initialPowerMode);
// initialize the display orientation transform.
- setProjection(DisplayState::eOrientationDefault, Rect::INVALID_RECT, Rect::INVALID_RECT);
- setProjection(DisplayState::eOrientation90, Rect::INVALID_RECT, Rect::INVALID_RECT);
}
DisplayDevice::~DisplayDevice() = default;
@@ -244,6 +244,12 @@ void DisplayDevice::setProjection(int orientation,
// the destination frame can be invalid if it has never been set,
// in that case we assume the whole display frame.
frame = Rect(w, h);
- int orient = 1; // landscape
- if (orient) {
- if (h > w) {
- frame = Rect(h, w);
- }
- }
}
--- a/frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5229,7 +5229,7 @@ void SurfaceFlinger::onInitializeDisplays() {
DisplayState::eLayerStackChanged;
d.token = token;
d.layerStack = 0;
- d.orientation = DisplayState::eOrientationDefault;
- d.orientation = DisplayState::eOrientation90;
d.frame.makeInvalid();
d.viewport.makeInvalid();
d.width = 0;
- 开机动画第二帧横屏
通过上面的修改,动画跟系统都能正常横屏显示了,但是,在动画快结束即将进入桌面的时候,最后一帧动画会变得异常,既不是横屏,也不是竖屏。增加以下修改即可解决问题。
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
@@ -361,7 +361,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
*
* @see #updateRotationUnchecked()
*/
- private int mRotation = 0;
+ private int mRotation = 1;
/**
* Last applied orientation of the display.