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

Commit 48f75dbb authored by Steve Elliott's avatar Steve Elliott
Browse files

Restrict rotation when global actions panel is enabled

Once the orientation changes to portrait, the panel will be displayed,
and the orientation will be locked to portrait.

If, when global actions is launched and a panel is available, the user
has their orientation locked to non-portrait, then their orientation
is unlocked, so that they may rotate to portrait in order to see the
panel.

In all cases, the user's orientation setting is restored once global
actions is dismissed.

Bug: 129343749

Test: unlock orientation, launch global actions in portrait, notice
      that orientation is locked, dismiss global actions, notice that
      orientation is unlocked

Test: unlock orientation, launch global actions in non-portrait,
      rotate to portrait, notice that orientation is now locked,
      dismiss global actions, notice that orientation is unlocked

Test: lock phone orientation to non-portrait, launch global actions,
      rotate to portrait, notice that orientation is locked, dismiss
      global actions, notice that orientation has reset and is locked

Change-Id: I3972929aede075de69ea5333dcaf445e6ace59b8
parent 2a51ad3b
Loading
Loading
Loading
Loading
+62 −21
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import com.android.internal.telephony.TelephonyProperties;
import com.android.internal.util.EmergencyAffordanceManager;
import com.android.internal.util.ScreenRecordHelper;
import com.android.internal.util.ScreenshotHelper;
import com.android.internal.view.RotationPolicy;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
@@ -1498,6 +1499,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        private boolean mKeyguardShowing;
        private boolean mShowing;
        private float mScrimAlpha;
        private ResetOrientationData mResetOrientationData;

        ActionsDialog(Context context, MyAdapter adapter,
                GlobalActionsPanelPlugin.PanelViewController plugin) {
@@ -1531,16 +1533,38 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
        }

        private boolean shouldUsePanel() {
            if (!isPanelEnabled(mContext) || mPanelController == null) {
                return false;
            return isPanelEnabled(mContext)
                    && mPanelController != null
                    && mPanelController.getPanelContent() != null;
        }
            if (mPanelController.getPanelContent() == null) {
                return false;

        private void initializePanel() {
            int rotation = RotationUtils.getRotation(mContext);
            boolean rotationLocked = RotationPolicy.isRotationLocked(mContext);
            if (rotation != RotationUtils.ROTATION_NONE) {
                if (rotationLocked) {
                    if (mResetOrientationData == null) {
                        mResetOrientationData = new ResetOrientationData();
                        mResetOrientationData.locked = true;
                        mResetOrientationData.rotation = rotation;
                    }
            return true;

                    // Unlock rotation, so user can choose to rotate to portrait to see the panel.
                    RotationPolicy.setRotationLockAtAngle(
                            mContext, false, RotationUtils.ROTATION_NONE);
                }
            } else {
                if (!rotationLocked) {
                    if (mResetOrientationData == null) {
                        mResetOrientationData = new ResetOrientationData();
                        mResetOrientationData.locked = false;
                    }

                    // Lock to portrait, so the user doesn't accidentally hide the panel.
                    RotationPolicy.setRotationLockAtAngle(
                            mContext, true, RotationUtils.ROTATION_NONE);
                }

        private void initializePanel() {
                FrameLayout panelContainer = new FrameLayout(mContext);
                FrameLayout.LayoutParams panelParams =
                        new FrameLayout.LayoutParams(
@@ -1553,6 +1577,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                                ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT));
            }
        }

        private void initializeLayout() {
            setContentView(getGlobalActionsLayoutId(mContext));
@@ -1683,19 +1708,30 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                        mBackgroundDrawable.setAlpha(alpha);
                    })
                    .start();
            if (mPanelController != null) {
                mPanelController.onDismissed();
            }
            dismissPanel();
            resetOrientation();
        }

        void dismissImmediately() {
            super.dismiss();
            mShowing = false;
            dismissPanel();
            resetOrientation();
        }

        private void dismissPanel() {
            if (mPanelController != null) {
                mPanelController.onDismissed();
            }
        }

        private void resetOrientation() {
            if (mResetOrientationData != null) {
                RotationPolicy.setRotationLockAtAngle(mContext, mResetOrientationData.locked,
                        mResetOrientationData.rotation);
            }
        }

        @Override
        public void onColorsChanged(ColorExtractor extractor, int which) {
            if (mKeyguardShowing) {
@@ -1725,6 +1761,11 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                refreshDialog();
            }
        }

        private static class ResetOrientationData {
            public boolean locked;
            public int rotation;
        }
    }

    /**