我是靠谱客的博主 沉静小懒虫,最近开发中收集的这篇文章主要介绍android 10 系统源码 framework 默认所有强制竖屏应用(SCREEN_ORIENTATION_PORTRAIT)横屏显示,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

frameworks/base/core/java/android/content/pm/PackageParser.java
@@ -169,6 +169,8 @@ public class PackageParser {
     private static final boolean MULTI_PACKAGE_APK_ENABLED = Build.IS_DEBUGGABLE &&
             SystemProperties.getBoolean(PROPERTY_CHILD_PACKAGES_ENABLED, false);
 
+    private static final boolean FORCE_LANDSCAPE_ENABLED = SystemProperties.getBoolean("persist.sys.force.landscape", true);
+
     private static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f;
     private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO = 1.333f;
     private static final float DEFAULT_PRE_Q_MIN_ASPECT_RATIO_WATCH = 1f;
@@ -4478,9 +4480,12 @@ public class PackageParser {
                 a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
             }
 
-            a.info.screenOrientation = sa.getInt(
-                    R.styleable.AndroidManifestActivity_screenOrientation,
-                    SCREEN_ORIENTATION_UNSPECIFIED);
+            int screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation, SCREEN_ORIENTATION_UNSPECIFIED);
+            a.info.screenOrientation = screenOrientation;
+            if (FORCE_LANDSCAPE_ENABLED && !("org.codeaurora.snapcam".equals(owner.packageName))
+                    && (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)) { //根据包名过滤某个应用
+                a.info.screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
+            }
 
             setActivityResizeMode(a.info, sa, owner);

frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java

int rotationForOrientation(int orientation, int lastRotation) {
	...
	String pkgName = mDisplayPolicy.getAppPackageName();
    boolean isSnapCamera = "org.codeaurora.snapcam".equals(pkgName); //根据包名过滤某个应用
    switch (orientation) {
        case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
+        	if (isSnapCamera) {
+       	    return Surface.ROTATION_0;
+        	}
        	// Return portrait unless overridden.
        	if (isAnyPortrait(preferredRotation)) {
				return preferredRotation;
        	}
-           return mPortraitRotation;
+           return preferredRotation;
       	 ...
         default:
        	// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
        	// just return the preferred orientation we already calculated.
        	if (preferredRotation >= 0) {
        		return preferredRotation;
        	}
        	return Surface.ROTATION_90;
     }
}

最后

以上就是沉静小懒虫为你收集整理的android 10 系统源码 framework 默认所有强制竖屏应用(SCREEN_ORIENTATION_PORTRAIT)横屏显示的全部内容,希望文章能够帮你解决android 10 系统源码 framework 默认所有强制竖屏应用(SCREEN_ORIENTATION_PORTRAIT)横屏显示所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部