无Sensor,默认横屏设备,碰到竖屏APP时,会旋转为竖屏显示,之后无法再主动转回来。因此可以禁用这种自动选择能力,让竖屏APP横屏显示。

1. 关闭自动选择能力

frameworks\base\core\res\res\values\config.xml 中的如下开关关闭:

  1. <!-- If true, enables auto-rotation features using the accelerometer.
  2. Otherwise, auto-rotation is disabled. Applications may still request
  3. to use specific orientations but the sensor is ignored and sensor-based
  4. orientations are not available. Furthermore, all auto-rotation related
  5. settings are omitted from the system UI. In certain situations we may
  6. still use the accelerometer to determine the orientation, such as when
  7. docked if the dock is configured to enable the accelerometer. -->
  8. <!-- Lock Display in Landscape. By Shawn.XiaFei@Emdoor, 20180321. -->
  9. <bool name="config_supportAutoRotation">false</bool>

2. 修改WMS

frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java

  1. boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
  2. long ident = Binder.clearCallingIdentity();
  3. try {
  4. /// START. Show Portrait-Apps in Landscape. By Shawn.XiaFei@Emdoor, 20180321.
  5. /// 直接返回0
  6. int req = 0/* getOrientationLocked() */;
  7. /// END. Show Portrait-Apps in Landscape. By Shawn.XiaFei@Emdoor, 20180321.
  8. if (req != mForcedAppOrientation) {
  9. mForcedAppOrientation = req;
  10. //send a message to Policy indicating orientation change to take
  11. //action like disabling/enabling sensors etc.,
  12. mPolicy.setCurrentOrientationLw(req);
  13. if (updateRotationUncheckedLocked(inTransaction)) {
  14. // changed
  15. return true;
  16. }
  17. }
  18. return false;
  19. } finally {
  20. Binder.restoreCallingIdentity(ident);
  21. }
  22. }