diff options
| author | 2017-09-19 23:32:17 +0000 | |
|---|---|---|
| committer | 2017-09-19 23:32:17 +0000 | |
| commit | dbb33c058b13cca8b4ba916bac9a4bd08d0ddcc4 (patch) | |
| tree | 1fdaefc79993886d8b7db4efb10583b7d75d481f | |
| parent | 667fb12d376812777c8eb55cea9c8d8c4164b47a (diff) | |
| parent | 1c2a6921c090d801d4991f16f31dbb85ef35dce5 (diff) | |
Merge "Consider task's root activity when determining if resizable." into oc-mr1-dev
am: 1c2a6921c0
Change-Id: I06e858733e21220b6008bd55c2d4119bc51cd2cd
3 files changed, 72 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 5b27c9c2c1f7..b2bbf199bfc1 100644 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -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); } /** diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java index 2252c85dddf2..e51f7a99a55f 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityRecordTests.java @@ -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); + } } diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java index a6c0cf17bd05..04ddae9313ef 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityTestsBase.java @@ -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) { |