Android11 强制所有第三方应用全屏

       最近遇到这么一个需求,在公司的Android11系统中发现部分下载的第三方应用,没有全屏显示并且两边有黑边。

        经过我分析,这个问题和横竖屏显示有关。反编译第三方的apk发现,Androidmainfest中

添加

android:screenOrientation="portrait"

因为我们作如下修改:

diff --git a/release/frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java b/release/frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
old mode 100644
new mode 100755
index fb8fd74545c..17a153d4314
--- a/release/frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
+++ b/release/frameworks/base/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
@@ -145,8 +145,20 @@ public class ParsedActivityUtils {
                 activity.configChanges = PackageParser.getActivityConfigChanges(
                         sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0),
                         sa.getInt(R.styleable.AndroidManifestActivity_recreateOnConfigChanges, 0));
-
-                int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+                /**
+                * Force horizontal display without SharedUserId
+                * edit 2022.08.09
+                */   
+                int screenOrientation;              
+                if (pkg.getSharedUserId() == null){
+                    screenOrientation = 0;
+                }else{
+                    screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+                }
+                /**
+                * Force horizontal display without SharedUserId
+                * edit 2022.08.09
+                */
                 int resizeMode = getActivityResizeMode(pkg, sa, screenOrientation);
                 activity.screenOrientation = screenOrientation;
                 activity.resizeMode = resizeMode;

考虑到可能还可能调用Activity.java里面的setRequestedOrientation方法去设置横竖屏

diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index bfa35da..e0c53eb 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -5773,12 +5773,12 @@ public class Activity extends ContextThemeWrapper
         if (mParent == null) {
             try {
+                if(mApplication != null && mApplication.getApplicationInfo() != null
+                    && mApplication.getApplicationInfo().uid > 10000){
+                    ActivityTaskManager.getService().setRequestedOrientation(
+                            mToken, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+                }else{
+                    ActivityTaskManager.getService().setRequestedOrientation(
+                            mToken, requestedOrientation);
-                 ActivityManager.getService().setRequestedOrientation(
-                        mToken, requestedOrientation);
-                        mToken, 0);
                } 
             } catch (RemoteException e) {
                 // Empty
             }
         } else {
+                if(mApplication != null && mApplication.getApplicationInfo() != null
+                    && mApplication.getApplicationInfo().uid > 10000){
+           mParent.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+                }else{
+                    mParent.setRequestedOrientation(requestedOrientation);
+                }
-            mParent.setRequestedOrientation(requestedOrientation);
         }
     }
 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值