实际开发中,有时项目需要设备默认开机横屏,这里我们默认第一帧第二帧依旧采用竖屏资源(Android7.0)。
frameworks/base/cmds/bootanimation/BootAnimation.cpp
frameworks/base/core/res/res/values/config.xml
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
frameworks/native/services/surfaceflinger/DisplayDevice.cpp
修改分为三部分:
1.上层UI修改
(1)
--- frameworks/base/core/res/res/values/config.xml (revision 139)
+++ frameworks/base/core/res/res/values/config.xml (working copy)
@@ -639,7 +639,7 @@
settings are omitted from the system UI. In certain situations we may
still use the accelerometer to determine the orientation, such as when
docked if the dock is configured to enable the accelerometer. -->
- <bool name="config_supportAutoRotation">true</bool>
+ <bool name="config_supportAutoRotation">false</bool>
<!-- If true, the screen can be rotated via the accelerometer in all 4
rotations as the default behavior. -->
@@ -694,7 +694,7 @@
<!-- The number of degrees to rotate the display when the keyboard is open.
A value of -1 means no change in orientation by default. -->
- <integer name="config_lidOpenRotation">-1</integer>
+ <integer name="config_lidOpenRotation">90</integer>
(2)
--- frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java (revision 116)
+++ frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java (working copy)
@@ -656,7 +656,7 @@
SparseArray<DisplayContent> mDisplayContents = new SparseArray<>(2);
- int mRotation = 0;
+ int mRotation = Surface.ROTATION_90;
int mLastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
boolean mAltOrientation = false;
@@ -7109,8 +7109,8 @@
final int oldRotation = mRotation;
/// M: [ALPS00502835] add for tablet IPO power-off/on issue in landscape mode
- int rotation = (mIsUpdateIpoRotation || mIsUpdateAlarmBootRotation) ? Surface.ROTATION_0 :
- mPolicy.rotationForOrientationLw(mLastOrientation, mRotation);
+ int rotation = Surface.ROTATION_90;//(mIsUpdateIpoRotation || mIsUpdateAlarmBootRotation) ? Surface.ROTATION_0 :
+ //mPolicy.rotationForOrientationLw(mLastOrientation, mRotation);
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
if (mHasReceiveIPO) {
// mRotation = 0;
mRotation = 1; //M chongqing 20180307
mPolicy.setRotationLw(mRotation);
Slog.v(TAG, "Re-initialize the rotation value to " + mRotation);
mHasReceiveIPO = false;
}
*******************上面的可以保证开机UI是横屏的 **************************
2: 底层(C++)修改开机动画横屏问题
(3)
--- frameworks/native/services/surfaceflinger/DisplayDevice.cpp (revision 116)
+++ frameworks/native/services/surfaceflinger/DisplayDevice.cpp (working copy)
@@ -211,7 +211,7 @@
}
// initialize the display orientation transform.
- setProjection(DisplayState::eOrientationDefault, mViewport, mFrame);
+ setProjection(DisplayState::eOrientation90, mViewport, mFrame);
(4)
--- frameworks/base/cmds/bootanimation/BootAnimation.cpp (revision 116)
+++ frameworks/base/cmds/bootanimation/BootAnimation.cpp (working copy)
@@ -417,11 +417,11 @@
if (status)
return -1;
/// M: The tablet rotation maybe 90/270 degrees, so set the lcm config for tablet
- SurfaceComposerClient::setDisplayProjection(dtoken, DisplayState::eOrientationDefault, Rect(dinfo.w, dinfo.h), Rect(dinfo.w, dinfo.h));
+ SurfaceComposerClient::setDisplayProjection(dtoken, DisplayState::eOrientation90, Rect(dinfo.h, dinfo.w), Rect(dinfo.h, dinfo.w));
// create the native surface
sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
- dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
+ dinfo.h, dinfo.w, PIXEL_FORMAT_RGB_565);
部分应用在系统强制横屏显示后,还是会以竖屏UI显示,导致应用不能正常使用。
修改路径:frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
private int getAppSpecifiedOrientation() {
//wc 强制设置第三方App横屏显示
if(true){
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
}
//wc 强制设置第三方App横屏显示
int lastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
boolean findingBehind = false;
boolean lastFullscreen = false;
DisplayContent displayContent = getDefaultDisplayContentLocked();
final ArrayList<Task> tasks = displayContent.getTasks();
final boolean inMultiWindow = isStackVisibleLocked(DOCKED_STACK_ID)
|| isStackVisibleLocked(FREEFORM_WORKSPACE_STACK_ID);
final boolean dockMinimized =
getDefaultDisplayContentLocked().mDividerControllerLocked.isMinimizedDock();
......
// The next app has not been requested to be visible, so we keep the current orientation
// to prevent freezing/unfreezing the display too early unless we are in multi-window, in
// which we don't let the app customize the orientation unless it was the home task that
// is handled above.
return inMultiWindow ? SCREEN_ORIENTATION_UNSPECIFIED : mLastOrientation;
}