测试同事反馈了个 bug,打开下拉菜单自动旋转后,所有的竖屏应用也会随着重力感应旋转。
代码没改动过这块,按理说竖屏应用,打开自动旋转后,竖屏app应该按应用本身设置的方向显示。
按着这个系列文章加 log 打印跟系统转屏流程
最后定位到问题 mIgnoreRotationForApps 引起的,之前没遇到过这个问题,因为很少用4:3这个比例的屏幕。
frameworksbaseservicescorejavacomandroidserverwmDisplayContent.java
@Override
int getOrientation() {
final WindowManagerPolicy policy = mWmService.mPolicy;
if (mIgnoreRotationForApps) {
return SCREEN_ORIENTATION_USER;
}
if (mWmService.mDisplayFrozen) {
if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
+ " is frozen, return " + mLastWindowForcedOrientation);
// If the display is frozen, some activities may be in the middle of restarting, and
// thus have removed their old window. If the window has the flag to hide the lock
// screen, then the lock screen can re-appear and inflict its own orientation on us.
// Keep the orientation stable until this all settles down.
return mLastWindowForcedOrientation;
} else if (policy.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.
if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Display id=" + mDisplayId
+ " is frozen while keyguard locked, return " + mLastOrientation);
return mLastOrientation;
}
} else {
// Not much of use to rotate the display for apps since it's close to square.
mIgnoreRotationForApps = isNonDecorDisplayCloseToSquare(Surface.ROTATION_0, width, height);
private boolean mIgnoreRotationForApps;



