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

Commit b79685e9 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Invoke the occluding callback only if the activity is occluded

Originally the callback is always called for non-top activities.
That may cause the starting window to be removed at unexpected
timing when calling cancelInitializingActivities.

Fixes: 156712576
Test: atest ActivityStackTests#testCheckBehindFullscreenActivity

Change-Id: I7797c6a295260b52e75d8f47aa8ba26c598697bf
parent fc48f7e5
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -382,6 +382,7 @@ class ActivityStack extends Task {
            return mBehindFullscreenActivity;
        }

        /** Returns {@code true} to stop the outer loop and indicate the result is computed. */
        private boolean processActivity(ActivityRecord r, ActivityRecord topActivity) {
            if (mAboveTop) {
                if (r == topActivity) {
@@ -397,7 +398,10 @@ class ActivityStack extends Task {
            }

            if (mHandlingOccluded) {
                // Iterating through all occluded activities.
                if (mBehindFullscreenActivity) {
                    mHandleBehindFullscreenActivity.accept(r);
                }
            } else if (r == mToCheck) {
                return true;
            } else if (mBehindFullscreenActivity) {
+14 −0
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.function.Consumer;

/**
 * Tests for the {@link ActivityStack} class.
 *
@@ -1327,6 +1330,8 @@ public class ActivityStackTests extends ActivityTestsBase {

    @Test
    public void testCheckBehindFullscreenActivity() {
        final ArrayList<ActivityRecord> occludedActivities = new ArrayList<>();
        final Consumer<ActivityRecord> handleBehindFullscreenActivity = occludedActivities::add;
        final ActivityRecord bottomActivity =
                new ActivityBuilder(mService).setStack(mStack).setTask(mTask).build();
        final ActivityRecord topActivity =
@@ -1337,12 +1342,21 @@ public class ActivityStackTests extends ActivityTestsBase {
        assertFalse(mStack.checkBehindFullscreenActivity(topActivity,
                null /* handleBehindFullscreenActivity */));

        // Top activity occludes bottom activity.
        mStack.checkBehindFullscreenActivity(null /* toCheck */, handleBehindFullscreenActivity);
        assertThat(occludedActivities).containsExactly(bottomActivity);

        doReturn(false).when(topActivity).occludesParent();
        assertFalse(mStack.checkBehindFullscreenActivity(bottomActivity,
                null /* handleBehindFullscreenActivity */));
        assertFalse(mStack.checkBehindFullscreenActivity(topActivity,
                null /* handleBehindFullscreenActivity */));

        occludedActivities.clear();
        // Top activity doesn't occlude parent, so the bottom activity is not occluded.
        mStack.checkBehindFullscreenActivity(null /* toCheck */, handleBehindFullscreenActivity);
        assertThat(occludedActivities).isEmpty();

        final ActivityRecord finishingActivity =
                new ActivityBuilder(mService).setStack(mStack).setTask(mTask).build();
        finishingActivity.finishing = true;