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

Commit dbb33c05 authored by Bryce Lee's avatar Bryce Lee Committed by android-build-merger
Browse files

Merge "Consider task's root activity when determining if resizable." into oc-mr1-dev

am: 1c2a6921

Change-Id: I06e858733e21220b6008bd55c2d4119bc51cd2cd
parents 667fb12d 1c2a6921
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1176,8 +1176,15 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
     *         can be put a secondary screen.
     */
    boolean canBeLaunchedOnDisplay(int displayId) {
        final TaskRecord task = getTask();

        // The resizeability of an Activity's parent task takes precendence over the ActivityInfo.
        // This allows for a non resizable activity to be launched into a resizeable task.
        final boolean resizeable =
                task != null ? task.isResizeable() : supportsResizeableMultiWindow();

        return service.mStackSupervisor.canPlaceEntityOnDisplay(displayId,
                supportsResizeableMultiWindow(), launchedFromPid, launchedFromUid, info);
                resizeable, launchedFromPid, launchedFromUid, info);
    }

    /**
+47 −0
Original line number Diff line number Diff line
@@ -20,15 +20,19 @@ import static android.view.WindowManagerPolicy.NAV_BAR_BOTTOM;
import static android.view.WindowManagerPolicy.NAV_BAR_LEFT;
import static android.view.WindowManagerPolicy.NAV_BAR_RIGHT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

import android.content.ComponentName;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;

import android.view.Display;
import org.junit.runner.RunWith;
import org.junit.Test;

@@ -46,6 +50,8 @@ public class ActivityRecordTests extends ActivityTestsBase {

    private final ComponentName testActivityComponent =
            ComponentName.unflattenFromString("com.foo/.BarActivity");
    private final ComponentName secondaryActivityComponent =
            ComponentName.unflattenFromString("com.foo/.BarActivity2");
    @Test
    public void testStackCleanupOnClearingTask() throws Exception {
        final ActivityManagerService service = createActivityManagerService();
@@ -131,4 +137,45 @@ public class ActivityRecordTests extends ActivityTestsBase {
        record.ensureActivityConfigurationLocked(0 /* globalChanges */, false /* preserveWindow */);
        assertEquals(expectedActivityBounds, record.getBounds());
    }


    @Test
    public void testCanBeLaunchedOnDisplay() throws Exception {
        testSupportsLaunchingResizeable(false /*taskPresent*/, true /*taskResizeable*/,
                true /*activityResizeable*/, true /*expected*/);

        testSupportsLaunchingResizeable(false /*taskPresent*/, true /*taskResizeable*/,
                false /*activityResizeable*/, false /*expected*/);

        testSupportsLaunchingResizeable(true /*taskPresent*/, false /*taskResizeable*/,
                true /*activityResizeable*/, false /*expected*/);

        testSupportsLaunchingResizeable(true /*taskPresent*/, true /*taskResizeable*/,
                false /*activityResizeable*/, true /*expected*/);
    }

    private void testSupportsLaunchingResizeable(boolean taskPresent, boolean taskResizeable,
            boolean activityResizeable, boolean expected) {
        final ActivityManagerService service = createActivityManagerService();
        service.mSupportsMultiWindow = true;


        final TaskRecord task = taskPresent
                ? createTask(service, testActivityComponent, TEST_STACK_ID) : null;

        if (task != null) {
            task.setResizeMode(taskResizeable ? ActivityInfo.RESIZE_MODE_RESIZEABLE
                    : ActivityInfo.RESIZE_MODE_UNRESIZEABLE);
        }

        final ActivityRecord record = createActivity(service, secondaryActivityComponent,
                task);
        record.info.resizeMode = activityResizeable ? ActivityInfo.RESIZE_MODE_RESIZEABLE
                : ActivityInfo.RESIZE_MODE_UNRESIZEABLE;

        record.canBeLaunchedOnDisplay(Display.DEFAULT_DISPLAY);

        assertEquals(((TestActivityStackSupervisor) service.mStackSupervisor)
                .getLastResizeableFromCanPlaceEntityOnDisplay(), expected);
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ public class ActivityTestsBase {
     */
    protected static class TestActivityStackSupervisor extends ActivityStackSupervisor {
        private final ActivityDisplay mDisplay;
        private boolean mLastResizeable;

        public TestActivityStackSupervisor(ActivityManagerService service, Looper looper) {
            super(service, looper);
@@ -170,6 +171,22 @@ public class ActivityTestsBase {
            mDisplay = new ActivityDisplay();
        }

        // TODO: Use Mockito spy instead. Currently not possible due to TestActivityStackSupervisor
        // access to ActivityDisplay
        @Override
        boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable, int callingPid,
                int callingUid, ActivityInfo activityInfo) {
            mLastResizeable = resizeable;
            return super.canPlaceEntityOnDisplay(displayId, resizeable, callingPid, callingUid,
                    activityInfo);
        }

        // TODO: remove and use Mockito verify once {@link #canPlaceEntityOnDisplay} override is
        // removed.
        public boolean getLastResizeableFromCanPlaceEntityOnDisplay() {
            return mLastResizeable;
        }

        // No home stack is set.
        @Override
        void moveHomeStackToFront(String reason) {