Android 10 TV系统 默认强制app横屏显示
电视类 投影仪类 系统app默认横屏显示
需要默认强制app横屏显示:
需要在framework 源码中修改
framework/base/services/core/java/com/android/server/wm/WindowManagerService.java
java
@Override
public void setWindowingMode(int displayId, int mode) {
if (!checkCallingPermission(INTERNAL_SYSTEM_WINDOW, "setWindowingMode()")) {
throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
}
synchronized (mGlobalLock) {
final DisplayContent displayContent = getDisplayContentOrCreate(displayId, null);
if (displayContent == null) {
Slog.w(TAG_WM, "Attempted to set windowing mode to a display that does not exist: "
+ displayId);
return;
}
int lastWindowingMode = displayContent.getWindowingMode();
mDisplayWindowSettings.setWindowingModeLocked(displayContent, mode);
reconfigureDisplayLocked(displayContent);
if (lastWindowingMode != displayContent.getWindowingMode()) {
// reconfigure won't detect this change in isolation because the windowing mode is
// already set on the display, so fire off a new config now.
mH.removeMessages(H.SEND_NEW_CONFIGURATION);
final long origId = Binder.clearCallingIdentity();
try {
// direct call since lock is shared.
sendNewConfiguration(displayId);
} finally {
Binder.restoreCallingIdentity(origId);
}
// Now that all configurations are updated, execute pending transitions
displayContent.executeAppTransition();
}
}
}
reconfigureDisplayLocked 为锁定屏幕显示
java
void reconfigureDisplayLocked(@NonNull DisplayContent displayContent) {
reconfigureDisplayLocked(displayContent, false);
}
void reconfigureDisplayLocked(@NonNull DisplayContent displayContent, boolean forced) {
if (!displayContent.isReady()) {
return;
}
displayContent.configureDisplayPolicy();
displayContent.setLayoutNeeded();
boolean configChanged = displayContent.updateOrientationFromAppTokens();
final Configuration currentDisplayConfig = displayContent.getConfiguration();
mTempConfiguration.setTo(currentDisplayConfig);
displayContent.computeScreenConfiguration(mTempConfiguration);
configChanged |= currentDisplayConfig.diff(mTempConfiguration) != 0;
if (configChanged || forced) {
displayContent.mWaitingForConfig = true;
startFreezingDisplayLocked(0 /* exitAnim */,
0 /* enterAnim */, displayContent);
displayContent.sendNewConfiguration();
}
mWindowPlacerLocked.performSurfacePlacement();
}
通过源码分析 调用displayContent.updateOrientationFromAppTokens() 来获取当前屏幕的方向
设置屏幕方向:
修改:
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1323,7 +1323,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
private boolean updateOrientationFromAppTokens(boolean forceUpdate) {
final int req = getOrientation();
final int req = Surface.ROTATION_0;
if (req != mLastOrientation || forceUpdate) {
mLastOrientation = req;
mDisplayRotation.setCurrentOrientation(req);