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;
     }
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐