最新方法:
https://blog.csdn.net/paullovazxq/article/details/52153182
vim frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
找到rotationForOrientationLw()方法
将返回值改为mLandscapeRotation;
mLandscapeRotation为默认的横屏方向。不要使用Surface.ROTATION_0,因为该值是会根据当前设备的宽高动态调整的。
以下方法对aosp9不管用
转自:https://blog.csdn.net/gjy_it/article/details/80743448
https://blog.csdn.net/baidu_20792589/article/details/54708621
1:WindowManagerService:
frameworks\base\services\core\java\com\android\server\wm\WindowManagerService.class
具体改动的地方看代码吧,
public int getOrientationFromWindowsLocked() {
....
-- return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
++ return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
/*
* Determine the new desired orientation of the display, returning
* a non-null new Configuration if it has changed from the current
* orientation. IF TRUE IS RETURNED SOMEONE MUST CALL
* setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
* SCREEN. This will typically be done for you if you call
* sendNewConfiguration().
*
* The orientation is computed from non-application windows first. If none of
* the non-application windows specify orientation, the orientation is computed from
* application tokens.
* @see android.view.IWindowManager#updateOrientationFromAppTokens(
* android.os.IBinder)
*/
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
int req = getOrientationFromWindowsLocked();
if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
-- mForcedAppOrientation = req;
-- req = getOrientationFromAppTokensLocked();
++req=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
if (req != mForcedAppOrientation) {
-- mForcedAppOrientation = req;
++ mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
....
}
boolean computeScreenConfigurationLocked(Configuration config) {
....
if (config != null) {
-- config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT:Configuration.ORIENTATION_LANDSCAPE;
++ config.orientation = Configuration.ORIENTATION_LANDSCAPE;
}
....
return true;
}
修改这几处代码便能把系统默认的竖屏变成横屏,但是会有其他的应用出现问题,比如拨号盘原本竖屏显示的,但是在这种横屏模式下打开拨号盘会报空指针错误,进源码一看原来拨号盘也准备了两套的布局,一套横屏一套竖屏的,单独修改windowmanagerservice后不知道为什么这些系统应用没有变成竖屏模式,或许是时间仓促,并没有对windowmanagerservice的流程作很详细的分析,以后有时间再找机会研究下这个流程吧。
2:PhoneWindowManager
public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled) {
if (mPortraitRotation < 0) {
// Initialize the rotation angles for each orientation once.
Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
if (d.getWidth() > d.getHeight()) {
mPortraitRotation = Surface.ROTATION_90;
mLandscapeRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_270;
mSeascapeRotation = Surface.ROTATION_180;
} else {
mPortraitRotation = Surface.ROTATION_0;
mLandscapeRotation = Surface.ROTATION_90;
mUpsideDownRotation = Surface.ROTATION_180;
mSeascapeRotation = Surface.ROTATION_270;
}
}
{
Log.i(TAG, "MediaPlayer.is not PlayingVideo");
synchronized (mLock) {
switch (orientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
//always return portrait if orientation set to portrait
//return mPortraitRotation;
return mUpsideDownRotation;
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
//always return landscape if orientation set to landscape
return mLandscapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
//always return portrait if orientation set to portrait
//return mUpsideDownRotation;
return mPortraitRotation;
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
//always return seascape if orientation set to reverse landscape
return mSeascapeRotation;
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
//return either landscape rotation based on the sensor
mOrientationListener.setAllow180Rotation(
isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentLandscapeRotation(lastRotation);
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
mOrientationListener.setAllow180Rotation(
!isLandscapeOrSeascape(Surface.ROTATION_180));
return getCurrentPortraitRotation(lastRotation);
}
mOrientationListener.setAllow180Rotation(
orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
|| orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
// case for nosensor meaning ignore sensor and consider only lid
// or orientation sensor disabled
//or case.unspecified
if (mLidOpen) {
return mLidOpenRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
return mCarDockRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
return mDeskDockRotation;
} else {
if (useSensorForOrientationLp(orientation)) {
return mOrientationListener.getCurrentRotation(lastRotation);
}
return Surface.ROTATION_0;
}
}
}
}
修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有
[java] view plaincopy
if (mPortraitRotation < 0) {
// Initialize the rotation angles for each orientation once.
Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
if (d.getWidth() > d.getHeight()) {
mPortraitRotation = Surface.ROTATION_90;
mLandscapeRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_270;
mSeascapeRotation = Surface.ROTATION_180;
} else {
mPortraitRotation = Surface.ROTATION_0;
mLandscapeRotation = Surface.ROTATION_90;
mUpsideDownRotation = Surface.ROTATION_180;
mSeascapeRotation = Surface.ROTATION_270;
}
}
让所有应用都横屏显示:
frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
public int rotationForOrientationLw(int orientation, int lastRotation,
boolean displayEnabled) {
// Initialize the rotation angles for each orientation once.
Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
if (d.getWidth() > d.getHeight()) {
mPortraitRotation = Surface.ROTATION_0; //jeff. ROTATION_90;
mLandscapeRotation = Surface.ROTATION_0;
mUpsideDownRotation = Surface.ROTATION_90; //jeff. 270;
mSeascapeRotation = Surface.ROTATION_180;
}
patch
diff --git a/device/rockchip/rk3288/system.prop b/device/rockchip/rk3288/system.prop
index ce784d7..2206861 100644 (file)
--- a/device/rockchip/rk3288/system.prop
+++ b/device/rockchip/rk3288/system.prop
@@ -28,7 +28,7 @@ sys.wallpaper.rgb565=0
sf.power.control=2073600
sys.rkadb.root=0
ro.sf.fakerotation=false
-ro.sf.hwrotation=0
+ro.sf.hwrotation=90
ro.rk.MassStorage=false
ro.rk.systembar.voiceicon=true
ro.rk.systembar.tabletUI=false
diff --git a/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java b/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
index f4ba143..50a4103 100755 (executable)
--- a/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -4360,7 +4360,7 @@ public class WindowManagerService extends IWindowManager.Stub
boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
long ident = Binder.clearCallingIdentity();
try {
- int req = getOrientationLocked();
+ int req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
if (req != mLastOrientation) {
mLastOrientation = req;
//send a message to Policy indicating orientation change to take
SCREEN_ORIENTATION_LANDSCAPE :横屏显示
SCREEN_ORIENTATION_PORTRAIT : 竖屏显示
---------------------