From a4ceea026d6373e9be4b1daf3aa4ed93de4157cf Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Tue, 31 Oct 2017 15:40:33 -0700 Subject: [PATCH] DO NOT MERGE Remove orientation restriction to only fullscreen activities. This changelist removes checks that enforce that only fullscreen, opaque activities may request orientation changes. An application may itself be compatible with the change and update their SDK level. However, it is possible they use a library that has not itself been updated and still leverages this feature for non-fullscreen activities. Fixes: 68684796 Test: bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests Change-Id: I75bbda96b132694c722b0b535e33ea5e1b9a55db --- core/java/android/app/Activity.java | 14 --------- .../java/android/content/pm/ActivityInfo.java | 31 ++----------------- .../com/android/server/am/ActivityRecord.java | 16 +++++----- .../com/android/server/wm/AppWindowToken.java | 11 ------- .../server/wm/AppWindowTokenTests.java | 2 +- 5 files changed, 12 insertions(+), 62 deletions(-) diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 0ff3215e12711..8c78ccbf2345c 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -16,8 +16,6 @@ package android.app; -import static android.os.Build.VERSION_CODES.O; - import static java.lang.Character.MIN_VALUE; import android.annotation.CallSuper; @@ -976,18 +974,6 @@ public class Activity extends ContextThemeWrapper @CallSuper protected void onCreate(@Nullable Bundle savedInstanceState) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); - - if (getApplicationInfo().targetSdkVersion > O && mActivityInfo.isFixedOrientation()) { - final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window); - final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta); - ta.recycle(); - - if (isTranslucentOrFloating) { - throw new IllegalStateException( - "Only fullscreen opaque activities can request orientation"); - } - } - if (mLastNonConfigurationInstances != null) { mFragments.restoreLoaderNonConfig(mLastNonConfigurationInstances.loaders); } diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index 18f9e53dc528b..86591407f5457 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -20,7 +20,6 @@ import android.annotation.IntDef; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Configuration.NativeConfig; -import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; import android.util.Printer; @@ -439,6 +438,7 @@ public class ActivityInfo extends ComponentInfo * @hide */ public static final int FLAG_SUPPORTS_PICTURE_IN_PICTURE = 0x400000; + /** * @hide Bit in {@link #flags}: If set, this component will only be seen * by the system user. Only works with broadcast receivers. Set from the @@ -976,19 +976,11 @@ public class ActivityInfo extends ComponentInfo * Returns true if the activity's orientation is fixed. * @hide */ - public boolean isFixedOrientation() { + boolean isFixedOrientation() { return isFixedOrientationLandscape() || isFixedOrientationPortrait() || screenOrientation == SCREEN_ORIENTATION_LOCKED; } - /** - * Returns true if the specified orientation is considered fixed. - * @hide - */ - static public boolean isFixedOrientation(int orientation) { - return isFixedOrientationLandscape(orientation) || isFixedOrientationPortrait(orientation); - } - /** * Returns true if the activity's orientation is fixed to landscape. * @hide @@ -1168,25 +1160,6 @@ public class ActivityInfo extends ComponentInfo dest.writeFloat(maxAspectRatio); } - /** - * Determines whether the {@link Activity} is considered translucent or floating. - * @hide - */ - public static boolean isTranslucentOrFloating(TypedArray attributes) { - final boolean isTranslucent = - attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsTranslucent, - false); - final boolean isSwipeToDismiss = !attributes.hasValue( - com.android.internal.R.styleable.Window_windowIsTranslucent) - && attributes.getBoolean( - com.android.internal.R.styleable.Window_windowSwipeToDismiss, false); - final boolean isFloating = - attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating, - false); - - return isFloating || isTranslucent || isSwipeToDismiss; - } - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public ActivityInfo createFromParcel(Parcel source) { diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index fe006fc061649..253bdc5d4e891 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -133,7 +133,6 @@ import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.GraphicBuffer; import android.graphics.Rect; -import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.IBinder; @@ -897,7 +896,15 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo Entry ent = AttributeCache.instance().get(packageName, realTheme, com.android.internal.R.styleable.Window, userId); - fullscreen = ent != null && !ActivityInfo.isTranslucentOrFloating(ent.array); + final boolean translucent = ent != null && (ent.array.getBoolean( + com.android.internal.R.styleable.Window_windowIsTranslucent, false) + || (!ent.array.hasValue( + com.android.internal.R.styleable.Window_windowIsTranslucent) + && ent.array.getBoolean( + com.android.internal.R.styleable.Window_windowSwipeToDismiss, + false))); + fullscreen = ent != null && !ent.array.getBoolean( + com.android.internal.R.styleable.Window_windowIsFloating, false) && !translucent; noDisplay = ent != null && ent.array.getBoolean( com.android.internal.R.styleable.Window_windowNoDisplay, false); @@ -2195,11 +2202,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo } void setRequestedOrientation(int requestedOrientation) { - if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen - && appInfo.targetSdkVersion > O) { - throw new IllegalStateException("Only fullscreen activities can request orientation"); - } - final int displayId = getDisplayId(); final Configuration displayConfig = mStackSupervisor.getDisplayOverrideConfiguration(displayId); diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index 2e4de8c586503..d176d9455d14a 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -72,8 +72,6 @@ import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; -import static android.os.Build.VERSION_CODES.O; - class AppTokenList extends ArrayList { } @@ -1293,15 +1291,6 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree */ @Override int getOrientation(int candidate) { - // We do not allow non-fullscreen apps to influence orientation beyond O. While we do - // throw an exception in {@link Activity#onCreate} and - // {@link Activity#setRequestedOrientation}, we also ignore the orientation here so that - // other calculations aren't affected. - if (!fillsParent() && mTargetSdk > O) { - // Can't specify orientation if app doesn't fill parent. - return SCREEN_ORIENTATION_UNSET; - } - if (candidate == SCREEN_ORIENTATION_BEHIND) { // Allow app to specify orientation regardless of its visibility state if the current // candidate want us to use orientation behind. I.e. the visible app on-top of this one diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java index b09601e698f90..77a04366fdd86 100644 --- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java @@ -175,7 +175,7 @@ public class AppWindowTokenTests extends WindowTestsBase { token.setOrientation(SCREEN_ORIENTATION_LANDSCAPE); token.setFillsParent(false); - // Can specify orientation if app doesn't fill parent. Allowed for SDK <= 25. + // Can specify orientation if app doesn't fill parent. assertEquals(SCREEN_ORIENTATION_LANDSCAPE, token.getOrientation()); token.setFillsParent(true);