Android11 强制所有APP 横屏显示
发布日期:2021-06-29 13:07:48 浏览次数:2 分类:技术文章

本文共 2202 字,大约阅读时间需要 7 分钟。

前言

由于平板项目没有 Gsensor,需要将所有第三方APP强制横屏, 无视 android:screenOrientation=“portrait” 属性

效果图

修改前

mno2z8.png

修改后

mnoV5q.png

修改源码

alps\frameworks\base\services\core\java\com\android\server\wm\DisplayRotation.java

@Surface.Rotation-    private int mRotation;+    private int mRotation = 3; @Override       boolean updateRotationUnchecked(boolean forceUpdate) {
//add+ if (true) {
+ return true;+ }//end final int displayId = mDisplayContent.getDisplayId(); if (!forceUpdate) {
if (mDeferredRotationPauseCount > 0) {
// Rotation updates have been paused temporarily. Defer the update until updates // have been resumed. ProtoLog.v(WM_DEBUG_ORIENTATION, "Deferring rotation, rotation is paused."); return false; }

alps\frameworks\base\services\core\java\com\android\server\wm\DisplayContent.java

@ScreenOrientation    @Override    int getOrientation() {
//add+ if (true) {
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;+ }//end mLastOrientationSource = null; if (mIgnoreRotationForApps) {
return SCREEN_ORIENTATION_USER; } if (mWmService.mDisplayFrozen) {
if (mWmService.mPolicy.isKeyguardLocked()) {
// Use the last orientation the while the display is frozen with the keyguard // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED // window. We don't want to check the show when locked window directly though as // things aren't stable while the display is frozen, for example the window could be // momentarily unavailable due to activity relaunch. ProtoLog.v(WM_DEBUG_ORIENTATION, "Display id=%d is frozen while keyguard locked, return %d", mDisplayId, getLastOrientation()); return getLastOrientation(); } } final int rootOrientation = mRootDisplayArea.getOrientation(); mLastOrientationSource = mRootDisplayArea.getLastOrientationSource(); return rootOrientation; }

转载地址:https://cczheng.blog.csdn.net/article/details/117379528 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android 通讯录号码匹配规则 SQL
下一篇:Android系统预装Chrome并自定义主页

发表评论

最新留言

不错!
[***.144.177.141]2024年04月03日 15时45分53秒