无Sensor,默认横屏设备,碰到竖屏APP时,会旋转为竖屏显示,之后无法再主动转回来。因此可以禁用这种自动选择能力,让竖屏APP横屏显示。
1. 关闭自动选择能力
将 frameworks\base\core\res\res\values\config.xml
中的如下开关关闭:
<!-- If true, enables auto-rotation features using the accelerometer.
Otherwise, auto-rotation is disabled. Applications may still request
to use specific orientations but the sensor is ignored and sensor-based
orientations are not available. Furthermore, all auto-rotation related
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. -->
<!-- Lock Display in Landscape. By Shawn.XiaFei@Emdoor, 20180321. -->
<bool name="config_supportAutoRotation">false</bool>
2. 修改WMS
frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
/// START. Show Portrait-Apps in Landscape. By Shawn.XiaFei@Emdoor, 20180321.
/// 直接返回0
int req = 0/* getOrientationLocked() */;
/// END. Show Portrait-Apps in Landscape. By Shawn.XiaFei@Emdoor, 20180321.
if (req != mForcedAppOrientation) {
mForcedAppOrientation = req;
//send a message to Policy indicating orientation change to take
//action like disabling/enabling sensors etc.,
mPolicy.setCurrentOrientationLw(req);
if (updateRotationUncheckedLocked(inTransaction)) {
// changed
return true;
}
}
return false;
} finally {
Binder.restoreCallingIdentity(ident);
}
}