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

Commit 25e0c530 authored by Massimo Carli's avatar Massimo Carli
Browse files

Handle tranlucent strategy on back

The first opaque activity beneath a transparent one must not be
a finishing activity.
This prevents a wrong behaviour in case of permission requests
launched from activities after the user presses back.

Bug: 261721427
Test:  Test on apps that automatically display permission dialog
       when returning from a full screen (e.g. App Info screen)
       Run `atest SizeCompatTests`

Change-Id: I04fb0f30087fad137ee6733889bcb32498b2e898
parent 7ef14c02
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -3906,6 +3906,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        }
    }
    }


    boolean isFinishing() {
        return finishing;
    }

    /**
    /**
     * This method is to only be called from the client via binder when the activity is destroyed
     * This method is to only be called from the client via binder when the activity is destroyed
     * AND finished.
     * AND finished.
+6 −1
Original line number Original line Diff line number Diff line
@@ -105,6 +105,7 @@ import com.android.server.wm.LetterboxConfiguration.LetterboxBackgroundType;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.function.BooleanSupplier;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;


/** Controls behaviour of the letterbox UI for {@link mActivityRecord}. */
/** Controls behaviour of the letterbox UI for {@link mActivityRecord}. */
// TODO(b/185262487): Improve test coverage of this class. Parts of it are tested in
// TODO(b/185262487): Improve test coverage of this class. Parts of it are tested in
@@ -114,6 +115,9 @@ import java.util.function.BooleanSupplier;
// TODO(b/263021211): Consider renaming to more generic CompatUIController.
// TODO(b/263021211): Consider renaming to more generic CompatUIController.
final class LetterboxUiController {
final class LetterboxUiController {


    private static final Predicate<ActivityRecord> FIRST_OPAQUE_NOT_FINISHING_ACTIVITY_PREDICATE =
            activityRecord -> activityRecord.fillsParent() && !activityRecord.isFinishing();

    private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxUiController" : TAG_ATM;
    private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxUiController" : TAG_ATM;


    private static final float UNDEFINED_ASPECT_RATIO = 0f;
    private static final float UNDEFINED_ASPECT_RATIO = 0f;
@@ -1390,7 +1394,8 @@ final class LetterboxUiController {
            return;
            return;
        }
        }
        final ActivityRecord firstOpaqueActivityBeneath = mActivityRecord.getTask().getActivity(
        final ActivityRecord firstOpaqueActivityBeneath = mActivityRecord.getTask().getActivity(
                ActivityRecord::fillsParent, mActivityRecord, false /* includeBoundary */,
                FIRST_OPAQUE_NOT_FINISHING_ACTIVITY_PREDICATE /* callback */,
                mActivityRecord /* boundary */, false /* includeBoundary */,
                true /* traverseTopToBottom */);
                true /* traverseTopToBottom */);
        if (firstOpaqueActivityBeneath == null) {
        if (firstOpaqueActivityBeneath == null) {
            // We skip letterboxing if the translucent activity doesn't have any opaque
            // We skip letterboxing if the translucent activity doesn't have any opaque
+16 −0
Original line number Original line Diff line number Diff line
@@ -254,6 +254,22 @@ public class SizeCompatTests extends WindowTestsBase {
        assertFalse(translucentActivity.inSizeCompatMode());
        assertFalse(translucentActivity.inSizeCompatMode());
    }
    }


    @Test
    public void testCheckOpaqueIsLetterboxedWhenStrategyIsApplied() {
        mWm.mLetterboxConfiguration.setTranslucentLetterboxingOverrideEnabled(true);
        setUpDisplaySizeWithApp(2000, 1000);
        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setLaunchedFromUid(mActivity.getUid())
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        spyOn(mActivity);
        mTask.addChild(translucentActivity);
        verify(mActivity).isFinishing();
    }

    @Test
    @Test
    public void testRestartProcessIfVisible() {
    public void testRestartProcessIfVisible() {
        setUpDisplaySizeWithApp(1000, 2500);
        setUpDisplaySizeWithApp(1000, 2500);