Android Framework 常见解决方案(05)Android默认所有应用横屏 解决方案

1 原理

屏幕 旋转的配置进行 锁屏,通过修改 PhoneWindowManager.java 来实现。

2 解决方案(Android O)

在文件 frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java 中做如下修改:

@@ -2252,6 +2252,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
 
         final Resources res = mContext.getResources();
         int shortSize, longSize;
         if (width > height) {
             shortSize = height;
             longSize = width;
@@ -7150,7 +7151,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
 
     @Override
     public int rotationForOrientationLw(int orientation, int lastRotation) {
-        if (false) {
+    //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;
+        mLandscapeRotation = Surface.ROTATION_0;
+        mUpsideDownRotation = Surface.ROTATION_90;
+        mSeascapeRotation = Surface.ROTATION_180;
+    }
+        if (false) {
             Slog.v(TAG, "rotationForOrientationLw(orient="
                         + orientation + ", last=" + lastRotation
                         + "); user=" + mUserRotation + " "

 

你可能感兴趣的:(常见解决方案,framework,android)