Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e83f34cd authored by Bryce Lee's avatar Bryce Lee
Browse files

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.

Change-Id: Ie1d300e3531fc8c588d2124dea698e4a876713c2
Fixes: 68684796
Test: bit FrameworksServicesTests:com.android.server.wm.AppWindowTokenTests
parent 3014116f
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.app;

import static android.os.Build.VERSION_CODES.O_MR1;

import static java.lang.Character.MIN_VALUE;

import android.annotation.CallSuper;
@@ -136,6 +134,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * An activity is a single, focused thing that the user can do.  Almost all
 * activities interact with the user, so the Activity class takes care of
@@ -991,17 +990,6 @@ public class Activity extends ContextThemeWrapper
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);

        if (getApplicationInfo().targetSdkVersion >= O_MR1 && 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);
        }
+1 −10
Original line number Diff line number Diff line
@@ -455,7 +455,6 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     */
    public static final int FLAG_TURN_SCREEN_ON = 0x1000000;


    /**
     * @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
@@ -1001,19 +1000,11 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
     * 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
+1 −6
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
import static android.content.res.Configuration.UI_MODE_TYPE_VR_HEADSET;
import static android.os.Build.VERSION_CODES.HONEYCOMB;
import static android.os.Build.VERSION_CODES.O;
import static android.os.Build.VERSION_CODES.O_MR1;
import static android.os.Process.SYSTEM_UID;
import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
import static android.view.WindowManagerPolicy.NAV_BAR_LEFT;
@@ -886,6 +885,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

        Entry ent = AttributeCache.instance().get(packageName,
                realTheme, com.android.internal.R.styleable.Window, userId);

        if (ent != null) {
            fullscreen = !ActivityInfo.isTranslucentOrFloating(ent.array);
            hasWallpaper = ent.array.getBoolean(R.styleable.Window_windowShowWallpaper, false);
@@ -2119,11 +2119,6 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
    }

    void setRequestedOrientation(int requestedOrientation) {
        if (ActivityInfo.isFixedOrientation(requestedOrientation) && !fullscreen
                && appInfo.targetSdkVersion >= O_MR1) {
            throw new IllegalStateException("Only fullscreen activities can request orientation");
        }

        final int displayId = getDisplayId();
        final Configuration displayConfig =
                mStackSupervisor.getDisplayOverrideConfiguration(displayId);
+0 −10
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
import static android.os.Build.VERSION_CODES.O_MR1;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
@@ -1201,15 +1200,6 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
     */
    @Override
    int getOrientation(int candidate) {
        // We do not allow non-fullscreen apps to influence orientation starting in O-MR1. 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_MR1) {
            // 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
+1 −1
Original line number Diff line number Diff line
@@ -193,7 +193,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);