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

Commit 5e770ac4 authored by Winson Chung's avatar Winson Chung
Browse files

Ignore exception when checking isRotationLocked()

- RotationPolicy (a fw helper class) uses the current user to resolve
  the system setting for whether rotation is currently locked.  However,
  Launcher uses this class and does not hold the INTERACT_ACROSS_USERS
  permission, which means that immediately following a user switch, there
  is a brief window between ActivityManager setting the current user
  and Launcher being notified that the user is changing (so it can
  unregister the rotation watcher).  In this brief window, the Launcher
  for the outgoing user receiving a rotation signal will try to call
  this check and fail with a SecurityException.

  Longer term, we should refactor this to support a non-current user
  path for Launcher.

Bug: 279561841
Test: Manual

Change-Id: I7ce869d8388081af53751226b22f018d45ec2de8
parent c8b8fcef
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -283,12 +283,28 @@ public class RotationButtonController {
    }

    public void setRotationLockedAtAngle(int rotationSuggestion, String caller) {
        RotationPolicy.setRotationLockAtAngle(mContext, /* enabled= */ isRotationLocked(),
        final Boolean isLocked = isRotationLocked();
        if (isLocked == null) {
            // Ignore if we can't read the setting for the current user
            return;
        }
        RotationPolicy.setRotationLockAtAngle(mContext, /* enabled= */ isLocked,
                /* rotation= */ rotationSuggestion, caller);
    }

    public boolean isRotationLocked() {
    /**
     * @return whether rotation is currently locked, or <code>null</code> if the setting couldn't
     *         be read
     */
    public Boolean isRotationLocked() {
        try {
            return RotationPolicy.isRotationLocked(mContext);
        } catch (SecurityException e) {
            // TODO(b/279561841): RotationPolicy uses the current user to resolve the setting which
            //                    may change before the rotation watcher can be unregistered
            Log.e(TAG, "Failed to get isRotationLocked", e);
            return null;
        }
    }

    public void setRotateSuggestionButtonState(boolean visible) {
@@ -462,7 +478,11 @@ public class RotationButtonController {

        // If the screen rotation changes while locked, potentially update lock to flow with
        // new screen rotation and hide any showing suggestions.
        boolean rotationLocked = isRotationLocked();
        Boolean rotationLocked = isRotationLocked();
        if (rotationLocked == null) {
            // Ignore if we can't read the setting for the current user
            return;
        }
        // The isVisible check makes the rotation button disappear when we are not locked
        // (e.g. for tabletop auto-rotate).
        if (rotationLocked || mRotationButton.isVisible()) {