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

Commit 95f71022 authored by Massimo Carli's avatar Massimo Carli
Browse files

[2/n] Send Transition when setRequestOrientation()

When setRequestOrientation is invoked we generate a Transition to notify that the activity
might be letterboxed. This happens if ActivityRcord#handlesOrientationChangeFromDescendant()
return false which means that no parent will be interested in the orientation change and so
the normal transition won't be triggered. In case handlesOrientationChangeFromDescendant()
returns true, the Transition won't be triggered because the one related to the rotation
will be generated.

Flag: com.android.window.flags.enable_transition_on_activity_set_requested_orientation
Bug: 409043134
Test: PreSubmit

Change-Id: I57fbebe596bc87fbe0b80a500a37349848369661
parent 8f2f30e7
Loading
Loading
Loading
Loading
+49 −3
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ import com.android.server.utils.quota.Categorizer;
import com.android.server.utils.quota.Category;
import com.android.server.utils.quota.CountQuotaTracker;
import com.android.server.vr.VrManagerInternal;
import com.android.window.flags.Flags;

/**
 * Server side implementation for the client activity to interact with system.
@@ -130,7 +131,8 @@ class ActivityClientController extends IActivityClientController.Stub {
    private final Context mContext;

    // Prevent malicious app abusing the Activity#setPictureInPictureParams API
    @VisibleForTesting CountQuotaTracker mSetPipAspectRatioQuotaTracker;
    @VisibleForTesting
    CountQuotaTracker mSetPipAspectRatioQuotaTracker;
    // Limit to 60 times / minute
    private static final int SET_PIP_ASPECT_RATIO_LIMIT = 60;
    // The timeWindowMs here can not be smaller than QuotaTracker#MIN_WINDOW_SIZE_MS
@@ -867,6 +869,15 @@ class ActivityClientController extends IActivityClientController.Stub {

    @Override
    public void setRequestedOrientation(IBinder token, int requestedOrientation) {
        if (Flags.enableTransitionOnActivitySetRequestedOrientation()) {
            setRequestedOrientationWithTransition(token, requestedOrientation);
        } else {
            setRequestedOrientationLegacy(token, requestedOrientation);
        }
    }

    // TODO(b/375339716): Clean up and remove legacy code.
    private void setRequestedOrientationLegacy(IBinder token, int requestedOrientation) {
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
@@ -882,6 +893,41 @@ class ActivityClientController extends IActivityClientController.Stub {
        }
    }

    private void setRequestedOrientationWithTransition(IBinder token, int requestedOrientation) {
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                final ActivityRecord r = ActivityRecord.isInRootTaskLocked(token);
                if (r == null) {
                    return;
                }
                // A new Transition need to be started in case the orientation update
                // won't make the Display to rotate.
                Transition transition = null;
                final int orientation = r.getRequestedConfigurationOrientation(false,
                        requestedOrientation);
                if (!r.handlesOrientationChangeFromDescendant(orientation)) {
                    transition = r.mTransitionController.isShellTransitionsEnabled()
                            && !r.mTransitionController.isCollecting()
                            ? r.mTransitionController.createTransition(TRANSIT_CHANGE) : null;
                }

                r.mTransitionController.collect(r);

                r.setRequestedOrientation(requestedOrientation);

                if (transition != null) {
                    r.mTransitionController.requestStartTransition(transition,
                            null /*startTask */, null /* remoteTransition */,
                            null /* displayChange */);
                    r.mTransitionController.setReady(r.getDisplayContent());
                }
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    @Override
    public int getRequestedOrientation(IBinder token) {
        synchronized (mGlobalLock) {