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

Commit 46ac6fa6 authored by Craig Mautner's avatar Craig Mautner
Browse files

Add force default orientation.

Devices can be configured to remain in their default landscape or
portrait orientation by setting config_forceDefaultOrientation true
in overlay/.../values/config.xml.

Activities that desire to run in the non-default orientation are
supported by creating a logical display within the physical display.
Transitions to and from the activity perform a crossfade rather than
the normal rotation animation.

Also, improve SurfaceTrace debug output.

Fixes bug 9695710.

Change-Id: I053e136cd2b9ae200028595f245b6ada5927cfe9
parent cb92a8d9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -477,6 +477,11 @@ public interface WindowManagerPolicy {
    public void init(Context context, IWindowManager windowManager,
            WindowManagerFuncs windowManagerFuncs);

    /**
     * @return true if com.android.internal.R.bool#config_forceDefaultOrientation is true.
     */
    public boolean isDefaultOrientationForced();

    /**
     * Called by window manager once it has the initial, default native
     * display dimensions.
+5 −0
Original line number Diff line number Diff line
@@ -1193,4 +1193,9 @@
        <item>com.android.internal.notification.DemoContactNotificationScorer</item>
    </string-array>

    <!-- Flag indicating that this device does not rotate and will always remain in its default
         orientation. Activities that desire to run in a non-compatible orientation will be run
         from an emulated display within the physical display. -->
    <bool name="config_forceDefaultOrientation">false</bool>

</resources>
+2 −1
Original line number Diff line number Diff line
@@ -281,6 +281,7 @@
  <java-symbol type="bool" name="config_dontPreferApn" />
  <java-symbol type="bool" name="config_speed_up_audio_on_mt_calls" />
  <java-symbol type="bool" name="config_useFixedVolume" />
  <java-symbol type="bool" name="config_forceDefaultOrientation" />
  
  <java-symbol type="integer" name="config_cursorWindowSize" />
  <java-symbol type="integer" name="config_extraFreeKbytesAdjust" />
+40 −19
Original line number Diff line number Diff line
@@ -273,6 +273,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    int mDemoHdmiRotation;
    boolean mDemoHdmiRotationLock;

    // Default display does not rotate, apps that require non-default orientation will have to
    // have the orientation emulated.
    private boolean mForceDefaultOrientation = false;

    int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
    int mUserRotation = Surface.ROTATION_0;
    boolean mAccelerometerDefault;
@@ -992,14 +996,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        mDisplay = display;

        final Resources res = mContext.getResources();
        int shortSize, longSize;
        if (width > height) {
            shortSize = height;
            longSize = width;
            mLandscapeRotation = Surface.ROTATION_0;
            mSeascapeRotation = Surface.ROTATION_180;
            if (mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_reverseDefaultRotation)) {
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mPortraitRotation = Surface.ROTATION_90;
                mUpsideDownRotation = Surface.ROTATION_270;
            } else {
@@ -1011,8 +1015,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            longSize = height;
            mPortraitRotation = Surface.ROTATION_0;
            mUpsideDownRotation = Surface.ROTATION_180;
            if (mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_reverseDefaultRotation)) {
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mLandscapeRotation = Surface.ROTATION_270;
                mSeascapeRotation = Surface.ROTATION_90;
            } else {
@@ -1021,17 +1024,15 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.status_bar_height);
        mStatusBarHeight =
                res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);

        // Height of the navigation bar when presented horizontally at bottom
        mNavigationBarHeightForRotation[mPortraitRotation] =
        mNavigationBarHeightForRotation[mUpsideDownRotation] =
                mContext.getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.navigation_bar_height);
                res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
        mNavigationBarHeightForRotation[mLandscapeRotation] =
        mNavigationBarHeightForRotation[mSeascapeRotation] =
                mContext.getResources().getDimensionPixelSize(
        mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
                com.android.internal.R.dimen.navigation_bar_height_landscape);

        // Width of the navigation bar when presented vertically along one side
@@ -1039,17 +1040,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        mNavigationBarWidthForRotation[mUpsideDownRotation] =
        mNavigationBarWidthForRotation[mLandscapeRotation] =
        mNavigationBarWidthForRotation[mSeascapeRotation] =
                mContext.getResources().getDimensionPixelSize(
                        com.android.internal.R.dimen.navigation_bar_width);
                res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);

        // SystemUI (status bar) layout policy
        int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
        int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;

        // Allow the navigation bar to move on small devices (phones).
        mNavigationBarCanMove = shortSizeDp < 600;

        mHasNavigationBar = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_showNavigationBar);
        mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
        // Allow a system property to override this. Used by the emulator.
        // See also hasNavigationBar().
        String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
@@ -1075,6 +1075,20 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            mDemoHdmiRotation = mLandscapeRotation;
        }
        mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);

        // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
        // http://developer.android.com/guide/practices/screens_support.html#range
        mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
                res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
                // For debug purposes the next line turns this feature off with:
                // $ adb shell setprop config.override_forced_orient true
                // $ adb shell wm size reset
                !"true".equals(SystemProperties.get("config.override_forced_orient"));
    }

    @Override
    public boolean isDefaultOrientationForced() {
        return mForceDefaultOrientation;
    }

    @Override
@@ -1453,6 +1467,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    }

    /** {@inheritDoc} */
    @Override
    public int subWindowTypeToLayerLw(int type) {
        switch (type) {
        case TYPE_APPLICATION_PANEL:
@@ -1469,10 +1484,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return 0;
    }

    @Override
    public int getMaxWallpaperLayer() {
        return windowTypeToLayerLw(TYPE_STATUS_BAR);
    }

    @Override
    public int getAboveUniverseLayer() {
        return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
    }
@@ -4345,6 +4362,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        );
        }

        if (mForceDefaultOrientation) {
            return Surface.ROTATION_0;
        }

        synchronized (mLock) {
            int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
            if (sensorRotation < 0) {
+18 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.graphics.Matrix;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.util.Slog;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceSession;

@@ -62,6 +61,10 @@ public class BlackFrame {
                            "  BLACK " + surface + ": CREATE layer=" + layer);
        }

        void setAlpha(float alpha) {
            surface.setAlpha(alpha);
        }

        void setMatrix(Matrix matrix) {
            mTmpMatrix.setTranslate(left, top);
            mTmpMatrix.postConcat(matrix);
@@ -93,6 +96,8 @@ public class BlackFrame {
    final float[] mTmpFloats = new float[9];
    final BlackSurface[] mBlackSurfaces = new BlackSurface[4];

    final boolean mForceDefaultOrientation;

    public void printTo(String prefix, PrintWriter pw) {
        pw.print(prefix); pw.print("Outer: "); mOuterRect.printShortString(pw);
                pw.print(" / Inner: "); mInnerRect.printShortString(pw);
@@ -106,10 +111,12 @@ public class BlackFrame {
        }
    }

    public BlackFrame(SurfaceSession session, Rect outer, Rect inner,
            int layer, final int layerStack) throws SurfaceControl.OutOfResourcesException {
    public BlackFrame(SurfaceSession session, Rect outer, Rect inner, int layer, int layerStack,
            boolean forceDefaultOrientation) throws SurfaceControl.OutOfResourcesException {
        boolean success = false;

        mForceDefaultOrientation = forceDefaultOrientation;

        mOuterRect = new Rect(outer);
        mInnerRect = new Rect(inner);
        try {
@@ -162,6 +169,14 @@ public class BlackFrame {
        }
    }

    public void setAlpha(float alpha) {
        for (int i=0; i<mBlackSurfaces.length; i++) {
            if (mBlackSurfaces[i] != null) {
                mBlackSurfaces[i].setAlpha(alpha);
            }
        }
    }

    public void setMatrix(Matrix matrix) {
        for (int i=0; i<mBlackSurfaces.length; i++) {
            if (mBlackSurfaces[i] != null) {
Loading