Loading services/core/java/com/android/server/wm/DisplayArea.java +15 −8 Original line number Diff line number Diff line Loading @@ -242,17 +242,24 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { * @return {@value true} if we need to ignore the orientation in input. */ boolean shouldIgnoreOrientationRequest(@ScreenOrientation int orientation) { // We always respect orientation request for ActivityInfo.SCREEN_ORIENTATION_LOCKED // ActivityInfo.SCREEN_ORIENTATION_NOSENSOR. // Main use case why this is important is Camera apps that rely on those // properties to ensure that they will be able to determine Camera preview // orientation correctly if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) { // Respect "locked" and "nosensor" for the compatibility of camera apps. // Respect "sensor" because the main purpose of ignoring is to avoid changing // display rotation by fixed-orientation request. return false; } else if (getIgnoreOrientationRequest()) { if (orientation == SCREEN_ORIENTATION_UNSET || orientation == SCREEN_ORIENTATION_UNSPECIFIED || orientation == ActivityInfo.SCREEN_ORIENTATION_USER) { // The behavior of non-fixed orientation is the same as ignoring. return true; } return !shouldRespectOrientationRequestDueToPerAppOverride(); } return getIgnoreOrientationRequest() && !shouldRespectOrientationRequestDueToPerAppOverride(); return false; } private boolean shouldRespectOrientationRequestDueToPerAppOverride() { Loading services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.Q; Loading Loading @@ -1149,6 +1150,12 @@ public class DisplayContentTests extends WindowTestsBase { activity.setRequestedOrientation(newOrientation); assertEquals("The display should be rotated.", 1, dc.getRotation() % 2); dc.setIgnoreOrientationRequest(true); activity.setRequestedOrientation(SCREEN_ORIENTATION_SENSOR); assertEquals("Sensor orientation must be respected with ignore-orientation-request", SCREEN_ORIENTATION_SENSOR, dc.getLastOrientation()); } @Test Loading Loading
services/core/java/com/android/server/wm/DisplayArea.java +15 −8 Original line number Diff line number Diff line Loading @@ -242,17 +242,24 @@ public class DisplayArea<T extends WindowContainer> extends WindowContainer<T> { * @return {@value true} if we need to ignore the orientation in input. */ boolean shouldIgnoreOrientationRequest(@ScreenOrientation int orientation) { // We always respect orientation request for ActivityInfo.SCREEN_ORIENTATION_LOCKED // ActivityInfo.SCREEN_ORIENTATION_NOSENSOR. // Main use case why this is important is Camera apps that rely on those // properties to ensure that they will be able to determine Camera preview // orientation correctly if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) { // Respect "locked" and "nosensor" for the compatibility of camera apps. // Respect "sensor" because the main purpose of ignoring is to avoid changing // display rotation by fixed-orientation request. return false; } else if (getIgnoreOrientationRequest()) { if (orientation == SCREEN_ORIENTATION_UNSET || orientation == SCREEN_ORIENTATION_UNSPECIFIED || orientation == ActivityInfo.SCREEN_ORIENTATION_USER) { // The behavior of non-fixed orientation is the same as ignoring. return true; } return !shouldRespectOrientationRequestDueToPerAppOverride(); } return getIgnoreOrientationRequest() && !shouldRespectOrientationRequestDueToPerAppOverride(); return false; } private boolean shouldRespectOrientationRequestDueToPerAppOverride() { Loading
services/tests/wmtests/src/com/android/server/wm/DisplayContentTests.java +7 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR; import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; import static android.os.Build.VERSION_CODES.P; import static android.os.Build.VERSION_CODES.Q; Loading Loading @@ -1149,6 +1150,12 @@ public class DisplayContentTests extends WindowTestsBase { activity.setRequestedOrientation(newOrientation); assertEquals("The display should be rotated.", 1, dc.getRotation() % 2); dc.setIgnoreOrientationRequest(true); activity.setRequestedOrientation(SCREEN_ORIENTATION_SENSOR); assertEquals("Sensor orientation must be respected with ignore-orientation-request", SCREEN_ORIENTATION_SENSOR, dc.getLastOrientation()); } @Test Loading