测试平台
Platform: RK3328
OS: Android 10.0
现象
机器没有内置重力传感器,所以部分强制竖屏的App(例如360)在上面显示有问题,所以我们强制所有App都横屏显示。
解决方案
以抖音为例,修改方法及效果如下所示
1. 强制横屏,居中竖屏显示
屏幕保持横屏,app竖屏居中如图所示
修改方案:
1.build.prop添加属性设置
persist.sys.forced_orient=2
ro.target.product=box
2.代码强制
diff --git a/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java b/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
index f2879ce..5a9c1ba 100644
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -245,10 +245,12 @@ public class DisplayRotation {
void configure(int width, int height, int shortSizeDp, int longSizeDp) {
。..
。..
。..
// $ adb shell wm size reset
&& !“true”.equals(SystemProperties.get(“config.override_forced_orient”));
- if(“2”.equals(SystemProperties.get(“persist.sys.forced_orient”,“0”))
+ if(“2”.equals(SystemProperties.get(“persist.sys.forced_orient”,“0”))
&&“box”.equals(SystemProperties.get(“ro.target.product”,“unknow”))){
mDefaultFixedToUserRotation = true;
}
+ mDefaultFixedToUserRotation = true;
+
}
2. 强制横屏,全屏显示
屏幕保持横屏,app全屏如图所示
修改方案:
diff --git a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
index cb38bac..81e345d 100644
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
@@ -27,6 +27,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
@@ -1323,7 +1324,8 @@ class DisplayContent extends WindowContainer《DisplayContent.DisplayChildWindowCo
private boolean updateOrientat
测试平台
Platform: RK3328
OS: Android 10.0
现象
机器没有内置重力传感器,所以部分强制竖屏的App(例如360)在上面显示有问题,所以我们强制所有App都横屏显示。
解决方案
以抖音为例,修改方法及效果如下所示
1. 强制横屏,居中竖屏显示
屏幕保持横屏,app竖屏居中如图所示
修改方案:
1.build.prop添加属性设置
persist.sys.forced_orient=2
ro.target.product=box
2.代码强制
diff --git a/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java b/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
index f2879ce..5a9c1ba 100644
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
@@ -245,10 +245,12 @@ public class DisplayRotation {
void configure(int width, int height, int shortSizeDp, int longSizeDp) {
。..
。..
。..
// $ adb shell wm size reset
&& !“true”.equals(SystemProperties.get(“config.override_forced_orient”));
- if(“2”.equals(SystemProperties.get(“persist.sys.forced_orient”,“0”))
+ if(“2”.equals(SystemProperties.get(“persist.sys.forced_orient”,“0”))
&&“box”.equals(SystemProperties.get(“ro.target.product”,“unknow”))){
mDefaultFixedToUserRotation = true;
}
+ mDefaultFixedToUserRotation = true;
+
}
2. 强制横屏,全屏显示
屏幕保持横屏,app全屏如图所示
修改方案:
diff --git a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
index cb38bac..81e345d 100644
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java
@@ -27,6 +27,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_USER;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
@@ -1323,7 +1324,8 @@ class DisplayContent extends WindowContainer《DisplayContent.DisplayChildWindowCo
private boolean updateOrientat
举报