There are two solutions to implement the default horizontal screen:
First method: Directory device/rockchip/rk356x/BoardConfig.mk
SF_PRIMARY_DISPLAY_ORIENTATION := 90
Second way:
The Android system displays vertical screen by default. If you want to complete horizontal screen display, follow the following steps to configure the function:
- Modify in the directory frameworks/base/cmds/bootanimation/BootAnimation.cpp
// create the native surface
sp control = session()->createSurface(String8("BootAnimation"),
- resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565);
+ resolution.getHeight(), resolution.getWidth(), PIXEL_FORMAT_RGB_565);
SurfaceComposerClient::Transaction t;
+ Rect destRect(resolution.getHeight(), resolution.getWidth());
+ t.setDisplayProjection(mDisplayToken, ui::ROTATION_90, destRect, destRect);
// this guest property specifies multi-display IDs to show the boot animation
- Modify in the directory frameworks/base/core/java/com/android/internal/view/RotationPolicy.java
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 = Surface.ROTATION_90;
private RotationPolicy() {
}
- Modify in the directory frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
public class DisplayRotation {
- private int mRotation;
+ private int mRotation = 1;
int mLandscapeRotation; // default landscape
if (preferredRotation >= 0) {
return preferredRotation;}
- return Surface.ROTATION_0;
+ return Surface.ROTATION_90;
- Secondly modify the native layer code, frameworks/native/services/surfaceflinger/DisplayDevice.cpp
setPowerMode(args.initialPowerMode);
// initialize the display orientation transform.
- setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
+ setProjection(ui::ROTATION_90, Rect::INVALID_RECT, Rect::INVALID_RECT);
}
DisplayDevice::~DisplayDevice() = default;
void DisplayDevice::setProjection(ui::Rotation orientation, Rect viewport, Rect
if (!frame.isValid()) {
// the destination frame can be invalid if it has never been set,
// in that case we assume the whole display frame.
+ if( displayWidth < displayHeight)
+ frame = Rect(displayHeight, displayWidth);
+ else
frame = Rect(displayWidth, displayHeight);
}
- Then in frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
void SurfaceFlinger::onInitializeDisplays() {
DisplayState::eLayerStackChanged;
d.token = token;
d.layerStack = 0;
- d.orientation = ui::ROTATION_0;
- d.orientation = ui::ROTATION_90;
d.frame.makeInvalid();
d.viewport.makeInvalid();
d.width = 0;
6.frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
Comment out the logic of switching between horizontal and vertical screens in the upper layer
boolean updateRotationUnchecked(boolean forceUpdate) {
//
/* final int displayId = mDisplayContent.getDisplayId();
if (!forceUpdate) {
if (mDeferredRotationPauseCount > 0) {
// Rotation updates have been paused temporarily. Defer the update until updates
// have been resumed.
ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, rotation is paused.");
return false;
}
final ScreenRotationAnimation screenRotationAnimation =
mDisplayContent.getRotationAnimation();
if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
// Rotation updates cannot be performed while the previous rotation change animation
// is still in progress. Skip this update. We will try updating again after the
// animation is finished and the display is unfrozen.
ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, animation in progress.");
return false;
}
if (mService.mDisplayFrozen) {
// Even if the screen rotation animation has finished (e.g. isAnimating returns
// false), there is still some time where we haven't yet unfrozen the display. We
// also need to abort rotation here.
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Deferring rotation, still finishing previous rotation");
return false;
}
if (mDisplayContent.mFixedRotationTransitionListener
.isTopFixedOrientationRecentsAnimating()) {
// During the recents animation, the closing app might still be considered on top.
// In order to ignore its requested orientation to avoid a sensor led rotation (e.g
// user rotating the device while the recents animation is running), we ignore
// rotation update while the animation is running.
return false;
}
}
if (!mService.mDisplayEnabled) {
// No point choosing a rotation if the display is not enabled.
ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, display is not enabled.");
return false;
}
final int oldRotation = mRotation;
final int lastOrientation = mLastOrientation;
final int rotation = rotationForOrientation(lastOrientation, oldRotation);
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Computed rotation=%s (%d) for display id=%d based on lastOrientation=%s (%d) and "
+ "oldRotation=%s (%d)",
Surface.rotationToString(rotation), rotation,
displayId,
ActivityInfo.screenOrientationToString(lastOrientation), lastOrientation,
Surface.rotationToString(oldRotation), oldRotation);
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Display id=%d selected orientation %s (%d), got rotation %s (%d)", displayId,
ActivityInfo.screenOrientationToString(lastOrientation), lastOrientation,
Surface.rotationToString(rotation), rotation);
if (oldRotation == rotation) {
// No change.
return false;
}
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Display id=%d rotation changed to %d from %d, lastOrientation=%d",
displayId, rotation, oldRotation, lastOrientation);
if (DisplayContent.deltaRotation(rotation, oldRotation) != 2) {
mDisplayContent.mWaitingForConfig = true;
}
mRotation = rotation;
mService.mWindowsFreezingScreen = WINDOWS_FREEZING_SCREENS_ACTIVE;
mService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT,
mDisplayContent, WINDOW_FREEZE_TIMEOUT_DURATION);
mDisplayContent.setLayoutNeeded();
if (shouldRotateSeamlessly(oldRotation, rotation, forceUpdate)) {
// The screen rotation animation uses a screenshot to freeze the screen while windows
// resize underneath. When we are rotating seamlessly, we allow the elements to
// transition to their rotated state independently and without a freeze required.
prepareSeamlessRotation();
} else {
prepareNormalRotationAnimation();
}
// Give a remote handler (system ui) some time to reposition things.
startRemoteRotation(oldRotation, mRotation); */
return true;
}
- The last step is also the most critical step, otherwise the app will switch back and forth between horizontal and vertical screens.
frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java
@ScreenOrientation
@Override
int getOrientation() {
//add
+ if (true) {
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ }//end
mLastOrientationSource = null;
if (mIgnoreRotationForApps) {
return SCREEN_ORIENTATION_USER;
}
if (mWmService.mDisplayFrozen) {
if (mWmService.mPolicy.isKeyguardLocked()) {
// Use the last orientation the while the display is frozen with the keyguard
// locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
// window. We don't want to check the show when locked window directly though as
// things aren't stable while the display is frozen, for example the window could be
// momentarily unavailable due to activity relaunch.
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Display id=%d is frozen while keyguard locked, return %d",
mDisplayId, getLastOrientation());
return getLastOrientation();
}
}
final int rootOrientation = mRootDisplayArea.getOrientation();
mLastOrientationSource = mRootDisplayArea.getLastOrientationSource();
return rootOrientation;
}
Note: In the modified part of the text, + means addition – means deletion