Merge "Add opt-out property for orientation loop override" into tm-qpr-dev am: 5351ad5ba4
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22239423 Change-Id: I29398d613f96d110745174a4ed6e4c85b0bde0d3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -852,6 +852,42 @@ public interface WindowManager extends ViewManager {
|
|||||||
String PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION =
|
String PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION =
|
||||||
"android.window.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION";
|
"android.window.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application level {@link android.content.pm.PackageManager.Property PackageManager.Property}
|
||||||
|
* for an app to inform the system that the app can be opted-out from the compatibility
|
||||||
|
* treatment that avoids {@link android.app.Activity#setRequestedOrientation} loops. The loop
|
||||||
|
* can be trigerred by ignoreRequestedOrientation display setting enabled on the device or
|
||||||
|
* by the landscape natural orientation of the device.
|
||||||
|
*
|
||||||
|
* <p>The system could ignore {@link android.app.Activity#setRequestedOrientation}
|
||||||
|
* call from an app if both of the following conditions are true:
|
||||||
|
* <ul>
|
||||||
|
* <li>Activity has requested orientation more than 2 times within 1-second timer
|
||||||
|
* <li>Activity is not letterboxed for fixed orientation
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Setting this property to {@code false} informs the system that the app must be
|
||||||
|
* opted-out from the compatibility treatment even if the device manufacturer has opted the app
|
||||||
|
* into the treatment.
|
||||||
|
*
|
||||||
|
* <p>Not setting this property at all, or setting this property to {@code true} has no effect.
|
||||||
|
*
|
||||||
|
* <p><b>Syntax:</b>
|
||||||
|
* <pre>
|
||||||
|
* <application>
|
||||||
|
* <property
|
||||||
|
* android:name=
|
||||||
|
* "android.window.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED"
|
||||||
|
* android:value="false"/>
|
||||||
|
* </application>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
// TODO(b/274924641): Make this public API.
|
||||||
|
String PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED =
|
||||||
|
"android.window.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application level {@link android.content.pm.PackageManager.Property PackageManager
|
* Application level {@link android.content.pm.PackageManager.Property PackageManager
|
||||||
* .Property} for an app to inform the system that it needs to be opted-out from the
|
* .Property} for an app to inform the system that it needs to be opted-out from the
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_V
|
|||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ENABLE_FAKE_FOCUS;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ENABLE_FAKE_FOCUS;
|
||||||
|
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION;
|
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION;
|
||||||
|
|
||||||
import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__BOTTOM;
|
import static com.android.internal.util.FrameworkStatsLog.APP_COMPAT_STATE_CHANGED__LETTERBOX_POSITION__BOTTOM;
|
||||||
@@ -239,6 +240,9 @@ final class LetterboxUiController {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final Boolean mBooleanPropertyIgnoreRequestedOrientation;
|
private final Boolean mBooleanPropertyIgnoreRequestedOrientation;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final Boolean mBooleanPropertyIgnoreOrientationRequestWhenLoopDetected;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Boolean mBooleanPropertyFakeFocus;
|
private final Boolean mBooleanPropertyFakeFocus;
|
||||||
|
|
||||||
@@ -260,6 +264,10 @@ final class LetterboxUiController {
|
|||||||
readComponentProperty(packageManager, mActivityRecord.packageName,
|
readComponentProperty(packageManager, mActivityRecord.packageName,
|
||||||
mLetterboxConfiguration::isPolicyForIgnoringRequestedOrientationEnabled,
|
mLetterboxConfiguration::isPolicyForIgnoringRequestedOrientationEnabled,
|
||||||
PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION);
|
PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION);
|
||||||
|
mBooleanPropertyIgnoreOrientationRequestWhenLoopDetected =
|
||||||
|
readComponentProperty(packageManager, mActivityRecord.packageName,
|
||||||
|
mLetterboxConfiguration::isPolicyForIgnoringRequestedOrientationEnabled,
|
||||||
|
PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED);
|
||||||
mBooleanPropertyFakeFocus =
|
mBooleanPropertyFakeFocus =
|
||||||
readComponentProperty(packageManager, mActivityRecord.packageName,
|
readComponentProperty(packageManager, mActivityRecord.packageName,
|
||||||
mLetterboxConfiguration::isCompatFakeFocusEnabled,
|
mLetterboxConfiguration::isCompatFakeFocusEnabled,
|
||||||
@@ -432,6 +440,8 @@ final class LetterboxUiController {
|
|||||||
*
|
*
|
||||||
* <p>This treatment is enabled when the following conditions are met:
|
* <p>This treatment is enabled when the following conditions are met:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
* <li>Flag gating the treatment is enabled
|
||||||
|
* <li>Opt-out component property isn't enabled
|
||||||
* <li>Per-app override is enabled
|
* <li>Per-app override is enabled
|
||||||
* <li>App has requested orientation more than 2 times within 1-second
|
* <li>App has requested orientation more than 2 times within 1-second
|
||||||
* timer and activity is not letterboxed for fixed orientation
|
* timer and activity is not letterboxed for fixed orientation
|
||||||
@@ -439,7 +449,11 @@ final class LetterboxUiController {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean shouldIgnoreOrientationRequestLoop() {
|
boolean shouldIgnoreOrientationRequestLoop() {
|
||||||
if (!mIsOverrideEnableCompatIgnoreOrientationRequestWhenLoopDetectedEnabled) {
|
if (!shouldEnableWithOptInOverrideAndOptOutProperty(
|
||||||
|
/* gatingCondition */ mLetterboxConfiguration
|
||||||
|
::isPolicyForIgnoringRequestedOrientationEnabled,
|
||||||
|
mIsOverrideEnableCompatIgnoreOrientationRequestWhenLoopDetectedEnabled,
|
||||||
|
mBooleanPropertyIgnoreOrientationRequestWhenLoopDetected)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import static android.view.WindowManager.PROPERTY_CAMERA_COMPAT_ENABLE_REFRESH_V
|
|||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_DISPLAY_ORIENTATION_OVERRIDE;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ALLOW_ORIENTATION_OVERRIDE;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_ENABLE_FAKE_FOCUS;
|
import static android.view.WindowManager.PROPERTY_COMPAT_ENABLE_FAKE_FOCUS;
|
||||||
|
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED;
|
||||||
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION;
|
import static android.view.WindowManager.PROPERTY_COMPAT_IGNORE_REQUESTED_ORIENTATION;
|
||||||
|
|
||||||
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
|
||||||
@@ -189,6 +190,8 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShouldIgnoreOrientationRequestLoop_overrideDisabled_returnsFalse() {
|
public void testShouldIgnoreOrientationRequestLoop_overrideDisabled_returnsFalse() {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
// Request 3 times to simulate orientation request loop
|
// Request 3 times to simulate orientation request loop
|
||||||
for (int i = 0; i <= MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
for (int i = 0; i <= MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
||||||
@@ -197,10 +200,32 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
||||||
|
public void testShouldIgnoreOrientationRequestLoop_propertyIsFalseAndOverride_returnsFalse()
|
||||||
|
throws Exception {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
|
mockThatProperty(PROPERTY_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED,
|
||||||
|
/* value */ false);
|
||||||
|
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
|
|
||||||
|
mController = new LetterboxUiController(mWm, mActivity);
|
||||||
|
|
||||||
|
// Request 3 times to simulate orientation request loop
|
||||||
|
for (int i = 0; i <= MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
||||||
|
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
||||||
|
/* expectedCount */ 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
||||||
public void testShouldIgnoreOrientationRequestLoop_isLetterboxed_returnsFalse() {
|
public void testShouldIgnoreOrientationRequestLoop_isLetterboxed_returnsFalse() {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
doReturn(true).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
doReturn(true).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
|
|
||||||
// Request 3 times to simulate orientation request loop
|
// Request 3 times to simulate orientation request loop
|
||||||
for (int i = 0; i <= MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
for (int i = 0; i <= MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
||||||
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
||||||
@@ -211,7 +236,10 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
|
|||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
||||||
public void testShouldIgnoreOrientationRequestLoop_noLoop_returnsFalse() {
|
public void testShouldIgnoreOrientationRequestLoop_noLoop_returnsFalse() {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
|
|
||||||
// No orientation request loop
|
// No orientation request loop
|
||||||
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
||||||
/* expectedCount */ 0);
|
/* expectedCount */ 0);
|
||||||
@@ -221,7 +249,10 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
|
|||||||
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
||||||
public void testShouldIgnoreOrientationRequestLoop_timeout_returnsFalse()
|
public void testShouldIgnoreOrientationRequestLoop_timeout_returnsFalse()
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
|
|
||||||
for (int i = MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i > 0; i--) {
|
for (int i = MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i > 0; i--) {
|
||||||
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
||||||
/* expectedCount */ 0);
|
/* expectedCount */ 0);
|
||||||
@@ -232,7 +263,10 @@ public class LetterboxUiControllerTest extends WindowTestsBase {
|
|||||||
@Test
|
@Test
|
||||||
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
@EnableCompatChanges({OVERRIDE_ENABLE_COMPAT_IGNORE_ORIENTATION_REQUEST_WHEN_LOOP_DETECTED})
|
||||||
public void testShouldIgnoreOrientationRequestLoop_returnsTrue() {
|
public void testShouldIgnoreOrientationRequestLoop_returnsTrue() {
|
||||||
|
doReturn(true).when(mLetterboxConfiguration)
|
||||||
|
.isPolicyForIgnoringRequestedOrientationEnabled();
|
||||||
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
doReturn(false).when(mActivity).isLetterboxedForFixedOrientationAndAspectRatio();
|
||||||
|
|
||||||
for (int i = 0; i < MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
for (int i = 0; i < MIN_COUNT_TO_IGNORE_REQUEST_IN_LOOP; i++) {
|
||||||
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
assertShouldIgnoreOrientationRequestLoop(/* shouldIgnore */ false,
|
||||||
/* expectedCount */ i);
|
/* expectedCount */ i);
|
||||||
|
|||||||
Reference in New Issue
Block a user