文章较长建议先收藏再看
拆解步骤
1、app 强制横屏显示,无视 android:screenOrientation="portrait" 属性
2、屏幕触摸坐标修改为横屏
3、开机动画横屏
4、开机logo、关机充电动画横屏
5、RecoveryUI 横屏
上代码
##1、app 强制横屏显示
修改 rotationForOrientationLw(), 默认返回 270
frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
@Override
public int rotationForOrientationLw(int orientation, int lastRotation, boolean defaultDisplay) {
....
synchronized (mLock) {
...
default:
// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
// just return the preferred orientation we already calculated.
if (preferredRotation >= 0) {
return preferredRotation;
}
// return Surface.ROTATION_0;
return Surface.ROTATION_270;//cczheng add for land scap
}
}
}
activity 默认强制属性为 SCREEN_ORIENTATION_LANDSCAPE
frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.java
boolean updateOrientationFromAppTokensLocked(int displayId, boolean forceUpdate) {
long ident = Binder.clearCallingIdentity();
try {
final DisplayContent dc = mRoot.getDisplayContent(displayId);
// final int req = dc.getOrientation();
int req = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;//cczheng add for land scap
if (req != dc.getLastOrientation() || forceUpdate) {
if (DEBUG_ORIENTATION) {
Slog.v(TAG, "updateOrientation: req= " + req + ", mLastOrientation= "
+ dc.getLastOrientation(), new Throwable("updateOrientation"));
}
dc.setLastOrientation(req);
//send a message to Policy indicating orientation change to take
//action like disabling/enabling sensors etc.,
// TODO(multi-display): Implement policy for secondary displays.
if (dc.isDefaultDisplay) {
mPolicy.setCurrentOrientationLw(req);
}
return dc.updateRotationUnchecked(forceUpdate);
}
return false;
} finally {
Binder.restoreCallingIdentity(ident);
}
}
DisPlayContent 显示 mRotation 默认改为 3 (270)
frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java
/**
* Current rotation of the display.
* Constants as per {@link android.view.Surface.Rotation}.
*
* @see #updateRotationUnchecked()
*/
// private int mRotation = 0;
private int mRotation = 3;//cczheng add for land scap
修改默认值 config_reverseDefaultRotation 为 true,翻转显示角