Loading services/core/java/com/android/server/wm/ActivityStackSupervisor.java +11 −3 Original line number Original line Diff line number Diff line Loading @@ -789,7 +789,15 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return startHomeOnDisplay(mCurrentUser, myReason, displayId); return startHomeOnDisplay(mCurrentUser, myReason, displayId); } } boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId) { /** * Check if home activity start should be allowed on a display. * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched. * @param displayId The id of the target display. * @param allowInstrumenting Whether launching home should be allowed if being instrumented. * @return {@code true} if allow to launch, {@code false} otherwise. */ boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId, boolean allowInstrumenting) { if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL && mService.mTopAction == null) { && mService.mTopAction == null) { // We are running in factory test mode, but unable to find the factory test app, so // We are running in factory test mode, but unable to find the factory test app, so Loading @@ -799,7 +807,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D final WindowProcessController app = final WindowProcessController app = mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); if (app != null && app.isInstrumenting()) { if (!allowInstrumenting && app != null && app.isInstrumenting()) { // Don't do this if the home app is currently being instrumented. // Don't do this if the home app is currently being instrumented. return false; return false; } } Loading Loading @@ -4246,7 +4254,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return false; return false; } } if (!canStartHomeOnDisplay(aInfo, displayId)) { if (!canStartHomeOnDisplay(aInfo, displayId, false /* allowInstrumenting */)) { return false; return false; } } Loading services/core/java/com/android/server/wm/ActivityStarter.java +4 −4 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,7 @@ import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.INVALID_DISPLAY; import static com.android.server.am.EventLogTags.AM_NEW_INTENT; import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; Loading @@ -72,7 +73,6 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; import static com.android.server.am.EventLogTags.AM_NEW_INTENT; import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; Loading Loading @@ -114,9 +114,9 @@ import com.android.internal.app.HeavyWeightSwitcherActivity; import com.android.internal.app.IVoiceInteractor; import com.android.internal.app.IVoiceInteractor; import com.android.server.am.EventLogTags; import com.android.server.am.EventLogTags; import com.android.server.am.PendingIntentRecord; import com.android.server.am.PendingIntentRecord; import com.android.server.pm.InstantAppResolver; import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch; import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch; import com.android.server.wm.LaunchParamsController.LaunchParams; import com.android.server.wm.LaunchParamsController.LaunchParams; import com.android.server.pm.InstantAppResolver; import java.io.PrintWriter; import java.io.PrintWriter; import java.text.DateFormat; import java.text.DateFormat; Loading Loading @@ -1284,8 +1284,8 @@ class ActivityStarter { // Do not start home activity if it cannot be launched on preferred display. We are not // Do not start home activity if it cannot be launched on preferred display. We are not // doing this in ActivityStackSupervisor#canPlaceEntityOnDisplay because it might // doing this in ActivityStackSupervisor#canPlaceEntityOnDisplay because it might // fallback to launch on other displays. // fallback to launch on other displays. if (r.isActivityTypeHome() if (r.isActivityTypeHome() && !mSupervisor.canStartHomeOnDisplay(r.info, && !mSupervisor.canStartHomeOnDisplay(r.info, mPreferredDisplayId)) { mPreferredDisplayId, true /* allowInstrumenting */)) { Slog.w(TAG, "Cannot launch home on display " + mPreferredDisplayId); Slog.w(TAG, "Cannot launch home on display " + mPreferredDisplayId); return START_CANCELED; return START_CANCELED; } } Loading services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java +32 −4 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,12 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; import static android.view.Display.DEFAULT_DISPLAY; import static com.android.server.wm.ActivityDisplay.POSITION_TOP; import static com.android.server.wm.ActivityDisplay.POSITION_TOP; import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static com.android.server.wm.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; import static com.android.server.wm.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; Loading @@ -54,6 +54,8 @@ import static org.mockito.Mockito.verify; import android.app.ActivityOptions; import android.app.ActivityOptions; import android.app.WaitResult; import android.app.WaitResult; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.graphics.Rect; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit; Loading Loading @@ -436,7 +438,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { * Tests that home activities can be started on the displays that supports system decorations. * Tests that home activities can be started on the displays that supports system decorations. */ */ @Test @Test public void testStartHomeOnAllDisplays() throws Exception { public void testStartHomeOnAllDisplays() { // Create secondary displays. // Create secondary displays. final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay()); final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay()); mSupervisor.addChild(secondDisplay, POSITION_TOP); mSupervisor.addChild(secondDisplay, POSITION_TOP); Loading @@ -450,7 +452,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { .create(any(), anyInt(), any(), any(), any(), any()); .create(any(), anyInt(), any(), any(), any(), any()); doReturn(true).when(mService.mStackSupervisor) doReturn(true).when(mService.mStackSupervisor) .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean()); .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean()); doReturn(true).when(mSupervisor).canStartHomeOnDisplay(any(), anyInt()); doReturn(true).when(mSupervisor).canStartHomeOnDisplay(any(), anyInt(), anyBoolean()); mSupervisor.startHomeOnAllDisplays(0, "testStartHome"); mSupervisor.startHomeOnAllDisplays(0, "testStartHome"); Loading @@ -463,7 +465,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { * Tests that home activities won't be started before booting when display added. * Tests that home activities won't be started before booting when display added. */ */ @Test @Test public void testNotStartHomeBeforeBoot() throws Exception { public void testNotStartHomeBeforeBoot() { final int displayId = 1; final int displayId = 1; final boolean isBooting = mService.mAmInternal.isBooting(); final boolean isBooting = mService.mAmInternal.isBooting(); final boolean isBooted = mService.mAmInternal.isBooted(); final boolean isBooted = mService.mAmInternal.isBooted(); Loading @@ -477,4 +479,30 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { mService.mAmInternal.setBooted(isBooted); mService.mAmInternal.setBooted(isBooted); } } } } /** * Tests whether home can be started if being instrumented. */ @Test public void testCanStartHomeWhenInstrumented() { final ActivityInfo info = new ActivityInfo(); info.applicationInfo = new ApplicationInfo(); final WindowProcessController app = mock(WindowProcessController.class); doReturn(app).when(mService).getProcessController(any(), anyInt()); // Can not start home if we don't want to start home while home is being instrumented. doReturn(true).when(app).isInstrumenting(); assertFalse(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, false /* allowInstrumenting*/)); // Can start home for other cases. assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, true /* allowInstrumenting*/)); doReturn(false).when(app).isInstrumenting(); assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, false /* allowInstrumenting*/)); assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, true /* allowInstrumenting*/)); } } } Loading
services/core/java/com/android/server/wm/ActivityStackSupervisor.java +11 −3 Original line number Original line Diff line number Diff line Loading @@ -789,7 +789,15 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return startHomeOnDisplay(mCurrentUser, myReason, displayId); return startHomeOnDisplay(mCurrentUser, myReason, displayId); } } boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId) { /** * Check if home activity start should be allowed on a display. * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched. * @param displayId The id of the target display. * @param allowInstrumenting Whether launching home should be allowed if being instrumented. * @return {@code true} if allow to launch, {@code false} otherwise. */ boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId, boolean allowInstrumenting) { if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL && mService.mTopAction == null) { && mService.mTopAction == null) { // We are running in factory test mode, but unable to find the factory test app, so // We are running in factory test mode, but unable to find the factory test app, so Loading @@ -799,7 +807,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D final WindowProcessController app = final WindowProcessController app = mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); if (app != null && app.isInstrumenting()) { if (!allowInstrumenting && app != null && app.isInstrumenting()) { // Don't do this if the home app is currently being instrumented. // Don't do this if the home app is currently being instrumented. return false; return false; } } Loading Loading @@ -4246,7 +4254,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D return false; return false; } } if (!canStartHomeOnDisplay(aInfo, displayId)) { if (!canStartHomeOnDisplay(aInfo, displayId, false /* allowInstrumenting */)) { return false; return false; } } Loading
services/core/java/com/android/server/wm/ActivityStarter.java +4 −4 Original line number Original line Diff line number Diff line Loading @@ -53,6 +53,7 @@ import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.INVALID_DISPLAY; import static android.view.Display.INVALID_DISPLAY; import static com.android.server.am.EventLogTags.AM_NEW_INTENT; import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.DEFER_RESUME; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; import static com.android.server.wm.ActivityStackSupervisor.ON_TOP; Loading @@ -72,7 +73,6 @@ import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_ import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; import static com.android.server.am.EventLogTags.AM_NEW_INTENT; import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; Loading Loading @@ -114,9 +114,9 @@ import com.android.internal.app.HeavyWeightSwitcherActivity; import com.android.internal.app.IVoiceInteractor; import com.android.internal.app.IVoiceInteractor; import com.android.server.am.EventLogTags; import com.android.server.am.EventLogTags; import com.android.server.am.PendingIntentRecord; import com.android.server.am.PendingIntentRecord; import com.android.server.pm.InstantAppResolver; import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch; import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch; import com.android.server.wm.LaunchParamsController.LaunchParams; import com.android.server.wm.LaunchParamsController.LaunchParams; import com.android.server.pm.InstantAppResolver; import java.io.PrintWriter; import java.io.PrintWriter; import java.text.DateFormat; import java.text.DateFormat; Loading Loading @@ -1284,8 +1284,8 @@ class ActivityStarter { // Do not start home activity if it cannot be launched on preferred display. We are not // Do not start home activity if it cannot be launched on preferred display. We are not // doing this in ActivityStackSupervisor#canPlaceEntityOnDisplay because it might // doing this in ActivityStackSupervisor#canPlaceEntityOnDisplay because it might // fallback to launch on other displays. // fallback to launch on other displays. if (r.isActivityTypeHome() if (r.isActivityTypeHome() && !mSupervisor.canStartHomeOnDisplay(r.info, && !mSupervisor.canStartHomeOnDisplay(r.info, mPreferredDisplayId)) { mPreferredDisplayId, true /* allowInstrumenting */)) { Slog.w(TAG, "Cannot launch home on display " + mPreferredDisplayId); Slog.w(TAG, "Cannot launch home on display " + mPreferredDisplayId); return START_CANCELED; return START_CANCELED; } } Loading
services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java +32 −4 Original line number Original line Diff line number Diff line Loading @@ -25,12 +25,12 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; import static android.view.Display.DEFAULT_DISPLAY; import static com.android.server.wm.ActivityDisplay.POSITION_TOP; import static com.android.server.wm.ActivityDisplay.POSITION_TOP; import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_DESTROYING; import static com.android.server.wm.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; import static com.android.server.wm.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; Loading @@ -54,6 +54,8 @@ import static org.mockito.Mockito.verify; import android.app.ActivityOptions; import android.app.ActivityOptions; import android.app.WaitResult; import android.app.WaitResult; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.graphics.Rect; import android.graphics.Rect; import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit; Loading Loading @@ -436,7 +438,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { * Tests that home activities can be started on the displays that supports system decorations. * Tests that home activities can be started on the displays that supports system decorations. */ */ @Test @Test public void testStartHomeOnAllDisplays() throws Exception { public void testStartHomeOnAllDisplays() { // Create secondary displays. // Create secondary displays. final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay()); final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay()); mSupervisor.addChild(secondDisplay, POSITION_TOP); mSupervisor.addChild(secondDisplay, POSITION_TOP); Loading @@ -450,7 +452,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { .create(any(), anyInt(), any(), any(), any(), any()); .create(any(), anyInt(), any(), any(), any(), any()); doReturn(true).when(mService.mStackSupervisor) doReturn(true).when(mService.mStackSupervisor) .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean()); .ensureVisibilityAndConfig(any(), anyInt(), anyBoolean(), anyBoolean()); doReturn(true).when(mSupervisor).canStartHomeOnDisplay(any(), anyInt()); doReturn(true).when(mSupervisor).canStartHomeOnDisplay(any(), anyInt(), anyBoolean()); mSupervisor.startHomeOnAllDisplays(0, "testStartHome"); mSupervisor.startHomeOnAllDisplays(0, "testStartHome"); Loading @@ -463,7 +465,7 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { * Tests that home activities won't be started before booting when display added. * Tests that home activities won't be started before booting when display added. */ */ @Test @Test public void testNotStartHomeBeforeBoot() throws Exception { public void testNotStartHomeBeforeBoot() { final int displayId = 1; final int displayId = 1; final boolean isBooting = mService.mAmInternal.isBooting(); final boolean isBooting = mService.mAmInternal.isBooting(); final boolean isBooted = mService.mAmInternal.isBooted(); final boolean isBooted = mService.mAmInternal.isBooted(); Loading @@ -477,4 +479,30 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { mService.mAmInternal.setBooted(isBooted); mService.mAmInternal.setBooted(isBooted); } } } } /** * Tests whether home can be started if being instrumented. */ @Test public void testCanStartHomeWhenInstrumented() { final ActivityInfo info = new ActivityInfo(); info.applicationInfo = new ApplicationInfo(); final WindowProcessController app = mock(WindowProcessController.class); doReturn(app).when(mService).getProcessController(any(), anyInt()); // Can not start home if we don't want to start home while home is being instrumented. doReturn(true).when(app).isInstrumenting(); assertFalse(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, false /* allowInstrumenting*/)); // Can start home for other cases. assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, true /* allowInstrumenting*/)); doReturn(false).when(app).isInstrumenting(); assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, false /* allowInstrumenting*/)); assertTrue(mSupervisor.canStartHomeOnDisplay(info, DEFAULT_DISPLAY, true /* allowInstrumenting*/)); } } }