Android11 强制所有APP 横屏显示

本文介绍了如何通过修改Android系统源码`DisplayRotation.java`和`DisplayContent.java`,强制所有第三方APP在平板上以横屏模式运行,无视原生的屏幕方向设置。主要修改了`mRotation`变量并调整`updateRotationUnchecked`及`getOrientation`方法,以确保横屏显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

由于平板项目没有 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;
    }
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cczhengv

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值